This repository has been archived by the owner on Feb 16, 2019. It is now read-only.
forked from hadisfr/ratatouille
-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.cpp
64 lines (52 loc) · 1.79 KB
/
order.cpp
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
#include "order.h"
#include "food.h"
#include "restaurant.h"
#include "system.h"
#include <string>
#include <vector>
using namespace std;
SubOrder::SubOrder(Food *_food, Restaurant *_restaurant, int _num, string _personalizations)
: food(_food), num(_num), personalizations(_personalizations), restaurant(_restaurant){}
string SubOrder::getBill() const{
return to_string(restaurant->getId()) + food->getDetails() + string(" ") + to_string(num)
+ string(" ") + to_string(num * food->getCost()) + ((personalizations != "") ? string(" ") + personalizations : string("")) + string("\n");
}
int SubOrder::getCost() const{
return food->getCost() * num;
};
bool SubOrder::isNear(const Customer &customer) const{
return System::isNear(customer, *(restaurant));
};
int Order::getPureTotalCost() const{
int sum = 0;
for(int i = 0; i < foods.size(); i++)
sum += foods[i].getCost();
return sum;
}
int Order::getTotalCost() const{
return getPureTotalCost() + getDeliveryCost();
}
int Order::getDeliveryCost() const{
return (getPureTotalCost() > 100000 || isNear()) ? 0 : 5000;
}
Order::Order(Customer *_customer, std::vector <SubOrder> _foods): customer(_customer){
for(int i = 0; i < _foods.size(); i++)
foods.push_back(_foods[i]);
}
void Order::addToOrder(Food *food, Restaurant *restaurant, int num, std::string personalizations){
foods.push_back(SubOrder(food, restaurant, num, personalizations));
}
string Order::getBill() const{
string result;
for(int i = 0; i < foods.size(); i++)
result += foods[i].getBill();
result += "delivery cost " + to_string(getDeliveryCost()) + string("\n");
result += "total cost " + to_string(getTotalCost()) + string("\n");
return result;
}
bool Order::isNear() const{
for(int i = 0; i < foods.size(); i++)
if(!foods[i].isNear(*(customer)))
return false;
return true;
}