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

Help C++. Construct a class named Room that declares two double-precision data m

ID: 3735411 • Letter: H

Question

Help C++.

Construct a class named Room that declares two double-precision data members named length and width. Include a constructor that initializes each data member to 1.0, when a room object is created. Add two accessor functions for displaying the length and width values of room object and two mutators functions that allows changing these data member values.

1-Modify the main () function to create a second room with a length of 9 and a width of 12.

2-Add a class function named area() that calculates and display a room’s area.

Explanation / Answer

#include <iostream>

using namespace std;
class Room {
private:
double length, width;
public:
Room() {
length = 1.0;
width = 1.0;
}
void setLength(double l) {
length = l;
}
void setWidth(double w) {
width = w;
}
double area() {
return length * width;
}
};
int main() {
Room r1,r2;
cout<<"Area: "<<r1.area()<<endl;
r2.setLength(9);
r2.setWidth(12);
cout<<"Area: "<<r2.area()<<endl;
  
}

Output:

Area: 1
Area: 108