欢迎来到天天文库
浏览记录
ID:42105154
大小:156.00 KB
页数:17页
时间:2019-09-07
《(第6版)中文版编程练习答案第10章_电脑基础知识_IT》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、第10章1、//Customs.h#include#inelude#inelude#ineludeusingnamespacestd;classCustoms{private:stringname;stringaccnum;doublebalanee;public:Customs(conststring&client,conststring&num,doublebal=0.0);~Customs();voidshow()const;booldeposit(
2、doublecash);boolwithdraw(doublecash);};//Customs.epp#include"Customs.h”Customs::Customs(conststring&client’conststring&num,doublebal){accnum=num;name=dient;balanee=bal;}Customs::~Customs()boolCustoms::deposit(doublecash){if(cash<=0){cout«"Depositmustgreaterthanzero
3、n”;returnfalse;}else{cout«HCustomdeposits$H«cash«Hdolars.";balanee+=cash;returntrue;}}boolCustoms::withdraw(doublecash){讦(cash<=011(balanee•cash)<0){cout«"Withdrawmoneyerror;mustlessthanbalaneeandgreaterthanzero";returnfalse;}else{cout«''Customwithdraws$H«cash«H
4、dolars”;balanee■二cash;returntrue;}}voidCustoms::show()const{cout«HAccountcustom'snameisH«name«endl;cout«HAccountnumberis"«accnum«endl;cout«"Custom'sbalaneeisH«balance«endl;}//main.卬p#include"Customs.h"intmain()doubleinput,output;charch;Customscustom=Customs(,,Jack
5、yll/,lJcll,3000.32);custom.showf);cout«''PleaseenterAtodepositbalanee,H«HPtowithdrawbalanee,orQtoquit.:H;while(cin»ch&&toupper(ch)!='Q'){while(cin.get()!='')continue;if(!isalpha(ch)){cout«、a‘;continue;}switch(ch){case'A*:case。':cout«"Enteraaccountnumbertodeposit
6、:,f;cin>>input;if(!custom.deposit(input))cout«HAdderrorH;elsecout«"Addsuccess";break;caseP:case'p1:cout«"Enteraaccountnumbertowithdraw:,f;cin>>output;if(!custom.withdraw(output))cout«nWithdrawerrorH;elsecout«"WithdrawsuccessM;break;}custom.show();cout«"Pleas
7、eenterAtodepositbalanee八rf«HPtowithdrawbalanee,orQtoquit:n;}cout«"ByeXn11;cin.get();cin.get();return0;2、//person.h#ifndefPERSON_H_#definePERSON_H_#include#include#inelude#ineludeusingnamespacestd;classPerson{private:staticconstint
8、Person::LIMIT=25;stringlname;charfname[LIMIT];public:Person(){Iname=fname[0]=' *;}Personfconststring&ln,constchar*fn二"HeyyouJ;voidShow()c
此文档下载收益归作者所有