Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need the code (VISUAL BASIC) for the following: (Account Inheritance Hierarchy) Create an inheritance hierarchythat a bank might use to represent customers' bank accounts.

I need the code (VISUAL BASIC) for the following: (Account Inheritance Hierarchy) Create an inheritance hierarchythat a bank might use to represent customers' bank accounts. All customers at this bank can deposit (i.e., credit) money into theiraccounts and withdraw (i.e., debit) money from their accounts. Morespecific types of accounts also exist. Savings accounts, forinstance, 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 andderived classes SavingsAccount and CheckingAccount that inheritfrom class Account. Base class Account should include one datamember of type double to represent the account balance. The classshould provide a constructor that receives an initial balance anduses it to initialize the data member. The constructor shouldvalidate the initial balance to ensure that it is greater than orequal to 0.0. If not, the balance should be set to 0.0 and theconstructor should display an error message, indicating that theinitial balance was invalid. The class should provide three memberfunctions. Member function credit should add an amount to thecurrent balance. Member function debit should withdraw money fromthe Account and ensure that the debit amount does not exceed theAccount's balance. If it does, the balance should be left unchangedand the function should print the message "Debit amount exceededaccount balance." Member function getBalance should return thecurrent balance. Derived class SavingsAccount should inherit the functionality of anAccount, but also include a data member of type double indicatingthe interest rate (percentage) assigned to the Account.SavingsAccount's constructor should receive the initial balance, aswell as an initial value for the SavingsAccount's interest rate.SavingsAccount should provide a public member functioncalculateInterest that returns a double indicating the amount ofinterest earned by an account. Member function calculateInterestshould determine this amount by multiplying the interest rate bythe account balance. [Note: SavingsAccount should inherit memberfunctions credit and debit as is without redefining them.] Derived class CheckingAccount should inherit from base classAccount and include an additional data member of type double thatrepresents the fee charged per transaction. CheckingAccount'sconstructor should receive the initial balance, as well as aparameter indicating a fee amount. Class CheckingAccount shouldredefine member functions credit and debit so that they subtractthe fee from the account balance whenever either transaction isperformed successfully. CheckingAccount's versions of thesefunctions should invoke the base-class Account version to performthe updates to an account balance. CheckingAccount's debit functionshould charge a fee only if money is actually withdrawn (i.e., thedebit amount does not exceed the account balance). [Hint: DefineAccount's debit function so that it returns a bool indicatingwhether money was withdrawn. Then use the return value to determinewhether a fee should be charged.] After defining the classes in this hierarchy, write an app thatcreates objects of each class and tests their member functions. Add interest to the SavingsAccount object by first invoking its calculate Interest function, then passing the returned interestamount 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

More Books

Students also viewed these Databases questions

Question

What were the reasons for your conversion or resistance?

Answered: 1 week ago