Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Sorry about that the language is C++ 11.10 (Account Inberitance Hierarcby) Create an inheritance hierarchy that a bank might use to represert ustomers bank accounts.
Sorry about that the language is C++
11.10 (Account Inberitance Hierarcby) Create an inheritance hierarchy that a bank might use to represert ustomers bank accounts. All customers at thisbank an deposit (i.e., credit money into theiraccous and wihdrai.c., debit) money from their accounts. Mor specific pes of acnts also exist. Savings accounts, for instance, carn interest on che money they hold. Checking accounts, on the other hand, charge a fee per transaction i.e, credit or debit) Create an inheriance hierarchy ci base class Account and derived classes Savings- Account and CheckingAccaunt tha from class Account. Bas class Accaunt should include one data member of type doub le to represent the account balance. The class should provide a coastrucoor that receives an inicial balance and uses it to initialize the data member The constructor should vali- date the initial balance to ensure that it's greater than or equal to 0.0. If not, the balance should he set to 0.0 and the constructor should display an error message, ndiaing that he was invalid. The class should provide three member funccions. Member funcrion credit should add an amount to the current balance. Member function debit should withdraw money ancd ensure that the debit amournt does not exceed the Account's balanceIit does, the balance should be left unchanged and t should pr the message "Debit anount exceeded account bl ance." Meber function geLBalance should rerurn the current balance. from the Account Derived class SavingsAccount should inherit the functionality of an Account, but also include a data member of type double indicaring the interest rate peentag assigned rthe Acont SavingsAccount's construc should reccive the initial balanoe. as well as an n value fr the SavingsAccount's interest rate. SavingsAccaunt should provide a public membe uncion calculateInterest that returns a double indicating the amount of interest earned by an account. Member function calculateInterest should determine this amount bymuiplyng the inrest tate by the auc balane. Note: Savings Acnt ould inerit memher fuctons credit and debi as is without rodefining them.] Derived class Checkingaccount should inherit from base class Account and include an addi tional data member of type double that represents the fee charged per transaction. Checking Account's csuc should reccive the initial balance, as well as a parameter indicating a fee amount. Class Checkingaccount should redefine member functions credit and desit so that they subtract the fee from the account balance whenever either transaction is performed successfully. CheckingAccount's versions of these furnctions should involke the base class Account version to per- form the updates o ao lance. Checkinghccount's debit function should chaige a fee only if moncy is actually withdrawn (i.c., the debit amount does not exceed the account balance. !Hint,' Define Accounts cebit function so that it returns a bool ndicating whether money was withdrawn. Then use the return value to determine whether a fee should be charged. After defining the classes in his hierarchy, write a program that creates objecis of cach class and tests their member functions. Add interest to the SavingsAccount object by first invoking its calculateInterest function, then passing the returned interest amount to the objects credit function 12.14 (Polymorphic Banking Program Using Account Hierarchy) Develop a polymorphic banking program using the Account hierarchy created in Exercise 11.10. Create a vector of Account pointers to SavingsAccount and CheckingAccount objects. For each Account in the vector, allow the user to specify an amount of money to withdraw from the Account using member function debit and an amount of money to deposit into the Account using member function credit. As you process each Account, determine its type. If an Account is a SavingsAccount, calculate the amount of interest owed to the Account using member function calculateInterest, then add the interest to the account balance using member function credit. After processing an Account, print the updated account balance obtained by invoking base-class member function getBalanceStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started