#include<iostream>
#include<iomanip>
using namespace std;
#define NUM 30
struct Deal//定义结构体记录交易
{
string time;//交易日期
double amount;//交易金钱数量
};
class Bank
{
private:
int _count;//账户
double _restMoney;//账户余额
string _date;//日期
public:
//定义结构体数组,记录近NUM天的交易记录
static struct Deal deals[NUM];
static int index;//记录索引
public:
Bank(int cout,string date,double restMoney=0);
void backin(double money,string date);//存钱
void bankout(double money,string date);//取钱
double getMoney();//查询余额
void showDeals();//查询交易明细
};
struct Deal Bank::deals[30];//初始化结构体数组
int Bank::index=0;
//构造函数,创建账户:账号、开户日期、余额
Bank::Bank(int count,string date,double restMoney)
{
_count=count;
_date=date;
deals[index].time=date;
deals[index].amount=restMoney;
index++;
_restMoney=restMoney;
}
void Bank::backin(double money,string date)
{
_restMoney+=money;//余额增加
_date=date;//记录日期
deals[index].time=date;//记录交易时间
deals[index].amount=money;//记录交易金钱数量
index++;//索引自增
}
void Bank::bankout(double money,string date)
{
_restMoney-=money;//余额减少
_date=date;//记录日期
deals[index].time=date;//记录交易时间
deals[index].amount=-money;//记录交易金钱数量
index++;//索引自增
}
double Bank::getMoney()//查询余额
{
return _restMoney;
}
void Bank::showDeals()//查询交易明细
{
for(int i=0;i<Bank::index;i++)
{
cout<<Bank::deals[i].time<<":"<<Bank::deals[i].amount<<endl;
}
}
int main()
{
//创建银行账户
Bank b(123456,"2020-01-14",100);
//存钱
b.backin(10000,"2020-03-02");
//查询余额
cout<<"账户余额:"<<b.getMoney()<<endl;
//取钱
b.bankout(5000,"2020-05-26");
//查询余额
cout<<"账户余额:"<<b.getMoney()<<endl;
//查询交易明细
b.showDeals();
return 0;
}