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

Introduction Create an inheritance hierarchy that a bank might use to represent

ID: 3907286 • Letter: I

Question

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()

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 "account4.h"

void Account::debit(double a){
    
    if (a <= balance){
        balance = balance - a;

    }
    else {
        cout << "Insufficient balance ";

    }

}
void Account::credit(double a){

    if (a > 0){
       balance = balance + a;

    }


}

double Account::getBalance(){

    return balance;

}

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();
     
};

checkingaccount.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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote