资源描述:
《C++语言基础教程 教学课件 作者 吕凤翥习题答案 1_ 第9章.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第9章习题解答9.1判断题对的有2,4,7,8,13,15,16,199.2单选题CCABDADBCD9.3填空题1.A*constp;2.Aconst*p;3.Aa[5];4.A*pa[5];5.A*p;p=newA(5);6.Aa1,*pa;pa=newA[3];7.staticAsa;8.Aa1;a1=A(8);9.4程序结果1.Defaultconstructorcalled.0Defaultconstructorcalled.0Defaultconstructorcalled.0Defaultconstructorcalled.0Destructorcalled
2、.2Destructorcalled.3Destructorcalled.4Destructorcalled.52345Destructorcalled.5Destructorcalled.4Destructorcalled.3Destructorcalled.22.1234Destructorcalled.1Destructorcalled.2Destructorcalled.3Destructorcalled.43.Defaultconstructorcalled.Defaultconstructorcalled.Defaultconstructorcalled.De
3、faultconstructorcalled.6Destructorcalled.1Destructorcalled.2Destructorcalled.3Destructorcalled.41234Destructorcalled.4Destructorcalled.3Destructorcalled.2Destructorcalled.11.Constructcalled.d1=5,d2=7Constructcalled.d1=3,d2=6Constructcalled.d1=7,d2=9Constructcalled.d1=1,d2=4Destructorcalle
4、d.d1=13,d2=23Destructorcalled.d1=12,d2=22Destructorcalled.d1=11,d2=21Destructorcalled.d1=10,d2=202.Constructorcalled.e1=5,e2=6Constructorcalled.e1=3,e2=4InFunE(E*e).e1=3,e2=4InFunE(E&e).e1=3,e2=43.1059.5编程题1.#includeconstintMax=50;classStack{public:Stack(){Top=-1;}voidPush(con
5、stinta);intPop();intPeek(){if(Top==-1)return0;returnList[Top];6}boolIsEmpty(){if(Top==0)returntrue;elsereturnfalse;}boolIsPull(){if(Top==Max-1)returntrue;elsereturnfalse;}private:intList[Max];intTop;};voidStack::Push(constinta){if(Top==Max-1)return;Top++;List[Top]=a;}intStack::Pop(){intel
6、ement;if(Top==-1)return0;element=List[Top];Top--;returnelement;}voidmain(){intn=1;StackS[2];for(inti=0;i<5;i++)S[0].Push(n++);for(i=0;i<4;i++)S[1].Push(10+n++);cout<
7、ut<#includeclassStudent{public:Student(chars[],intn){strcpy(name,s);score=n;}friendvoidMaxScore(Student*);private:charname[20];intscore;};voidMaxScore(Student*s)