您好,欢迎访问三七文档
C++课程设计报告学号:班级:13级计科二班姓名:指导教师:王定成个人银行综合实例一.设计目的将理论教学中涉及到的知识点贯穿起来,对不同的数据类型,程序控制结构,数据结构做一比较和总结,结合设计题目进行综合性应用,对所学知识打到融会贯通的程度。通过课程设计,学生在下述方面的能力应该得到提升:1)进一步巩固加深学生所学专业课程,理论联系实际,进一步培养学生综合分析能力,解决问题的能力。2)全面考核学生所掌握的基本理论知识及其实际业务能力,从而达到提高学生素质的最终目的。3)利用所学知识,开发小型应用系统,掌握运用C++语言编写调试应用系统程序,训练独立开发应用系统,进行数据处理的综合能力。4)对于给定的设计题目,如何进行分析,理清思路,并给出相应的数学模型。5)掌握面向对象程序设计的方法。6)熟练掌握C++语言的基本语法,灵活运用各种数据类型。7)进一步掌握在集成环境下如何调试程序和修改程序。二.设计说明:一个人可以有多个活期储蓄账户,一个活期储蓄账户包括账号(id),余额(balance),年利率(rate)等信息,还包括显示账户信息(show),存款(deposit),取款(withdraw),结算利息(settle)等操作。设计一个类SavingsAccount,将id,balance,rate均作为其成员数据,将show,deposit,withdraw,settle均作为其成员函数。无论存款,取款还是结算利息,都需要修改当前的余额并且将余额的变动输出,这些公共操作由私有成员函数record来执行。实现该类的难点在于利息的计算。由于账户的月是不断变化的,因此不能通过余额与年利率相乘的办法来计算年利,而是需要将一年当中每天的余额累积起来再除以一年的总天数,得到一个日均余额,再乘以年利率。为了计算余额的按日累积值,SavingsAccount引入了私有数据成员lastDate,accumulation和私有成员函数accumulate。lastDate用来存储上一次余额变动的日期,accumulation用来存储上次计算利息以后直到最近一次余额变动时余额按日累加的值,accumulate成员函数用来计算截至指定日期的账户余额按日累积值。三.源代码8-8.cpp#includeaccount.h#includeiostreamusingnamespacestd;intmain()//起始日期{Datedate(2008,11,1);//建立几个帐户SavingsAccountsa1(date,s3755217,0.015);SavingsAccountsa2(date,02342342,0.015);CreditAccountca(date,c5392394,10000,0.0005,50);Account*accounts[]={&sa1,&sa2,&ca};//账户总数constintn=sizeof(accounts)/sizeof(Account*);cout(d)deposit(w)withdraw(s)show(c)changeday(n)nextmonth(e)exitendl;charcmd;do{//显示日期和总金额date.show();cout\tTotal:Account::getTotal()\tcommand;intindex,day;doubleamount;stringdesc;cincmd;switch(cmd){case'd'://存入现金cinindexamount;getline(cin,desc);accounts[index]-deposit(date,amount,desc);break;case'w'://取出现金cinindexamount;getline(cin,desc);accounts[index]-withdraw(date,amount,desc);break;case's'://查询各帐户信息inti;for(i=0;in;i++){cout[i];accounts[i]-show();coutendl;}break;case'c'://改变日期cinday;if(daydate.getDay())coutYoucannotspecifyapreviousday;elseif(daydate.getMaxDay())coutInvalidday;elsedate=Date(date.getYear(),date.getMonth(),day);break;case'n'://进入下个月if(date.getMonth()==12)date=Date(date.getYear()+1,1,1);elsedate=Date(date.getYear(),date.getMonth()+1,1);for(i=0;in;i++)accounts[i]-settle(date);break;}}while(cmd!='e');return0;}account.cpp#includeaccount.h#includecmath#includeiostreamusingnamespacestd;doubleAccount::total=0;//Account类的实现Account::Account(constDate&date,conststring&id):id(id),balance(0){date.show();cout\t#idcreatedendl;}voidAccount::record(constDate&date,doubleamount,conststring&desc){amount=floor(amount*100+0.5)/100;//保留小数点后面两位balance+=amount;total+=amount;date.show();cout\t#id\tamount\tbalance\tdescendl;}voidAccount::error(conststring&msg)const{coutError(#id):msgendl;}//voidSavingsAccount::deposit(constDate&date,doubleamount,conststring&desc)//{record(date,amount,desc);}voidAccount::show()const{coutid\tBlancebalance;}//SavingsAccount类相关成员函数的实现SavingsAccount::SavingsAccount(constDate&date,conststring&id,doublerate):Account(date,id),rate(rate),acc(date,0){}voidSavingsAccount::deposit(constDate&date,doubleamount,conststring&desc){record(date,amount,desc);acc.change(date,getBalance());}voidSavingsAccount::withdraw(constDate&date,doubleamount,conststring&desc){if(amountgetBalance())error(notenoughmoney);else{record(date,-amount,desc);acc.change(date,getBalance());}}voidSavingsAccount::settle(constDate&date){if(date.getMonth()==1){doubleinterest=acc.getSum(date)*rate/(date-Date(date.getYear()-1,1,1));//计算年息if(interest!=0)record(date,interest,interest);acc.reset(date,getBalance());}}//CreditAccount类相关成员函数的实现CreditAccount::CreditAccount(constDate&date,conststring&id,doublecredit,doublerate,doublefee):Account(date,id),credit(credit),rate(rate),fee(fee),acc(date,0){}voidCreditAccount::deposit(constDate&date,doubleamount,conststring&desc){record(date,amount,desc);acc.change(date,getDebt());}voidCreditAccount::withdraw(constDate&date,doubleamount,conststring&desc){if(amount-getBalance()credit)error(notenoughcredit);else{record(date,-amount,desc);acc.change(date,getDebt());}}voidCreditAccount::settle(constDate&date){doubleinterest=acc.getSum(date)*rate;if(interest!=0)record(date,interest,interest);if(date.getMonth()==1)record(date,-fee,annualfee);acc.reset(date,getDebt());}voidCreditAccount::show()const{Account::show();cout\tAvailablecredit:getAvailableCredit();}account.h#ifndef_ACCOUNT_H_#define_ACCOUNT_H_#includedate.h#includeaccumulator.h#includestringclassAccount{//账户类private:std::stringid;//账号doublebalance;//余额staticdoubletotal;//所有账户的总金额protected://供派生类调用的构造函数,id为账户Account(constDate&date,conststd::string&id);//记录一笔账,date为日期,account为金额,desc为说明voidrecord(constDate&date,doubleamount,conststd::string&desc);//报告错误信息voiderror(conststd::string&msg)const;public:conststd::string&getId()const{returnid;}doublegetBalance()const{returnbalance;}staticdoublegetTotal(){returntotal;}//显示账户信息virtualvoiddeposit(constDate&date,doubleamount,conststd::string&desc)=0;virtualvoidwithdraw(constDate&date,doubleamount,conststd::string&desc)=0;virtualvoidsettle(constDate&date)=0;virtualvoidshow()const;};c
本文标题:c++实验报告
链接地址:https://www.777doc.com/doc-5234844 .html