Advertisement
chevengur

СПРИНТ № 5 | Распределение кода по файлам | Урок 4: Заголовочные файлы и файлы с реализацией 2/2

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