shushus

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

Dec 12th, 2022
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. -----------------------------------------------------------------------
  2. main.cpp
  3. -----------------------------------------------------------------------
  4.  
  5. #include <iostream>
  6. #include "builder.h"
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11.     Wall wall(3.5, 2.45);
  12.     Builder tom;
  13.     // Попросите Тома посчитать кирпичи для стены 3.5 х 2.45
  14.     const auto num_of_bricks = tom.CalcBricksNeeded(wall);
  15.     cout<<num_of_bricks;
  16. }
  17. -----------------------------------------------------------------------
  18. builder.h
  19. -----------------------------------------------------------------------
  20. #include "wall.h"
  21.  
  22. class Builder {
  23. public:
  24.     double CalcBricksNeeded(const Wall& wall) const {
  25.         double height = wall.GetHeight();
  26.         double width = wall.GetWidth();
  27.         return width * height * 5;
  28.     }
  29. };
  30. -----------------------------------------------------------------------
  31. wall.h
  32. -----------------------------------------------------------------------
  33. class Wall {
  34. public:
  35.     Wall(double width, double height)
  36.         : width_(width)
  37.         , height_(height) {
  38.     }
  39.  
  40.     double GetHeight() const {
  41.         return height_;
  42.     }
  43.     double GetWidth() const {
  44.         return width_;
  45.     }
  46.  
  47. private:
  48.     double width_;
  49.     double height_;
  50. };
  51.  
Advertisement
Add Comment
Please, Sign In to add comment