Question
C++ (please add comments) Program 4) Modify the main() function in the following program to add a Bathroom of size (10.2, 10.5) and existing Dining
C++ (please add comments)
Program 4)
Modify the main() function in the following program to add a Bathroom of size (10.2, 10.5) and
existing Dining room is now modified to be 10.6, 8.0 instead of 14,10.5
Add comments where you are adding or modifying the code
Your program should display Total area of the home after the changes.
Extra points:
Add functionality so you can enter the price per square feet as a public variable.
Then you add new code to calculate price of each Room and total price of the house.
#include
#include
using namespace std;
class RoomType
{
private:
double length; //Declare length as a double variable double width; //Declare width as a double
variable
public:
RoomType(double = 0.0, double = 0.0); //The constructor's declaration void showRoomValues();
void setNewRoomValues(double, double);
double calculateRoomArea();
};
//Class implementation section
RoomType::RoomType(double l, double w) //This is a constructor {
length = l;
width = w; }
void RoomType::showRoomValues() //Accessor {
cout << " Length = " << length
<< " width = " << width << endl;
}
void RoomType::setNewRoomValues(double l, double w) //Mutator {
length = l;
width = w; }
double RoomType::calculateRoomArea() //Performs the area calculation {
return (length * width);
}
int main() {
//Declares variable of type of RoomType with length x width dimensions
RoomType hall(12.40, 3.5);
RoomType kitchen(14, 14);
RoomType LivingRoom(12.4, 20);
RoomType DiningRoom(14, 10.5);
double sum = 0; //Sum double variable to stores the area of each room after calculation
cout << "---------Hall---------------- ";
cout << "The area of the hall is: " << hall.calculateRoomArea(); cout << endl;
sum = sum + hall.calculateRoomArea(); //Adds hall area into sum
cout << " ---------Kitchen------------- ";
cout << "The area of the kitchen is: " << kitchen.calculateRoomArea(); cout << endl;
sum = sum + kitchen.calculateRoomArea(); //Adds kitchen area into sum
cout << " ---------Living Room--------- ";
cout << "The area of the living room is: " << LivingRoom.calculateRoomArea(); cout << endl;
sum = sum + LivingRoom.calculateRoomArea(); //Adds living room area into sum
cout << " ---------Dining Room--------- ";
cout << "The area of the dining room is: " << DiningRoom.calculateRoomArea(); cout << endl;
sum = sum + DiningRoom.calculateRoomArea(); //Adds dining room area into sum
cout << " ---------All 4 Rooms--------- ";
cout << "The total area of all 4 rooms combined is: "
<< sum; //Outputs value of each room's area that has been stored into sum
cout << endl << endl;
system("pause");
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