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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

《C++大学教程第五版》课后习题答案第39章.docx

1、C+大学教程第五版课后习题答案第39章3.11GradeBook类定义:#include / program uses C+ standard string classusing std:string;class GradeBookpublic: / constructor initializes course name and instructor name GradeBook( string, string ); void setCourseName( string ); / function to set the course name string getCourseName(); /

2、 function to retrieve the course name void setInstructorName( string ); / function to set instructor name string getInstructorName(); / function to retrieve instructor name void displayMessage(); / display welcome message and instructor nameprivate: string courseName; / course name for this GradeBoo

3、k string instructorName; / instructor name for this GradeBook; / end class GradeBook类成员函数:#include using std:cout;using std:endl;#include GradeBook.h/ constructor initializes courseName and instructorName / with strings supplied as argumentsGradeBook:GradeBook( string course, string instructor ) set

4、CourseName( course ); / initializes courseName setInstructorName( instructor ); / initialiZes instructorName / end GradeBook constructor/ function to set the course namevoid GradeBook:setCourseName( string name ) courseName = name; / store the course name / end function setCourseName/ function to re

5、trieve the course namestring GradeBook:getCourseName() return courseName; / end function getCourseName/ function to set the instructor namevoid GradeBook:setInstructorName( string name ) instructorName = name; / store the instructor name / end function setInstructorName/ function to retrieve the ins

6、tructor namestring GradeBook:getInstructorName() return instructorName; / end function getInstructorName/ display a welcome message and the instructors namevoid GradeBook:displayMessage() / display a welcome message containing the course name cout Welcome to the grade book forn getCourseName() ! end

7、l; / display the instructors name cout This course is presented by: getInstructorName() endl; / end function displayMessage测试文件:#include using std:cout; using std:endl;/ include definition of class GradeBook from GradeBook.h#include GradeBook.h/ function main begins program executionint main() / cre

8、ate a GradeBook object; pass a course name and instructor name GradeBook gradeBook( CS101 Introduction to C+ Programming, Professor Smith ); / display initial value of instructorName of GradeBook object cout gradeBook instructor name is: gradeBook.getInstructorName() nn; / modify the instructorName

9、using set function gradeBook.setInstructorName( Assistant Professor Bates ); / display new value of instructorName cout new gradeBook instructor name is: gradeBook.getInstructorName() nn; / display welcome message and instructors name gradeBook.displayMessage(); return 0; / indicate successful termi

10、nation / end main3.12类定义:class Accountpublic: Account( int ); / constructor initializes balance void credit( int ); / add an amount to the account balance void debit( int ); / subtract an amount from the account balance int getBalance(); / return the account balanceprivate: int balance; / data membe

11、r that stores the balance; / end class Account类成员函数:#include using std:cout;using std:endl;#include Account.h / include definition of class Account/ Account constructor initializes data member balanceAccount:Account( int initialBalance ) balance = 0; / assume that the balance begins at 0 / if initia

12、lBalance is greater than 0, set this value as the / balance of the Account; otherwise, balance remains 0 if ( initialBalance 0 ) balance = initialBalance; / if initialBalance is negative, print error message if ( initialBalance 0 ) cout Error: Initial balance cannot be negative.n balance ) / debit a

13、mount exceeds balance cout Debit amount exceeded account balance.n endl; if ( amount = balance ) / debit amount does not exceed balance balance = balance - amount; / end function debit/ return the account balanceint Account:getBalance() return balance; / gives the value of balance to the calling fun

14、ction / end function getBalance测试函数:#include using std:cout;using std:cin;using std:endl;/ include definition of class Account from Account.h#include Account.h/ function main begins program executionint main() Account account1( 50 ); / create Account object Account account2( 25 ); / create Account o

15、bject / display initial balance of each object cout account1 balance: $ account1.getBalance() endl; cout account2 balance: $ account2.getBalance() endl; int withdrawalAmount; / stores withdrawal amount read from user cout withdrawalAmount; / obtain user input cout nattempting to subtract withdrawalA

16、mount from account1 balancenn; account1.debit( withdrawalAmount ); / try to subtract from account1 / display balances cout account1 balance: $ account1.getBalance() endl; cout account2 balance: $ account2.getBalance() endl; cout withdrawalAmount; / obtain user input cout nattempting to subtract with

17、drawalAmount from account2 balancenn; account2.debit( withdrawalAmount ); / try to subtract from account2 / display balances cout account1 balance: $ account1.getBalance() endl; cout account2 balance: $ account2.getBalance() endl; return 0; / indicate successful termination / end main3.13类定义:#includ

18、e / program uses C+ standard string classusing std:string;/ Invoice class definitionclass Invoicepublic: / constructor initializes the four data members Invoice( string, string, int, int ); / set and get functions for the four data members void setPartNumber( string ); / part number string getPartNu

19、mber(); void setPartDescription( string ); / part description string getPartDescription(); void setQuantity( int ); / quantity int getQuantity(); void setPricePerItem( int ); / price per item int getPricePerItem(); / calculates invoice amount by multiplying quantity x price per item int getInvoiceAm

20、ount(); private: string partNumber; / the number of the part being sold string partDescription; / description of the part being sold int quantity; / how many of the items are being sold int pricePerItem; / price per item; / end class Invoice类成员函数:#include using std:cout;using std:endl;/ include defi

21、nition of class Invoice from Invoice.h#include Invoice.h/ Invoice constructor initializes the classs four data membersInvoice:Invoice( string number, string description, int count, int price ) setPartNumber( number ); / store partNumber setPartDescription( description ); / store partDescription setQ

22、uantity( count ); / validate and store quantity setPricePerItem( price ); / validate and store pricePerItem / end Invoice constructor/ set part numbervoid Invoice:setPartNumber( string number ) partNumber = number; / no validation needed / end function setPartNumber/ get part numberstring Invoice:ge

23、tPartNumber() return partNumber; / end function getPartNumber/ set part descriptionvoid Invoice:setPartDescription( string description ) partDescription = description; / no validation needed / end function setPartDescription/ get part descriptionstring Invoice:getPartDescription() return partDescrip

24、tion; / end function getPartDescription/ set quantity; if not positive, set to 0void Invoice:setQuantity( int count ) if ( count 0 ) / if quantity is positive quantity = count; / set quantity to count if ( count = 0 ) / if quantity is not positive quantity = 0; / set quantity to 0 cout 0 ) / if pric

25、e is positive pricePerItem = price; / set pricePerItem to price if ( price = 0 ) / if price is not positive pricePerItem = 0; / set pricePerItem to 0 cout npricePerItem cannot be negative. pricePerItem set to 0.n; / end if / end function setPricePerItem/ get price per itemint Invoice:getPricePerItem

26、() return pricePerItem; / end function getPricePerItem/ calulates invoice amount by multiplying quantity x price per itemint Invoice:getInvoiceAmount() return getQuantity() * getPricePerItem(); / end function getInvoiceAmount测试函数:#include using std:cout;using std:cin;using std:endl;/ include definit

27、ion of class Invoice from Invoice.h#include Invoice.h/ function main begins program executionint main() / create an Invoice object Invoice invoice( 12345, Hammer, 100, 5 ); / display the invoice data members and calculate the amount cout Part number: invoice.getPartNumber() endl; cout Part description: invoice.getPartDescription() endl; cout Quantity: invoice.getQu

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

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