Please help with the following. READ INSTRUCTIONS CAREFULLY PLEASE Extend the in
ID: 3911070 • Letter: P
Question
Please help with the following. READ INSTRUCTIONS CAREFULLY PLEASE
Extend the inheritance hierarchy from the previous project by changing the classes to template classes. Do not worry about rounding in classes that are instantiated as integer classes, you may just use the default rounding. You will add an additional data member, method, and bank account type that inherits SavingsAccount (“CD”, or certificate of deposit).
1. Account class
Change to a template class and add/modify the following items.
1.1 Data Members
accountNumber (string)
1.2 Member Functions
Constructors
Add accountNumber to the constructor.
Accessors
string getAccountNumber() Returns the account number.
void displayAccount() Prints the account type, fee or interest rate, and balance. Determine if this should be virtual, pure virtual, or regular.
2 SavingsAccount class
Change to a template class. Add accountNumber to the constructor. You may make interestRate ‘protected’ so you can directly access it in CDAccount. No other modifications.
3 CheckingAccount class
Change to a template class. Add accountNumber to the constructor. No other modifications.
4 CDAccount class
Implement a template class that is derived from SavingsAccount class.
4.1 Data Members
No additional data members (inherits its data members).
4.2 Member Functions
Constructors
Defines a parameterized constructor which calls the SavingsAccount constructor.
Destructor
Defines destructor. If you have allocated memory, clean it up.
Mutators
void debit(amount) Redefines the member function to debit nothing from the balance and return false, since you are not allowed to debit from a CD during its term.
void credit(amount) Invokes the base class credit member function to add to the account.
5 The Driver Program
In your driver, prompt the user for input as shown below. Create two vectors (savingsAccounts and checkingAccounts). The first has Account pointers with type double that point to a CD and a Savings account, the second has Account pointers with integer type and point to two Checking accounts. Initialize the objects with the user’s input and appropriate constructors.
Next, create a loop that, for each savingsAccount, allows the user to deposit and withdraw from the account using the base class member functions. After withdrawing and depositing, downcast to a SavingsAccount pointer and add interest. Print the updated information by invoking the base class member function dis- playAccount().
Create another loop for each checkingAccount that allows the user to deposit and withdraw from the account using the base class member functions. After withdrawing and depositing, print the updated information by invoking the base class member function displayAccount(). Verify that, even if doubles are passed to the constructor, their values are coerced to integers.
Extended Banking
5.1 Example input:
CD Account 1
Please enter the account number: 98765432 Please enter the balance: 70
Please enter the interest rate: 0.1
(repeat for the savings account)
Checking Account 1
Please enter the account number: 01010101 Please enter the balance: 70.55
Please enter the fee: 1.99
(repeat for next checking account)
5.2 Example output:
CD Account 1 balance: $70.00
Enter an amount to withdraw from Account 1: 10.00
Cannot debit from a CD account.
Enter an amount to deposit into Account 1: 35.00
Adding $10.50 interest to Account 1
CD account 01234567 has an interest rate of 0.10 and a balance of $115.50
Checking Account 1 balance: $70
Enter an amount to withdraw from Account 1: 9.99 0
$1 transaction fee charged
Enter an amount to deposit into Account 1: .99
$1 transaction fee charged.
Checking account 01010101 has a $1 transaction fee and a balance of $59
My code from the past project is the following:
Driver.cpp
#include "account.h"
Account.h
Account.cpp
#include "account.h"
Savingsaccount.h
#ifndef SAVINGSACCOUNT_H
savingsaccount.cpp
#include "savingsaccount.h"
checkingaccount.h
#ifndef CHECKINGACCOUNT_H
checkingaccount.cpp
#include
Explanation / Answer
savings.cpp
#include <iostream>
#include "savings.h"
using namespace std;
Savings::Savings(int accNum, double newBalance) : Account(accNum, newBalance)
{
setBalance(newBalance);
}
double Savings::withdrawal(double amount)
{
if ( (getBalance() - amount) >= 0)
{
setBalance(getBalance() + getBalance());
}
else
{
cout << "Not enough funds in savings for transaction" << endl << endl;
}
return 0;
}
savings.h
#ifndef _savings_h
#define _savings_h
#include "account.h"
class Savings: public Account
{
public:
Savings(int accNum, double newBalance);
double withdrawal(double amount);
};
#endif
checking.cpp
#include <stdlib.h>
#include <iostream>
#include "checking.h"
using namespace std;
Checking::Checking(int accNum, double newBalance) : Account(accNum, newBalance)
{
setBalance(newBalance);
}
double Checking::withdrawal(double amount)
{
if ( getBalance() - amount >= 0)
{
setBalance(getBalance() + amount);
}
else
{
cout << "Not enough funds in checking for transaction" << endl << endl;
}
return 0;
}
checking.h
#ifndef _checking_h
#define _checking_h
#include "account.h"
class Checking: public Account
{
public:
Checking(int accNum, double newBalance);
double withdrawal(double);
};
#endif
account.cpp
#include <iostream>
#include "account.h"
using namespace std;
Account::Account(int accNum, double newBalance)
{
if (newBalance > 0)
{
balance = newBalance;
}
else
{
cout << "Illegal Balance" << endl << endl;
}
}
double Account::getBalance() const
{
return balance;
}
void Account::setBalance(double newBalance)
{
if (newBalance > 0)
{
balance = newBalance;
}
else
{
cout << "Illegal Balance" << endl << endl;
}
}
double Account::deposit(double amount)
{
if (amount >= 0)
{
balance = balance + amount;
}
else
{
cout << "Illegal deposit" << endl << endl;
}
return balance;
}
account.h
#ifndef _account_h
#define _account_h
class Account
{
public:
Account(int accNum, double newBalance);
double deposit(double amount);
virtual double withdrawal(double amount) = 0;
double getBalance() const;
void setBalance(double newBalance);
private:
double balance;
};
#endif
testing
#include <iostream>
#include <iomanip>
#include <vector>
#include "account.h"
#include "checking.h"
#include "savings.h"
using namespace std;
int main()
{
vector <Checking *> checking(50);
vector <Savings *> savings(50);
int accNumS = 0, accNumC = 0;
double bal = 0, amt = 0;
int choice = 0;
int acct = 0;
while(true)
{
cout << "###############################################" << endl;
cout << "# Enter one of the following: #" << endl;
cout << "# 1) Create a new Checking account #" << endl;
cout << "# 2) Create a new Savings account #" << endl;
cout << "# 3) Make a deposit to Checking accounts #" << endl;
cout << "# 4) Make a withdrawl from Checking accounts #" << endl;
cout << "# 5) Make a deposit to Savings accounts #" << endl;
cout << "# 6) Make a withdrawal from Savings accounts #" << endl;
cout << "# 7) Display all accounts #" << endl;
cout << "# 8) Exit #" << endl;
cout << "###############################################" << endl;
cin >> choice;
if(choice == 8)
break;
else
{
switch(choice)
{
case 1:
cout << "Enter balance for account #" << accNumC+1 << ": ";
cin >> bal;
checking[accNumC] = new Checking(accNumC+1,bal);
accNumC++;
break;
case 2:
cout << "Enter balance for account #" << accNumS+1 << ": ";
cin >> bal;
checking[accNumS] = new Checking(accNumS+1,bal);
accNumS++;
break;
case 3:
cout << "Which checking account: ";
cin >> acct;
cout << "Amount of deposit: ";
cin >> amt;
(*checking[acct-1]).deposit(amt);
break;
case 4:
cout << "Which checking account: ";
cin >> acct;
cout << "Amount of withdrawal: ";
cin >> amt;
(*checking[acct-1]).withdrawal(amt);
break;
case 5:
cout << "Which savings account: ";
cin >> acct;
cout << "Amount of deposit: ";
cin >> amt;
(*savings[acct-1]).deposit(amt);
break;
case 6:
cout << "Which savings account: ";
cin >> acct;
cout << "Amount of withdrawal: ";
cin >> amt;
(*savings[acct-1]).withdrawal(amt);
break;
case 7:
//print balance
break;
}
}
}
}