1. Engineering
  2. Computer Science
  3. create an inheritance hierarchy that a bank might use to...

Question: create an inheritance hierarchy that a bank might use to...

Question details

Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit money into their accounts and withdraw money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction.

Create an inheritance hierarchy containing base class Account and derived classes SavingsAccount and CheckingAccount that inherit from class Account. Base class Account should include data members like name, gender (male/female), phone number, address and account_balance. The class should provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0.0. If not, the balance should be set to 0.0, and the constructor should display an error message, indicating that the initial balance was invalid.

The class should provide three functions. The function Credit() should add an amount to the current balance. The function Debit() should withdraw amount from the account balance and ensure that he debit amount does not exceed the account balance. If it does, the balance should be left unchanged and the function should print the message “Debit amount exceeds account balance”. Function getBalance() should return the current balance.

Derived class SavingsAccount should inherit the functionality of the calss Account, but also include a data member interest-rate of type double indicating the interest rate (percentage). SavingsAccount’s constructor should receive the initial balance, as well as an initial interest_rate for the SavingsAccount. SavingsAccount should provide public method Calculate-Interest() that returns a double value indicating the amount of interest earned by an account. The function CalculateInterest() should determine this amount by multiplying the amount by the interest rate. [Note: the SavingsAccount should inherit the public functions Credit and Debit without redefining them.]

Derived class CheckingAccount should inherit the functionality of the class Account, but also include a data member fee-charged of type double indicating the fee charged per transaction (let’s say $0.50 per transaction). CheckingAccount’ s constructor should retrieve the initial balance, as well as a parameter indicating a fee amount. CheckingAccount should provide a public function IsFeeChareged() that returns a Boolean value indicating weather the fee amount is charged or not. If the transaction is successful then only fee must be charged. If the transaction is cancelled then the fee must not be charged. [Note: the CheckingAccount should inherit the public functions Credit and Debit as is without redefining them].

After defining the classes in this hierarchy, write a program that creates objects of each class and tests their functions. Add interest to the SavingsAccount object by first invoking its CalculateInteres() function, then passing the returned interest amount to the object’s Credit function

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution