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

The base class Account : The class contains following private data members: acco

ID: 3825245 • Letter: T

Question

The base class Account:

The class contains following private data members: accountNumber (integer from 1000 to 4999), accountOwner (name as a string), accountBalance (type double).

The constructor receives account number, account owner’s name, and an initial balance as parameters. If the initial balance is less than 0.0 the constructor should set the account balance to 0.0 and also issue an error message such as “Initial balance was invalid.”

The class provides three member functions:

credit: adds an amount to the current balance.

debit: withdraw money from the account and ensure that the debit amount does not exceed the current balance. if it does, the balance should be left unchanged, and the function should print the message likes “Debit amount exceeded account balance.”

getBalance: returns and print out the current balance. This is a const function.

Derived class: SavingsAccount

The SavingsAccount should inherit the functionality of an Account, but also include a private data member interestRate (type double value such as 0.03).

The constructor receives an account number, account owner’s name, an initial balance, as well as initial value of interest rate.

This class should provide a public member function calculateInterest which returns the amount of interest that is calculated by multiplying the interest rate with the account balance. Don’t add the interest to account balance using this function,

The class should inherit credit and debit without redefining them.

Derived class: CheckingAccount

The CheckingAccount includes a new data member fee (type double) that represent the fee charged per transaction.

The constructor should receive the account number, account owner, initial balance and a parameter indicating a fee amount.

It should redefine the credit and debit function so that they subtract the fee from account balance whenever each transaction is performed successfully. The debit function should charge the fee only if money is actually withdrawn.

Write a test driver program that creates objects of all three classes (Account, SavingsAccount, and Checking Account) and tests their member functions. In testing the SavingAccount, add interest to the SavingsAccout object by first invoking its calculateInterst function, then passing the returned interest amount to the object’s credit function.

Explanation / Answer

#include <iostream>
using namespace std;

class Account //base class
{
private:
double balance;
  
public:
Account(double balance)
{
if(balance >0.0)
this->balance = balance;
else
{
cout<<"Invalid initial balance";
this->balance = 0.0;
}
  
}
void credit(double amount) //credit account
{
balance = balance + amount;
}
bool debit(double amount) //debit account
{
if(balance < amount)
{
cout<<"Debit amount exceeded account balance";
return false;
}
else
{
balance = balance - amount;
return true;
}
}
double getBalance()
{
return balance;
}
};

class SavingAccount: Account //derived class
{
private:
double interestRate;
  
public:
SavingAccount(double balance,double interestRate):Account(balance) //constructor
{
this->interestRate = interestRate;
  
}
double calculateInterest()
{
return getBalance()*interestRate;
}

void display()
{
cout<<" Saving Account : Balance = "<<getBalance();
}

};
class CheckingAccount : Account //derived class
{
private:
double feeCharged;
public:
CheckingAccount(double balance,double feeCharged) :Account(balance)//constructor
{
this->feeCharged = feeCharged;
  
}
double credit(double amount) //credit account
{
return ( getBalance() + amount - feeCharged);
}
bool debit(double amount) //debit account
{
bool result;
double bal;
result = Account::debit(amount);
if(result == true)
bal = getBalance() - amount - feeCharged;
return result;
}

void display()
{
cout<<" Checking Account : Balance = "<<getBalance();
}
};


  
int main()
{


SavingAccount sa(1456,6.7);
cout<<" Interest = "<<sa.calculateInterest();
sa.display();

CheckingAccount ca(1004,23);
ca.debit(200);
ca.display();


   return 0;
}

Output:

Interest = 9755.2
Saving Account : Balance = 1456
Checking Account : Balance = 804

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