Account作为其他类的基类,将其定义成抽象类,display() 和 withdrawl() 都是纯虚函数,后面用其实现多态。
//==================================
//account.h
//==================================
#pragma once
#include<string>
using std::string;
//--------------------------------
class Account {
string acntNumber;
double balance;
public:
Account(string acntNo, double balan = 0.0);
string getAcntNum()const { return acntNumber; }
double getBalan()const { return balance; }
void setBalan(double balan) { balance = balan; }
void deposit(double amount) { balance += amount; }
virtual void display()const = 0;
virtual void withdrawl(double amount) = 0;
bool operator==(const Account& a) { return acntNumber == a.acntNumber; }
};//==============================
Savings类是存款账户,包含账号、余额等信息,同时包含对象创建、存款、取款及显示等操作。
//================================
//savings.h