// File: account.h // Header file for the account class class account { protected: double balance; // current balance public: account(double bal); // the constructor account(void); // default constructor void deposit(double amt); double getBalance(void); }; // account // File: account.cpp // implementation file for the account class #include "account.h" account::account(double bal) { balance = bal; } account::account(void) { balance = 0; } void account::deposit(double amt) { balance += amt; } double account::getBalance(void) { return balance; } // file accountDemo.cpp #include #include "account.h" void main(void) { account a(50.45), b; // a has $50.45, b has $0.0 initially a.deposit(30); cout << " account a now has $" << a.getBalance() << endl; b.deposit(130); cout << " account a now has $" << b.getBalance() << endl; } // File: checkingAccount.h // header file for the checkingAccount class #include "account.h" class checkingAccount : public account // inherits from account class { protected: double limit; // lower limit for free checking double charge; // per-check charge for low balance public: checkingAccount(double bal, double lim, double chg); double cashCheck(double amt); }; // File: checkingAccount.cpp // implementation file for class checkingAccount #include "checkingAccount.h" checkingAccount::checkingAccount( double bal, double lim, double chg) : account( bal ) { limit = lim; charge = chg; } double checkingAccount::cashCheck(double amt) { if ((balance < limit) && (amt + charge <= balance)) { balance -= amt + charge; return amt + charge; } else if ((balance >= limit) && (amt <= balance)) { balance -= amt; return amt; } else return 0.0; }