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

Program name: main4.cpp, account.hpp, account.cpp savings account.hpp, savings_a

ID: 3757545 • Letter: P

Question

Program name: main4.cpp, account.hpp, account.cpp savings account.hpp, savings_account.cpp, checking account.hpp, checking account.cpp, makefile Executable file name: bank Rubrics that apply: Points Possible: 100 Description 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 it (ie, debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, can earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction (i.e, credit or debit). Create an inheritance hierarchy containing base class Account and derived classes Savings account and Checking account that inherit from base class Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0. If not, the balance should be set to 0 and the constructor should display an error message, indicating that the initial balance was invalid. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money from the Account and ensure that the debit amount does not exceed the Account's balance. If it does, the balance should be left unchanged and the function should print the message "Debit amount exceeded account balance." Member function get balance should return the current balance Derived class Savings_account should inherit the functionality of an Account, but also include a data member of type double indicating the interest (percentage) assigned to the Account Savings_account's constructor should receive the initial balance, as well as an initial value for the Savings account's interest rate. Savings account should provide a public member function calculate interest that returns a double indicating the amount of interest earned by an account. Member function calculate_interest should determine this amount by multiplying the interest rate by the account balance. [Note: Savings_account should inherit member functions credit and debit as is without redefining them.] Derived class Checking account should inherit from base class Account and include an additional data member of type double that represents the fee charged per transaction. Checking_account's constructor should receive the initial balance, as well as a parameter indicating a fee amount. Class Check_account should redefine member functions credit and debit so that they subtract the fee from the account balance whenever either transaction is performed successfully. Checking account's versions of these functions should invoke the base-class Account version to perform the updates to an account balance. Checking account's debit function should charge a fee only if money is actually withdrawn (i.e., the debit amount does not exceed the account balance). [Hint: Define Account's debit function so that it returns a bool indicating whether money was withdrawn. Then use the return to value to determine whether a fee should be charged.] After defining the classes in this hierarchy, write a program that creates objects of each class and tests their member functions. Add interest to the Savings_account object by first invoking its calculate interest function, then passing the returned interest amount to the object's credit function. Using user input is not sufficient to test this routine. You must prove that each of the things asked for are working correctly in your program. The intent is to create the correct classes and prove that they wor

Explanation / Answer

// here is the full code

// output is attached
// plz comment if you need any clarification
// hit like if you liked it


#include<iomanip> // it has the setprecision method
#include "savings_account.h"
#include "checking_account.h"
using namespace std;

int main() {

    // Instantiate the objects
    Account account(2000.0);
    SavingsAccount sAccount(2500, 11);

    // add some credits to both accounts
    account.credit(500);
    sAccount.credit(500);

    // withdraw some amount from both the objects
    account.debit(300);
    sAccount.debit(240);

    cout<< "Interest for savings bank account is "<<sAccount.calculateInterest()<<endl;
    cout<< "Current Balance of Account is "<<account.getBalance()<<endl;
    cout<< "Current Balance of Savings Account is "<<sAccount.getBalance()<<endl;
    return 0;
}

/////////////////////////////////////

#include<iostream>
#include "account.h"
using namespace std;

account::account(double bal) { // constructor
    this->balance = bal;
}

account::account() { // default constructor
    this->balance = 0.0;
}

double account::getBalance() { // returns the balance in the account
    return this->balance;
}

void account::credit(double amount) {
    balance += amount; // add diposited amount to the balance
}

void account::debit(double amount) { // withdraw some amount
if(amount > balance) { // else if there is no sufficient balance in the account
  cout<<"Error:Insufficient Amount in the Account"<<endl;
} else { // subtract the withdrawl amount from balance
  balance -= amount;
}
}

//////////////////////////////////////////////////////

#ifndef __SAVINGS_ACCOUNT__
#define __SAVINGS_ACCOUNT__

#include "account.h"
class savings_account : public account {
private:
double interestRate;
    public:
    savings_account(double balance, double interestRate);
    double calculateInterest();
};
#endif // __SAVINGS_ACCOUNT__

////////////////////////////////////////////////////////////////////////

#include "savings_account.h"
using namespace std;
savings_account::savings_account(double balance, double interestRate) : Account(balance) {
        // calls the Account() constructor
  this-> interestRate = interestRate*0.001; // set the interest rate, it is given in percentage
}

double savings_account::calculateInterest() {
  return this->getBalance() * interestRate;
}

/////////////////////////////////////////////////////////////////////////////////////

#include "checking_account.h"
using namespace std;

checking_account::checking_account(double balance, double interestRate) : account(balance) {
        // calls the Account() constructor
  this-> interestRate = interestRate*0.001; // set the interest rate, it is given in percentage
}

double checking_account::calculateInterest() {
  return this->getBalance() * interestRate;
}

////////////////////////////////////////////////////////////////////////////


#ifndef __CHECKING_ACCOUNT__
#define __CHECKING_ACCOUNT__

#include "account.h"
class checking_account : public account {
private:
double interestRate;
    public:
    checking_account(double balance, double interestRate);
    double calculateInterest();
};
#endif // __CHECKING_ACCOUNT__

///////////////////////////////////////////////////////////////////////////////////