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

C++ 3 CheckingAccount class Change to a template class. Add accountNumber to the

ID: 3915753 • Letter: C

Question

C++ 3 CheckingAccount class

Change to a template class. Add accountNumber to the constructor. No other modifications.

//

// checkingaccount.cpp

// Homework 3

//

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

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

//

#include "checkingaccount.h"

void CheckingAccount::debit(double amount){

  

account::debit(amount); // withdraws ammount

account::debit(feeForTransaction); // withdraws trasation fee

  

}

void CheckingAccount::credit(double amount){

  

account::credit(amount); // adds amount

account::debit(feeForTransaction); // calculate transaction fee

  

}

double CheckingAccount::getFeeForTransaction(){

  

return feeForTransaction; // return the transaction fee

  

}

//

// checkingaccount.hpp

// Homework 3

//

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

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

//

#ifndef checkingaccount_h

#define checkingaccount_h

#include<iostream>

#include "account.h"

using namespace std;

class CheckingAccount:public account{

  

public: // public data members

CheckingAccount() : account(){

feeForTransaction = 0;

}

CheckingAccount(double bal, double fee) : account(bal){

  

if (fee > 0) // check if the fee for transaction is more than 0

{

feeForTransaction = fee;} // assign it to the value

else // if fee is nore more than 0 print error message and assign 0 to it

{

cout << "error Fee for transaction is smaller than 0" << endl;

feeForTransaction = 0;

}

  

}

  

   // destrcutor definition

~CheckingAccount(){

}

  

virtual void credit(double amount); // declare virtual function credit

virtual void debit(double amount); // declare victural function debit

double getFeeForTransaction();

  

private: // private data members

double feeForTransaction;

};

#endif

Explanation / Answer

---------------------------checkingaccount.hpp-----------------------

//

// checkingaccount.hpp

// Homework 3

//

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

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

//

#ifndef checkingaccount_h

#define checkingaccount_h

#include<iostream>

#include "account.h"

using namespace std;

template<class T>

class CheckingAccount : public account{

    public: // public data members

   

        CheckingAccount() : account(){

            feeForTransaction = 0;

        }

       

        CheckingAccount(T bal, T fee) : account(bal)

        {

            if (fee > 0) // check if the fee for transaction is more than 0

                feeForTransaction = fee; // assign it to the value     

            else // if fee is nore more than 0 print error message and assign 0 to it

            {

                cout << "error Fee for transaction is smaller than 0" << endl;

                feeForTransaction = 0;

            }

        }

       

        // destrcutor definition

        ~CheckingAccount()

        {}

       

        virtual void credit(T amount); // declare virtual function credit

        virtual void debit(T amount); // declare victural function debit   

        T getFeeForTransaction();

   

    private: // private data members

   

        T feeForTransaction;

};

#endif

------------------------------checkingaccount.cpp-------------------------

//

// checkingaccount.cpp

// Homework 3

//

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

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

//

#include "checkingaccount.hpp"

template<class T>

void CheckingAccount<T>::debit(T amount)

{

    account::debit(amount); // withdraws ammount

    account::debit(feeForTransaction); // withdraws trasation fee

}

template<class T>

void CheckingAccount<T>::credit(T amount)

{

    account::credit(amount); // adds amount

    account::debit(feeForTransaction); // calculate transaction fee

}

template<class T>

T CheckingAccount<T>::getFeeForTransaction()

{

    return feeForTransaction; // return the transaction fee

}