Answer to Question #246214 in C++ for Boo

Question #246214

Create an Investment class that contains fields to hold the initial value of an investment, the 

current value, the profit (calculated as the difference between current value and initial value), 

and the percent profit (the profit divided by the initial value). Include a constructor that 

requires initial and current values and a display function. 

Create a House class that includes fields for street address and square meter, a constructor 

that requires values for both fields, and a display function. 

Create a HouseThatIsAnInvestment class that inherits from Investment and House. It includes a 

constructor and a display function that calls the display functions of the parents. 

Write a main() function that declares a HouseThatIsAnInvestment and displays its values.


1
Expert's answer
2021-10-04T04:57:25-0400
#include <iostream>
#include <string>
using namespace std;
 
class Investment
{
public:
	Investment(double cur, double init);
	void Display()
	{
		cout << "Profit is: " << Profit << endl;
		cout << "Percent profit is: " << PercentProfit << endl;
	}
private:
	double CurrValue;
	double Profit;
	double InitialValue;
	double PercentProfit;
};
 
class House
{
public:
	House(string add, double met);
	void Display()
	{
		cout << "Address is: " << Address << endl;
		cout << "Square is: " << meter << endl;
	}
 
private:
	string Address;
	double meter;
};
 
House::House(string add, double met): Address(add), meter(met)
{
}
 
 
Investment::Investment(double cur, double init) : CurrValue(cur), InitialValue(init)
{
	Profit = CurrValue - InitialValue;
	PercentProfit = 100 * (CurrValue / InitialValue);
}
 
class HouseThatIsAnInvestment : public Investment, House
{
public:
	HouseThatIsAnInvestment(double cur, double init, double met, string add);
	void DisplayProf()
	{
		Investment::Display();
	}
	void DisplayHouse()
	{
		House::Display();
	}
};
 
HouseThatIsAnInvestment::HouseThatIsAnInvestment(double cur, double init, double met, string add) : Investment(cur, init), House(add, met)
{}
 
int main()
{
	Investment ob1(125, 100);
	ob1.Display();
	House ob2("Green str. 125", 250);
	ob2.Display();
	HouseThatIsAnInvestment ob3(150, 125, 350, "Brown str. 200");
	ob3.DisplayHouse();
	ob3.DisplayProf();
	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS