资源描述:
《C++语言基础教程 教学课件 作者 吕凤翥习题答案 1_ 第8章.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第8章习题解答8.1判断题对的有4,6,7,9,11,13,15,16,18,20,21,23,24,25.268.2单选题CDADCACCBC8.3填空题1.publicprivateprotected2.私有公有3.默认默认4.类<类名>::5.类体非所有6.friendAA8.4程序结果1.Defaultconstructorcalled.Constructorcalled.a1=0,a2=0a1=5,a2=8Destructorcalled.Destructorcalled.2.11121
2、3131312113.2005/10/12005/12/94.c1=12,c2=185.1{}{1,2,3,4,5}10{1,2,3,4,5,6,7,8,9,10}8.5编程题1.#includeclassRectangle{public:Rectangle(inti,intj)4{width=i;length=j;}doublePerimenter(){return2*(width+length);}doubleAear(){returnwidth*length;}voi
3、dChangeSize(intx,inty){width=x;length=y;}voidPrint(){cout<<"width="<4、cout<<"Aear:"<5、ndl;cout<<"Aear:"<classCalculator{public:Calculator(doublei,doublej){x=i;y=j;}doubleAdd(){returnx+y;}doubleSub(){returnx-y;}doubleMul(){returnx*y;}doubleDiv()4{returnx/y;}voidPrint(){cout<<"x="<6、="<>d1>>d2;Calculatorc(d1,d2);c.Print();cout<classStudent{public
7、:Student(charn[],inti){name=n;score=i;totalScore+=score;count++;}staticintTotalScore(){returntotalScore;}staticdoubleAverage(){return(double)totalScore/count;}voidPrint(){cout<<"nmae="<8、icinttotalScore,count;};intStudent::totalScore=0;intStudent::count=0;4voidmain(){Students1("Ma",98),s2("Lu",90),s3("Hu",88),s4("li",85),s5("Gao",85);s2.Print();s5.Print();cout<<"TotalScore="<