c++个人银行账户管理3
在C++个人银行账户管理2的基础再设计一个基类Account用来表述所有账户的共性,然后将SavingsAccount类变为其派生类,此外还要再派生出用来表示信用账户的类CreditAccount。
整个程序分为5个文件:date.h account.h是类定义头文件,date.cpp account.cpp是类实现文件,main.cpp是主函数文件。
main.cpp
#include<iostream>
#include<string.h>
#include"date.h"
#include"account.h"
using namespace std;
double Account::total = 0;
int main()
{
Date d01(2008,11,5),d02(2008,12,5),d11(2008,11,25),d12(2008,12,20),d2(2009,1,1),dc1(2008,11,15),dc2(2008,12,1);
cout<<"--------------------------------"<<"1001"<<"------------------------------"<<endl;
SavingsAccount s0(2008,11,1,1001,0,0.015);
s0.deposit(d01,5000);
s0.deposit(d02,5500);
s0.settle(d2);
d2.show();
s0.show();
cout<<"------------------------------------------------------------------"<<endl;
cout<<"--------------------------------"<<"1002"<<"------------------------------"<<endl;
SavingsAccount s1(2008,11,1,1002,0,0.015);
s1.deposit(d11,10000);
s1.withdraw(d12,4000);
s1.settle(d2);
d2.show();
s1.show();
cout<<"------------------------------------------------------------------"<<endl;
cout<<"--------------------------------"<<"1003"<<"------------------------------"<<endl;
CreditAccount c0(2008,11,1,1003,0,10000,0.0005,50);
c0.deposit(dc1,2000);
c0.withdraw(dc2,2000);
c0.withdraw(dc2,-c0.getDebt(dc2)); //结算利息
c0.getDebt(d2);
d2.show();
c0.show();
cout<<"-----------------------------"<<"各账户总金额"<<"-------------------------"<<endl;
d2.show();
c0.getTotal();
cout<<"-------------------------------------------------------------------"<<endl;
}
account.h
#ifndef ACCOUNT_H_
#define