实现银行系统的储蓄账户和信用账户模式#include <iostream>
#include "account.h"
USING namespace std;
double Account::total = 0;
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)
{
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(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("余额不足");
}
else
{
record(date, -amount, desc);
acc.change(date, getBalance());
}
}
void SavingsAccount::settle(const Date &date)
{
//每年一月计算利息
if (date.getMonth() == 1)
{
double intrest = acc.getSum(date)*rate / (date - Date(date.getYear() - 1, 1, 1));
if (intrest != 0)
{
record(date, intrest, "存款利息");
acc.reset(date, getBalance());
}
}
}
//信用卡相关函数
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("信用额度不足");
}
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, "信用卡利息");
}
if (date.getMonth() == 1)
{
record(date, -fee, "信用卡年费");
}
acc.reset(date, getDebt());
}
void CreditAccount::show() const
{
Account::show();
cout << "\t可用信用额度:" << getAvaiLableCredit();
}
来源:搜素材网素材
搜素材网所有素材均为本站用户上传,仅供学习与参考,请勿用于商业用途,如有侵犯您的版权请联系客服服务QQ
本站提供各类html5响应式模板,前端js素材,网站模板,后台模板素材,程序源码素材。
由于技术有限本站不提供安装服务与bug修复,各类源码只提供分享服务,感谢您的理解。
如果对本站有任何意见请点击右侧侧边栏的反馈意见,我们会及时处理。