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

  The staffs need a program that can determine

The staffs need a program that can determine whether children have been naughty or nice. individual data files(can be any name) for each childred are available that consist of 368(365+3)integer number each.

  Write program to read from file to find number of integers

Write down the program which reads from file numbers.txt 30 integers in range 0 - 200. Program ‎then determines number of integers in each of given ranges.

  Ruby implement primitive types

How does Ruby implement primitive types, such as those for integer and floating-point data?  3-What is the single most important practical difference between Smalltalk and C++?

  Write a program to find the middle element in a linked list

1. Write a program to check if there is a loop in a linked list. Create a loop in a linked list and use your method 'isLoop' to identify that the loop exists. The method isLoop should return a Boolean type.2.

  Performs a binary search instead of a linear search.

Modify the following program so it performs a binary search instead of a linear search. Use the selection sort algorithm to sort the array before the binary search is performed.

  Prepare a businesspartner

Prepare a BusinessPartner class that contains a company name, first name and a telephone number.

  Write a method named negative sum

Write a method named negativeSum that accepts a Scanner as a parameter reading input from a file containing a series of integers, and determine whether the sum starting from the first number is ever negative

  Print each employee''s identification number

1) in a program you need to store the identification numbers of 10 employees (as ints) and their weekly gross pay (as doubles) A) Define two arrays that may be used in parallel to store the 10 employee indentificcation numbers and gross pay amounts B..

  First display the smallest volume and then the largest volum

first display the smallest volume and then the largest volume.

  Write a program that inputs a dollar amount to be printed

Write a program that inputs a dollar amount to be printed on a check and then prints the amount in check-protected format with leading asterisks if necessary

  Three dimensional array representing parking spaces

start with code in the file lab.cpp. This program works with a three dimensional array representing parking spaces in a parking garage on several floors. The code is incomplete. The functions "main", "display" and "showSpace" are complete. Your job i..

  Program to translates letter grade into number grade

In C++ (should be able to compile in Visual Studio 2010): Write a program to translates letter grade into number grade. Letter grades are A,B,C,D and F, possibly followed by a + or -.

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