shushus

Спринт 5. Независимость заголовочных файлов. Задание 2.

Dec 12th, 2022
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.87 KB | None | 0 0
  1. -----------------------------------------------------------------------
  2. accountant.h
  3. -----------------------------------------------------------------------
  4. #pragma once
  5. #include "wall.h"
  6.  
  7. class Accountant {
  8. public:
  9.     double CalcPaintNeeded(const Wall& wall) const;
  10.     double CalcBricksNeeded(const Wall& wall) const;
  11. };
  12. -----------------------------------------------------------------------
  13. builder.h
  14. -----------------------------------------------------------------------
  15. #pragma once
  16. #include "square_calculation.h"
  17.  
  18. class Builder {
  19. public:
  20.     void HoldDoor() const {
  21.         for (int i = 100; i != 0; --i) {
  22.             /* держит дверь */
  23.         }
  24.     }
  25. };
  26. -----------------------------------------------------------------------
  27. carpenter.cpp
  28. -----------------------------------------------------------------------
  29. #include "carpenter.h"
  30.  
  31. #include "square_calculation.h"
  32.  
  33. int Carpenter::CalcShelves(const Wall& wall) const {
  34.     double height = wall.GetHeight();
  35.     double width = wall.GetWidth();
  36.     return CalcSquare(width, height) / 2;
  37. }
  38.  
  39. void Carpenter::InstallDoor(Wall& wall, const Builder& builder) const {
  40.     // Hold the door, builder! Hold the door!
  41.     builder.HoldDoor();
  42.     wall.SetDoorInstalled();
  43. }
  44. -----------------------------------------------------------------------
  45. carpenter.h
  46. -----------------------------------------------------------------------
  47. #pragma once
  48. #include "builder.h"
  49. #include "wall.h"
  50.  
  51. class Carpenter {
  52. public:
  53.     int CalcShelves(const Wall& wall) const;
  54.     void InstallDoor(Wall& wall, const Builder& builder) const;
  55. };
  56. -----------------------------------------------------------------------
  57. main.cpp
  58. -----------------------------------------------------------------------
  59. #include <iostream>
  60.  
  61. #include "accountant.h"
  62. #include "builder.h"
  63. #include "carpenter.h"
  64. #include "painter.h"
  65.  
  66. using namespace std;
  67.  
  68. int main() {
  69.     Builder tom;
  70.     Carpenter jack;
  71.     Accountant ray;
  72.     Wall wall(3.5, 2.45);
  73.  
  74.     cout << ray.CalcBricksNeeded(wall) << endl;
  75.     cout << ray.CalcPaintNeeded(wall) << endl;
  76.  
  77.     jack.InstallDoor(wall, tom);
  78.     cout << wall.IsDoorInstalled() << endl;
  79.     return 0;
  80. }
  81. -----------------------------------------------------------------------
  82. painter.h
  83. -----------------------------------------------------------------------
  84. #pragma once
  85. #include "square_calculation.h"
  86. #include "wall.h"
  87.  
  88. class Painter {
  89. public:
  90.     void Paint(Wall& wall, Wall::Color color) const {
  91.         wall.SetColor(color);
  92.     }
  93. };
  94. -----------------------------------------------------------------------
  95. square_calculation.cpp
  96. -----------------------------------------------------------------------
  97. #include "square_calculation.h"
  98.  
  99. double CalcSquare(double width, double height) {
  100.     return width * height;
  101. }
  102. -----------------------------------------------------------------------
  103. square_calculation.h
  104. -----------------------------------------------------------------------
  105. #pragma once
  106. double CalcSquare(double width, double height);
  107. -----------------------------------------------------------------------
  108. wall.cpp
  109. -----------------------------------------------------------------------
  110. #include "wall.h"
  111.  
  112. Wall::Wall(double width, double height)
  113.     : width_(width)
  114.     , height_(height)
  115.     , color_(Color::WHITE)
  116.     , is_door_installed_(false) {
  117. }
  118.  
  119. double Wall::GetHeight() const {
  120.     return height_;
  121. }
  122. double Wall::GetWidth() const {
  123.     return width_;
  124. }
  125. void Wall::SetColor(Color color) {
  126.     color_ = color;
  127. }
  128. Wall::Color Wall::GetColor() const {
  129.     return color_;
  130. }
  131. bool Wall::IsDoorInstalled() const {
  132.     return is_door_installed_;
  133. }
  134. void Wall::SetDoorInstalled() {
  135.     is_door_installed_ = true;
  136. }
  137. -----------------------------------------------------------------------
  138. wall.h
  139. -----------------------------------------------------------------------
  140. #pragma once
  141.  
  142. class Wall {
  143. public:
  144.     enum class Color { BLUE, GREEN, RED, WHITE, YELLOW };
  145.  
  146.     Wall(double width, double height);
  147.  
  148.     double GetHeight() const;
  149.     double GetWidth() const;
  150.     void SetColor(Color color);
  151.     Color GetColor() const;
  152.     bool IsDoorInstalled() const;
  153.     void SetDoorInstalled();
  154.  
  155. private:
  156.     double width_;
  157.     double height_;
  158.     Color color_;
  159.     bool is_door_installed_;
  160. };
  161. -----------------------------------------------------------------------
  162. accountant.cpp
  163. -----------------------------------------------------------------------
  164. #include "accountant.h"
  165. #include "square_calculation.h"
  166.  
  167. double Accountant::CalcPaintNeeded(const Wall& wall) const{
  168.     double height = wall.GetHeight();
  169.     double width = wall.GetWidth();
  170.     return CalcSquare(width, height) * 0.4;
  171. }
  172.  
  173. double Accountant::CalcBricksNeeded(const Wall& wall) const{
  174.     double height = wall.GetHeight();
  175.     double width = wall.GetWidth();
  176.     return CalcSquare(width, height) * 5;
  177. }
Advertisement
Add Comment
Please, Sign In to add comment