C++ primer plus中文编程练习答案第10章.docx
《C++ primer plus中文编程练习答案第10章.docx》由会员分享,可在线阅读,更多相关《C++ primer plus中文编程练习答案第10章.docx(13页珍藏版)》请在三一办公上搜索。
1、C+ primer plus中文编程练习答案第10章第10章 1、 /Customs.h #include #include #include #include using namespace std; class Customs private: string name; stringaccnum; double balance; public: Customs(const string &client, const string &num, double bal = 0.0); Customs; void showconst; bool deposit(double cash); bool
2、 withdraw(double cash); ; /Customs.cpp #include Customs.h Customs:Customs(const string &client,const string &num, double bal) accnum = num; name = client; balance = bal; Customs:Customs bool Customs:deposit(double cash) if (cash = 0) cout Deposit must greater than zeron; return false; else cout Cust
3、om deposits $ cash dolars.n; balance += cash; return true; bool Customs:withdraw(double cash) if (cash = 0 | (balance - cash) 0) cout Withdraw money error, must less than balance and greater than zeron; return false; else cout Custom withdraws $ cash dolarsn; balance -= cash; return true; void Custo
4、ms:showconst cout Account customs name is name endl; cout Account number is accnumendl; cout Customs balance is balance endl; /main.cpp #include Customs.h int main double input, output; charch; Customs custom=Customs(Jacky,Jc,3000.32); custom.show; cout Please enter A to deposit balance ,n ch&touppe
5、r(ch)!=Q) while (cin.get != n) continue; if (!isalpha(ch) cout a; continue; switch (ch) caseA: casea: cout input; if (!custom.deposit(input) cout Add errorn; else cout Add successn; break; caseP: casep: cout output; if (!custom.withdraw(output) cout Withdraw errorn; else cout Withdraw successn; brea
6、k; custom.show; cout Please enter A to deposit balance ,n P to withdraw balance, or Q to quit: ; cout Byen; cin.get; cin.get; return 0; 2、 /person.h #ifndef PERSON_H_ #define PERSON_H_ #include #include #include #include using namespace std; class Person private: staticconstint Person:LIMIT = 25; st
7、ringlname; charfnameLIMIT; public: Person lname = ; fname0 = 0; Person(const string &ln, const char *fn = Heyyou); void Showconst; voidFormalShowconst; ; #endif /person.cpp #include person.h Person:Person(const string &ln, const char *fn) lname = ln; strncpy_s(fname, fn, LIMIT); fnameLIMIT = 0; void
8、 Person:Showconst coutfname lname; void Person:FormalShowconst coutlname , fname; /usePerson.cpp #include person.h int main Person one; Person two(Smythecraft); Person three(Dimwiddy, Sam); one.Show; coutendl; one.FormalShow; coutendl; two.Show; coutendl; two.FormalShow; coutendl; three.Show; couten
9、dl; three.FormalShow; coutendl; cin.get; return 0; 3、 /golf.h #ifndef GOLF_H_ #define GOLF_H_ #include #include using namespace std; class golf private: staticconstint Len = 40; charfullnameLen; int handicap; public: golf; golf(const char *name, inthc = 0); golf(golf &g); golf; voidhandicapf(inthc);
10、 void showconst; ; #endif /golf.cpp #include golf.h golf:golf golf:golf(const char *name, inthc) strncpy_s(fullname, name, Len); fullnameLen = 0; handicap = hc; golf:golf(golf &g) strncpy_s(this-fullname, g.fullname, Len); this-handicap = g.handicap; golf:golf void golf:handicapf( inthc) handicap =
11、hc; void golf:showconst coutfullname , handicap endl; /main.cpp #include golf.h int main char name40 = 0; int no; cout Enter a name: ; cin.getline(name, 40); cout no; golfann(name, no); ann.show; golfandy = golf(ann); andy.show; cin.get; cin.get; return 0; 4、 /Sales.h #ifndef SALE_H_ #define SALE_H_
12、 #include #include using namespace std; namespace SALES class Sales private: staticconstint QUARTERS = 4; double salesQUARTERS; double average; double max; double min; public: Sales; Sales(const double *ar); Sales(Sales &s); Sales; voidshowSalesconst; ; #endif /Sales.cpp #include Sales.h using names
13、pace SALES; Sales:Sales salesQUARTERS = 0; average = 0.0; max = 0.0; min = 0.0; Sales:Sales(const double *ar) double sum=0.0; for (inti = 0; i QUARTERS; i+) salesi = ari; sum += salesi; average = sum / QUARTERS; max = sales0; for (inti = 0; i QUARTERS-1; i+) if (salesi salesi + 1) max = salesi + 1;
14、min = sales0; for (inti = 0; i salesi + 1) min = salesi + 1; Sales:Sales(Sales &s) for (inti = 0; isalesi = s.salesi; this-average = s.average; this-max = s.max; this-min = s.min; Sales:Sales void Sales:showSalesconst cout The sales number is n; for (inti = 0; i QUARTERS; i+) cout salesi ; coutendl;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ primer plus中文编程练习答案第10章 plus 中文 编程 练习 答案 10
链接地址:https://www.31ppt.com/p-3153657.html