面向对象的c++程序设计第六版课后习题答案第十章.docx
- 文档编号:3088462
- 上传时间:2022-11-17
- 格式:DOCX
- 页数:24
- 大小:24.29KB
面向对象的c++程序设计第六版课后习题答案第十章.docx
《面向对象的c++程序设计第六版课后习题答案第十章.docx》由会员分享,可在线阅读,更多相关《面向对象的c++程序设计第六版课后习题答案第十章.docx(24页珍藏版)》请在冰豆网上搜索。
面向对象的c++程序设计第六版课后习题答案第十章
Chapter10
DEFININGCLASSESANDABSTRACTDATATYPES
1.SolutionsforandRemarksonSelectedProgrammingProblems
ThischaptercanbedoneafterChapter7,Arrays.However,Ihavenotusedanythingfromthatchapterinthesesolutions.Severalofthesesolutionscouldbesimplifiedingoodmeasureifarrayswereusedinsteadoftheextensiveswitchandnestedifelsestatements.
1.Classgradingprogram
Ihaveputstatementsofprogrammingstrategyandoftheproblemintheprogramcomments.
One
structStudentRecord
{
intstudentNumber;
doublequiz1;
doublequiz2;
doublemidterm;
doublefinal;
doubleaverage;
chargrade;
};
voidinput(StudentRecord&student);
voidcomputeGrade(StudentRecord&student);
voidoutput(constStudentRecordstudent);
intmain()
{
StudentRecordstudent[CLASS_SIZE];
for(inti=0;i input(student[i]); <<"Theseare100pointtests\n"; cin>>>>; cout<<<<""<< < } voidcomputeGrade(StudentRecord&student) { n"; abort(); } =letterGrade[index]; } voidoutput(constStudentRecordstudent) { cout<<"Therecordforstudentnumber: " <<< <<"Thequizgradesare: " <<<<""<< < <<"Themidtermandexamgradesare: " <<<<""<< < <<"Thenumericaverageis: "<< < <<"andthelettergradeassignedis" << < } Dataforthetestrun: 17109095 2989080 3787080 4585070 5404035 Commandlinecommandtoexecutethetextrun: ch10prg1 Output: enterthestudentnumber: 1 entertwo10pointquizes 710 enterthemidtermandfinalexamgrades.Theseare100pointtests 9095 enterthestudentnumber: 2 entertwo10pointquizes 98 enterthemidtermandfinalexamgrades.Theseare100pointtests 9080 enterthestudentnumber: 3 entertwo10pointquizes 78 enterthemidtermandfinalexamgrades.Theseare100pointtests 7080 enterthestudentnumber: 4 entertwo10pointquizes 58 enterthemidtermandfinalexamgrades.Theseare100pointtests 5070 enterthestudentnumber: 5 entertwo10pointquizes 40 enterthemidtermandfinalexamgrades.Theseare100pointtests 4035 Therecordforstudentnumber: 1 Thequizgradesare: 710 Themidtermandexamgradesare: 9095 Thenumericaverageis: andthelettergradeassignedisA Therecordforstudentnumber: 2 Thequizgradesare: 98 Themidtermandexamgradesare: 9080 Thenumericaverageis: andthelettergradeassignedisB Therecordforstudentnumber: 3 Thequizgradesare: 78 Themidtermandexamgradesare: 7080 Thenumericaverageis: andthelettergradeassignedisC Therecordforstudentnumber: 4 Thequizgradesare: 58 Themidtermandexamgradesare: 5070 Thenumericaverageis: andthelettergradeassignedisD Therecordforstudentnumber: 5 Thequizgradesare: 40 Themidtermandexamgradesare: 4035 Thenumericaverageis: andthelettergradeassignedisF */ 2.RedefineCDAccountfromDisplaytobeaclassratherthanstruct. Usethesamevariables,makethemprivate. Addmemberfunctions: toreturninitialbalance toreturnbalanceatmaturity toreturninterestrate toreturntheterm defaultconstructor constructortosetspecifiedvalues inputfunction(istream&); outputfunction(ostream&); Embedinatestprogram ThecodeinDisplaymakesthebehavioroftherequiredfunctionsclear. Noteoncapitalizationschemes: Iuseaslightlydifferentcapitalizationschemethantheauthor.Youshouldmakeyourconventionscleartothestudent.Anycapitalizationthatproducesreadablecodeisacceptabletothisauthor.Theinstructor,asalways,isleftfreetodoasiswished. CDaccount,differentinterface RedothedefinitionofclassCDAccountfromProject2sothattheinterfaceisthesamebuttheimplementationisdifferent.ThenewimplementationissimilartothesecondimplementationofBankAccountinDisplay.Herethebalanceisrecordedintwointvalues,onefordollars,oneforcents.Themembervariableforinterestratestorestheinterestasafractionratherthanapercentage.TermisstoredasinProject2. Remark: Thechangestobemadeareinthefunctionsthattakebalanceasargument.Theimplementationofthemembersmustchange: 1)togeneratetheintobjectsdollarsandcentsfromtheexternalrepresentationofbalance(adouble) 2)totakedollarsandcents(intobjects)fromtheinternalrepresentationandgeneratetheexternalinformation. interestrateisadouble(decimal)fractionrather termisstoredthesame #include usingnamespacestd; classCDAccount { public: CDAccount(); CDAccount(doublebal,doubleintRate,intT); doubleInterestRate(); doubleInitialBalance(); doubleBalanceAtMaturity(); intTerm(); voidinput(istream&);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 面向 对象 c+ 程序设计 第六 课后 习题 答案 第十