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

发布时间:2021-06-08

账户信息

virtual void show() const;
};

class SavingsAccount:public Account //储蓄账户类
{
private:
Accumulator acc;//辅助计算利息的累加器
double rate;//存款的年利率

public:
//构造函数
SavingsAccount(const Date &date,const std::string &id,double rate);
double getRate() const {return rate;}
void deposit(const Date &date,double amount,const std::string &desc); //存入现金
void withdraw(const Date &date,double amount,const std::string &desc); //取出现金
void settle(const Date &date); //结算利息,每年1月1日调用一次该函数
void show() const; //显示账户信息

};
class CreditAccount:public Account //信用账户类
{
private:
Accumulator acc;//辅助计算利息的累加器
double credit;//信用额度
double rate;//欠款的日利率
double fee;//信用卡年费
double getDebt() const//获得欠款额
{
double balance=getBalance();
return (balance<0?balance:0);
}
public:
//构造函数
CreditAccount(const Date &date,const std::string &id,double credit,double rate,double fee);
double getCredit() const{return credit;}
double getRate() const{return rate;}
double getFee() const{return fee;}
double getAvailableCredit() const//获得可用信用额度
{
if(getBalance()<0)
return credit+getBalance();
else
return credit;
}
void deposit(const Date &date,double amount,const std::string &desc); //存入现金
void withdraw(const Date &date,double amount,const std::string &desc); //取出现金
void settle(const Date &date); //结算利息,每年1月1日调用一次该函数
void show() const; //显示账户信息
};
#endif//__ACOUNT_H__



//account.cpp
#include "account.h"
#include <cmath>
#include <iostream>
using namespace std;

double Account::total=0;
//Accout类的实现
Account::Account(const Date &date,const string &id):id(id),balance(0)
{
date.show();
cout<<"\t#"<<id<<"created"<<endl;
}

void Account::record(const Date &date,double amount,const string &desc)
{
amount=floor(amount*100+0.5)/100; //保留小数点后两位
balance+=amount;
total+=amount;
date.show ();
cout<<"\t#"<<id<<"\t"<<amount<<"\t"<<balance<<"\t"<<desc<<endl;
}
void Account::show() const
{
cout<<id<<"\tBalance:"<<balance;
}
void Account::error(const string &msg)const
{
cout<<"Error(#"<<id<<"):"<<msg<<endl;
}

//SavingsAccount类相关成员函数的实现
SavingsAccount::SavingsAccount(const Date &date,const string &id,double rate):Account(date,id),rate(rate),acc(date,0){}
void SavingsAccount::deposit(const Date &date,double amount,const string &desc)
{
record (date,amount,desc);
acc.change(date,getBalance());
}
void SavingsAccount::withdraw(const Date &date,double amount,const string &desc)
{
if(amount>getBalance())
error("not enough money");

else
record(date,-amount,desc);
acc.change(date,getBalance());
}
void

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

精彩图片

热门精选

大家正在看

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

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

支付方式:

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

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