c++银行账户管理程序2
在 C++个人银行账户管理1的基础上进行以下改进:
(1)在类SavingsAccount中增加一个静态数据成员total,用来记录各个账户的总金额,并为其增加相应的静态成员函数getTotal用来对其进行访问。
(2)将类SavingsAccount中不需要改变对象状态的成员函数声明为常成员函数,比如getBalance等。
(3)增加日期类Date
整个程序分为5个文件:date.h account.h是类定义头文件,date.cpp account.cpp是类实现文件,main.cpp是主函数文件。
main.cpp
#include<iostream>
#include"date.h"
#include"account.h"
using namespace std;
double SavingsAccount::total = 0;
int main()
{
SavingsAccount s0(1001,0.015,2008,11,1);
SavingsAccount s1(1002,0.015,2008,11,1);
Date d01(2008,11,5),d02(2008,12,5),d11(2008,11,25),d12(2008,12,20),d2(2009,1,1);
s0.deposit(d01,5000);
s1.deposit(d11,10000);
s0.deposit(d02,5500);
s1.withdraw(d12,4000);
s0.settle(d2);
s1.settle(d2);
cout<<"-----------------------------------------------------------------------"<<endl;
s0.show();
s1.show();
cout<<"各账户总额:"<<s0.getTotal()<<endl;
}
account.h
#ifndef ACCOUNT_H_
#define <