Change the inheritance to private inheritance

Assignment Help C/C++ Programming
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;

}

 

 

Reference no: EM13166212

Questions Cloud

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.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd