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

2 SavingsAccount class Change to a template class. Add accountNumber to the cons

ID: 3914680 • Letter: 2

Question

2 SavingsAccount class

Change to a template class. Add accountNumber to the constructor. You may make interestRate ‘protected’ so you can directly access it in CDAccount. No other modifications.

//

// savingaccount.cpp

// Homework 3

//

// Created by ines said on 6/20/18.

// Copyright © 2018 ines said. All rights reserved.

//

#include "savingaccount.h"

double SavingAccount::calcInterest() // defining the calcInterest function

{

return getBalance() * interestRate ; // returning the balance after interest rate

}

//

// savingaccount.hpp

// Homework 3

//

// Created by ines said on 6/20/18.

// Copyright © 2018 ines said. All rights reserved.

//

#ifndef savingaccount_h

#define savingaccount_h

#include<iostream>

#include "account.h"

using namespace std;

class SavingAccount:public account

{

private: // declaring private members

double interestRate;

public: // declaring public members

   // default constrcutor

SavingAccount() : account(){

interestRate = 0; // sets interest rate to 0

}

  

  

// parametrized constrcutor

SavingAccount(double bal, double interest) : account(bal){

   if (interestRate > 0 ) // check if the given interest rate is more than 0

   {

   interestRate = interest; // if it is more than 0 assign it to ineterest rate

   }

else // if interest rate is not more than 0 prints error and set it to 0

  

{ cout << "Error interest Rate less than 0" << endl;

interestRate = 0;}

  

  

  

}

// destructor

~SavingAccount(){

}

double calcInterest(); // fucntion to calculate interest

  

};

#endif /* savingaccount_hpp */

Explanation / Answer

#ifndef savingaccount_h

#define savingaccount_h

#include<iostream>

#include "account.h"

using namespace std;

class SavingAccount:public account

{

protected: // declaring private members

double interestRate;

public: // declaring public members
long int accountNumber;
// default constrcutor

SavingAccount() : account(){

interestRate = 0; // sets interest rate to 0
accountNumber=0;

}

  

  

// parametrized constrcutor

SavingAccount(double bal, double interest) : account(bal){

if (interestRate > 0 ) // check if the given interest rate is more than 0

{

interestRate = interest; // if it is more than 0 assign it to ineterest rate

}

else // if interest rate is not more than 0 prints error and set it to 0

  

{ cout << "Error interest Rate less than 0" << endl;

interestRate = 0;}

  

  

  

}

// destructor

~SavingAccount(){

}

double calcInterest(); // fucntion to calculate interest

  

};

#endif /* savingaccount_hpp */

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