#include using std::cout; using std::cin; using std::endl; class BankAccount { protected: double balance; public: BankAccount() { balance = 0; } double getBalance() { return balance; } void deposit(double amt) { balance += amt; } void withdrawl(double amt) { balance -= amt; } }; class NoOverdraftAccount : public BankAccount { public: void withdrawl(double amt) { if (amt <= getBalance()) { BankAccount::withdrawl(amt); } } }; class NoWithdrawlAccount : public BankAccount { public: void withdrawl(double amt) { } /* or to prevent use of withdrawl completely ... private: void withdrawl(double amt) { } */ }; class InterestAccount : public BankAccount { private: double rate; public: InterestAccount(double r) { rate = r; } void earnInterest() { balance = balance * (1+rate/100.0); } }; int main() { InterestAccount acct(5.2); acct.deposit(500); acct.deposit(300); acct.earnInterest(); cout << acct.getBalance() << endl; }