IN C++ Create a header and implementation file to define an apartment class. Cre
ID: 3882483 • Letter: I
Question
IN C++
Create a header and implementation file to define an apartment class. Create a driver program to test the class, and create a make file to compile the driver program.
Create two files called apartment.h and appartmentImp.cpp along with creating a driver program named testApartment.cpp containing the main function.
Program Requirements:
• Class attributes should include integers for number of rooms, monthly rent, and square feet, as well as booleans for washer/dryer connections and pets allowed or not
• Driver file should create two apartment objects: onCampusApt and offCampusApt
• Prompt the user to enter all the attributes for both apartments.
• Display the attributes for both apartments with neat formatting
• Display whether the two apartments have identical values for all their attributes (testing for equality)
• Set the off-campus apartment to allow pets, have washer and dryer connections, and increase its square feet by 150
• Display the attributes for both again with neat formatting
• Display the price per square foot for both apartments
Your implementation file should provide the functionality for the class to accomplish all the program requirements.
Format your output so that the user of your program understands the values that were input and what was output for each calculation. Your program should have a user-friendly interface. Make sure your program is properly documented and good programming standards are followed.
Explanation / Answer
#include<iostream>
using namespace std;
class Apartment{
private:
int num_rooms;
double monthly_rent;
double area;
bool washer_dryer_connection;
bool pet_allowed;
public:
Apartment(int a, double b, double c,bool d, bool e){
num_rooms = a;
monthly_rent = b;
area = c;
washer_dryer_connection = d;
pet_allowed = e;
}
void setWasherDryerConnection(bool a){
washer_dryer_connection = a;
}
void setPetAllowed(bool a){
pet_allowed = a;
}
void setArea(double a){
area = a;
}
int getNumRooms(){
return num_rooms;
}
double getMonthlyRent(){
return monthly_rent;
}
bool getWasherdryerConnection(){
return washer_dryer_connection;
}
bool getPetAllowed(){
return pet_allowed;
}
double getArea(){
return area;
}
bool equal(Apartment a){
if (num_rooms == a.getNumRooms() && monthly_rent == a.getMonthlyRent() && washer_dryer_connection == a.getWasherdryerConnection() &&
pet_allowed == a.getPetAllowed())
{
return true;
}
else {
return false;
}
}
void disp(){
cout << "Number of rooms : " << num_rooms << endl;
cout << "Monthly Rent : $" << monthly_rent << endl;
cout << "Area(Sq feet) : " << monthly_rent << endl;
if (washer_dryer_connection == false)
cout << "Washer/dryer connection : " << "No" << endl;
else
cout << "Washer/dryer connection : " << "Yes" << endl;
if (pet_allowed == false)
cout << "Pet Allowed : " << "No" << endl;
else
cout << "Pet Allowed : " << "Yes" << endl;
}
};
int main(){
int num_rooms;
double monthly_rent;
double area;
bool washer_dryer_connection;
bool pet_allowed;
cout << "Enter number of rooms for onCampusApt :";
cin >> num_rooms;
cout << "Enter monthly rent for onCampusApt :";
cin >> monthly_rent;
cout << "Enter area for onCampusApt :";
cin >> area;
cout << "Enter washer/dryer connection for onCampusApt (0-false/1-true) :";
cin >> washer_dryer_connection;
cout << "Enter pet allowed for onCampusApt(0-false/1-true) :";
cin >> pet_allowed;
Apartment onCampusApt(num_rooms,monthly_rent, area,washer_dryer_connection,pet_allowed);
cout << "OnCampusApt data is as follows:" << endl;
onCampusApt.disp();
cout<< endl;
cout << "Enter number of rooms for offCampusApt :";
cin >> num_rooms;
cout << "Enter monthly rent for offCampusApt :";
cin >> monthly_rent;
cout << "Enter area for offCampusApt :";
cin >> area;
cout << "Enter washer/dryer connection for offCampusApt (0-false/1-true):";
cin >> washer_dryer_connection;
cout << "Enter pet allowed for offCampusApt (0-false/1-true):";
cin >> pet_allowed;
Apartment offCampusApt(num_rooms,monthly_rent, area,washer_dryer_connection,pet_allowed);
cout << "OffCampusApt data is as follows:" << endl;
offCampusApt.disp();
cout<< endl;
if (onCampusApt.equal(offCampusApt)){
cout << "Both are equal" << endl;
}
else {
cout << "Both are not equal" << endl;
}
offCampusApt.setWasherDryerConnection(true);
offCampusApt.setPetAllowed(true);
offCampusApt.setArea(offCampusApt.getArea() + 150);
return 0;
}