C++编程思想 课后答案第二章 其他章请点击用户名找 thinking in C++ annotat.pdfVIP

  • 1
  • 0
  • 约1.31万字
  • 约 18页
  • 2026-02-08 发布于河南
  • 举报

C++编程思想 课后答案第二章 其他章请点击用户名找 thinking in C++ annotat.pdf

[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)

1亿VIP精品文档

相关文档