C++程序设计教程(修订版)——设计思想与实现习题解答钱能.docx

上传人:公**** 文档编号:562954886 上传时间:2022-11-27 格式:DOCX 页数:80 大小:60.59KB
返回 下载 相关 举报
C++程序设计教程(修订版)——设计思想与实现习题解答钱能.docx_第1页
第1页 / 共80页
C++程序设计教程(修订版)——设计思想与实现习题解答钱能.docx_第2页
第2页 / 共80页
C++程序设计教程(修订版)——设计思想与实现习题解答钱能.docx_第3页
第3页 / 共80页
C++程序设计教程(修订版)——设计思想与实现习题解答钱能.docx_第4页
第4页 / 共80页
C++程序设计教程(修订版)——设计思想与实现习题解答钱能.docx_第5页
第5页 / 共80页
点击查看更多>>
资源描述

《C++程序设计教程(修订版)——设计思想与实现习题解答钱能.docx》由会员分享,可在线阅读,更多相关《C++程序设计教程(修订版)——设计思想与实现习题解答钱能.docx(80页珍藏版)》请在金锄头文库上搜索。

1、二 2.1 #include void main() /本题原考虑在 16 位机器上实验目前多为 32 位机器故已过时。 int a = 42486; cout oct a endl hex a endl; unsigned b = 42486; cout dec (signed)b endl; 2.2 #include #include const double pi = 3.1415926; void main() double radius1, radius2; cout radius1 radius2; cout setw(10) pi setw(10) radius1 setw(10

2、) (pi*radius1*radius1) endl setw(10) pi setw(10) radius2 setw(10) (pi*radius2*radius2) endl; 2.3 #include #include const double e = 2.718281828; void main() cout setprecision(10) e endl setiosflags(ios:fixed) setprecision(8) e endl setiosflags(ios:scientific) e endl; 2.4 #include void main() cout Ho

3、w many students here?n 500n; 2.5 #include void main() cout size of char sizeof(char) byten size of unsigned char sizeof(unsigned char) byten size of signed char sizeof(signed char) byten size of int sizeof(int) byten size of unsigned sizeof(unsigned) byten size of signed sizeof(signed) byten size of

4、 short sizeof(short) byten size of unsigned short sizeof(unsigned short) byten size of long sizeof(long) byten size of signed long sizeof(signed long) byten size of unsigned long sizeof(unsigned long) byten size of float sizeof(float) byten size of double sizeof(double) byten size of long double siz

5、eof(long double) byten; 2.6 1) please input 3 sides of one triangle: 6,6,8 a= 6.00,b= 6.00,c= 8.00 area of triangle is 17.88854 2) 该程序计算三角形的面积前后分为三部分输入处理输出。 3) /#include #include #include #include void main() float a,b,c,s,area; /printf(please input 3 sides of one triangle:n); cout a b c; /输入时以空格作为数

6、据间隔 s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c); /printf(a=%7.2f,b=%7.2f,c=%7.2fn,a,b,c); cout setiosflags(ios:fixed) setprecision(2) a= setw(7) a ,b= setw(7) b ,c= setw(7) c endl; /printf(area of triangle is %10.5f,area); cout area of triangle is setw(10) setprecision(5) area endl; 4) #include #incl

7、ude #include float area(float a, float b, float c); /函数声明 void main() float a,b,c; cout a b c; /输入时以空格作为数据间隔 float result = area(a,b,c); /函数调用 cout setiosflags(ios:fixed) setprecision(2) a= setw(7) a ,b= setw(7) b ,c= setw(7) c endl; cout area of triangle is setw(10) setprecision(5) result endl; flo

8、at area(float a, float b, float c) /函数定义 float s=(a+b+c)/2; return sqrt(s*(s-a)*(s-b)*(s-c); 2.7In main(): Enter two numbers: 3 8 Calling add(): In add(),received 3 and 8 and return 11 Back in main(): c was set to 11 Exiting. 2.8 #include #include double Cylinder(double r, double h); void main() dou

9、ble radius, height; cout radius height; double volume = Cylinder(radius, height); cout 该圆柱体的体积为 volume endl; double Cylinder(double r, double h) return r*r*M_PI*h; 三 3.1 (1) sqrt(pow(sin(x),2.5) (2) (a*x+(a+x)/(4*a)/2 (3) pow(c,x*x)/sqrt(2*M_PI) /M_PI 为 BC 中 math.h 中的圆周率常数 3.2 13.7 2.5 9 3.3 (1) a1=

10、1 a2=1 (2) 1.1 (3) 2,0.0 (4) 20 3.4 #include void main() int x; cout x; if(x=-1) cout (x-1) -1 & x=2) cout 2*x endl; if(2x & x=10) cout x*(x+2); 3.5 #include void main() int a; cout a; int c1 = a%3 =0; int c2 = a%5 =0; int c3 = a%7 =0; switch(c12)+(c21)+c3) case 0: cout 不能被 3,5,7 整除.n; break; case 1: cout 只能被 7 整除.n; break; case 2: cout 只能被 5 整除.n; break; case 3: cout 可以被 5,7 整除.n; break; case 4: cout 只能被 3 整除.n; break; case 5: cout 可以被 3,7 整除.n; break; case 6: cout 可以被 3,5 整除.n; break; case 7: cout

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号