fork download
  1. // Calculate the area required for painting a room and the cost
  2. // Language used C++
  3.  
  4. /*
  5. Room is an object whose data members are the 4 walls and the ceiling
  6.   All the 4 walls are themselves an object with data members being their length and breadth
  7. */
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. class Wall
  13. {
  14. private:
  15. float length ;
  16. float breadth ;
  17. public:
  18. void getWallDimensions()
  19. {
  20. if (length ==0 || breadth ==0)
  21. {
  22. cout << " The dimensions have not been set ";
  23. }
  24. else
  25. {
  26. cout << " The length of the wall is" << length << endl;
  27. }
  28. }
  29.  
  30. void setWallDimensions()
  31. {
  32. cout << " Enter the length of the wall" << endl;
  33. cin >> length;
  34. cout << " Enter the breadth of the wall" << endl;
  35. cin >> breadth;
  36. }
  37.  
  38. float getWallArea()
  39. {
  40. float wall_area;
  41. wall_area = length * breadth;
  42. return wall_area;
  43. }
  44. };
  45.  
  46. class Room
  47. {
  48.  
  49. private:
  50. Wall f_w; //First Wall object
  51. Wall s_w; //Second wall object
  52. Wall t_w; //Third wall object
  53. Wall ft_w; //Fourth wall object
  54. Wall c; //Ceiling object
  55.  
  56. float room_area;
  57.  
  58.  
  59. public:
  60.  
  61.  
  62. void setRoomDimensions() // Sets the length and breadth for all the walls and ceiling of the room
  63. {
  64. cout << " Enter the dimensions for the first wall" << endl;
  65. f_w.setWallDimensions();
  66.  
  67. cout << " Enter the dimensions for the second wall" << endl;
  68. s_w.setWallDimensions();
  69.  
  70. cout << " Enter the dimensions for the third wall" << endl;
  71. t_w.setWallDimensions();
  72.  
  73. cout << " Enter the dimensions for the fourth wall" << endl;
  74. f_w.setWallDimensions();
  75.  
  76. cout << " Enter the dimensions for the ceiling" << endl;
  77. c.setWallDimensions();
  78. }
  79.  
  80. void getRoomArea()
  81.  
  82. {
  83. room_area = f_w.getWallArea() + s_w.getWallArea() + t_w.getWallArea() + ft_w.getWallArea() + c.getWallArea();
  84. cout << " The total area of the room is : " << room_area;
  85. }
  86.  
  87.  
  88. };
  89.  
  90.  
  91.  
  92.  
  93. int main ()
  94. {
  95. Room bedroom;
  96. bedroom.setRoomDimensions();
  97. bedroom.getRoomArea();
  98. return 0;
  99. }
Success #stdin #stdout 0s 3148KB
stdin
Standard input is empty
stdout
 Enter the dimensions for the first wall
 Enter the length of the wall
 Enter the breadth of the wall
 Enter the dimensions for the second wall
 Enter the length of the wall
 Enter the breadth of the wall
 Enter the dimensions for the third wall
 Enter the length of the wall
 Enter the breadth of the wall
 Enter the dimensions for the fourth wall
 Enter the length of the wall
 Enter the breadth of the wall
 Enter the dimensions for the ceiling
 Enter the length of the wall
 Enter the breadth of the wall
 The total area of the room is : 2.1087