个人银行账户管理程序【简化】

//自学,对于“获得到指定日期为止的存款金额按日累加值”这句话理解不能T_T。因此修改类部分内容,忽略部分逻辑=_=……
#include    
#include   
using namespace std;

class SavingsAccount {       //储蓄账户类
private:
	int id;                  //账号
	double balance;          //余额
	double rate;             //存款的年利率
	double interest=0.0;     //利息   

	//记录一笔账,date为日期,amout为金额,desc为说明
	void record(int date, double amout);

public:
	SavingsAccount(int date, int id, double rate);
	int getID() { return id; }
	double getBalance() { return balance; }
	double getRate() { return rate; }
	void deposit(int date, double amount);
	void withdraw(int dadte, double amount);
	

	//结算利息
	double lixi(int date, double amount);

	//显示账户信息
	void show();
};


//SavingsAccount相关成员函数的实现
SavingsAccount::SavingsAccount(int date, int id, double rate)
	:id(id), balance(0), rate(rate) {
	cout << date << "\t#" << id << " is created" << endl;
}

void SavingsAccount::record(int date, double amount) {
	amount = floor(amount * 100+0.5)/100;              //floor函数的目的:保留小数点后两位
	balance += amount;
	cout << date << "\t#" << id << "\t" << amount <<"\t"<< balance << endl;
}

void SavingsAccount::deposit(int date, double amount) {
	record(date, amount);
	lixi(date, amount);
}

void SavingsAccount::withdraw(int date, double amount) {
	if (amount > getBalance())                   //如果要取的钱大于存款余额
		cout << "Error:not enough money" << endl;
	else
		record(date, -amount);
	    lixi(date, -amount);
}
 

void SavingsAccount::show() {
	cout << "#" << id << "\tBalance:" << (balance+interest)<

你可能感兴趣的:(个人银行账户管理程序【简化】)