派生类C ++ BankAccount程序

时间:2013-03-26 15:35:12

标签: c++ derived-class

我正在尝试使用派生类CheckingAccount创建BankAccount类。我遇到的问题如下:

  1. CheckingAccount应包含一个数据成员,以跟踪在该帐户上进行的提款交易的数量。每当提款时,这个数字都应该递增。
  2. 覆盖基类,取款功能,并添加从帐户中扣除交易费用的功能
  3. BankAccount.h

    class BankAccount {
    private:
        /* ATTRIBUTES */
        int accountNumber;
        double balance;
    
    public:
            /* METHODS */
        BankAccount();
    
        void setAccountNumber( int );
        void deposit( double );
    
        int getAccountNumber();
        int getBalance();
    
        double withdraw( double );
    };
    

    CheckingAccount.h

    #include "BankAccount.h"
    class CheckingAccount: public BankAccount {
    private:
            /* ATTRIBUTES */
        int withdrawalAmount;
        double balance;
    
            /* METHODS */
    public:
            /* METHODS */
        CheckingAccount();
    };
    

    CheckingAccount.cpp

    #include "CheckingAccount.h"
    
    CheckingAccount::CheckingAccount() {
    //Initialize
    }
    
    double CheckingAccount::withdraw( double a ) {
        //This doesn't work.
    }
    

1 个答案:

答案 0 :(得分:2)

只需在BankAccount类中进行虚拟撤销,并在CheckingAccount中声明它。

virtual double withdraw( double );