Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Account Class: The Account class is designed to represent customers bank accounts (base class). It includes a data member (of type double) to represent the

Account Class: The Account class is designed to represent customers bank accounts (base class). It includes a data member (of type double) to represent the account balance. This class provides a constructor that receives an initial balance and uses it to initialize the data member. Write the constructor that validates the initial balance to ensure that its greater than or equal to 0. If not, set the balance to the safe empty state (balance equals to -1.0). Write the virtual member function credit that adds an amount to the current balance. Write the virtual member function debit that withdraws money from the account and ensure that the debit amount does not exceed the Accounts balance. If the balance is less the amount, the balance should be left unchanged and the function should return false (otherwise it should return true). Add the prototype of pure virtual function display that receives a reference to ostream. This function needs to be overridden by the classes derived from the Account class. NOTE: The getBalance and setBalance have been already defined as the protected function in Account class so they can be used in any member function of the derived class. SavingsAccount: Derived class SavingsAccount that inherits the functionality of an Account, but also include a data member of type double indicating the interest rate (for example 0.12) assigned to the Account (interestRate). Write the SavingsAccounts constructor that receives the initial balance, as well as an initial value for the SavingsAccounts interest rate, and then initializes the object. If interest rate is less than zero, the interstRate will be set to zero. Write the public member function calculateInterest for SavingsAccount class that returns the amount of interest earned by an account. Member function calculateInterest should determine this amount by multiplying the interest rate by the account balance. Note: SavingsAccount should inherit member functions credit and debit as are without redefining them. Override the display function in the Account class that print a SavingsAccount in the following format (this is an example): Account type: Saving Balance: $ 400.00 Interest Rate (%): 12.00 The following code (w8_in_lab.cpp) will test your code: // OOP244 Workshop 8: Virtual Functions // File: 244_w8_home.cpp // Version: 1.0 // Date: 2017/03/15 // Author: Heidar Davoudi // Description: // This file tests in_lab section of your workshop /////////////////////////////////////////////////// #include #include "Account.h" #include "SavingsAccount.h" using namespace ict; using namespace std; int main() { // Create Account for Angelina Account * Angelina_Account[2]; // initialize Angelina Accounts (Both Saving) Angelina_Account[ 0 ] = new SavingsAccount( 400.0, 0.12 ); Angelina_Account[ 1 ] = new SavingsAccount( 600.0, 0.15 ); cout << "**************************" << endl; cout << "DISPLAY Angelina Accounts:" << endl; cout << "**************************" << endl; Angelina_Account[0]->display(cout); cout << "-----------------------" << endl; Angelina_Account[1]->display(cout); cout << "**************************" << endl ; cout << "DEPOSIT $ 2000 $ into Angelina Accounts ..." << endl ; for(int i=0 ; i < 2 ; i++){ Angelina_Account[i]->credit(2000); } cout << "WITHDRAW $ 1000 and $ 500 from Angelina Accounts ..." << endl ; Angelina_Account[0]->debit(1000); Angelina_Account[1]->debit(500); cout << "**************************" << endl; cout << "DISPLAY Angelina Accounts:" << endl; cout << "**************************" << endl; Angelina_Account[0]->display(cout); cout << "Interest is: " << ((SavingsAccount *) Angelina_Account[0])->calculateInterest() << endl; cout << "-----------------------" << endl; Angelina_Account[1]->display(cout); cout << "Interest is: " << ((SavingsAccount *) Angelina_Account[1])->calculateInterest() << endl; cout << "-----------------------" << endl; return 0; } The following is the exact output of the tester program: Account type: Saving Balance: $ 400.00 Interest Rate (%): 12.00 ----------------------- Account type: Saving Balance: $ 600.00 Interest Rate (%): 15.00 ************************** DEPOSIT $ 2000 $ into Angelina Accounts ... WITHDRAW $ 1000 and $ 500 from Angelina Accounts ... ************************** DISPLAY Angelina Accounts: ************************** Account type: Saving Balance: $ 1400.00 Interest Rate (%): 12.00 Interest is: 168.00 ----------------------- Account type: Saving Balance: $ 2100.00 Interest Rate (%): 15.00 Interest is: 315.00 -----------------------

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

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions

Question

List the types of turnover.

Answered: 1 week ago