1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
class Room
{
public:
Room ( const double& _dHeight
, const double& _dWidth
, const int& _iFloor
, const std::string& _sColor
)
: m_dHeight (_dHeight)
, m_dWidth (_dWidth)
, m_dDimension (_dheight * _dWidth)
, m_iFloor (_iFloor)
, m_sColor (_sColor)
{
}
std::string color() const
{
return m_sColor;
}
double dimension() const
{
return m_dDimension;
}
int floor() const
{
return m_iFloor,
}
private:
double m_dHeight;
double m_dWidth;
double m_dDimension;
int m_iFloor;
std::string m_sColor;
};
class Building
{
public:
Building(const int& _iFloor) : m_iFloor (_iFloor)
{
}
~Building()
{
for (auto& pRoom : m_vRoom)
{
delete pRoom;
}
std::vector<Room*> ().swap(m_vRoom);
}
void add ( const double& _dHeight
, const double& _dWidth
, const int& _iFloor
, const std::string& _sColor
)
{
Room* pRoom (new Room(_dHeight, _dWidth, _iFloor, _sColor));
m_vRoom.push_back(pRoom)
}
double area() const
{
double dArea (0.0);
for (auto& pRoom : m_vRoom)
{
dArea += pRoom->dimension();
}
return dArea;
}
double area(const int& _iFloor) const
{
double dArea (0.0);
for (auto& pRoom : m_vRoom)
{
if (pRoom->floor() == _iFloor)
{
dArea += pRoom->dimension();
}
}
return dArea;
}
std::string color(const size_t& _stRoom) const
{
return m_vRoom.at(_stRoom)->color();
}
double dimension(const size_t& _stRoom) const
{
return m_vRoom.at(_stRoom)->dimension();
}
int floor(const size_t& _stRoom) const
{
return m_vRoom.at(_stRoom)->floor();
}
private:
int m_iFloor; // Number of floors
std::vector<Room*> m_vRoom;
};
|