Reference no: EM13166212
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() << "\n\n";
cout << ia2.getName() << " has " << ia2.getBal()
<< " dollars with a rate of " << ia2.getRate() << "\n\n";
ia2.addInt();
cout << "after adding interest\n";
cout << ia2.getName() << " now has " << ia2.getBal()
<< " dollars\n\n";
return 0;
}
Choice lists of the case statement
: In Ada, the choice lists of the case statement must be exhaustive, so that there can be no unrepresented values in the control expression. In C++,
|
Create a program that draws a two-dimensional house
: Create a program that draws a two-dimensional house seen from the front, the way a child would see it: with a door, two windows, and a roof with a chimney
|
What is the molarity of nabr in the solution
: a 50 ml solution containing NaBr was treated with excess AgNo3 to precipitate 0.2146g of AgBr. what is the molarity of NaBr in the solution.
|
Deal two cards at a time
: Deal two cards at a time, print them out.- Check if they are identical, have just the same rank or just same suit or are completely.different. Print out a message indicating the result of your comparison.
|
Change the inheritance to private inheritance
: 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.
|
Which pair is written with first member having the higher
: Which pair is written with the first member having the higher boiling point?
|
Draw a lewis structure for h2nnh2
: Draw a Lewis Structure for C3O2. Draw a Lewis Structure for C2H3NO5
|
State what concentration of ca remains in solution
: If 2.55 g of NaOH were added to a 100.0 mL solution containing 0.10 M Ca(NO3)2, what concentration of Ca 2+ remains in solution?
|
The grid is populated randomly
: Initially, the grid is populated randomly with occupied and empty cells. Once the initial grid has been created, the program loops. Each iteration of the loop represents a tick or time step in the environment.
|