设计一个Bank类,实现银行某账号的资金往来账目管理

设计一个Bank类,实现银行某账号的资金往来账目管理,包括建账号、存入、取出等 Bank类包括私有数据成员账号numberrest(账户余额)和成功操作的交易记录string records[50](或者char records[50][100])。每一条记录包含的信息有:交易时间(精确到秒)、交易类型(存钱和取钱)和交易金额,Bank类有一个构造函数(设置账号和初始余额)和三个成员函数bankin(double m)(处理存入账)bankout( double m)处理取出账)disp(Bank b) (输出明细账)

#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
using namespace std;
int i = 0;

class Bank {
private:
	struct tm* p[50];
	time_t now = time(0);
	int number;
	double rest;
	string records[50];
	double arr[50];

public:
	Bank(int num,double re) {
		number = num;
		rest = re;
	}
	void bankin(double m) {
		p[i] = localtime(&now);
		rest += m;
		arr[i] = m;
		records[i++] ="存入";
	}
	void bankout(double m) {
		p[i] = localtime(&now);
		arr[i] ;
		rest -= m;
		arr[i] = m;
		records[i++] = "取出";
	}
	void disp(Bank b) {
		int j = 0;
		cout << "账号:" << number << endl;
		cout << "账户余额:" << rest << endl;
			for(;j < i; j++)
			{
				cout << "交易记录:" << endl;
				cout << records[j]<<" " << arr[j]<<" ";
				printf("%d/%d/%d %02d:%02d:%02d\n", 1900 + p[j]->tm_year, 1 + p[j]->tm_mon, p[j]->tm_mday, p[j]->tm_hour, p[j]->tm_min, p[j]->tm_sec);
		}

	}
};

int main()
{
	Bank s1(10001,0.0);
	s1.bankin(800.0);
	s1.bankout(300.0);
	s1.disp(s1);
	return 0;
}

其中最主要的就是时间的获取和时间数据的存储。

你可能感兴趣的:(c++)