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 */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.