C++复习资料Word文档格式.docx
- 文档编号:21447164
- 上传时间:2023-01-30
- 格式:DOCX
- 页数:31
- 大小:35.60KB
C++复习资料Word文档格式.docx
《C++复习资料Word文档格式.docx》由会员分享,可在线阅读,更多相关《C++复习资料Word文档格式.docx(31页珍藏版)》请在冰豆网上搜索。
called,whichallowsprogrammerstospecifythatmanyactivitiescan
proceedinparallel.
FillintheblanksineachofthefollowingsentencesabouttheC++environment.
a.C++programsarenormallytypedintoacomputerusinga(n)
program.
b.InaC++system,a(n)__preprocessor__programexecutesbeforethecompiler'
s
translationphasebegins.
c.The_linker_programcombinestheoutputofthecompilerwithvarious
libraryfunctionstoproduceanexecutableimage.
d.TheprogramtransferstheexecutableimageofaC++programfrom
disktomemory.
Fillintheblanksineachofthefollowingstatements
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.
Whyissomuchattentiontodayfocusedonobject-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.
【参考教材的答案】面向对象的编程让编程者可以建立可重用的软件组件,这些组件是现实
世界事物的抽象模型。
软件工业的目标是快速、正确、有效率的开发软件。
面向对象的设计
和实现方法模型已经被事实证明是可以提高生产效率和减少开发时间、错误和代价。
【参考讲义的答案】面向对象的编程方法中,以类和对象来组织源代码,可以方便的实现与
现实物理世界事物的映射。
采用这种方法,易于在大型软件开发中进行软件的设计、重用和
维护,因此受到软件行业的支持和采用。
Youareprobablywearingonyourwristoneoftheworld'
smostcommontypesofobjectsawatch.Discusshoweachofthefollowingtermsandconceptsappliestothenotionofawatch:
object,attributes,behaviors,class,inheritance(consider,for
example,analarmclock),abstraction,modeling,messages,encapsulation,interface,
informationhiding,datamembersandmemberfunctions.
可能现在你的手腕上就戴着世界上最普遍的对象类型之一——手表。
论述以下这些术
语和概念如何应用于手表这个概念上:
对象、属性、行为、类、继承(例如,考虑闹钟)、
封装、接口、信息隐藏、数据成员和成员函数。
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.
Fillintheblanksineachofthefollowing.
a.EveryC++programbeginsexecutionatthefunction_main_.
b.The__leftbrace({)_beginsthebodyofeveryfunctionandthe__rightbrace(})_endsthebodyofeveryfunction.
c.EveryC++statementendswitha(n)__semicolon_______.
d.Theescapesequence\nrepresentsthe__character,whichcausesthecursortopositiontothebeginningofthenextlineonthescreen.
e.The___statementisusedtomakedecisions.
Statewhethereachofthefollowingistrueorfalse.Iffalse,explainwhy.Assumethestatementusingstd:
:
cout;
isused.
a.Commentscausethecomputertoprintthetextaftertheb.Theescapesequence\n,whenoutputwithcoutandthestreaminsertionoperator,
causesthecursortopositiontothebeginningofthenextlineonthescreen.
c.Allvariablesmustbedeclaredbeforetheyareused.
d.Allvariablesmustbegivenatypewhentheyaredeclared.
e.C++considersthevariablesnumberandNuMbErtobeidentical.
f.DeclarationscanappearalmostanywhereinthebodyofaC++function.
g.Themodulusoperator(%)canbeusedonlywithintegeroperands.
h.Thearithmeticoperators*,/,%,+andallhavethesamelevelofprecedence.
i.AC++programthatprintsthreelinesofoutputmustcontainthreestatementsusing
coutandthestreaminsertionoperator.
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
WriteasingleC++statementtoaccomplisheachofthefollowing(assumethatusingdeclarationshavenotbeenused):
a.Declarethevariablesc,thisIsAVariable,q76354andnumbertobeoftypeint.
b.Prompttheusertoenteraninteger.Endyourpromptingmessagewithacolon(:
)
followedbyaspaceandleavethecursorpositionedafterthespace.
c.Readanintegerfromtheuseratthekeyboardandstorethevalueenteredininteger
variableage.
d.Ifthevariablenumberisnotequalto7,print"
Thevariablenumberisnotequalto7"
.
e.Printthemessage"
ThisisaC++program"
ononeline.
f.Printthemessage"
ontwolines.Endthefirstlinewith
C++.
g.Printthemessage"
witheachwordonaseparateline.
h.Printthemessage"
witheachwordseparatedfromthe
nextbyatab.
ANS;
a.intc,thisIsAVariable,q76354,number;
b.std:
cout<
<
"
Enteraninteger:
;
c.std:
cin>
>
age;
d.if(number!
=7)
std:
Thevariablenumberisnotequalto7\n"
e.std:
ThisisaC++program\n"
f.std:
ThisisaC++\nprogram\n"
g.std:
This\nis\na\nC++\nprogram\n"
h.std:
This\tis\ta\tC++\tprogram\n"
Writeastatement(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.
a.intx;
inty;
intz;
intresult;
c.cout<
Enterthreeintegers:
d.cin>
x>
y>
z;
e.result=x*y*z;
f.cout<
<
result<
endl;
g.return0;
UsingthestatementsyouwroteinExercise,writeacompleteprogramthatcalculatesanddisplaystheproductofthreeintegers.Addcommentstothecodewhereappropriate.[Note:
Youwillneedtowritethenecessaryusingdeclarations.]
1if(c<
7);
cislessthan7\n"
b.if(c=>
7)
cisequaltoorgreaterthan7\n"
a.Error:
Semicolonaftertherightpa
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 复习资料
