shushus

Спринт 5. Проблема двойного включения.

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