Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write c++ code 19.10 (Account Inheritance Hierardyy) Create an inheritance hierarchy that a bank might use to represent customers' bank accounts. All customers at this

write c++ code

image text in transcribed

19.10 (Account Inheritance Hierardyy) Create an inheritance hierarchy that a bank might use to represent customers' bank accounts. All customers at this bank can deposit (i.e., credit) moncy into their accounts and withdraw (i.e., debit) money from their accounts. More specific types of accounts also cxist. Savings accounts, for instancc, carn interest on the moncy thcy hold. Checking accounts, on rhe orher hand, charge a fee per rransacrion (i.e., credit or debir). Create an inheritance hierarchy containing base class Account and derived classes SavingsAccount and CheckingAccount that inherit from class Account. Base class Account should include one data member of type double to represent the accounc 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's greater than or equal to 0.0. If not, the balance should be set to 0.0 and the construcror should display an error message, indicating that the inirial 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 Account and cnsure that the debit amount docs not cxcced the Account's balance. If it docs, the balance should be leff unchanged and the funcrion should print the message "Debit amount exceeded account ba7ance," Member function getbalance should return the current balance. Derived class SavingsAccount should inherit the functionality of an Account, but also include a data member of type double indicating the interest rate (percentage) assigned to the Account. SavingsAccount's constructor should receive the initial balance, as well as an initial value for the SavingsAccount's interest rate. SavingsAccount should provide a public member funcrion calcu1ateInterest that returns a double indicating the amount of interest earned by an account. Member funcrion calcu7ateInterest should determine this amount by mulriplying the interest rate by rhe account balance. [Note: SavingsAccount should inheric member funcrions credit and debit as is without redefining them.] Derived class CheckingAccount should inherit from base class Account and include an addirional dara member of rype double thar represents the fee charged per transacrion. CheckingAccount's constructor should receive the initial balance, as well as a parameter indicating a fee amount. Class CheckingAccount should redefine member funcrions credit and debit so thar they subtract the fee from the account balance whenever cither transaction is performed successfully. CheckingAccount's versions of these functions should invoke the base-class Account version to perform the updates to an account balance. CheckingAccount's 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 Account's debit function so that it returns a boo] indicating whether moncy 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 objects of cach class and rests their member functions. Add interest to the SavingsAccount object by first invoking its calculateInterest function, then passing the returned interest amount to the object's credit function

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2021 Workshops Biokdd Iwcfs Mlkgraphs Al Cares Protime Alsys 2021 Virtual Event September 27 30 2021 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Anna Fensel ,Jorge Martinez-Gil ,Lukas Fischer

1st Edition

3030871002, 978-3030871000

More Books

Students also viewed these Databases questions