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.
#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;
}
Comments
Leave a comment