电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

C++程序设计教程课后习题答案[钱能]清华版

C++程序设计教程课后习题答案[钱能]清华版_第1页
C++程序设计教程课后习题答案[钱能]清华版_第2页
C++程序设计教程课后习题答案[钱能]清华版_第3页
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) 该程序计算三角形的面积 前后分为三部分:输入,处理,输出。 2.7 In 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... 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=1 a2=1 (2) 1.1 (3) 2,0.0 (4) 20 5.4 Main--x=5,y=1,n=1 Func--x=6,y=21,n=11 Main--x=5,y=1,n=11 Func--x=8,y=31,n=21 5.6 double poly(int n, double) { if(n==0) return 1; if(n==0) return x; return ((2*n-1)*x*poly(n-1,x)-(n-1)*poly(n-2,x))/n; } 6.1 //6_1 (1) //file1.cpp int x=1; int func() { //... } //file2.cpp extern int x; int func(); void g() { x=func(); } //file3.cpp extern int x=2; //error: extern int 变量若有赋值,则成定义 int g(); //error: 函数声明与前面不一致 void main() { x=g(); //... } (2) //file1.cpp int x=5; int y=8; extern int z; //file2.cpp int x; //error: int x;重复定义 extern double y; //error: y 同一名字不同类型定义 extern int z; //error: z 只有声明,却无定义 6.2 25 10.4 //10_4 (1) 见 10_4_1.cpp (2) data? 3 data? 5 data? 7 data? 6 data? 4 data? 8 data? -3 3 5 7 6 4 8 (3) 见 10_4_3 12.1 Constructing normally. Constructing with a number: 20 Display a number: 1 Display a number: 20 Destructing. Destru cting. 12.2 //12_2 //见employ ee.h // employ ee.cpp 12.3 //12_3.tx t //见employ .h // employ .cpp //13_1.tx t 物质 有机物 生物 动物 哺乳动物 人类 猿类 猫科类 ... 卵生动物 植物 非生物 无机物 //13_2 Ignore //14_1 Mu lti[0] is:0 Mu lti[1] is:1 Mu lti[2] is:4 Mu lti[3] is:9 Mu lti[4] is:16 Mu lti[5] is:25 Mu lti[6] is:36 Mu lti[7] is:49 Mu lti[8] is:64 Mu lti[9] is:81 Destroy ing..9 Destroy ing..8 Destroying..7 Destroying..6 Destroying..5 Destroying..4 Destroying..3 Destroying..2 Destroying..1 Destroying..0 //14_2 //运行结果为: 1 2 3 4 5 6 7 8 9 10 //增加拷贝构造函数后的运行结果为: 0 1 4 9 16 25 36 49 64 81 //14_3 //运行结果为: create a X object with 1 create a X object with 2 //创建临时对象 call a func with para X object create a X object from other X object erase a object //析构临时对象 create a X object from other X object call a func with para X object create a X object from other X object erase a object erase a object erase a object erase a object 17.1 class A{ public: int GetpA(){ return pA; } void SetpA(int a){ pA=a; } private: int pA; }; class B :public A{ public: void OnB(){} }; class C :virtual public A, virtual public B{ public: Sc(){ /*use GetpA() and SetpA()... */ } }; 19.5 Dill Arnson 8869533 139****1080 Welch Shammas 6695482 130****9001 Portel Braumbel 5937221 139****2991

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

小辰+ 关注
实名认证
内容提供者

出售各种文档和资料

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部