用C++解决问题第十版Chapter 10.docx

上传人:b****4 文档编号:4114445 上传时间:2022-11-28 格式:DOCX 页数:14 大小:18.05KB
下载 相关 举报
用C++解决问题第十版Chapter 10.docx_第1页
第1页 / 共14页
用C++解决问题第十版Chapter 10.docx_第2页
第2页 / 共14页
用C++解决问题第十版Chapter 10.docx_第3页
第3页 / 共14页
用C++解决问题第十版Chapter 10.docx_第4页
第4页 / 共14页
用C++解决问题第十版Chapter 10.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

用C++解决问题第十版Chapter 10.docx

《用C++解决问题第十版Chapter 10.docx》由会员分享,可在线阅读,更多相关《用C++解决问题第十版Chapter 10.docx(14页珍藏版)》请在冰豆网上搜索。

用C++解决问题第十版Chapter 10.docx

用C++解决问题第十版Chapter10

TRUE/FALSE

1.Astructvariableisdeclareddifferentlyfromapredefinedtypesuchasanint.

ANSWER:

FALSE

2.Twodifferentstructuredefinitionsmayhavethesamemembernames.

ANSWER:

TRUE.

3.Astructurecanonlybepassedtoafunctionasacall-by-valueparameter

ANSWER:

FALSE

4.Afunctionmayreturnastructure.

ANSWER:

TRUE

5.Differentclassmaynothavememberfunctionswiththesamename.

ANSWER:

FALSE

6.Aclassmemberfunctionmaybeprivate.

ANSWER:

TRUE

7.Classdatamembersarealmostalwayspublic.

ANSWER:

FALSE

8.Itispossibletohavemultipleprivatelabelsinaclassdefinition.

ANSWER:

TRUE

9.Theassignmentoperatormaynotbeusedwithobjectsofaclass.

ANSWER:

FALSE

10.Allconstructorsforaclassmustbeprivate.

ANSWER:

FALSE

11.Aderivedclassismorespecificthanitsparent,orbaseclass.

ANSWER:

TRUE

ShortAnswer

1.Thekeyword________definesastructuretypedefinition.

ANSWER:

struct

2.Astructuredefinitionendswiththeclosingbraceanda_________.

ANSWER:

semicolon

3.Astructurevariableisacollectionofsmallervaluescalled____________values

ANSWER:

member

4.Whenastructurecontainsanotherstructurevariableasoneofitsmembers,itisknownasa___________________.

ANSWER:

hierarchicalstructure

5.Whenseveralitems(variablesorvariablesandfunctions)aregroupedtogetherintoasinglepackage,thatisknownas______________.

ANSWER:

(data)encapsulation

6.Thedoublecolon(:

:

)isknownasthe__________operator.

ANSWER:

scoperesolutionoperator

7.Whocanaccessprivatemembersinaclass?

ANSWER:

onlyothermembersoftheclass

8.Amemberfunctionthatallowstheuseroftheclasstofindoutthevalueofaprivatedatatypeiscalleda___________________.

ANSWER:

accessorfunction.

9.Amemberfunctionthatallowstheuseroftheclasstochangethevalueofaprivatedatatypeiscalleda____________________.

ANSWER:

mutatorfunction.

10.Ifyouhaveaclasswithamemberfunctioncalleddisplay(ostream&out),thatwillsendthevaluesintheclasstotheparameterstream,andyouneedtocallthatfunctionfromwithinanothermemberfunction,howwouldyoucallittoprintthedatatothescreen?

___________________________

ANSWER:

display(cout);

11.Whatcanaconstructorreturn?

_______________

ANSWER:

nothing

12.Thenameofaconstructoris_____________

ANSWER:

thenameoftheclass

13.Theconstructorofaclassthatdoesnothaveanyparametersiscalleda__________constructor.

ANSWER:

default

14.Inthefollowingclassconstructordefinition,thepartoftheheaderstartingwithasinglecoloniscalledthe________________.

BankAccount:

:

BankAccount():

balance(0),interest(0.0)

ANSWER:

initializationsection

15.Aclassinwhichmodificationstotheimplementationappeartobeinvisibletotheuseroftheclassisknownas_________________.

ANSWER:

anAbstractDataType(ADT)

16.Amemberfunctionthatgetscalledautomaticallywhenanobjectoftheclassisdeclarediscalleda_______________.

ANSWER:

constructor

17.IfclassAisderivedfromclassB,thenBisa_______ofA.

ANSWER:

parent

18.C++11allowsyoutodirectlysetthemembervariablestoinitialvaluesinthedefinitionoftheclass.Thisfeatureiscalled__________________.

ANSWER:

memberinitializers

19.C++11allowsyoutohaveaconstructorcallanotherconstructor.Thisfeatureiscalled_________________________.

ANSWER:

constructordelegation

MultipleChoice

1.Inastructuredefinition,theidentifiersdeclaredinthebracesarecalled

a.classes

b.structs

c.membernames

d.variables

ANSWER:

C

2.Youspecifyanindividualmemberofastructbyusing

a.theassignmentoperator

b.anampersand

c.anunderscore

d.Thedotoperator

ANSWER:

D

3.Toassignvaluestoastructurevariable,youusethe

a.equalsoperator

b.assignmentoperator

c.extractionoperator

d.lessthanoperator

ANSWER:

B

4.Whatiswrongwiththefollowingstructuredefinition?

structMyStruct

{

intsize;

floatweight;

}

a.Nothing

b.Cannothavemixeddatatypesinastructure

c.missingsemicolon

d.Bracesarenotneeded.

ANSWER:

C

5.Giventhefollowingstrucuredefinitions,whatisthecorrectwaytoprinttheperson'sbirthyear?

structDateType

{

intday;

intmonth;

intyear;

}

structPersonType

{

intage;

floatweight;

DateTypebirthday;

}

PersonTypeperson;

a.cout<

b.cout<

c.cout<

d.cout<

ANSWER:

A

6.Giventhefollowingstrucuredefinition,whatisthecorrectwaytoinitializeavariablecalledtoday?

structDateType

{

intday;

intmonth;

intyear;

}

a.DateTypetoday(1,1,2000);

b.DateTypetoday=(1,1,2000);

c.DateTypetoday={1,1,2000);

d.DateTypetoday={1,1,2000,0);

ANSWER:

C

7.Whendefiningaclass,theclassshouldbecomposedofthekindofvaluesavariableoftheclasscancontain,and

a.memberfunctionsforthatclass

b.thekeywordprivate

c.otherclassdefinitions

d.nothingelse

ANSWER:

A

8.WhichofthefollowingisthecorrectfunctiondefinitionheaderforthegetAgefunctionwhichisamemberofthePersonclass?

a.intgetAge();

b.intgetAge()

c.intPerson:

getAge()

d.intPerson:

:

getAge()

ANSWER:

D

9.Giventhefollowingclassdefinitionandthefollowingmemberfunctionheader,whichisthecorrectwaytooutputtheprivatedata?

classPerson

{

public:

voidoutputPerson(ostream&out);

private:

intage;

floatweight;

intid;

};

voidPerson:

:

outputPerson(ostream&out)

{

//whatgoeshere?

}

a.out<

b.out<

c.out<

d.outputPerson(person);

ANSWER:

C

10.Whydoyouwanttousuallymakedatamembersprivateinaclass?

a.sothatnoonecanusetheclass.

b.ensuredataintegrity

c.providedataabstraction.

d.provideinformationhiding.

e.BandD

f.B,CandD

ANSWER:

F

11.Amemberfunctionofaclassshouldbemadeprivate

a.always

b.onlyifitwillneverbeused

c.ifitwillonlybeusedbyothermembersoftheclass

d.never,itisillegaltomakeamemberfunctionprivate.

ANSWER:

C

12.Amemberfunctionthatallowtheuseroftheclasstochangethevalueinadatamemberisknownas

a.amutatorfunction

b.amutation

c.amanipulatorfunction

d.anaccessorfunction

ANSWER:

A

13.AMemberfunctionthatallowstheuseroftheclasstoseethevalueinadatamemberisknownas

a.amutatorfunction

b.amutation

c.amanipulatorfunction

d.anaccessorfunction

ANSWER:

D

14.Ifyoudesignaclasswithprivatedatamembers,anddonotprovidemutatorsandaccessors,then

a.Theprivatedatamemberscanstillbeaccessedfromoutsidetheclassbyusingthe&operator

b.Thedatacannotbechangedorviewedbyanyone.

c.Noneoftheabove

d.AandB

ANSWER:

B

15.Aclassmemberfunctionthatautomaticallyinitializesthedatamembersofaclassiscalled

a.theinitfunction

b.anoperator

c.aconstructor

d.acast

ANSWER:

C

16.IfyouhaveaclassnamedmyPersonClass,whichofthefollowingcorrectlydeclareaconstructorintheclassdefinition?

a.myPersonClass:

:

myPersonClass();

b.myPersonClass();

c.init();

d.cast();

ANSWER:

B

17.giventhefollowingclassdefinition,howcouldyouusetheconstructortoassignvaluestoanobjectofthisclass?

classCDAccount

{

public:

CDAccount();

CDAccount(floatinterest,floatnewBalance);

floatgetBalance();

floatgetRate();

voidsetRate(floatinterest);

voidsetBalance(floatnewBalance);

private:

floatbalance,rate;

};

andthefollowingobjectdeclaration

CDAccountmyAccount;

a.myAccount=CDAccount(floatmyRate,floatmyBalance);

b.myAccount=CDAccount{myRate,myBalance};

c.myAccount=CDAccount[myRate,myBalance];

d.myAccount=CDAccount(myRate,myBalance);

ANSWER:

D

18.Giventhefollowingclassdefinition,whatismissing?

classItemClass

{

public:

ItemClass(intnewSize,floatnewCost);

intgetSize();

floatgetCost();

voidsetSize(intnewSize);

voidsetCost(floatnewCost);

private:

intsize;

floatcost;

};

a.nothing

b.adefaultconstructor

c.accessorfunctions

d.mutatorfunctions

ANSWER:

B

19.Giventhefollowingclassdefinition,howwouldyoudeclareanobjectoftheclass,sothattheobjectautomaticallycalledthedefaultconstructor?

classItemClass

{

public:

ItemClass();

ItemClass(intnewSize,floatnewCost);

intgetSize();

floatgetCost();

voidsetSize(intnewSize);

voidsetCost(floatnewCost);

private:

intsize;

floatcost;

};

a.ItemClass()myItem;

b.ItemClassmyItem(1,0.0);

c.ItemClassmyItem;

d.ItemClassmyItem();

e.Youcannotdothis

ANSWER:

C

20.Adatatypeconsistingofdatamembersandoperationsonthosememberswhichcanbeusedbyaprogrammerwithoutknowingtheimplementationdetailsofthedatatypeiscalled

a.anabstractdefinitiontype

b.anavailabledatatype

c.anabstractdatatype

d.aprimitivedatatype

ANSWER:

C

21.WhichpartoftheADTtellstheprogrammerusingithowtouseit?

a.theimplementation

b.theinterface

c.theabstractness

d.thescoperesolution

ANSWER:

B

22.IfyouaredesigningaclassforanADT,youcantelliftheclassisanADTif

a.whenyouchangetheimplementationoftheclass,noneoftherestoftheprogramneedstochange.

b.whenyouchangetheinterfaceoftheclass,nothingelseneedstochange.

c.youchangetheprivtepartandtherestoftheprogramusingtheADTdoesnotcompile.

d.everythingmustbechanged.

ANSWER:

A

23.DevelopinganADTmeansthattheuserofyourclassdoesnothavetoknowthedetailsabouthowtheclassisimplemented.Thisisknownas

a.interface

b.implementation

c.testinganddebugging

d.informationhiding

ANSWER:

D

24.Giventhefollowingclass,whatwouldbethebestdeclarationforamutatorfunctionthatallowstheuseroftheclas

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

当前位置:首页 > 解决方案 > 商业计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1