青岛理工大学C++考试真题

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

I.Judgment.(Therightansweris“T”,thewrongoneis“F”.Eachjudgmentis2points,total20points.)Number12345678910T/F1.Bothconstructoranddestructorofbaseclasscanbeinheritedbyderivedclass.2.Staticdatamemberissharedbyallobjectsofthisclass.3.Constructorscanbedeclaredasvirtualfunction.4.Whenoverloadinganoperator,atleastoneargumentoftheresultingoverloadedoperatormustbeofaclasstype.5.Constructorshavenoreturntype.6.Afriendfunctionisnotamemberoftheclass,butitcanaccesstheprivatemembersofthatclass.7.Wecanonlylisttypesofformalparametersinfunctiondeclarations.8.Thereareloopstatementscanbewroteintheinlinefunction.9.Theassignmentoperatorcanonlybeoverloadedintoamemberfunction.10.InC++,STLisastandardfunctiontemplatelibrary.II.Fillintheblank.(Eachblankis1point,total:10points)1.Thedefaultaccesslabelforclassis___________.2.Theconstructorandthedestructormusthavethesameastheclass,.3.Thememberfunctionsofderivedclassescangetaccessto___membersand__membersofabaseclass,donotgetaccesstoprivatemembersofabaseclass.4.InC++,aclasswithapurevirtualfunctioniscalledan_______.5.SupposewehaveaclassnamedasDc,whensuchcodelike“Dca[5],b(2),*p;”isimplemented,thesystemwillauto-calltheconstructorofclassDcfor_______times.6.Statement___________cancatchallkindsofexceptions.7.InC++,inadditionto“.”,“*”,“sizeof”,theoperator________and_______arealsocan’tbeoverload.8.Classistreamisusedtosupportinputoperation,andclass_______isusedtosupportoutputoperation.III.SingleChoice(Eachchoiceis2point,total:10points)1.()Usuallycopyconstructor’sparameterisA)thenameofsomeobjectB)thereferenceofsomeobjectC)membernameofsomeobjectD)thepointerofsomeobject2.()Whichiswrongaboutconstructor?A)Thecompilermaysupplydefaultconstructor.B)Constructorscanhaveparameters,andreturnedvalue.C)Constructorscanbeoverloaded.D)Constructorscanhavedefaultparametervalue.3.()Whichiswrongaboutfriend?A)Thekeywordfriendisusedtodeclarethefriend.B)Thememberfunctionofoneclasscanbethefriendofanotherclass.C)Thefriendfunctionscanaccessanyspecifiedaccesslabelmember.D)Thefriendfunctionsaccessthememberofsomeobjectbythispointer.4.()Thepurposeofvirtualbaseclassis.A)toeliminate(消除)ambiguityB)tomakeaprogramsimpleC)toincreasetherunefficiencyD)toreducetheobjectcodes5.()Whichisrightaboutthestaticdatamember?A)Thestaticdatamembercannotbecalledbytheobjectname.B)Thestaticdatamembercanbeinitializedintheconstructors.C)Thestaticdatamemberbelongstoacertainclass.D)Thestaticdatamembermustnotbeinitializedinthefilescope.Ⅳ.Pointouttheerrorthefollowingprogrammingandexplainthereason(writeouterrorlinenumber,total:10points)1.constsize=10;//L1inta[size];//L22.classPoint{public:Point(){c=0;x=-1;}//L3Point(Pointpobj);//L4Point(Point&p);//L5private:intx;//L6constintc;//L7};3.#includeiostreamusingnamespacestd;classExample{public:Example(inti){m=i;}//L8voidExample(){m=0;}//L9voidshow(){coutm;}//L10private:intm;//L11};intmain(){Exampleex1;//L12Exampleex2(5);//L13ex2.m+=10;//L14Example.show();//L15return0;}4.intx=9,*x_ptr=&x;//L16inty=78;//L174.intx=9,*x_ptr=&x;//L16inty=78;//L17*x_ptr=&y;//L18*x_ptr=&y;//L185.#includeiostreamusingnamespacestd;classBC{public:voidset_x(inta){x=a;}//L19protected:intget_x()const{returnx;}//L20private:intx;};classDC:publicBC{public:voidadd2()//L21{intc=get_x();set_x(c+2);}//L22voidadd3(){x+=3;}//L23};intmain(){DCd;d.set_x(3);//L24coutd.get_x()endl;//L25d.x=77;//L26d.add2();//L27return0;}Number/LineReasonNumber/LineReason1/6/2/7/3/8/4/9/5/10/Ⅴ.Writeouttheresultsofthefollowingprograms.(Eachsubjectis5points;total:30points)1.#includeiostreamusingnamespacestd;charstr[20]=HelloC++world.;char&rep(intk){returnstr[k];}intmain(){rep(15)='!';coutThestringis:strendl;return0;}2.#includeiostream#includeiomanipusingnamespacestd;intmain(){doublevalues[]={1.23,35.36,657.6,778.2};char*names[]={Zoot,Jimmy,A1,Stan};for(inti=0;i4;i++)coutleftsetw(6)names[i]rightsetw(6)fixedsetprecision(1)values[i]endl;return0;}3.#includeiostreamconstdoublePI=3.14;usingnamespacestd;classFigure{public:Figure(){};virtualdoublearea()const{return0.0;}};classCircle:publicFigure{public:Circle(doublemyr){R=myr;}doublearea()const{returnPI*R*R;}protected:doubleR;};classRectangle:publicFigure{public:Rectangle(doublemyl,doublemyw){L=myl;W=myw;}doublearea()const{returnL*W;}private:doubleL,W;};voidfunc(Figure&p){coutp.area()endl;}intmain(){Figurefig;coutAreaofFigureis;func(fig);Circlec(3.0);cout“Areaofcircleis”;func(c);Rectanglerec(4.0,5.0);coutAreaofrectangleis;func(rec);return0;}4.#includefstream#includeiostreamusingnamespacestd;intmain(){cout“Openingdata.txtforappending.”endl;ofstreamfout;fout.open(“data.txt”,ios::app);if(fout.fail()){cout“Inputfileopeningfailed.”endl;exit(1);}fout“HelloC++world!”endl“Thisisanappendingprogram.”endl;fout.close();cout“Endofappendingtofile.”endl;return0;}Supposethatthereisthecontent:“Thisisatestprogram!”inthedata.txt.whentheprogramexecutes,whatcontentwillexistinthedata.txt?5.#includeiostreamusingnamespacestd;classBase1{public:Base1(inti){a=i;coutconstructingBase1a=

1 / 21
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功