Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I've been trying to keep up with C++ as much as I possibly can (studying at least 30 hours a week) but some of the

I've been trying to keep up with C++ as much as I possibly can (studying at least 30 hours a week) but some of the problems I'm tasked with seem way above my level of knowledge. I'm thankful for any insight:

Create an inheritance hierarchy that a bank might use to represent customers bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e., debit) 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 (i.e., credit or debit).

Create an inheritance hierarchy containing base-class Bank-Account and derived classes Savings and Checking that inherit from class Bank-Account. Base-class Bank-Account should include one data member of type double to represent the bank accounts 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 its 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 member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money from the Bank-Account and ensure that the debit amount does not exceed the Bank-Accounts balance. If it does, the balance should be left unchanged and the function should print the message The balance is less than the debit amount. Member function getBalance should return the current balance.

Derived class Savings should inherit the functionality of a Bank-Account, but also include a data member of type double indicating the interest rate (percentage) assigned to the Bank-Account. Savings constructor should receive the initial balance, as well as an initial value for the Savings interest rate. Savings should provide a public member function calculateInterest that returns a double indicating the amount of interest earned by an account. Member function calculateInterest should determine this amount by multiplying the interest rate by the bank account balance. [Note: Savings should inherit member functions credit and debit as is without redefining them.]

Derived-class Checking should inherit from base-class Bank-Account and include an additional data member of type double that represents the fee charged per transaction. Checkings constructor should receive the initial balance, as well as a parameter indicating a fee amount. Class Checking should redefine member functions credit and debit so that they subtract the fee from the account balance whenever either transaction is performed successfully. Checkings version of these functions should invoke the base-class Bank-Account to perform the updates to an account balance. Checkings debit function should charge a fee only if money is actually withdrawn (i.e., the debit amount does not exceed the account balance). [Hint: Define Bank-Accounts debit function so that it returns a bool indicating whether money was withdrawn. Then use the return value to determine whether a fee should be charged.]

After defining the classes in this hierarchy, write a program that:

1) Creates an object of Bank-Account, Savings, and Checking class. Each of the three objects should have an initial balance. The Savings object should also have an interest rate and the Checking object should also have a transaction fee.

2) Prints out the balance of all the three objects.

3) Debits a certain amount from all the three objects.

4) Prints out the balance of all the three objects (after the debits) in the previous step.

5) Credits a certain amount to all the three objects. Prints out the balance of all the three objects (after the credits) in the previous step.

6) Computes the interest for the Savings object and adds it to its balance, then prints out the new balance.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

(d) Estimate the factors? Which ones are significant?

Answered: 1 week ago

Question

2. Describe why we form relationships

Answered: 1 week ago

Question

5. Outline the predictable stages of most relationships

Answered: 1 week ago