程序设计技术总复习.docx
- 文档编号:30208207
- 上传时间:2023-08-07
- 格式:DOCX
- 页数:28
- 大小:25.60KB
程序设计技术总复习.docx
《程序设计技术总复习.docx》由会员分享,可在线阅读,更多相关《程序设计技术总复习.docx(28页珍藏版)》请在冰豆网上搜索。
程序设计技术总复习
“程序设计技术”总复习
一、SimpleChoiceQuestions((每题2分,16题共32分)
1.Whichofthefollowingfunctiondeclarationsareillegal?
a.voidt1(intx,inty=0,intz);
b.voidt4(intx=0,inty=0,intz=0);
c.voidt2(intx=0,inty=0,intz);
d.voidt3(intx,inty=0,intz=0);
e.aandc
Key:
e
#
2.Whatistheprintoutofthefollowingcode?
#include
usingnamespacestd;
voidf(int&p1,intp2)
{
p1++;
p2++;
}
intmain()
{
intx1=1;
intx2=1;
f(x1,x2);
cout<<"x1is"< } a.x1is2x2is2 b.x1is1x2is2 c.x1is1x2is1 d.x1is2x2is1 Key: d # 3.Thefollowingprograminvokesp()threetimes.Whatistheprintoutfromthelastcallofp()? #include usingnamespacestd; intj=40; voidp() { inti=5; staticintj=5; i++; j++; cout<<"iis"< } intmain() { p(); p(); p(); } a.iis6jis6 b.iis6jis7 c.iis6jis9 d.iis6jis8 Key: d # 4.Whatistheoutputofthefollowingcode? #include usingnamespacestd; voidf(double&p) { p+=2; } intmain() { doublex=1; doubley=1; f(x); f(y); cout<<"xis"< cout<<"yis"< return0; } a.xis1yis2 b.xis2yis1 c.xis1yis1 d.xis2yis2 e.xis3yis3 Key: e # 5.Analyzethefollowingcode: voidf(intx[],intlength) { for(inti=0;i cout<<""< } intmain() { intx[]={0,1,2,3,4,5}; f(x,5); } a.Theprogramdisplays012345. b.Theprogramdisplays01234andthenraisesaruntimeexception. c.Theprogramdisplays01234. d.Theprogramdisplays012345andthenraisesaruntimeexception. Key: c # 6.Showtheprintoutofthefollowingcode charcity[7]="Dallas"; cout< a.7 b.6 c.5 d.8 Key: b # 7.Analyzethefollowingcode. intmain() { intx[3]; cout<<"x[0]is"< } a.x[0]hasanarbitraryvalue. b.Theprogramhasacompileerrorbecausethesizeofthearraywasn'tspecifiedwhendeclaringthearray. c.Theprogramrunsfineanddisplaysx[0]is0. d.Theprogramhasaruntimeerrorbecausethearrayelementsarenotinitialized. e.Theprogramhasaruntimeerrorbecausethearrayelementx[0]isnotdefined. Key: a # 8.Showtheoutputofthefollowingcode: #include usingnamespacestd; classA { public: intx; inty; intz; A(): x (1),y (2),z(3) { } }; intmain() { Aa; cout< return0; } a.333 b.222 c.123 d.111 e.112 Key: c # 9.Whatiswronginthefollowingcode? #include usingnamespacestd; classTempClass { public: inti; TempClass() { inti=5; } }; intmain() { TempClasstemp (2); } a.Theprogramcompilesfine,butitdoesnotrunbecauseclassCisnotpublic. b.TheprogramhasacompilationerrorbecauseTempClassdoesnothaveadefaultconstructor. c.Theprogramcompilesandrunsfine. d.TheprogramhasacompilationerrorbecauseTempClassdoesnothaveaconstructorwithanintargument. Key: d # 10.Analyzethefollowingcode. #include usingnamespacestd; classTest { public: intx; Test() { cout<<"Test"; } }; intmain() { Testtest; cout< } a.TheprogramhasacompileerrorbecauseTestdoesnothaveadefaultconstructor. b.Theprogramhasacompileerrorbecausexhasnotbeeninitialized. c.Theprogramhasacompileerrorbecausetestisnotinitialized. d.Theprogramrunsfine,buttest.xisunpredictable. Key: d # 11.Whatistheoutputofthefollowingcode? #include usingnamespacestd; classFoo { public: intx;//datafield inty;//datafield Foo() { x=10; y=10; } voidp() { intx=20;//localvariable cout<<"xis"< cout<<"yis"< } }; intmain() { Foofoo; foo.p(); return0; } a.xis20yis10 b.xis10yis20 c.xis20yis20 d.xis10yis10 Key: a # 12.Whatistheoutputofthefollowingcode? strings("abc"); s.append("welcome",3); cout< a.welcomeabc b.abcwel c.abc d.abcwelcome Key: b # 13.Whatistheoutputofthefollowingcode? strings("abcdefg"); s.insert(1,3,'w'); cout< a.abcdefg b.aweldefg c.awelbcdefg d.awwwbcdefg Key: d # 14.Whatistheprintoutofthefollowingcode? #include usingnamespacestd; classCount { public: intcount; Count(intc) { count=c; } Count() { count=0; } }; voidincrement(Countc,int×) { c.count++; times++; } intmain() { CountmyCount; inttimes=0; for(inti=0;i<100;i++) increment(myCount,times); cout<<"myCount.countis"< cout<<"timesis"< return0; } a.myCount.countis100timesis0 b.myCount.countis100timesis100 c.myCount.countis0timesis0 d.myCount.countis0timesis100 Key: d # 15.Supposeyoudeclareanarraydoublelist[]={1,3.4,5.5,3.5}andcompilerstoresitinthememorystartingwithaddress04BFA810.Assumeadoublevaluetakeseightbytesonacomputer.&list[1]is______. a.04BFA818 b.04BFA810 c.3.4 d.1 Key: a # 16.Supposeyoudeclareanarraydoublelist[]={1,3.4,5.5,3.5}.&list[1]issameas________. a.list+2 b.list[0] c.list[1] d.list e.list+1 Key: e # 17.Analyzethefollowingcode. #include usingnamespacestd; intmain() { char*p; cout<<"Enterastring: "; cin>>p; cout< return0; } a.Ifyouruntheprogramandenterabc,unpredictablecharacterswillbedisplayed. b.Ifyouruntheprogramandenterabc,abcwillbedisplayed. c.Ifyouruntheprogramandenterabc,nothingwillbedisplayed.Theprogramrunswithouterrors. d.Ifyouruntheprogramandenterabc,aruntimeerrorwilloccur,becausepisusedwithoutbeinginitialized. Key: d # 18.Whatistheoutputofthefollowingcode? #include usingnamespacestd; intmain() { intlist[]={10,20,30,40}; cout<<*(list+1)<<""<<*list+1< return0; } a.1010 b.2011 c.3030 d.2020 Key: b # 19.Whatiswronginthefollowingcode? #include #include usingnamespacestd; intmain() { vector cout< return0; } a.Theprogramhasacompileerroronv[0]. b.Theprogramhasacompileerroronvector c.Theprogramhasaruntimeerroronvector d.Theprogramhasaruntimeerroronv[0],becausethevectorisempty. Key: d # 20.Ifyoudefinetheswapfunctionasfollows: template voidswap(T&var1,T&var2) { Ttemp=var1; var1=var2; var2=temp; } Youcaninvokeswapusing______. a.intv1=1;intv2=2;swap(v1,v2); b.swap(1,2) c.intv1=1;intv2=2;swap(&v1,&v2); d.intv1=1;doublev2=2;swap(v1,v2); Key: a # 21.Toaddanintvalue5toavectorvofintegers,use_________. a.v.insert(5); b.v.add(5); c.v.append(5); d.v.push_back(5); Key: d # 22.Supposeyoudeclareintvalue=99,towriteittoabinaryfile,use________. a.binaryio.write(reinterpret_cast b.binaryio.write(reinterpret_cast c.binaryio.write(value); d.binaryio.write(reinterpret_cast e.binaryio.write(reinterpret_cast Key: e # 23.Whatdothefollowingstatementsdo? ifstreamstream; stream.open("scores.txt"); a.Openafileforoutput,thestatementfailsifthefilealreadyexists. b.Openafileforoutput,thecontentsofthefileisdestroyedifthefilealreadyexists. c.Openafileforinput. d.Openafileforinput,thestatementfailsifthefiledoesnotexist. Key: c # 24.Whichofthefollowingisanabstractfunction? a.virtualdoublegetArea()=0; b.virtualdoublegetArea(); c.doublegetArea(); d.doublegetArea()=0; Key: a # 25.Whatistheprintoutofthefollowingcode? #include usingnamespacestd; classC { public: virtualstringtoString() { return"C"; } }; classB: publicC { stringtoString() { return"B"; } }; classA: publicB { stringtoString() { return"A"; } }; voiddisplayObject(Cp) { cout< } intmain() { displayObject(A()); displayObject(B()); displayObject(C()); return0; } a.BBB b.CCC c.ABC d.CBA e.AAA Key: b # 26.Supposethatstatement3throwsanexceptionoftypeException3inthefollowingstatement: try{ statement1; statement2; statement3; } catch(Exception1ex1) { } catch(Exception2ex2) { } catch(Exception3ex3) { Statement4; throw; } statement5; Whichstatementsareexecutedafterstatement3isexecuted? a.statement1 b.statement4 c.statement5 d.statement2 e.statement3 Key: b # 27.Whatiswronginthefollowingcode? vector v[0]=2.5; a.Theprogramhasacompileerrorbecausetherearenoelementsinthevector. b.Theprogramhasaruntimeerrorbecausetherearenoelementsinthevector. c.Theprogramhasaruntimeerrorbecauseyoucannotassignadoublevaluetov[0]. d.Theprogramhasacompileerrorbecauseyoucannotassignadoublevaluetov[0]. Key: b # 28.Tocreateamapwithintkeytypeandstringvalue,use_______. a.map b.map c.map d.map Key: c # 29.Toobtainaniteratorthatpointstothenextelementafterthelaste
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 程序设计 技术 复习