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

For your program you will create a class that represents a room. I have provided

ID: 3573855 • Letter: F

Question

For your program you will create a class that represents a room. I have provided a main function (house.cpp) that tests the class that you will write. I have also provided a header file with the class declaration: Room.h. Your task is follow the comments in this file and implement the class (that is, write the definitions of the class member functions), as well as initializing the static data members. You also need to follow the comments in house.cpp to make the specified changes to this file.

When you run the main function I provided in house.cpp without the specified changes your output should look like the picture below. To see what your output should look like after the changes run my sample solution please.

House.cpp

#include "Room-solution.h"

////////////////////////
//
// MODIFY THIS FILE ACCORDING TO THE INSTRUCTIONS SHOWN BELOW IN CAPITAL LETTERS:
//
////////////////////////

int main()
{
// Create four room objects
Room lr(15, 12, "Living Room");
Room dr(12, 11, "Dining Room");
Room b1(13, 10, "Master Bedroom");
Room b2(10, 10, "Guest Bedroom");
// ADD A REST ROOM rr (size 6 by 7)

// ADD ANOTHER GUEST BEDROOM b3 WITH DEFAULT DIMENSIONS AND NAME

// ASSIGN TO b3 THE DIMENSIONS AND NAME OF b2

// CHANGE THE LENGTH AND WIDTH OF b3 TO 9 AND 8 RESPECTIVELY

int area; // area of the house
  
// Change the units of measurement to feet
Room::units = "feet";

// Print the number of rooms in the house
cout << "Number of rooms in the house = ";
cout << Room::numRooms << endl;

// Print the rooms in the house
cout << endl;
Room::printHeader();
lr.print();
cout << endl;
dr.print();
cout << endl;
b1.print();
cout << endl;
b2.print();
// INCLUDE THE ADDED ROOMS IN YOUR PRINT OUT

cout << endl << endl;

// INCLUDE THE AREA OF THE ADDED ROOMS IN THE CALCULATION OF THE TOTAL AREA

// Calculate and print the total area of the house
area = lr.getArea() + dr.getArea() + b1.getArea() + b2.getArea();
cout << "Total area of the house = " << area << " ";
cout << Room::units << endl;
  
system("pause");
return 0;

Room.H

#include<iostream>
#include<iomanip>
#include<string>

using namespace std;


// Class definition: do not modify
class Room
{
public:
Room(int l = 1, int w = 1, string n = "NULL");
~Room();
void setLength(int l);
int getLength() const;
void setWidth(int w);
int getWidth() const;
void setName(string n);
string getName() const;
int getArea() const;
void print() const;
static void printHeader();
static int numRooms;
static string units;
  
private:
int length;
int width;
string name;
};

////////////////////////////////////
// Your code begins here
// I have provided comments describing each function that you need to write.

// Initialize the static variables
// Set counter of rooms to 0 and the units to "meters"
//

//
// Constructor
//
// Use the MUTATOR functions to set the values of the private data members
// Increment the counter of rooms
//


//
// Destructor
// Decrement the counter of rooms
//


//
// Set the length of the room
//
// The length must be greater than zero, if the length provided is not greater than zero, set it to 1
//


//
// Return the length of the room
//


//
// Set the width of the room
//
// The width must be greater than zero, if the width provided is not greater than zero, set it to 1
//

//
// Return the width of the room
//


//
// Set the name of the room
//

//
// Return the name of the room
//


//
// Calculate the area of the room
//


//
// Print information about the room in a nice format
//
// Follow the example in the lab assignment picture
//


//
// Print a header for room information
//
// Follow the example in the lab assignment picture
//

// End of your code
////////////////////////////////////

Explanation / Answer

////definiation of Room.cpp class

include Room.H

// Initialize the static variables

// Set counter of rooms to 0 and the units to "meters"

numRooms=0;

units="meters";

//

// Constructor

//

Room::Room(int len,int width,string name){

setLength(len);

setWidth(width);

setName(name);

// Increment the counter of rooms

numRooms= numRooms+1;

}

//

// destructor

//

Room::~Room(){

// decrement the counter of rooms

numRooms= numRooms-1;

}

//

/ / MUTATOR functions to set the values of the private data members

//

void Room::setLength(int l){

if(l<0){

length=1;

}

else{

length = l;

}

}

int Room::getLength(){

return length;

}

void Room::setWidth(int w){

if(l<0){

width=1;

}

else{

width = w;

}

}

int Room::getWidth(){

return width;

}

void Room::setName(string n){

name = n;

}

int Room::getName(){

return name;

}

//

// Calculate the area of the room

//

int Room:: getArea(){

int area= length*width;

return area;

}

//

// Print information about the room in a nice format

//

void Room:: print(){

cout << "length of the house = " << length<< " ";

cout << "width of the house = " << width << " ";

}

//

// Print a header for room information

//

// house.cpp

////////////////////////

int main()

{

// Create four room objects

// Room lr(15, 12, "Living Room");

Room lr= Room(15, 12, "Living Room");

//Room dr(12, 11, "Dining Room");

Room dr = Room(12, 11, "Dining Room");

// Room b1(13, 10, "Master Bedroom");

Room b1= Room(13, 10, "Master Bedroom");

//Room b2(10, 10, "Guest Bedroom");

Room b2=Room(10, 10, "Guest Bedroom");

// ADD A REST ROOM rr (size 6 by 7)

Room rr=Room(6,7,"Rest Room");

// ADD ANOTHER GUEST BEDROOM b3 WITH DEFAULT DIMENSIONS AND NAME

Room b3=Room();

// ASSIGN TO b3 THE DIMENSIONS AND NAME OF b2

b3.length=b2.length;

b3.width=b2.width;

b3.name=b2.name;

// CHANGE THE LENGTH AND WIDTH OF b3 TO 9 AND 8 RESPECTIVELY

b3.length=9;

b3.width=8;

  

int area; // area of the house

  

// Change the units of measurement to feet

Room::units = "feet";

// Print the number of rooms in the house

cout << "Number of rooms in the house = ";

cout << Room::numRooms << endl;

// Print the rooms in the house

cout << endl;

Room::printHeader();

lr.print();

cout << endl;

dr.print();

cout << endl;

b1.print();

cout << endl;

b2.print();

// INCLUDE THE ADDED ROOMS IN YOUR PRINT OUT

rr.print();

cout << endl;

b3.print();

cout << endl << endl;

// INCLUDE THE AREA OF THE ADDED ROOMS IN THE CALCULATION OF THE TOTAL AREA

// Calculate and print the total area of the house

area = lr.getArea() + dr.getArea() + b1.getArea() + b2.getArea()+rr.getArea ()+b3.getArea();

cout << "Total area of the house = " << area << " ";

cout << Room::units << endl;

  

system("pause");

return 0;

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