Answer to Question #246526 in C++ for Ahlam

Question #246526

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. Save the file as HouseThatIsAnInvestment.cpp


1
Expert's answer
2021-10-04T23:11:05-0400
#include <string>
#include <iostream>
using namespace std;

class Investment 
{
    public:
    	double initialValue,currentValue,profit,percent ;
    public:
    	Investment(double initial, double current)
    	{
    		initialValue=initial;
    		currentValue=current;
    		profit=currentValue-initialValue;
    	}
    
        void display()
        {
          cout << "Initial Value: "<< initialValue <<"\t Current Value: " << currentValue << "\t Profit: " << profit << "," << profit/initialValue << endl;
        }
};
class House 
{
	string street;
	double squareMeter;

    public:
    	House (string s, double meter)
    	{
    	    street=s;
    	    squareMeter=meter;
    	}
    	void display()
    	{ 
          cout << "Street: " << street << "\t Square Meter: " << squareMeter << endl;
    	}

};
class HouseThatIsAnInvestment : public Investment, public House
{
    public:
    	HouseThatIsAnInvestment (double initial, double current, string street , double area):Investment(initial,current),House(street,area){}
        void display()
        { 
            Investment::display();
            House::display();
        }
    
};
    
int main()
{
    HouseThatIsAnInvestment house(10,15,"street address",100);
    house.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