ImageVerifierCode 换一换
格式:DOCX , 页数:59 ,大小:30.97KB ,
资源ID:27062562      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/27062562.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(面向对象的C++程序设计 第六版 课后习题答案 第十章.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

面向对象的C++程序设计 第六版 课后习题答案 第十章.docx

1、面向对象的C+程序设计 第六版 课后习题答案 第十章Chapter 10DEFINING CLASSES AND ABSTRACT DATA TYPES1. Solutions for and Remarks on Selected Programming ProblemsThis chapter can be done after Chapter 7, Arrays. However, I have not used anything from that chapter in these solutions. Several of these solutions could be simpl

2、ified in good measure if arrays were used instead of the extensive switch and nested if else statements.1. Class grading programI have put statements of programming strategy and of the problem in the program comments./ch10Prg1.cpp#include using namespace std;const int CLASS_SIZE = 5;/ The problem sa

3、ys this is for a class, rather than one student. One/ programming stratagem is to deal with a single student, then extend/ to treat an array of N students. /Grading Program/Policies:/ Two quizzes, 10 points each/ midterm and final exam, 100 points each/ Of grade, final counts 50%, midterm 25%, quize

4、s25%/ Letter Grade is assigned:/ 90 or more A/ 80 or more B/ 70 or more C/ 60 or more D/ less than 60, F/ Read a students scores, / output record: scores + numeric average + assigned letter grade/ Use a struct to contain student record.struct StudentRecord int studentNumber; double quiz1; double qui

5、z2; double midterm; double final; double average; char grade;void input(StudentRecord& student);/prompts for input for one student, sets the/structure variable members.void computeGrade(StudentRecord& student);/calculates the numeric average and letter grade.void output(const StudentRecord student);

6、/outputs the student record.int main() StudentRecord studentCLASS_SIZE; for(int i = 0; i CLASS_SIZE; i+) input(studenti); / Enclosing block fixes VC+ for loop control defined outside loop for(int i = 0; i CLASS_SIZE; i+) computeGrade(studenti); output(studenti); cout endl; return 0;void input(Studen

7、tRecord &student) cout student.studentNumber; cout student.studentNumber endl; cout enter two 10 point quizes student.quiz1 student.quiz2; cout student.quiz1 student.quiz2 endl; cout enter the midterm and final exam grades. student.midterm student.final; cout student.midterm student.final endl endl;

8、void computeGrade(StudentRecord& student)/ Of grade, final counts 50%, midterm 25%, quizes25% double quizAvg= (student.quiz1 + student.quiz2)/2.0; double quizAvgNormalized = quizAvg * 10; student.average = student.final * 0.5 + student.midterm * 0.25 + quizAvgNormalized * 0.25; char letterGrade= FFF

9、FFFDCBAA; int index = static_cast(student.average/10); if(index 0 | 10 = index) cout Bad numeric grade encountered: student.average endl Aborting.n; abort(); student.grade = letterGradeindex;void output(const StudentRecord student) cout The record for student number: student.studentNumber endl The q

10、uiz grades are: student.quiz1 student.quiz2 endl The midterm and exam grades are: student.midterm student.final endl The numeric average is: student.average endl and the letter grade assigned is student.grade endl;Data for the test run:1 7 10 90 952 9 8 90 803 7 8 70 804 5 8 50 705 4 0 40 35Command

11、line command to execute the text run:ch10prg1 dataOutput:enter the student number: 1enter two 10 point quizes7 10enter the midterm and final exam grades. These are 100 point tests90 95enter the student number: 2enter two 10 point quizes9 8enter the midterm and final exam grades. These are 100 point

12、tests90 80enter the student number: 3enter two 10 point quizes7 8enter the midterm and final exam grades. These are 100 point tests70 80enter the student number: 4enter two 10 point quizes5 8enter the midterm and final exam grades. These are 100 point tests50 70enter the student number: 5enter two 1

13、0 point quizes4 0enter the midterm and final exam grades. These are 100 point tests40 35The record for student number: 1The quiz grades are: 7 10The midterm and exam grades are: 90 95The numeric average is: 91.25and the letter grade assigned is AThe record for student number: 2The quiz grades are: 9

14、 8The midterm and exam grades are: 90 80The numeric average is: 83.75and the letter grade assigned is BThe record for student number: 3The quiz grades are: 7 8The midterm and exam grades are: 70 80The numeric average is: 76.25and the letter grade assigned is CThe record for student number: 4The quiz

15、 grades are: 5 8The midterm and exam grades are: 50 70The numeric average is: 63.75and the letter grade assigned is DThe record for student number: 5The quiz grades are: 4 0The midterm and exam grades are: 40 35The numeric average is: 32.5and the letter grade assigned is F*/2. Redefine CDAccount fro

16、m Display 10.1 to be a class rather than struct.Use the same variables, make them private.Add member functions:to return initial balanceto return balance at maturityto return interest rateto return the termdefault constructorconstructor to set specified valuesinput function (istream&);output functio

17、n (ostream&);Embed in a test programThe code in Display 10.1 makes the behavior of the required functions clear. Note on capitalization schemes: I use a slightly different capitalization scheme than the author. You should make your conventions clear to the student. Any capitalization that produces r

18、eadable code is acceptable to this author. The instructor, as always, is left free to do as is wished./ File: ch10Prg2.cpp/ Title: CDAccount#include using namespace std;class CDAccount public: CDAccount(); CDAccount(double bal, double intRate, int T ); double InterestRate(); double InitialBalance();

19、 double BalanceAtMaturity(); int Term(); void input(istream&); void output(ostream&);private: double balance; double interestRate; / in PER CENT int term; / months to maturity;int main() double balance; double intRate; int term; CDAccount account = CDAccount( 100.0, 10.0, 6 ); cout CD Account intere

20、st rate: account.InterestRate() endl; cout CD Account initial balance: account.InitialBalance() endl; cout CD Account balance at maturity is: account.BalanceAtMaturity() endl; cout CD Account term is: account.Term() months endl; account.output(cout); cout Enter CD initial balance, interest rate, and

21、 term: endl; account.input(cin); cout CD Account interest rate: account.InterestRate() endl; cout CD Account initial balance: account.InitialBalance() endl; cout CD Account balance at maturity is: account.BalanceAtMaturity() endl; cout CD Account term is: account.Term() months endl; account.output(

22、cout ); cout balance; inStream interestRate; inStream term;void CDAccount:output(ostream& outStream) outStream.setf(ios:fixed); outStream.setf(ios:showpoint); outStream.precision(2); outStream when your CD matures in term months endl it will have a balance of BalanceAtMaturity() endl;/*A typical run

23、 follows:CD Account interest rate: 10CD Account initial balance: 100CD Account balance at maturity is: 105CD Account term is: 6 monthswhen your CD matures in 6 monthsit will have a balance of 105.00Enter CD initial balance, interest rate, and term:2001012CD Account interest rate: 10.00CD Account ini

24、tial balance: 200.00CD Account balance at maturity is: 220.00CD Account term is: 12 monthswhen your CD matures in 12 monthsit will have a balance of 220.00*/3. CD account, different interfaceRedo the definition of class CDAccount from Project 2 so that the interface is the same but the implementatio

25、n is different. The new implementation is similar to the second implementation of BankAccount in Display 10.7. Here the balance is recorded in two int values, one for dollars, one for cents. The member variable for interest rate stores the interest as a fraction rather than a percentage. Term is sto

26、red as in Project 2.Remark: The changes to be made are in the functions that take balance as argument. The implementation of the members must change:1) to generate the int objects dollars and cents from the external representation of balance (a double)2) to take dollars and cents (int objects) from

27、the internal representation and generate the external information./File: ch10Prg3.cpp/Title: CDAccount - modification of Program1, but with /different implementation but SAME interface./The new implementation should be similar to Display 10.7/record balance as two int values: One for dollars, one for/cents. interest rate is a double (decimal) fraction rather /than a percent (0.043, not 4.3%). term is stored the same / way as Program 1.#include using namespace std;class CDAccountpublic: CDAccount(); CDAccount(double bal, double intRate, int T ); double Inte

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

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