Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | May 2017 |
Last Sign in: | 307 Weeks Ago, 4 Days Ago |
Questions Answered: | 66690 |
Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
C++ Polymorphism
Â
First of all, list the four essential ingredients for having a polymorphic method call in the multi-line comment at the top of the .cpp file. Label the code (including in main()) with comments where each of the four ingredients is manifest. Additionally, add a comment indicating the polymorphic call. Furthermore, add four classes. First, add an abstract base class named Account. Choose the method to make it an abstract base class wisely. Additionally, add a SavingsAccount, aCheckingAccount, and a CDAccount each of which inherits from Account. Make sure you put the common private data members and member methods in Account.
Â
Finally, when your code is executed, the output must match this.
(Bank account index 0) Savings Account Information: Balance: $222.21 Interest rate: 1.2% (Bank account index 1) Checking Account Information: Balance: $5.69 Last check number processed: 234 (Bank account index 2) CD Account Information: Balance: $5000 Interest rate: 2.5% Maturity: 6 months /* Four essential ingredients for having a polymorphic method call: * 1) * 2) * 3) * 4) */ #include <iostream> using std::cout; using std::endl; // add class declaration and implementations HERE const double SAVINGS_INTEREST_RATE = 1.2; const double CD_INTEREST_RATE = 2.5; const int NUM_BANK_ACCOUNTS = 3; int main(){ SavingsAccount firstHome( 1234.56, SAVINGS_INTEREST_RATE); CheckingAccount gasMoney( 78.90); CDAccount tuition( 5000.00, CD_INTEREST_RATE, 6); Account* bankAccounts[ NUM_BANK_ACCOUNTS ]; // array of 3 Account pointers firstHome.deposit( 987.65); gasMoney.deposit( 12.34); firstHome.withdraw( 2000.00); int checkNumber = 234; gasMoney.processCheck( 55.55, checkNumber); bankAccounts[0] = &firstHome; bankAccounts[1] = &gasMoney; bankAccounts[2] = &tuition; bankAccounts[1]->deposit( 20.00); bankAccounts[1]->withdraw( 50.00); for( int i = 0; i < NUM_BANK_ACCOUNTS; i++){ cout << "(Bank account index " << i << ")\n"; bankAccounts[i]->printInfo(); cout << endl; } return 0; }
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll