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

Please implement the following problem in basic C++ code and include detailed co

ID: 3584935 • Letter: P

Question

Please implement the following problem in basic C++ code and include detailed comments so that I am able to understand the processes for the solution. Thanks in advance.

// Question1.cpp

Please review "Questionl.cpp". It uses a House class which has not yet been defined. It is your task to define the class within the Questionl.cpp file for use within the main block. You will need the following A default and parameterized constructor Methods to get and set the number of bedrooms, bathrooms, parking spots, and the year the house was built. Private members to store the state for each of the data items. 1. 2. 3. The output should match the example below. Example 1: How many bedrooms does your house have? 5 How many bathrooms does your househave? 2 How many cars fit in your garage? 1 What year was your house built? 2010 Your house has 2 more bedrooms Your house has 1 more bathrooms Your garage holds 2 fewer cars Your house was built 9 years after my own

Explanation / Answer

#include<iostream>
#include<cmath>
using namespace std;

/*
* Definition of class House goes here
*/
class House {
private:
int baths, beds, cars, year;
public:
House() {

}
House(int bed, int bath, int car, int y) {
beds = bed;
baths = bath;
cars = car;
year = y;
}
void setBeds(int bed) {
beds = bed;
}
void setBaths(int bath) {
baths = bath;
}
void setCars(int car) {
cars = car;
}
void setYear(int y) {
year = y;
}
int getBeds() {
return beds;
}
int getBaths() {
return baths;
}
int getCars() {
return cars;
}
int getYear() {
return year;
}
};

/*
* Remainder of file remains unchanged
*/
int main(void) {
House myHouse(3, 1, 3, 2001);
House yourHouse;

int input;
cout << "How many bedrooms does your house have? ";
cin >> input;
yourHouse.setBeds(input);

cout << "How many bathrooms does your house have? ";
cin >> input;
yourHouse.setBaths(input);

cout << "How many cars fit in your garage? ";
cin >> input;
yourHouse.setCars(input);

cout << "What year was your house built? ";
cin >> input;
yourHouse.setYear(input);

int diff = myHouse.getBeds() - yourHouse.getBeds();
cout << "Your house has " << abs(diff) << (diff < 0 ? " more" : " fewer") << " bedrooms" << endl;

diff = myHouse.getBaths() - yourHouse.getBaths();
cout << "Your house has " << abs(diff) << (diff < 0 ? " more" : " fewer") << " bathrooms" << endl;

diff = myHouse.getCars() - yourHouse.getCars();
cout << "Your garage holds " << abs(diff) << (diff < 0 ? " more" : " fewer") << " cars" << endl;

diff = myHouse.getYear() - yourHouse.getYear();
cout << "Your house was built " << abs(diff) << " years" << (diff < 0 ? " after" : " before") << " my own." << endl;

return 0;
}

Output: