shushus

Спринт 5. Директива #include. Задание 2.

Dec 12th, 2022
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. -----------------------------------------------------------------------
  2. main.cpp
  3. -----------------------------------------------------------------------
  4. #include "painter.h"
  5.  
  6. int main() {
  7.     Painter bill;
  8.     Wall wall(3.5, 2.45);
  9.  
  10.     bill.Paint(wall, Wall::Color::BLUE);
  11. }
  12. -----------------------------------------------------------------------
  13. wall.h
  14. -----------------------------------------------------------------------
  15. class Wall {
  16. public:
  17.     enum class Color { BLUE, GREEN, RED, WHITE, YELLOW };
  18.  
  19.     Wall(double width, double height)
  20.         : width_(width)
  21.         , height_(height)
  22.         , color_(Color::WHITE) {
  23.     }
  24.  
  25.     double GetHeight() const {
  26.         return height_;
  27.     }
  28.     double GetWidth() const {
  29.         return width_;
  30.     }
  31.     void SetColor(Color color) {
  32.         color_ = color;
  33.     }
  34.     Color GetColor() const {
  35.         return color_;
  36.     }
  37.  
  38. private:
  39.     double width_;
  40.     double height_;
  41.     Color color_;
  42. };
  43. -----------------------------------------------------------------------
  44. painter.h
  45. -----------------------------------------------------------------------
  46. #include "wall.h"
  47.  
  48. class Painter {
  49. public:
  50.     void Paint(Wall& wall, Wall::Color color) const {
  51.         wall.SetColor(color);
  52.     }  
  53. };
Advertisement
Add Comment
Please, Sign In to add comment