Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the code in C++ Introduction Create an inheritance hierarchy that a ban

ID: 3907294 • Letter: C

Question

Complete the code in C++

Introduction

Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers can deposit (“credit”) into their accounts and withdraw (“debit”) 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, can charge a fee per transaction. Create an inheritance hierarchy containing base class Account and derived classes SavingsAccount and CheckingAccount that inherit from Account.

Deliverables

• A driver program (driver.cpp)

• An implementation of Account class (account.h, account.cpp)

• An implementation of SavingsAccount (savingsaccount.h, savingsaccount.cpp)

• An implementation of CheckingAccount (checkingaccount.h, checkingaccount.cpp)

1 Account class

Implement the base class.

1.1 Data Members

balance (double)

1.2 Member Functions

Constructors

Defines default and paramaterized constructors. Confirm balance not below zero. If so, set to zero and output an error message.

Destructor

Defines destructor. Clean up any allocated memory.

Accessors

double getBalance()

Mutators

void debit(amount) Withdraws from the account if the amount does not exceed the balance. If so, nothing is debited and an error message is printed. This method may change when you implement the derived class.

void credit(amount)

Deposits into the account.

2 SavingsAccount class

Implement the derived class.

2.1 Data Members

interestRate (double). This value should be [0, 1.0]

2.2 Member Functions

Constructors

Defines default and parameterized constructor. Confirm interestRate not below zero. If so, set to zero and output an error message.

Destructor

Defines destructor. Clean up any allocated memory.

Accessors

double calcInterest() Returns the current interest of the account (balance multiplied by interest rate).

3 CheckingAccount class

Implement the derived class.

3.1 Data Members

feeForTransaction (double)

3.2 Member Functions

Constructors

Defines default and parameterized constructor. Confirm feeForTransaction not below zero. If so, set to zero and output an error message.

Destructor

Defines destructor. Clean up any allocated memory.

Mutators

void debit(amount) Invokes the base class debit member function and subtracts the fee if successful debit (Hint: redefine parent method to return a value you can check).

void credit(amount) Invokes the base class credit member function and subtracts the fee. (Yes, it is terrible for this bank to charge you to deposit money which they are profiting from investing, but that’s just the way life goes sometimes.)

4 The Driver Program

In your driver, prompt the user for input as shown below. Create a vector of six Account pointers (alternating Checking then Saving) and point them to objects you initialize with the user’s input. Then, create a loop that, for each account, allows the user to deposit and withdraw from the account using the appropriate member functions. As you process each account, determine its type. If it is a SavingsAccount, calculate and add interest after the deposit. After processing each account, print the updated balance by invoking the base-class member function getBalance().

4.1 Example output:

Checking Account 0

Please enter the balance:

Please enter the fee:

Savings Account 1

Please enter the balance:

Please enter the interest rate:

(repeat for Accounts 3 through 6)

Account 1 balance: $70.00

Enter an amount to withdraw from Account 1: 80.00

Debit amount exceeded account balance.

Enter an amount to deposit into Account 1: 35.00

$1.00 transaction fee charged.

Updated Account 1 balance: $104.00

Account 2 balance: $80.00

Enter an amount to withdraw from Account 2: 10.00

Enter an amount to deposit into Account 2: 35.00

Adding $5.00 interest to Account 2 (a SavingsAccount)

Updated Account 2 balance: $110.00

(repeat for Accounts 3 through 6)

Submit the following files to Canvas (named EXACTLY as shown below)

1. driver.cpp

2. account.h

3. account.cpp

4. savingsaccount.h

5. savingsaccount.cpp

6. checkingaccount.h

7. checkingaccount.cpp

Explanation / Answer

account.h

/*Account.h */
#include<iostream>

using namespace std;

class Account{
   private:
      double balance;
   public:
      Account(){
         balance = 0;
      }
  
      Account(double d){
         balance = d;
         if (balance < d)
            balance = 0;
      }
      ~Account(){
      }
      void debit(double a);
      void credit(double a);
      double getBalance();
     
};

account.cpp

#include<iostream>

using namespace std;

class Account {
private:

    double balance;
    double rate;
public:
    Account(double bal, double rt){
         
          balance = bal;
          rate = rt;
    }
    double getBalance(){
         return balance;
    }
    void display(){

        cout << "Balance :" << balance << endl;
        cout << "Rate of Intrest :" << rate << endl;
    }
    double intrest_calculate(){
           return balance * (rate/100);
    }
    void withdrawl(double a){
         balance = balance - a;
    }
    void deposit(double a){
         balance = balance + a;
    }

};

int main(){

   Account at(1000, 2.5);

   at.display();
   cout << "Intrest : " << at.intrest_calculate() << endl;
  
   at.withdrawl(50);
   cout << "Balance after withdrawl: " << at.getBalance() << endl;
   at.deposit(2000);
   cout << "Balance after deposit: " << at.getBalance() << endl;
  
  
   return 0;
}

savingsaccount.h

/*SavingsAccount.h */
#include<iostream>
#include "account4.h"

using namespace std;

class SavingsAccount : public Account {
   private:
      double intrestRate;
   public:
      SavingsAccount() : Account(){
         intrestRate = 0;
      }
      SavingsAccount(double d, double intr) : Account(d){
         intrestRate = intr;
      }
  
      ~SavingsAccount(){
      }
      double calcIntrest();
     
};

savingsaccount.cpp

#include "savingsaccount4.h"

double SavingsAccount::calcIntrest(){
          return getBalance() * intrestRate;
}

checkingaccount.h

/*SavingsAccount.h */
#include<iostream>
#include "savingsaccount4.h"


using namespace std;

class CheckingAccount : public Account{
   private:
      double feeForTransaction;
   public:
      CheckingAccount() : Account(){
         feeForTransaction = 0;
      }
      CheckingAccount(double d, double fee) : Account(d){
         feeForTransaction = fee;
      }
  
      ~CheckingAccount(){
      }
      void credit(double a);
      void debit(double a);
      double getFeeForTransaction();
     
};

checkingaccount4.cpp

#include "checkingaccount4.h"

void CheckingAccount::debit(double a){

      Account::debit(a);
      Account::debit(feeForTransaction);
}
void CheckingAccount::credit(double a){

      Account::credit(a);
      Account::debit(feeForTransaction);

}

double CheckingAccount::getFeeForTransaction(){

    return feeForTransaction;

}

driver.cpp

#include "checkingaccount4.h"


using namespace std;


int main(){

    cout << "Please enter balance:";
    double bal;
    cin >> bal;
    cout << "Please enter balance:";
    double fee;
    cin >> fee;

    CheckingAccount c(bal,fee);

    cout << "Please enter balance:";
   
    cin >> bal;
    double intr;
    while(true){
        cout << "Please enter intrest rate:";
        //double intr;
        cin >> intr;
        if (intr < 0 || intr > 1){
           cout << "Invalid value ";
        }
        else
           break;
    }
    SavingsAccount s(bal,intr);

    cout << "Saving Account balance:" << s.getBalance() << endl;
    cout << "Enter an amount to withdraw(Savings Account):";
    cin >> bal;
    s.debit(bal);
    cout << "Saving Account balance:" << s.getBalance() << endl;

}