Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Note: calculate the profit and percent profit for the investment inside its cons

ID: 3705401 • Letter: N

Question

Note: calculate the profit and percent profit for the investment inside its constructor.

an Investment class that contains fields to hold the initial value of an investment, he current value, the profit (calculated as the difference between current value and al 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 dass 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. Save the file as HouseThatIsAnInvestment.cpp

Explanation / Answer


// C++ code
#include <iostream>
#include <string.h>
#include<fstream>
#include<iomanip>

using namespace std;

class Investment

{

private:
double initialInvestment, currentInvestment, totalProfit, percenttotalProfit;


public:

Investment(double ivalue, double cvalue)
{

initialInvestment = ivalue;

currentInvestment = cvalue;


totalProfit = cvalue - ivalue;

percenttotalProfit = (totalProfit / ivalue) * 100;

}


void display()

{

cout << endl << left << setw(15) << "Initial Value" << ": $" << initialInvestment;

cout << endl << left << setw(15) << "Current Value" << ": $" << currentInvestment;

cout << endl << left << setw(15) << "totalProfit" << ": $" << totalProfit;

cout << endl << left << setw(15) << "Percent totalProfit" << ": " << percenttotalProfit << "%";

}

};


class House

{

private:

string streetAddress;

double houseStreetFeet;


public:

House(string address, double feet)

{

streetAddress = address;

houseStreetFeet = feet;

}


void display()

{

cout << endl << "The house at street address " << streetAddress << " has " << houseStreetFeet << " square feet.";

}

};


class HouseThatIsAnInvestment: public Investment, public House

{

public:

HouseThatIsAnInvestment(double initialInvestment, double currentInvestment,

string streetAddress, double houseStreetFeet) :

Investment(initialInvestment, currentInvestment), House(streetAddress, houseStreetFeet)

{

}


void display()

{

Investment::display();

House::display();

}

};


int main()

{

Investment investment(32111, 34222);

House house("334 Wall Street", 346);

HouseThatIsAnInvestment houseThatIsAnInvestment(32111, 34222,

"334 Wall Street", 346);


cout << "This is a plain investment. ";

investment.display();


cout << endl << endl << "This is a plain House. ";

house.display();


cout << endl << endl << "This is a Hosue that is also an Investment. ";

houseThatIsAnInvestment.display();

}

/*
output:

This is a plain investment.

Initial Value : $32111
Current Value : $34222
totalProfit : $2111
Percent totalProfit: 6.57407%

This is a plain House.

The house at street address 334 Wall Street has 346 square feet.

This is a Hosue that is also an Investment.

Initial Value : $32111
Current Value : $34222
totalProfit : $2111
Percent totalProfit: 6.57407%
The house at street address 334 Wall Street has 346 square feet.
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote