-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacade.cpp
More file actions
122 lines (105 loc) · 2.77 KB
/
facade.cpp
File metadata and controls
122 lines (105 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
using namespace std;
// https://bukovel.com/ru/ski/hire
class SkiRent // аренда снаряжения
{
public:
double rentBoots(int feetSize, int skierLevel) // ботинки
{
double price = 159.99;
// if (feetSize < 40) price -= 20; // скидка для детей
return price;
}
double rentHelmet(int feetSize, int skierLevel) // шлем
{
return 120;
}
double rentSki(int weight, int skierLevel) // лыжи
{
return 180;
}
double rentSkiPoles(int height) // лыжные палки
{
return 50;
}
};
// https://bukovel24.com/ru/skipass
class SkiResortTicketSystem // покупка билетов
{
public:
double buyOneDayTicket()
{
return 1100;
}
double buyTwoDaysTicket()
{
return 2050;
}
double buyThreeDaysTicket()
{
return 2900;
}
double buyFourDaysTicket()
{
return 3800;
}
double buyFiveDaysTicket()
{
return 4600;
}
double buySixDaysTicket()
{
return 5150;
}
double buySevenDaysTicket()
{
return 5800;
}
};
// https://bukovel24.com/uk/hotels
class HotelBookingSystem // заказ гостиницы
{
public:
double bookRoom(int roomQuality) {
switch (roomQuality) {
case 3:
return 5670 / 2;
case 4:
return 9240 / 2;
case 5:
return 41500 / 2;
default:
throw "roomQuality should be in range [3;5]";
}
}
};
class SkiResortFacade // реализация паттерна "фасад"
{
SkiRent sr;
SkiResortTicketSystem ts;
HotelBookingSystem hb;
public:
double haveAVeryVeryNiceTime(int height, int weight, int feetSize, int skierLevel, int roomQuality)
{
double skiPrice = sr.rentSki(weight, skierLevel);
double skiBootsPrice = sr.rentBoots(feetSize, skierLevel);
double polesPrice = sr.rentSkiPoles(height);
double skiPassPrice = ts.buySevenDaysTicket();
double hotelPrice = hb.bookRoom(roomQuality);
return skiPrice + skiBootsPrice + polesPrice + skiPassPrice + hotelPrice;
}
double haveALittleFunWithYourOwnEquipmentAndTent()
{
double skiPassPrice = ts.buyOneDayTicket();
return 0 + 0 + 0 + skiPassPrice + 0;
}
};
int main()
{
SkiResortFacade facade;
double vacationPrice = facade.haveAVeryVeryNiceTime(177, 80, 43, 0, 5);
// double vacationPrice = facade.haveAVeryVeryNiceTime(177, 80, 43, 0, 4);
// double vacationPrice = facade.haveAVeryVeryNiceTime(177, 80, 43, 0, 3);
// double vacationPrice = facade.haveALittleFunWithYourOwnEquipmentAndTent();
cout << "Price: " << vacationPrice << " UAH\n";
}