Advertisement
chevengur

СПРИНТ № 5 | Распределение кода по файлам | Урок 3: Директива #include 2/2

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