-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cpp
More file actions
319 lines (293 loc) · 10.4 KB
/
Copy pathserver.cpp
File metadata and controls
319 lines (293 loc) · 10.4 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#include "restaurant.hpp"
Restaurant::Restaurant(string nameR , string districtR , string foodsDetail , int openingTimeR , int closingTimeR , int numberOfTablesR){
name = nameR;
district = districtR;
AddToFoodMenu(foodsDetail);
openingTime = openingTimeR;
closingTime = closingTimeR;
numberOfTables = numberOfTablesR;
MakeTableDetail();
}
void Restaurant::MakeTableDetail(){
for(int i = 1 ; i <= numberOfTables ; i++)
{
RestaurantTable* newTable = new RestaurantTable;
newTable->numberOfTable = i;
tables.push_back(newTable);
}
}
string Restaurant::DistrictGeter(){
return district;
}
bool Restaurant::FoodCheker(string foodN){
for(auto food : foodsMenu){
if(food->name == foodN){
return true;
}
}
return false;
}
void Restaurant::PrintBaseDetail(){
cout << name << SPACE << PARENTHESE_1 << district << PARENTHESE_2 << endl;
}
int Restaurant::reserveIDGeter(){
return reserveIdNumber;
}
void Restaurant::AddReserve(ReserveMethod* newReserve){
tables[(newReserve->table) - 1]->reserves.push_back(newReserve);
reserveIdNumber++;
}
bool Restaurant::ReserveIdCheker(int reserveID){
for(auto table : tables)
{
for(auto reserve : table->reserves)
{
if(reserve->reserveID == reserveID){
return true;
}
}
}
return false;
}
void Restaurant::DeleteReserve(ReserveMethod* deleteReserve){
int i = 0;
for(auto reserve : tables[deleteReserve->table - 1]->reserves)
{
if(reserve->reserveID == deleteReserve->reserveID && reserve->resturantName == deleteReserve->resturantName){
tables[deleteReserve->table - 1]->reserves.erase(tables[deleteReserve->table - 1]->reserves.begin() + i);
throw (OK_MESSAGE);
}
i++;
}
}
vector<int> Restaurant::FoodCalculator(vector<string> foods){
vector<int> price(2);
for(auto food : foods)
{
for(auto foodMenu : foodsMenu)
{
if(food == foodMenu->name)
{
if(foodMenu->foodDiscount != NULL){
cout << foodMenu->foodDiscount->DiscountValueGeter() << endl;
price[1] += foodMenu->foodDiscount->DiscountValueGeter();
}
price[0] += stoi(foodMenu->price);
}
}
}
return price;
}
int Restaurant::TotalPriceDiscountCalculator(int price){
int discount = 0;
if(totalPriceDiscount == NULL){
return discount;
}
if(price >= minimumPriceForDiscount){
discount = totalPriceDiscount->discountCalculator(price);
}
return discount;
}
int Restaurant::FirstOrderDiscountCalculator(int price , string userName){
int discount = 0;
if(firstOrderDiscount == NULL){
return discount;
}
for(auto user : userUserFirstOrderDiscount){
if(user == userName){
return discount;
}
}
discount = firstOrderDiscount->discountCalculator(price);
return discount;
}
void Restaurant::ReserveCheker(string userName , string &tableID , string &startTime , string &endTime , vector<string> &foods){
int startT = stoi(startTime) , endT = stoi(endTime);
if(tables.size() < stoi(tableID)){
throw (NOT_FOUND_MESSAGE);}
for(auto reserve : tables[stoi(tableID) - 1]->reserves)
{
if((startT > reserve->startingTime && startT < reserve->endingTime) || (endT > reserve->startingTime && endT < reserve->endingTime)){
throw (PERMISSION_DENIED_MESSAGE);}
}
if(startT < openingTime || endT > closingTime){
throw (PERMISSION_DENIED_MESSAGE);}
bool foodSituation = false;
for(auto foodReserve : foods)
{
for(auto food : foodsMenu)
{
if(foodReserve == food->name)
{
foodSituation = true;
}
}
if(foodSituation == false){
throw (NOT_FOUND_MESSAGE);}
foodSituation = false;
}
}
void Restaurant::AddToFoodMenu(string foodsDetail){
stringstream foodsDetailNote(foodsDetail);
string foodDetail;
while(getline(foodsDetailNote , foodDetail , ';'))
{
Food* newFood = new Food;
stringstream foodDetailNote(foodDetail);
getline(foodDetailNote , newFood->name , ':');
getline(foodDetailNote , newFood->price);
foodsMenu.push_back(newFood);
}
}
string Restaurant::NameGeter(){
return name;
}
void Restaurant::RestaurantDetail(){
int number = 1;
cout << NAME << name << endl;
cout << DISTRICT << district << endl;
cout << TIME << openingTime << MINUS << closingTime << endl;
cout << MENU ;
PrintFoodMenu();
for(auto table : tables)
{
cout << number << COLON;
PrintTableDetail(number);
number++;
}
PrintDiscountDetail();
}
void Restaurant::PrintDiscountDetail(){
if(totalPriceDiscount != NULL){
cout << ORDER_AMOUNT_NOTE << totalPriceDiscount->TypeGeter() << COMMA << SPACE << minimumPriceForDiscount << COMMA << SPACE << totalPriceDiscount->DiscountValueGeter() << endl;
}
if(FoodDiscountCheker()){
cout << ITEM_SPECIFIC_NOTE ;
int i = 0;
for(auto food : foodsMenu){
if((food->foodDiscount != NULL) && (i == 0)){
cout << SPACE << food->name << PARENTHESE_1 << food->foodDiscount->TypeGeter() << COLON << SPACE << food->foodDiscount->DiscountValueGeter() << PARENTHESE_2;
i++;
}
else if(food->foodDiscount != NULL){
cout << COMMA << SPACE << food->name << PARENTHESE_1 << food->foodDiscount->TypeGeter() << COLON << SPACE << food->foodDiscount->DiscountValueGeter() << PARENTHESE_2;
}
}
cout << endl;
}
if(firstOrderDiscount != NULL){
cout << FIRST_ORDER_NOTE << firstOrderDiscount->TypeGeter() << COMMA << SPACE << firstOrderDiscount->DiscountValueGeter() << endl;
}
}
bool Restaurant::FoodDiscountCheker(){
for(auto food : foodsMenu){
if(food->foodDiscount != NULL){
return true;
}
}
return false;
}
void Restaurant::PrintFoodMenu(){
int number = 0;
vector<Food*> foodsMenuSort = foodsMenu;
sort(foodsMenuSort.begin(), foodsMenuSort.end(), [](const Food* d1, const Food* d2) { return d1->name < d2->name; });
for(auto foodMenuSort : foodsMenuSort)
{
if(number == (foodsMenu.size() - 1)){
cout << SPACE << foodMenuSort->name << PARENTHESE_1 << foodMenuSort->price << PARENTHESE_2 << endl ;
}
else{
cout << SPACE << foodMenuSort->name << PARENTHESE_1 << foodMenuSort->price << PARENTHESE_2 << COMMA ;
}
number++;
}
}
void Restaurant::PrintTableDetail(int numberTable){
int number = 0;
numberOfTables--;
if(tables[numberOfTables]->reserves.size() == 0){
cout << endl;
}
else{
sort(tables[numberOfTables]->reserves.begin(), tables[numberOfTables]->reserves.end(), [](const ReserveMethod* r1, const ReserveMethod* r2) { return r1->startingTime < r2->startingTime; });
for(auto reserve : tables[numberOfTables]->reserves)
{
if(number == tables[numberOfTables]->reserves.size() - 1){
cout << SPACE << PARENTHESE_1 << reserve->startingTime << MINUS << reserve->endingTime << PARENTHESE_2 << endl;
}
else{
cout << SPACE << PARENTHESE_1 << reserve->startingTime << MINUS << reserve->endingTime << PARENTHESE_2 << COMMA;
}
number++;
}
}
}
void Restaurant::DiscountLineReader(string discountLine){
stringstream discountLineNote(discountLine);
string totalPriceDiscountLine , firstOrderDiscountLine , foodDiscountLine;
getline(discountLineNote , totalPriceDiscountLine , COMMA);
getline(discountLineNote , firstOrderDiscountLine , COMMA);
getline(discountLineNote , foodDiscountLine , COMMA);
if(totalPriceDiscountLine != NONE){
TotalPriceDiscountLineReader(totalPriceDiscountLine);}
if(firstOrderDiscountLine != NONE){
FirstOrderDiscountLineReader(firstOrderDiscountLine);}
if(foodDiscountLine != NONE){
FoodDiscountLineReader(foodDiscountLine);}
}
void Restaurant::TotalPriceDiscountLineReader(string totalPriceDiscountLine){
string type , minimume , value;
stringstream totalPriceDiscountLineNote(totalPriceDiscountLine);
getline(totalPriceDiscountLineNote , type , SEMICOLON);
getline(totalPriceDiscountLineNote , minimume , SEMICOLON);
getline(totalPriceDiscountLineNote , value , SEMICOLON);
minimumPriceForDiscount = stoi(minimume);
if(type == PERCENT){
Percent* totalDiscountType = new Percent(stoi(value));
totalPriceDiscount = totalDiscountType;
}
else if(type == AMOUNT){
Amount* totalDiscountType = new Amount(stoi(value));
totalPriceDiscount = totalDiscountType;
}
}
void Restaurant::FirstOrderDiscountLineReader(string firstOrederDiscountLine){
string type , value;
stringstream firstOrederDiscountLineNote(firstOrederDiscountLine);
getline(firstOrederDiscountLineNote , type , SEMICOLON);
getline(firstOrederDiscountLineNote , value , SEMICOLON);
if(type == PERCENT){
Percent* firstOrderDiscountType = new Percent(stoi(value));
firstOrderDiscount = firstOrderDiscountType;
}
else if(type == AMOUNT){
Amount* firstOrderDiscountType = new Amount(stoi(value));
firstOrderDiscount = firstOrderDiscountType;
}
}
void Restaurant::FoodDiscountLineReader(string foodDiscountLine){
string foodLine;
stringstream foodDiscountLineNote(foodDiscountLine);
while(getline(foodDiscountLineNote , foodLine , VERTICAL_BAR)){
EachFoodLineDiscountReader(foodLine);
}
}
void Restaurant::EachFoodLineDiscountReader(string foodLine){
string type , foodName , value;
stringstream foodLineNote(foodLine);
getline(foodLineNote , type , SEMICOLON);
getline(foodLineNote , foodName , COLON);
getline(foodLineNote , value);
for(auto food : foodsMenu){
if(food->name == foodName){
if(type == PERCENT){
Percent* foodDiscountType = new Percent(stoi(value));
food->foodDiscount = foodDiscountType;
}
else if(type == AMOUNT){
Amount* foodDiscountType = new Amount(stoi(value));
food->foodDiscount = foodDiscountType;
}
}
}
}