Create a software 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 (ProfitAccount), for instance, earn interest on the money they hold. Checking accounts (CurrentAccount), on the other hand, charge a fee per transaction (i.e., deposit or withdraw). Develop an inheritance hierarchy containing base class Account and derived classes ProfitAccount and CurrentAccount that inherit from class Account. Base class Account should include one data member, bal, of type double to represent the 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, then 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 as follows. Member function deposit should add an amount to the current balance. Member function withdraw should withdraw money from the Account and ensure that the withdrawal amount does not exceed the Account's balance. If it does, the balance should be left unchanged and the function should display the message "Withdrawal amount exceeded account balance". Member function giveBalance should return the current balance. Derived class ProfitAccount should inherit the functionality of an Account, but also include a data member, rate, of type double indicating the interest rate (percentage). ProfitAccount's constructor should receive the initial balance, as well as an initial value for the ProfitAccount's interest rate. ProfitAccount should provide a public member function computeInterest that returns a double indicating the amount of interest earned by an account. Member function computeInterest should determine this amount by multiplying the interest rate by the account balance. [Note: ProfitAccount should inherit member functions deposit and withdraw as is without redefining them.] Derived class CurrentAccount should inherit from base class Account and include an additional data member of type double that represents the fee charged per transaction. CurrentAccount's constructor should receive the initial balance, as well as a parameter indicating a fee amount. Class CurrentAccount should redefine member functions deposit and withdraw so that they subtract the fee from the account balance whenever either transaction is performed successfully. CurrentAccount's versions of these functions should invoke the base-class Account version to perform the updates to an account balance. CurrentAccount's withdraw function should charge a fee only if money is actually withdrawn (i.e., the withdrawal amount does not exceed the account balance). [Hint: Define Account's withdraw 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 creates two objects of each class (one with valid balance amount and one with invalid balance amount) and tests their member functions. Add interest to the ProfitAccount object by first invoking its computeInterest function, then passing the returned interest amount to the object's deposit function. Create an array of four Account pointers to hold the addresses of ProfitAccount and CurrentAccount objects, using up-casting. For each Account in the array, specify an invalid and a valid amount of money to withdraw from the Account using member function withdraw and an amount of money to deposit into the Account using member function deposit. Remember to use virtual wherever required to process each Account, depending on the type of object. If an Account is a ProfitAccount, calculate the amount of interest owed to the Account using member function computeInterest after down-casting, then add the interest to the account balance using member function deposit. After processing an Account, print the updated account balance obtained by invoking base class member function giveBalance. (Object-Oriented Programming)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Create a software 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 (ProfitAccount), for instance, earn interest on the money they hold. Checking accounts (CurrentAccount), on the other hand, charge a fee per transaction (i.e., deposit or withdraw).

Develop an inheritance hierarchy containing base class Account and derived classes ProfitAccount and CurrentAccount that inherit from class Account. Base class Account should include one data member, bal, of type double to represent the 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, then 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 as follows. Member function deposit should add an amount to the current balance. Member function withdraw should withdraw money from the Account and ensure that the withdrawal amount does not exceed the Account's balance. If it does, the balance should be left unchanged and the function should display the message "Withdrawal amount exceeded account balance". Member function giveBalance should return the current balance.

Derived class ProfitAccount should inherit the functionality of an Account, but also include a data member, rate, of type double indicating the interest rate (percentage). ProfitAccount's constructor should receive the initial balance, as well as an initial value for the ProfitAccount's interest rate. ProfitAccount should provide a public member function computeInterest that returns a double indicating the amount of interest earned by an account. Member function computeInterest should determine this amount by multiplying the interest rate by the account balance. [Note: ProfitAccount should inherit member functions deposit and withdraw as is without redefining them.]

Derived class CurrentAccount should inherit from base class Account and include an additional data member of type double that represents the fee charged per transaction. CurrentAccount's constructor should receive the initial balance, as well as a parameter indicating a fee amount. Class CurrentAccount should redefine member functions deposit and withdraw so that they subtract the fee from the account balance whenever either transaction is performed successfully. CurrentAccount's versions of these functions should invoke the base-class Account version to perform the updates to an account balance. CurrentAccount's withdraw function should charge a fee only if money is actually withdrawn (i.e., the withdrawal amount does not exceed the account balance). [Hint: Define Account's withdraw 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 creates two objects of each class (one with valid balance amount and one with invalid balance amount) and tests their member functions. Add interest to the ProfitAccount object by first invoking its computeInterest function, then passing the returned interest amount to the object's deposit function. Create an array of four Account pointers to hold the addresses of ProfitAccount and CurrentAccount objects, using up-casting. For each Account in the array, specify an invalid and a valid amount of money to withdraw from the Account using member function withdraw and an amount of money to deposit into the Account using member function deposit. Remember to use virtual wherever required to process each Account, depending on the type of object. If an Account is a ProfitAccount, calculate the amount of interest owed to the Account using member function computeInterest after down-casting, then add the interest to the account balance using member function deposit. After processing an Account, print the updated account balance obtained by invoking base class member function giveBalance.

(Object-Oriented Programming)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY