/* Four essential ingredients for having a polymorphic method call: * 1) Inheritance * 2) Virtual method (base class) * 3) Virtual method overridden in derived class * 4) Pointer or reference of the base class type, but pointing to/referencing the derived class */ #include #include #include "Account.h" #include "SavingsAccount.h" #include "CheckingAccount.h" using std::cout; using std::endl; using std::string; const double INTEREST_RATE = 1.2; // interest rate for savings account // display the header and then the account details void displayAccount( Account* acct, string header ){ cout << header << endl; acct->display(); cout << endl; } int main(){ SavingsAccount firstHome( 1234.56, INTEREST_RATE); CheckingAccount gasMoney( 78.90); displayAccount( &firstHome, "After initialization:"); displayAccount( &gasMoney, "After initialization:"); firstHome.deposit( 987.65); gasMoney.deposit( 12.34); firstHome.withdraw( 2000.00); int checkNumber = 234; gasMoney.processCheck( 55.55, checkNumber); Account& acctRef1 = firstHome; Account& acctRef2 = gasMoney; acctRef1.deposit( 3333.33 ); acctRef2.deposit( 66.66 ); acctRef1.withdraw( 3555.00 ); acctRef2.withdraw( 66.66 ); acctRef1.display(); acctRef2.display(); return 0; }