Answer to Question #236532 in C++ for lll

Question #236532

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 feet, 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-09-13T18:36:25-0400
#include<iostream>
#include <string>
using namespace std;


class Investment 
{
public:
	double Init;
	double cur;
	double profit;
	double percent ;
public:
	Investment(double x, double y)
	{
		Init=x;
		cur=y;
	}
	double calc()
	{
	profit=cur-Init;
	return profit;}


	double percentage()
	{
		return profit/Init;
	}


void display()
{
cout<<Init<<cur<<calc()<<percentage();
}


};
class House 
{
	string street;
	double feet;


public:
	House (string s, double f)
	{street=s;
	feet=f;
	}
	void display()
	{ cout<<street;
	cout<<feet;}


};
//constructor
class HouseThatIsAnInvestment : public Investment, public House
{


public:


	HouseThatIsAnInvestment(double n, double m, string s , double w):Investment(n,m),House(s,w)
	{ 
	  cout<<"d";
	}
void display()
{
   Investment::display();
   House::display();
}


};
int main()
{


HouseThatIsAnInvestment object(20,18,"hh",75);


object.display();




	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