Need help starting this program.

Hi,

I need to write a program that does calculates the floor area in a house for carpeting material.

It must do the following.

1) Asks for the number of floors in a house.
2) Asks for the number of rooms on each floor.
3) Asks for the dimensions of the floor space in each room.
4) Asks for the colour of the floor in each room.

It must then output a file that;

1) Calculates the size of the floor in each room and the colour of the flooring material.
2)Calculates the total floor area per floor.
3)Calculates the total floor area in the whole house.


I'm thinking of somehow running a loop with the number of rooms within a loop for the number of floors. But how would I store the dimensions and floor specs?

Any help would be massively appreciated!
I would define the following types(structs or classes) depending what you are allowed to use.

Room:
- colour
- dimension

Floor:
- number of rooms
- array of Room

House:
- number of floors
- array of floors
closed account (oGN8b7Xj)
I would do:

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;
};
Last edited on
Topic archived. No new replies allowed.