Take the provided code and finish defining the function members of the House cla
ID: 3553550 • Letter: T
Question
Take the provided code and finish defining the function members of the House class. Be sure and test the House class in a main function. The default constructor for House can be left as is. Don't make changes to the Room class. The display function should mention, by name each room (kitchen, etc.) and show each square foot area. Also display the total area of the house.
#include <iostream>
using namespace std;
class Room
{
public:
Room()
{
size = 100.0;
}
Room(double s)
{
if (s > 50.0)
size = s;
else
size = 100.0;
}
void set(double s)
{
if (s > 50.0)
size = s;
}
double get()
{
return size;
}
private:
double size; // square feet
};
class House
{
public:
House()
{
}
House(double brsz, double lrsz, double ktsz)
{
}
void setSize(double brsz, double lrsz, double ktsz)
{
}
void display()
{
}
private:
Room bedroom, livingroom, kitchen;
};
int main()
{
House hs1(1100.0, 1300.0, 800.0) hs2;
hs2.setSize(1400.0, 2300.0, 1200.0);
hs1.display();
hs2.display();
return 0;
}
Explanation / Answer
#include <iostream>
using namespace std;
class Room
{
public:
Room()
{
size = 100.0;
}
Room(double s)
{
if (s > 50.0)
size = s;
else
size = 100.0;
}
void set(double s)
{
if (s > 50.0)
size = s;
}
double get()
{
return size;
}
private:
double size; // square feet
};
class House
{
public:
House()
{
}
House(double brsz, double lrsz, double ktsz)
{
bedroom.set(brsz);
livingroom.set(lrsz);
kitchen.set(lrsz);
}
void setSize(double brsz, double lrsz, double ktsz)
{
bedroom.set(brsz);
livingroom.set(lrsz);
kitchen.set(lrsz);
}
void display()
{
cout<<"Bedroom size::"<<bedroom.get()<<" square foot area"<<endl;
cout<<"Livingroom size::"<<livingroom.get()<<" square foot area"<<endl;
cout<<"Kitchen size::"<<kitchen.get()<<" square foot area"<<endl;
cout<<"Total Area of the House::"<<bedroom.get()+livingroom.get()+kitchen.get()<<" square foot area"<<endl;
}
private:
Room bedroom, livingroom, kitchen;
};
int main()
{
House hs1(1100.0, 1300.0, 800.0),hs2;
hs2.setSize(1400.0, 2300.0, 1200.0);
hs1.display();
hs2.display();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.