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

  Write a program that allows users to enter a dollar amount

Write a program that allows users to enter a dollar amount for their bank account balance at the beginning of the month. Then ask the user to enter a dollar amount for any number of checks written in a month, up to 50. Include an approriate sentinel ..

  Write a program that reads from a file a list of course name

Write a program that reads from a file a list of course names, letter grades for each course and number of credits each course is worth. The program will read each course name, grade earned and number of credits from the file and print out the course..

  Calculates the sum of the cube roots of two integers.

Wrtie a program that calculates the sum of the cube roots of two integers. The program should use the following functions as well as a main funcion. 1) enter one positive value 2) compute the cube root of one integer 3) report the value of two intege..

  Write a program to read a data file and extract parameters

Write a C/C++ program to read a data file and extract parameters. The program must obtain the filename via a command-line argument.

  Write a bouncing ball video game

The balls bounces within the screen where the two horizontal walls are fixed

  Prepare the weighted scoring model for three exams

Prepare the weighted scoring model. Final grades are based on three exams worth 15%, 20%, and 25%, respectively; homework is worth 20%.

  Calculate that implements a simple arithmetic calculator

Write a  C program  calc.c that implements a simple arithmetic calculator. Input to the calculator consists of lines composed of integer constants separated by the five arithmetic operators used in C: +, -, *, /, and %. For each line of input,

  Program which calculates the average and sum of the numbers

write down a program which calculates the average and sum of the numbers enter by a user.Using a While Loop

  For this program reads the first 11 characters

E main for this program reads the first 11 characters from input, saving them. It then reads 26 short integers into |vals|, and passes them and the characters to EmbedWatermark, which subtly alters the contents of vals to contain the characters. A..

  Implement a function to recursively

Implement a function to recursively determine if a word is a palindrome. A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction.

  Write a recursive and iterative versions of binary search

in C++ write a recursive and iterative versions of binary search and compare their run times using the array a[i]=i, i=0,..., n-1

  Prompt the user for and read 6 numbers

Write a program using an array that will store input data. Prompt the user for and read 6 numbers between 70 and 90. Verify the numbers should be greater than 70 and less than 90. If the number is less than or equal to 70 or greater than 90, repro..

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