- 1
- 0
- 约1.31万字
- 约 18页
- 2026-02-08 发布于河南
- 举报
[ViewingHints][BookHomePage][FreeNewsletter]
[Seminars][SeminarsonCDROM][Consulting]
AnnotatedSolutionGuide
Revision1.0
forThinkinginC++,2ndedition,Volume1
byChuckAllison
©2001MindView,Inc.AllRightsReserved.
[PreviousChapter][TableofContents][NextChapter]
Chapter2
2-1
ModifyHello.cppsothatitprintsoutyournameandage(orshoesize,oryourdog‟sage,ifthat
makesyoufeelbetter).Compileandruntheprogram.
Solution:
TheoriginalHello.cppappearedinthetextasfollows:
//SayingHellowithC++
#includeiostream//Streamdeclarations
usingnamespacestd;
intmain(){
coutcout
88endl;
}
Here‟smyrewrite:
//:S02:Hello2.cpp
#includeiostream
usingnamespacestd;
intmain(){
coutcoutendl;
coutcoutendl;
coutcout55endl;
coutcoutendl;
coutcoutendl;
}
/*Output:
Hello,World!IamChuckAllison.
Ihavetwodogs:
Sheba,whois5,and
Muffy,whois8.
(Ifeelmuchbetter!)
*////:~
Ichosetohaveseparatestatementsthatsendoutputtocout,butIcouldhaveprintedeverythingin
asinglestatementifIhadwanted,liketheexampleinthetextdoes.Notethatinthecaseof
Sheba‟sage,Iprinted5asaninteger,butforMuffyIincludedthenumeralintheliteraltext.In
thiscaseitmakesnodifference,butwhenyouprintfloating-pointnumbersthathavedecimals,
youget6decimalsbydefault.Brucediscusseslaterinthetexthowtocontroloutputof
floating-pointnumbers.
2-2
StartingwithStream2.cppandNumconv.cpp,createaprogramthatasksforthera
原创力文档

文档评论(0)