Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Урок 7: Независимость заголовочных файлов 7.1
- -----------------------------------------------------------------------
- accountant.h
- -----------------------------------------------------------------------
- #pragma once
- #include "square_calculation.h"
- #include "wall.h"
- class Accountant {
- public:
- double CalcPaintNeeded(const Wall& wall) const {
- double height = wall.GetHeight();
- double width = wall.GetWidth();
- return CalcSquare(width, height) * 0.4;
- }
- double CalcBricksNeeded(const Wall& wall) const {
- double height = wall.GetHeight();
- double width = wall.GetWidth();
- return CalcSquare(width, height) * 5;
- }
- };
- -----------------------------------------------------------------------
- builder.h
- -----------------------------------------------------------------------
- #pragma once
- class Builder {
- public:
- void HoldDoor() const {
- for (int i = 100; i != 0; --i) {
- /* держит дверь */
- }
- }
- };
- -----------------------------------------------------------------------
- carpenter.cpp
- -----------------------------------------------------------------------
- #include "carpenter.h"
- #include "square_calculation.h"
- int Carpenter::CalcShelves(const Wall& wall) const {
- double height = wall.GetHeight();
- double width = wall.GetWidth();
- return CalcSquare(width, height) / 2;
- }
- void Carpenter::InstallDoor(Wall& wall, const Builder& builder) const {
- // Hold the door, builder! Hold the door!
- builder.HoldDoor();
- wall.SetDoorInstalled();
- }
- -----------------------------------------------------------------------
- carpenter.h
- -----------------------------------------------------------------------
- #pragma once
- #include "builder.h"
- #include "wall.h"
- class Carpenter {
- public:
- int CalcShelves(const Wall& wall) const;
- void InstallDoor(Wall& wall, const Builder& builder) const;
- };
- -----------------------------------------------------------------------
- main.cpp
- -----------------------------------------------------------------------
- #include <iostream>
- #include "accountant.h"
- #include "builder.h"
- #include "carpenter.h"
- #include "painter.h"
- using namespace std;
- int main() {
- Builder tom;
- Painter bill;
- Carpenter jack;
- Accountant ray;
- Wall wall(3.5, 2.45);
- cout << ray.CalcBricksNeeded(wall) << endl;
- cout << ray.CalcPaintNeeded(wall) << endl;
- jack.InstallDoor(wall, tom);
- cout << wall.IsDoorInstalled() << endl;
- return 0;
- }
- -----------------------------------------------------------------------
- painter.h
- -----------------------------------------------------------------------
- #pragma once
- #include "wall.h"
- class Painter {
- public:
- void Paint(Wall& wall, Wall::Color color) const {
- wall.SetColor(color);
- }
- };
- -----------------------------------------------------------------------
- square_calculation.cpp
- -----------------------------------------------------------------------
- #include "square_calculation.h"
- double CalcSquare(double width, double height) {
- return width * height;
- }
- -----------------------------------------------------------------------
- square_calculation.h
- -----------------------------------------------------------------------
- #pragma once
- double CalcSquare(double width, double height);
- -----------------------------------------------------------------------
- wall.cpp
- -----------------------------------------------------------------------
- #include "wall.h"
- Wall::Wall(double width, double height)
- : width_(width)
- , height_(height)
- , color_(Color::WHITE)
- , is_door_installed_(false) {
- }
- double Wall::GetHeight() const {
- return height_;
- }
- double Wall::GetWidth() const {
- return width_;
- }
- void Wall::SetColor(Color color) {
- color_ = color;
- }
- Wall::Color Wall::GetColor() const {
- return color_;
- }
- bool Wall::IsDoorInstalled() const {
- return is_door_installed_;
- }
- void Wall::SetDoorInstalled() {
- is_door_installed_ = true;
- }
- -----------------------------------------------------------------------
- wall.h
- -----------------------------------------------------------------------
- #pragma once
- class Wall {
- public:
- enum class Color { BLUE, GREEN, RED, WHITE, YELLOW };
- Wall(double width, double height);
- double GetHeight() const;
- double GetWidth() const;
- void SetColor(Color color);
- Color GetColor() const;
- bool IsDoorInstalled() const;
- void SetDoorInstalled();
- private:
- double width_;
- double height_;
- Color color_;
- bool is_door_installed_;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement