欢迎来到天天文库
浏览记录
ID:32936912
大小:39.50 KB
页数:9页
时间:2019-02-17
《继承与多态性习题参考答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C++程序设计语言习题及实验指导第8章继承与多态性习题参考答案8.3习题8.3.1选择题题号12345678910答案CDADABCBDD题号11121314151617181920答案DDACBCCCAC8.3.2填空题1.(1)a、b、c、x、y、z(2)b、y(3)c、z(4)a、x(5)b、c、x、y、z(6)b、y(7)y(8)b、c、z(9)a、x(10)b、c、x、y、z(11)y(12)y(13)z(14)a、b、c、x(15)b、c、x、y、z(16)y2.私有3.抽象4.虚基5.(1)基类(2)对象6.(1)静态(2)编译(3)虚函数7.(1)21(2)058.
2、(1)10020030030(2)10100(3)202009.(1)510(2)end.(3)201010.(1)classAclassB(2)end.(3)~classB~classA11.(1)10(2)buildB(3)buildC(4)releaseA12.(1)classB(2)classC(3)classD(4)513.(1)55(2)202014.(1)10(2)102015.(1)1(2)3(3)5(4)1001016.(1)B::f()(2)B::fun()(3)A::f()(4)B::fun()17.(1)姓名陈涛年薪6.8万元。(2)姓名李原(3)姓名李原月
3、工资4000元18.(1)110(2)222019.(1)protected或public(2)Base1(s1),Base2(s2)或Base2(s2),Base1(s1)(3)Base1::str(4)test.print()20.(1)virtualvoidshow()=0(2)C(int,int,int)(注:参数可有任一名称)(3)b1(y)(4)&t8.3.3编程题1.求长方形的面积和长方体的表面积、体积#includeclassRectangle{protected:floatL;//长方形的长floatW;//长方形的宽9/9floatare
4、a;//长方形的面积public:Rectangle(floatL1,floatW1){L=L1;W=W1;}voidfunction(){area=L*W;}voidshow(){cout<<"长为"<5、;}voidfun(){volume=L*W*H;}voidshow(){cout<<"长为"<#includeclassCircle{protected:doubleradius;d6、oublearea;public:Circle(doubler){radius=r;}};classTable{9/9protected:doubleheight;public:Table(doubleh){height=h;}};classRoundtable:publicTable,publicCircle{char*color;public:Roundtable(doubleh,doubler,charc[]):Circle(r),Table(h){color=newchar[strlen(c)+1];strcpy(color,c);}voidfun(){area=3.14*7、radius*radius;}voidshow(){cout<<"高度:"<#i
5、;}voidfun(){volume=L*W*H;}voidshow(){cout<<"长为"<#includeclassCircle{protected:doubleradius;d
6、oublearea;public:Circle(doubler){radius=r;}};classTable{9/9protected:doubleheight;public:Table(doubleh){height=h;}};classRoundtable:publicTable,publicCircle{char*color;public:Roundtable(doubleh,doubler,charc[]):Circle(r),Table(h){color=newchar[strlen(c)+1];strcpy(color,c);}voidfun(){area=3.14*
7、radius*radius;}voidshow(){cout<<"高度:"<#i
此文档下载收益归作者所有