Need to get the following output by Editing Account.h ,Account.cpp, SavingAcooun
ID: 3803564 • Letter: N
Question
Need to get the following output by Editing Account.h ,Account.cpp, SavingAcoount.h and SavingAccount.cpp
Main.cpp and instructions included
***In this workshop, we 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).
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 it’s 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 Account’s 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 SavingsAccount’s constructor that receives the initial balance, as well as an initial value for the SavingsAccount’s 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.
SavingAcoount.h
#ifndef ICT_SAVINGSACCOUNT_H__
#define ICT_SAVINGSACCOUNT_H__
#include "Account.h"
using namespace std;
namespace ict{
class SavingsAccount : public Account{
private:
double interestRate; // interest rate (percentage)
public:
// TODO: put prototypes here
};
};
#endif
SavingAccount.cpp
#include "SavingsAccount.h"
using namespace std;
namespace ict{
// TODO: Implement SavingsAccount member functions here
}
Account.h
#ifndef ICT_ACCOUNT_H__
#define ICT_ACCOUNT_H__
#include <iostream>
using namespace std;
namespace ict{
class Account{
private:
double balance; // data member that stores the balance
protected:
double getBalance() const; // return the account balance
void setBalance( double ); // sets the account balance
public:
// TODO: Write a prototype for constructor which initializes balance
// TODDO: Write a function prototype for the virtual function credit
// TODO: Write a function prototype for the virtual function debit
// TODO: Write a function prototype for the virtual function display
};
};
#endif
Account.cpp
#include "Account.h"
using namespace std;
namespace ict{
// constructor
// credit (add) an amount to the account balance
// debit (subtract) an amount from the account balance return bool
double Account::getBalance() const
{
return balance;
}
void Account::setBalance( double newBalance )
{
balance = newBalance;
}
}
Main.cpp
#include <iostream>
#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;
}
Output:
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
-----------------------
#ifndef ICT_SAVINGSACCOUNT_H__
Explanation / Answer
char displayAccountSelectionMenu();
char displayAccountActionMenu();
void makeDeposit(Account *acct);
void withdraw(Account *acct);
int main()
{
Account Savings;
Account Checkings;
Account *acct = NULL;
char choice;
do
{
choice = displayAccountSelectionMenu();
switch (choice)
{
case 'A':
acct = &Savings;
break;
case 'B':
acct = &Checkings;
break;
case 'C':
return 0;
}
cout << fixed << showpoint << setprecision(2);
do
{
choice = displayAccountActionMenu();
switch (choice)
{
case 'A':
cout << "The current balance is $"
<< acct->getBalance() << endl;
break;
case 'B':
cout << "There have been "
<< acct->getTransactions()
<< " transactions." << endl;
break;
case 'C':
cout << "Interest earned for this period: $"
<< acct->getInterest() << endl;
break;
case 'D':
makeDeposit(acct);
break;
case 'E':
withdraw(acct);
break;
case 'F':
acct->calcInterest();
cout << "Interest added." << endl;
break;
case 'G':
break;
case 'H':
return 0;
}
}
while (choice != 'G');
}
while (true);
return 0;
}
char displayAccountSelectionMenu()
{
char choice;
cout << "Select an account: ";
cout << "A) Savings ";
cout << "B) Checking ";
cout << "C) Exit the program ";
cout << "Enter your choice: ";
cin >> choice;
choice = toupper(choice);
while ((choice < 'A') || (choice > 'C'))
{
cout << "Please make a choice in the range of A through C:";
cin >> choice;
choice = toupper(choice);
}
return choice;
}
char displayAccountActionMenu()
{
char choice;
cout << "Select an action: ";
cout << " Display the account balance ";
cout << " Display the number of transactions ";
cout << " Display interest earned for this period ";
cout << " Make a deposit ";
cout << " Make a withdrawal ";
cout << " Add interest for this period ";
cout << " Select a different account ";
cout << " Exit the program ";
cout << " Enter your choice: ";
cin >> choice;
choice = toupper(choice);
while ((choice < 'A') || (choice > 'H'))
{
cout << "Please make a choice in the range of A through H:";
cin >> choice;
choice = toupper(choice);
}
return choice;
}
void makeDeposit(Account *acct)
{
}
void withdraw(Account *acct)
{
// ...
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.