综合实例_个人银行账户管理程序(3)

发布时间:2021-06-08

SavingsAccount::settle(const Date &date)
{
double interest=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(const Date &date,const string &id,double credit,double rate,double fee)
:Account(date,id),credit(credit),rate(rate),fee(fee),acc(date,0){}
void CreditAccount::deposit(const Date &date,double amount,const string &desc)
{
record (date,amount,desc);
acc.change(date,getDebt());
}
void CreditAccount::withdraw(const Date &date,double amount,const string &desc)
{
if(amount-getBalance()>credit)
{
error("not enough money");
}
else
record(date,-amount,desc);
acc.change(date,getDebt());
}
void CreditAccount::settle(const Date &date)
{
double interest=acc.getSum(date)*rate;
if (interest!=0) record(date,interest,"interest");
if (date.getMonth ()==1)
record(date,-fee,"annual fee");
acc.reset(date,getDebt());
}

void CreditAccount::show() const
{
Account::show();
cout<<"\tAvailable credit:"<<getAvailableCredit();
}



//8_8.cpp
#include "account.h"
#include <iostream>
using namespace std;
void main()
{
Date date(2008,11,1); //起始日期
//建立几个账户
SavingsAccount sa1(date,"03755217",0.015);
SavingsAccount sa2(date,"02342342",0.015);
CreditAccount ca(date,"C5392394",1000,0.0005,50);
Account*accounts[]={&sa1,&sa2,&ca};
const int n=sizeof(accounts)/sizeof(Account*);//账户总数

cout<<"(d)desposit (w)withdraw (s)show (c)change day (n)next month (e)exit"<<endl;
char cmd;
do
{
date.show();//显示日期和总金额
cout<<"\tTotal:"<<Account::getTotal ()<<"\tcommand>";
int index,day;
double amount;
string desc;

cin>>cmd;
switch (cmd)
{
case 'd'://存入现金
cin>>index>>amount;
getline(cin,desc);
accounts[index]->deposit (date,amount,desc);
break;

case 'w'://取出现金
cin>>index>>amount;
getline(cin,desc);
accounts[index]->withdraw (date,amount,desc);
break;

case 's'://查询各账户信息
for (int i=0; i<n; i++)
{
cout<<"["<<i<<"]";
accounts[i]->show ();
cout<<endl;
}
break;

case 'c'://改变日期
cin>>day;
if (day<date.getDay ())
cout<<"You cannot specify a previous day";
else if (day>date.getMaxDay ())
cout<<"Invalid day";
else
date=Date(date.getYear (),date.getMonth (),day);
break;

case 'n':
if(date.getMonth ()==12)
date=Date(date.getYear ()+1,1,1);
else

date=Date(date.getYear(),date.getMonth()+1,1);

for(i=0;i<n;i++)
accounts[i]->settle(date);
break;
}

}
while (cmd!='e');
}

综合实例_个人银行账户管理程序(3).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219