C++复习全资料1.docx

上传人:b****4 文档编号:24248637 上传时间:2023-05-25 格式:DOCX 页数:52 大小:39.98KB
下载 相关 举报
C++复习全资料1.docx_第1页
第1页 / 共52页
C++复习全资料1.docx_第2页
第2页 / 共52页
C++复习全资料1.docx_第3页
第3页 / 共52页
C++复习全资料1.docx_第4页
第4页 / 共52页
C++复习全资料1.docx_第5页
第5页 / 共52页
点击查看更多>>
下载资源
资源描述

C++复习全资料1.docx

《C++复习全资料1.docx》由会员分享,可在线阅读,更多相关《C++复习全资料1.docx(52页珍藏版)》请在冰豆网上搜索。

C++复习全资料1.docx

C++复习全资料1

1.1Fillintheblanksineachofthefollowing:

a.Thecompanythatpopularizedpersonalcomputingwas_Apple.__

b.Thecomputerthatmadepersonalcomputinglegitimateinbusinessand

industrywasthe__IBMPersonalComputer

c.Computersprocessdataunderthecontrolofsetsofinstructionscalled

computer__programs_______.

d.Thesixkeylogicalunitsofthecomputerarethe_inputunit_,__outputunit,

__memoryunit__,_arithmeticandlogicunit__,_centralprocessingunit__andthe__secondarystorageunit___

e.Thethreeclassesoflanguagesdiscussedinthechapterare_machinelanguages_,

_assemblylanguages_,and__high-levellanguages__.

f.Theprogramsthattranslatehigh-levellanguageprogramsintomachine

languagearecalled___compilers___.

g.Ciswidelyknownasthedevelopmentlanguageofthe_UNIX_operating

system.

h.The_Pascal__languagewasdevelopedbyWirthforteachingstructured

programming.

i.TheDepartmentofDefensedevelopedtheAdalanguagewithacapability

called__multitasking.__,whichallowsprogrammerstospecifythatmanyactivitiescan

proceedinparallel.

1.2FillintheblanksineachofthefollowingsentencesabouttheC++environment.

a.C++programsarenormallytypedintoacomputerusinga(n)_editor.__

program.

b.InaC++system,a(n)__preprocessor__programexecutesbeforethecompiler's

translationphasebegins.

c.The_linker_programcombinestheoutputofthecompilerwithvarious

libraryfunctionstoproduceanexecutableimage.

d.The__loader.__programtransferstheexecutableimageofaC++programfrom

disktomemory.

1.3Fillintheblanksineachofthefollowingstatements

a.Objectshavethepropertyof__informationhiding_althoughobjectsmayknowhowto

communicatewithoneanotheracrosswell-definedinterfaces,theynormally

arenotallowedtoknowhowotherobjectsareimplemented.

b.C++programmersconcentrateoncreating_classes_,whichcontaindata

membersandthememberfunctionsthatmanipulatethosedatamembersand

provideservicestoclients.

c.Classescanhaverelationshipswithotherclasses.Theserelationshipsarecalled

__associations___.

d.Theprocessofanalyzinganddesigningasystemfromanobject-orientedpoint

ofviewiscalled__object-orientedanalysisanddesign(OOAD).___.

e.OODalsotakesadvantageof_inheritance__relationships,wherenewclassesof

objectsarederivedbyabsorbingcharacteristicsofexistingclasses,thenadding

uniquecharacteristicsoftheirown.

f.__TheUnifiedModelingLanguage(UML)__isagraphicallanguagethatallowspeoplewhodesignsoftware

systemstouseanindustry-standardnotationtorepresentthem.

g.Thesize,shape,colorandweightofanobjectareconsidered_attributes__ofthe

object.

1.7Whyissomuchattentiontodayfocusedonobject-orientedprogrammingingeneralandC++inparticular?

ANS1:

Object-orientedprogrammingenablestheprogrammertobuildreusable

softwarecomponentsthatmodelitemsintherealworld.Buildingsoftwarequickly,correctly,and

economicallyhasbeenanelusivegoalinthesoftwareindustry.Themodular,object-oriented

designandimplementationapproachhasbeenfoundtoincreaseproductivitywhilereducing

developmenttime,errors,andcost.

ANS2:

Inobject-orientedprogramming,thesourcecodeisorganizedinclassesandobjects,which

iseasytobemappingintotheitemsinphysicalworld.Itiseasytodesign,reuseandmaintain

suchkindofsoftwareinlargescalesoftwaredevelopment,whichisfavoredbythesoftware

industry.

【参考教材的答案】面向对象的编程让编程者可以建立可重用的软件组件,这些组件是现实

世界事物的抽象模型。

软件工业的目标是快速、正确、有效率的开发软件。

面向对象的设计

和实现方法模型已经被事实证明是可以提高生产效率和减少开发时间、错误和代价。

【参考讲义的答案】面向对象的编程方法中,以类和对象来组织源代码,可以方便的实现与

现实物理世界事物的映射。

采用这种方法,易于在大型软件开发中进行软件的设计、重用和

维护,因此受到软件行业的支持和采用。

1.10Youareprobablywearingonyourwristoneoftheworld'smostcommontypesofobjectsawatch.Discusshoweachofthefollowingtermsandconceptsappliestothenotionofawatch:

object,attributes,behaviors,class,inheritance(consider,for

example,analarmclock),abstraction,modeling,messages,encapsulation,interface,

informationhiding,datamembersandmemberfunctions.

1.10可能现在你的手腕上就戴着世界上最普遍的对象类型之一——手表。

论述以下这些术

语和概念如何应用于手表这个概念上:

对象、属性、行为、类、继承(例如,考虑闹钟)、

封装、接口、信息隐藏、数据成员和成员函数。

ANS:

Theentirewatchisanobjectthatiscomposedofmanyotherobjects(suchasthemovingparts,theband,theface,etc.)Watchattributesaretime,color,band,style(digitaloranalog),etc.Thebehaviorsofthewatchincludesettingthetimeandgettingthetime,Awatchcanbeconsideredaspecifictypeofclock(ascananalarmclock),Withthatinmind,itispossiblethataclasscalledClockcouldexistfromwhichotherclassessuchaswatchandalarmclockcaninheritthebasicfeaturesintheclock.Thewatchisanabstractionofthemechanicsneededtokeeptrackofthetime.Theuserofthewatchdoesnotneedtoknowthemechanicsofthewatchinordertouseit;theuseronlyneedstoknowthatthewatchkeepsthepropertime.Inthissense,themechanicsofthewatchareencapsulated(hidden)insidethewatch.Theinterfacetothewatch(itsfaceandcontrolsforsettingthetime)allowstheusertosetandgetthetime.Theuserisnotallowedtodirectlytouchtheinternalmechanicsofthewatch.Allinteractionwiththeinternalmechanicsiscontrolledbytheinterfacetothewatch.Thedatamembersstoredinthewatcharehiddeninsidethewatchandthememberfunctions(lookingatthefacetogetthetimeandsettingthetime)providetheinterfacetothedata.

 

2.1Fillintheblanksineachofthefollowing.

a.EveryC++programbeginsexecutionatthefunction_main_.

b.The__leftbrace({)_beginsthebodyofeveryfunctionandthe__rightbrace(})_endsthebodyofeveryfunction.

c.EveryC++statementendswitha(n)__semicolon_______.

d.Theescapesequence\nrepresentsthe__newline._______character,whichcausesthecursortopositiontothebeginningofthenextlineonthescreen.

e.The___if.______statementisusedtomakedecisions.

2.2Statewhethereachofthefollowingistrueorfalse.Iffalse,explainwhy.Assumethestatementusingstd:

:

cout;isused.

a.Commentscausethecomputertoprintthetextafterthe//onthescreenwhenthe

programisexecuted.

b.Theescapesequence\n,whenoutputwithcoutandthestreaminsertionoperator,

causesthecursortopositiontothebeginningofthenextlineonthescreen.

c.Allvariablesmustbedeclaredbeforetheyareused.

d.Allvariablesmustbegivenatypewhentheyaredeclared.

e.C++considersthevariablesnumberandNuMbErtobeidentical.

f.DeclarationscanappearalmostanywhereinthebodyofaC++function.

g.Themodulusoperator(%)canbeusedonlywithintegeroperands.

h.Thearithmeticoperators*,/,%,+andallhavethesamelevelofprecedence.

i.AC++programthatprintsthreelinesofoutputmustcontainthreestatementsusing

coutandthestreaminsertionoperator.

ANS:

a.False.Commentsdonotcauseanyactiontobeperformedwhentheprogramisexecuted.Theyareusedtodocumentprogramsandimprovetheirreadability.

b.True.c.True.d.True.e.False.C++iscasesensitive,sothesevariablesareunique.f.True.g.True.h.False.Theoperators*,/and%havethesameprecedence,andtheoperators+and–havealowerprecedence.i.False.Asinglecoutstatementwithmultiple\nescapesequencescanprintseverallines

2.3WriteasingleC++statementtoaccomplisheachofthefollowing(assumethatusingdeclarationshavenotbeenused):

a.Declarethevariablesc,thisIsAVariable,q76354andnumbertobeoftypeint.

b.Prompttheusertoenteraninteger.Endyourpromptingmessagewithacolon(:

followedbyaspaceandleavethecursorpositionedafterthespace.

c.Readanintegerfromtheuseratthekeyboardandstorethevalueenteredininteger

variableage.

d.Ifthevariablenumberisnotequalto7,print"Thevariablenumberisnotequalto7".

e.Printthemessage"ThisisaC++program"ononeline.

f.Printthemessage"ThisisaC++program"ontwolines.Endthefirstlinewith

C++.

g.Printthemessage"ThisisaC++program"witheachwordonaseparateline.

h.Printthemessage"ThisisaC++program"witheachwordseparatedfromthe

nextbyatab.

ANS;a.intc,thisIsAVariable,q76354,number;

b.std:

:

cout<<"Enteraninteger:

";

c.std:

:

cin>>age;

d.if(number!

=7)

std:

:

cout<<"Thevariablenumberisnotequalto7\n";

e.std:

:

cout<<"ThisisaC++program\n";

f.std:

:

cout<<"ThisisaC++\nprogram\n";

g.std:

:

cout<<"This\nis\na\nC++\nprogram\n";

h.std:

:

cout<<"This\tis\ta\tC++\tprogram\n";

2.4Writeastatement(orcomment)toaccomplisheachofthefollowing(assumethatusingdeclarationshavebeenused):

a.Statethataprogramcalculatestheproductofthreeintegers.

b.Declarethevariablesx,y,zandresulttobeoftypeint(inseparatestatements).

c.Prompttheusertoenterthreeintegers.

d.Readthreeintegersfromthekeyboardandstoretheminthevariablesx,yandz.

e.Computetheproductofthethreeintegerscontainedinvariablesx,yandz,and

assigntheresulttothevariableresult.

f.Print"Theproductis"followedbythevalueofthevariableresult.

g.Returnavaluefrommainindicatingthattheprogramterminatedsuccessfully.

ANS:

a.//Calculatetheproductofthreeintegers

b.intx;

inty;

intz;

intresult;

c.cout<<"Enterthreeintegers:

";

d.cin>>x>>y>>z;

e.result=x*y*z;

f.cout<<"Theproductis"<

g.return0;

2.5UsingthestatementsyouwroteinExercise2.4,writeacompleteprogramthatcalculatesanddisplaystheproductofthreeintegers.Addcommentstothecodewhereappropriate.[Note:

Youwillne

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

当前位置:首页 > 考试认证 > IT认证

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

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