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

Q no 1 Create an inheritance hierarchy by writing the source code,containing bas

ID: 3616040 • Letter: Q

Question

Q no 1

Create an inheritance hierarchy by writing the source code,containing base class Account and derived classesSavingsAccount and CheckingAccount that inherit from class Account.Make sure all return values, arguments, and member functions aredeclared const where appropriate.

i. Base class Account shouldinclude one data member of type double to represent the accountbalance. The class should provide a constructor that receives aninitial balance and uses it to initialize the data member. Theconstructor should validate the initial balance to ensure that itis greater than or equal to 0.0. If not, the balance should be setto 0.0 and the constructor should display an error message,indicating that the initial balance was invalid. (You may wish touse the cerr object, which functions just like cout except that itoutputs to the standard error output rather than standard textoutput. Usually, but not always, the two are functionallysimilar.)

The class should provide four member functions. Memberfunction Credit should add an amount to the current balance. Memberfunction Debit should withdraw money from the Account and ensurethat the debit amount does not exceed the Account's balance. If itdoes, the balance should be left unchanged and the function shouldprint the message "Debit amount exceeded account balance." Memberfunction getBalance should return the current balance.

ii. Derived class SavingsAccountshould inherit the functionality of an Account, but alsoinclude a data member of type double indicating the yearly interestrate (percentage) assigned to the Account. SavingsAccount'sconstructor should receive the initial balance, as well as aninitial value for the SavingsAccount's interest rate. (Make sure tocall the base class constructor appropriately.) SavingsAccountshould provide a public member function calculateInterest thatreturns a double indicating the amount of interest earned by anaccount. Member function calculateInterest should take one integerargument indicating the number of years gone by, and shoulddetermine the interest amount by the formula I = B*(1+ r)t , where I is the interest, B is theinitial balance, r is the interest rate, and t is the number ofyears gone by. [Note: SavingsAccount should inherit memberfunctions credit and debit as is without redefiningthem.]

iii. Derived classCheckingAccount should inherit from base classAccount and include an additional data member of type double thatrepresents the fee charged per transaction. CheckingAccount'sconstructor should receive the initial balance, as well as aparameter indicating a fee amount.

Please sir help me

Explanation / Answer

class account{
public:
account();
account(double startBalance);
void Credit(double amount);
void Debit(double amount);
double getBalance();


private:
double balance;
};

//***********************************************************
account::account(){
balance = 0;
}

account::account(doublestartBalance){
if (startBalance >= 0 )
  balance = startBalance;
else{
  balance = 0;
  cerr << "Invalid start balance! Balance set to 0"<< endl;
}
}
//***********************************************************
void account::Credit(double amount){
balance += amount;

}
//***********************************************************
void account::Debit(double amount){
if(amount <= balance)
  balance -= amount;
else
  cout<<"Debit amount exceeded account balance."<< endl;

}
//***********************************************************
double account::getBalance(){
return balance;

class savings : publicaccount{
public:
savings(double Balance, double rate);
double calculateInterest(int years);


private:
double yearlyInterestRate;
};

savings::savings(doubleBalance, double rate) : account(Balance),yearlyInterestRate(rate)
{

}
//***************************************************************
double savings::calculateInterest(int years){
/*
determine the interest amount by the formula I = B *(1+ r)t , whereI is the interest, B is
the initial balance, r is the interest rate, and t is thenumber of years gone by
*/
return    getBalance() * (( 1 + yearlyInterestRate ) * years );

class check : publicaccount {
public:
check(double Balance, doubletransactionFee);
private:
double fee;

check::check(double Balance, doubletransactionFee) : account(Balance), fee(transactionFee)
{

}