chapter56e 函数.docx

上传人:b****3 文档编号:10556189 上传时间:2023-05-26 格式:DOCX 页数:16 大小:18.04KB
下载 相关 举报
chapter56e 函数.docx_第1页
第1页 / 共16页
chapter56e 函数.docx_第2页
第2页 / 共16页
chapter56e 函数.docx_第3页
第3页 / 共16页
chapter56e 函数.docx_第4页
第4页 / 共16页
chapter56e 函数.docx_第5页
第5页 / 共16页
chapter56e 函数.docx_第6页
第6页 / 共16页
chapter56e 函数.docx_第7页
第7页 / 共16页
chapter56e 函数.docx_第8页
第8页 / 共16页
chapter56e 函数.docx_第9页
第9页 / 共16页
chapter56e 函数.docx_第10页
第10页 / 共16页
chapter56e 函数.docx_第11页
第11页 / 共16页
chapter56e 函数.docx_第12页
第12页 / 共16页
chapter56e 函数.docx_第13页
第13页 / 共16页
chapter56e 函数.docx_第14页
第14页 / 共16页
chapter56e 函数.docx_第15页
第15页 / 共16页
chapter56e 函数.docx_第16页
第16页 / 共16页
亲,该文档总共16页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

chapter56e 函数.docx

《chapter56e 函数.docx》由会员分享,可在线阅读,更多相关《chapter56e 函数.docx(16页珍藏版)》请在冰点文库上搜索。

chapter56e 函数.docx

chapter56e函数

TRUE/FALSE

1.Avoidfunctioncanreturnanyvalue

ANSWER:

FALSE

2.Avoidfunctioncanbeusedinanassignment.

ANSWER:

FALSE

3.Avoidfunctionmaynotbeusedinanoutputstatement.

ANSWER:

TRUE

4.Functionscanreturnatmostonevalue.

ANSWER:

TRUE

5.Thefollowingislegalinavoidfunction

return;

ANSWER:

TRUE

6.Inafunctionwithcall-by-referenceparameters,thevaluesoftheactualargumentsarepassedtothefunction.

ANSWER:

FALSE,Theactualvariables(ormorepreciselytheirmemoryaddresses)arepassed.

7.Inafunctionwithcall-by-referenceparameters,anychangestotheformalparameterswillchangetheactualargumentspassedtothefunction.

ANSWER:

TRUE

8.Itisacceptabletohavebothcall-by-valueandcall-by-referenceparametersinthesamefunctiondeclaration.

ANSWER:

True

9.Itisillegaltocallotherfunctionsfrominsideafunctiondefinition.

ANSWER:

FALSE

10.Astubisafunctionthatiscompletelydefinedandwelltested

ANSWER:

FALSE

SHORTANSWER

1.A___________isamainprogramthatonlychecksthatfunctionsexecutecorrectly.

ANSWER:

driver

2.Thevaluesorvariableslistedinthefunctiondeclarationarecalled_________tothefunction.

ANSWER:

(formal)parameters

3.Giventhefollowingfunctiondefinitionfragment,forwhichvaluesofmyIntshouldthefunctionbetested?

intdoSomething(intmyInt)

{

if(myInt<0)

{

//dosomestuffhere

}

}

ANSWER:

-1,0,1

4.Whentheaddressoftheactualargumentispassedtotheformalparameter,thisiscalled__________________________

ANSWER:

call-by-reference–or-pass-by-reference

5.Ifwewanttotestifagivenfunctionworkscorrectly,wewouldwritea_________totestit.

ANSWER:

driver

6.Thevariablespassedafunctionarecalled_________.

ANSWER:

arguments

7.Whatisthecorrectwaytocallthefollowingfunction?

_________________________

voidsetDisplay();

ANSWER:

setDisplay();

8.Afunctionthatdoesnotreturnavalueisknownasa________function.

ANSWER:

void

9.Whattypeofvaluedoesavoidfunctionreturn?

____________

ANSWER:

nothing

10.Whatsymbolisusedtosignifythataparameterisareferenceparameter?

______

ANSWER:

ampersand(&)

11.Whatisthecorrectwaytocallthefollowingfunction?

AssumethatyouhavetwovariablesnamedintArgument(int)andfloatArgument(float).

voiddoThings(floatx,inty);

ANSWER:

doThings(floatArgument,intArgument);

12.Usingfunctionsinaprogramiscalled_____________.

ANSWER:

proceduralabstraction

13.preandpostconditionsforafunctionshouldbewritten(before/after)thefunctiondefinitioniswritten.

ANSWER:

before

14.A________isasimplifiedversionofafunctionusedtotestthemainprogram.

ANSWER:

stub

15.Testingaprogramwithvaluesthatareclosetovaluesthatwillchangetheexecutionofaprogramiscalled_________________.

ANSWER:

boundarytesting

MULTIPLECHOICE

1.WhichofthefollowingisalegalcalltothedisplayOutputfunction?

voiddisplayOutput(inttotal);

a.voiddisplayOutput(myTotal);

b.displayOutput(intmytotal);

c.displayOutput(myTotal);

d.cout<

ANSWER:

C

2.Theprecondition(s)forafunctiondescribe:

a.Whatistrueafterthefunctionisexecuted

b.Whatthefunctiondoes

c.Howtocallthefunction

d.Whatmustbetruebeforethefunctionexecutes

ANSWER:

D

3.Whichofthefollowingistrueforavoidfunction?

a.Therecannotbeareturnstatement.

b.Thevalueofvoidshouldbereturned.

c.Thevalueof0shouldbereturned.

d.Nothingisreturned.

ANSWER:

D

4.Call-by-referenceparametersarepassed

a.nothing

b.theactualargument.

c.thevalueintheactualargument.

d.theaddressoftheargument.

ANSWER:

B(我觉得B和D都对啊。

)?

5.Ifyouneedafunctiontogetboththenumberofitemsandthecostperitemfromauser,whichwouldbeagoodfunctiondeclarationtouse?

a.int,floatgetData();

b.intgetData(floatcost);

c.voidgetData(intcount,floatcost);

d.voidgetData(int&count,float&cost);

ANSWER:

D

6.Whatistheoutputofthefollowingfunctionandfunctioncall?

voidcalculateCost(intcount,float&subTotal,float&taxCost);

floattax=0.0,

subTotal=0.0;

calculateCost(15,subTotal,tax);

cout<<"Thecostfor15itemsis"<

<<",andthetaxfor"<

//endoffragment

voidcalculateCost(intcount,float&subTotal,float&taxCost)

{

if(count<10)

{

subTotal=count*0.50;

}

else

{

subTotal=count*0.20;

}

taxCost=0.1*subTotal;

}

a.Thecostfor15itemsis3.00,andthetaxfor3.00is0.30;

b.Thecostfor15itemsis0.00,andthetaxfor3.00is0.00;

c.Thecostfor15itemsis0.00,andthetaxfor3.00is0.30;

d.Thecostfor15itemsis3.00,andthetaxfor3.00is0.00;

ANSWER:

A

7.Whatistheoutputofthefollowingfunctionandfunctioncall?

voidcalculateCost(intcount,float&subTotal,floattaxCost);

floattax=0.0,

subtotal=0.0;

calculateCost(15,subtotal,tax);

cout<<"Thecostfor15itemsis"<

<<",andthetaxfor"<

//endoffragment

voidcalculateCost(intcount,float&subTotal,floattaxCost)

{

if(count<10)

{

subTotal=count*0.50;

}

else

{

subTotal=count*0.20;

}

taxCost=0.1*subTotal;

}

a.Thecostfor15itemsis3.00,andthetaxfor3.00is0.30;

b.Thecostfor15itemsis0.00,andthetaxfor3.00is0.00;

c.Thecostfor15itemsis0.00,andthetaxfor3.00is0.30;

d.Thecostfor15itemsis3.00,andthetaxfor3.00is0.00;

ANSWER:

D

8.Whichofthefollowingfunctionprototypesarenotvalid?

a.voiddoSomething(int&x,inty);

b.voiddoSomething(int&x,int&y);

c.voiddoSomething(intx,inty);

d.allarenotvalid

e.allarevalid

ANSWER:

E

9.Youshouldmakeaparameterareferenceparameterif:

a.Youneedthefunctiontochangethevalueoftheargumentpassedtothefunction.

b.youneedtobeabletochangethevalueoftheparameterinthefunction,butnotthevalueoftheargument.

c.Always.

d.Ifanyoftheotherparametersarereferenceparameters.

ANSWER:

A

10.Whichofthefollowingaretrue?

a.afunctioncancallanotherfunction.

b.aslongasthefunctionisdefinedanywhereinyourprogram,itcanbeusedanywhereelse.

c.afunctiondefinitioncancontainanotherfunctiondefinition.

d.ifyouhavefunctionprototypes,theorderinwhichyoudefineyourfunctionsisimportant.

ANSWER:

A

11.Thepostconditionofafunction

a.determineshowthefunctionwillcompleteitsjob.

b.tellswhatmustbetruebeforethefunctionexecutes.

c.declaresthefunctionforthecompiler.

d.tellswhatwillbetrueafterthefunctionexecutes.

ANSWER:

D

12.Whatisthevalueofchoiceafterthefollowingstatements?

voidgetChoice(int&par_choice,inpar_count);

intchoice,count=3;

getChoice(choice,count);

voidgetChoice(int&par_choice,inpar_count)

{

if(par_count<0)

par_choice=0;

if(par_count=0)

par_choice=-1;

else

par_choice=99;

return;

}

a.3

b.0

c.–1

d.99

ANSWER:

D

13.Whatiswrongwiththefollowingfunctionbody?

voidcalculate(intcount,floatprice,float&cost)

{

if(count<0)

cost=0.0;

else

cost=count*price;

return;

}

a.voidfunctionsmaynothaveareturnstatement.

b.voidfunctionsmustreturnavalue

c.nothing

d.cannotmixreferenceandvalueparameters

ANSWER:

C

14.Ifyouweretowriteafunctionfordisplayingthecostofanitemtothescreen,whichfunctionprototypewouldbemostappropriate?

a.voiddisplay();

b.voiddisplay(floatmyCost);

c.intdisplay(floatmyCost);

d.floatdisplay();

ANSWER:

B

15.Giventhefunctiondefinition

voidsomething(inta,int&b)

{

intc;

c=a+2;

a=a*3;

b=c+a;

}

whatistheoutputofthefollowingcodefragmentthatinvokessomething?

(Allvariablesareoftypeint.)

r=1;

s=2;

t=3;

something(t,s);

cout<

a.1143

b.1103

c.5143

d.1149

e.noneoftheabove

ANSWER:

A

16.Giventhefollowingfunctiondeclarationandlocalvariabledeclarations,whichofthefollowingisnotacorrectfunctioncall?

intmyInt;

floatmyFloat;

charch;

voidsomeFunction(int&first,floatsecond,charthird);

a.someFunction(1,2.0,ch);

b.someFunction(myInt,myFloat,ch);

c.someFunction(myInt,2.0,'c');

d.someFunction(myInt,myFloat,'1');

ANSWER:

A

17.Giventhefollowingfunctiondefinition

voidshift(int&a,int&b)

{

a=b;

b=a;

}

Whatistheoutputafterthefollowingfunctioncall?

intfirst=0,second=10;

shift(first,second);

cout<

a.010

b.100

c.00

d.1010

ANSWER:

D

18.Whatistheoutputofthefollowingcodefragments?

inttrial(int&a,intb)

{

if(b>a)

{

a=b;

return–a;

}

else

{

return0;

}

}

floatx=0,y=10,z;

z=trial(y,x);

cout<

a.–1000

b.0100

c.1000

d.0010

ANSWER:

D

19.Whenavoidfunctioniscalled,itisknownas

a.Anoutputfunction.

b.Areturnedvalue.

c.Anexecutablestatement.

d.Acomment

ANSWER:

C

20.Ifafunctionneedstomodifymorethanonevariable,itmust

a.bepassbyvalue

b.beavoidfunction

c.returnallvaluesneeded

d.beacallbyreferencefunction

ANSWER:

D

21.Inthefollowingfunction,whatispassedtothefirstparameter?

voidf1(int&value1,intvalue2);

intx,y;

f1(x,y);

a.Thevalueofx

b.nothing,itisavoidfunction

c.thevalueofy

d.thevariablex(oritsmemorylocation)

ANSWER:

D

22.Giventhefollowingfunctiondefinitionsandprogramfragments,whatistheoutput?

voidf1(int&z,int&q)

{

inttemp;

temp=q;

q=z;

z=temp;

}

voidf2(int&a,int&b)

{

if(a<

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2