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

INHERITANCE C++ So this is what the assignment asks us to do. I\'ve done each se

ID: 662199 • Letter: I

Question

INHERITANCE C++ So this is what the assignment asks us to do. I've done each section separately but not sure how they all come together. (5 Sections)

Design and implement a hierarchy inheritance system of banking, which includes Savings and Checking accounts of a particular customer. Inheritance and virtual functions must be used and applied; otherwise, there is no credit. Insert comments in your code. No comment or just a few added will result in deduction of 5 points.

The following features must be incorporated:

1. The account must have an ID and customer

Explanation / Answer

main.cpp


#include "Account.h"
#include "CheckingAccount.h"
#include "SavingsAccount.h"

#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;

int main(){

Account test1(100.00);
CheckingAccount test2(100.00, 1.00);
SavingsAccount test3(10000, .01);

test1.credit(50.0);
cout << test1.getBalance() << endl;
test1.debit(50.0);
cout << test1.getBalance() << endl;
test1.debit(2000);

test2.credit(100);
cout << test2.getBalance() << endl;
test2.debit(50);
cout << test2.getBalance() << endl;
test2.debit(2000);

double interest = test3.calculateInterest();
test3.credit(interest);
cout << test3.getBalance() << endl;
return 0;
}

SavingsAccount.h

#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include "Account.h"

class SavingsAccount : public Account
{
public:
    double interestRate; //percentage

    explicit SavingsAccount(double initBalance, double initInterest);

    double calculateInterest();
private:
protected:
};
#endif

SavingsAccount.cpp

#include "SavingsAccount.h"
#include "Account.h"

#include <iostream>
#include <string>


SavingsAccount::SavingsAccount(double initBalance, double initInterest)
    : interestRate(initInterest), Account(initBalance)
{}


double SavingsAccount::calculateInterest(){
    double mGained = interestRate * Account::getBalance();
    return mGained;
}

CheckingAccount.h

#ifndef CHECKINGACCOUNT_H
#define CHECKINGACCOUNT_H
#include "Account.h"


class CheckingAccount : public Account
{
public:
    double transChargeFee;

    explicit CheckingAccount(double initBalance, double feeAmt);

    void credit(double addAmount);
    void debit(double withdrawAmount);
private:
protected:
};
#endif

CheckingAccount.cpp

#include "CheckingAccount.h"
#include "Account.h"

#include <iostream>
#include <string>

CheckingAccount::CheckingAccount(double initBalance, double feeAmt)
    : transChargeFee(feeAmt), Account(initBalance)
{}

void CheckingAccount::credit(double addAmount){
    addAmount -= transChargeFee;
    Account::credit(addAmount);
}

void CheckingAccount::debit(double withdrawAmount){
    if (Account::debit(withdrawAmount)){
      Account::accBalance -= transChargeFee;
    }
}


Account.h

#ifndef ACCOUNT_H
#define ACCOUNT_H

class Account{

public:
    double accBalance;

    explicit Account(double initBalance);

    void credit(const double addAmount);
    bool debit(const double withdrawAmount);
    double getBalance();
private:
protected:

};
#endif

Account.cpp
#include "Account.h"

#include <string>
#include <iostream>

Account::Account(double initBalance){

    if (initBalance < 0.0){
      accBalance = 0.0;
    }
    else
      accBalance = initBalance;
}

void Account::credit(const double addAmount){

    accBalance+= addAmount;

}

bool Account::debit(const double withdrawAmount){

    if (withdrawAmount > accBalance){
      std::cout << "Debit Amount Exceeded Account Balance." << std::endl;
      return false;
    }
    else {
      accBalance-= withdrawAmount;
      return true;
    }
}

double Account::getBalance(){
      return accBalance;
}


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