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

Take the following C++ code and make the following changes. Change the inheritan

ID: 3552730 • Letter: T

Question

Take the following C++ code and make the following changes. Change the inheritance to private inheritance. Change the private data member balance to protected. Define get function members of IntAccount class to retrieve name and balance. Since the inheritance is private, an object of IntAccount will not be able to call getName or getBal. Functions that do those must be defined in the IntAccount class. If you realize what protected means, you can change the definition of addInt.


#include <iostream>

#include <string>

using namespace std;


class Account

{

public:

Account()

{

name = "John Doe";

balance = 0.0;

}

Account(string n, double b)

{

set(n, b);

}

void set(string n, double b)

{

name = n;

balance = b;

}

string getName()

{

return name;

}

double getBal()

{

return balance;

}

private:

string name;

double balance;

};


class IntAccount : public Account

{

public:

IntAccount()

{

rate = 0.0;

}

IntAccount(string n, double b, double r)

: Account(n, b)

{

if (0.0 <= r && r <= 1.0)

rate = r;

else

rate = 0.0;

}

void set(string n, double b, double r)

{

Account::set(n, b);

if (0.0 <= r && r <= 1.0)

rate = r;

else

rate = 0.0;

}

double getRate()

{

return rate;

}

void addInt()

{

double bl;

bl = getBal()*(1+rate);

Account::set(getName(), bl);

}

private:

double rate;

};


int main()

{

IntAccount ia1, ia2("Sarah Smith", 100.0, 0.03);

ia1.set("Mary Smith", 200.0, 0.04);

cout << ia1.getName() << " has " << ia1.getBal()

<< " dollars with a rate of " << ia1.getRate() << " ";

cout << ia2.getName() << " has " << ia2.getBal()

<< " dollars with a rate of " << ia2.getRate() << " ";

ia2.addInt();

cout << "after adding interest ";

cout << ia2.getName() << " now has " << ia2.getBal()

<< " dollars ";

  

return 0;

}

Explanation / Answer

http://pastebin.com/tY8wq5FD
I made the changes and it compiles and runs, ask if you have any questions

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