Question
C++ Please read the question clearly and match the example output provided at the end. You will find files named Question1.cpp. It uses a House
C++
Please read the question clearly and match the example output provided at the end.
You will find files named Question1.cpp. It uses a House class which has not yet been defined. It is your task to define the class within the Question1.cpp file for use within the main block. You will need the following: 1. A default and parameterized constructor 2. Methods to get and set the number of bedrooms, bathrooms, parking spots, and the year the house was built. 3. Private members to store the state for each of the data items.
The output should match the example below. Example 1: How many bedrooms does your house have? 5 How many bathrooms does your house have? 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.
Question01.cpp
#include
/* * Definition of class House goes here */
/* * 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; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started