shushus

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

Dec 12th, 2022
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. -----------------------------------------------------------------------
  2. carpenter.h
  3. -----------------------------------------------------------------------
  4. #include "wall.h"
  5.  
  6. class Carpenter {
  7. public:
  8.     int CalcShelves(const Wall& wall) const;
  9. };
  10. -----------------------------------------------------------------------
  11. carpenter.cpp
  12. -----------------------------------------------------------------------
  13. #include "square_calculation.h"
  14. #include "carpenter.h"
  15.  
  16.  
  17. int Carpenter::CalcShelves(const Wall& wall) const{
  18.     double height = wall.GetHeight();
  19.     double width = wall.GetWidth();
  20.     return (int)CalcSquare(height, width)/2;
  21. }
  22. -----------------------------------------------------------------------
  23. wall.h
  24. -----------------------------------------------------------------------
  25. class Wall {
  26. public:
  27.     enum class Color { BLUE, GREEN, RED, WHITE, YELLOW };
  28.  
  29.     Wall(double width, double height);
  30.  
  31.     double GetHeight() const;
  32.     double GetWidth() const;
  33.     void SetColor(Color color);
  34.     Color GetColor() const;
  35.  
  36. private:
  37.     double width_;
  38.     double height_;
  39.     Color color_;
  40. };
  41. -----------------------------------------------------------------------
  42. square_calculation.h
  43. -----------------------------------------------------------------------
  44.  
  45. double CalcSquare(double width, double height);
  46.  
  47. -----------------------------------------------------------------------
  48. square_calculation.cpp
  49. -----------------------------------------------------------------------
  50.  
  51. double CalcSquare(double height, double width) {
  52.     return width * height;
  53. }
  54.  
  55. -----------------------------------------------------------------------
  56. wall.cpp
  57. -----------------------------------------------------------------------
  58. #include "wall.h"
  59.  
  60. Wall::Wall(double width, double height)
  61.     : width_(width)
  62.     , height_(height)
  63.     , color_(Color::WHITE) {
  64. }
  65.  
  66. double Wall::GetHeight() const {
  67.     return height_;
  68. }
  69. double Wall::GetWidth() const {
  70.     return width_;
  71. }
  72. void Wall::SetColor(Color color) {
  73.     color_ = color;
  74. }
  75. Wall::Color Wall::GetColor() const {
  76.     return color_;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment