shushus

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

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