-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPizza.cpp
63 lines (51 loc) · 1.72 KB
/
Pizza.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
#include "Pizza.h"
#include <string>
Pizza::Pizza() : _name("Custom pizza") { }
Pizza::Pizza(std::string name) : _name(name) { }
void Pizza::AddIngredient(Ingredient* ingredient) {
_ingredients.push_back(ingredient);
}
void Pizza::ChangeName(std::string name) {
_name = name;
}
void Pizza::AddDefaultIngredients() {
IngredientFactory factory;
_ingredients.push_back(factory.Create(Ingredients::Cheese));
_ingredients.push_back(factory.Create(Ingredients::Peperroni));
}
std::string Pizza::ToString() const {
std::string string = _name + "(";
if (_ingredients.empty()) {
return string + "Nothing)";
}
for (auto ingredient : _ingredients) {
string += ingredient->ToString() + ", ";
}
string = string.substr(0, string.size() - 2);
string += ")";
return string;
}
int Pizza::CalculateCost() const {
int cost = 0;
for (auto ingredient : _ingredients) {
cost += ingredient->GetPrice();
}
return cost;
}
void PeperonniPizza::AddDefaultIngredients() {
IngredientFactory factory;
_ingredients.push_back(factory.Create(Ingredients::Peperroni));
_ingredients.push_back(factory.Create(Ingredients::TomatoSauce));
_ingredients.push_back(factory.Create(Ingredients::MozarellaCheese));
}
void MargaritaPizza::AddDefaultIngredients() {
IngredientFactory factory;
_ingredients.push_back(factory.Create(Ingredients::TomatoSauce));
_ingredients.push_back(factory.Create(Ingredients::MozarellaCheese));
}
void FarmPizza::AddDefaultIngredients() {
IngredientFactory factory;
_ingredients.push_back(factory.Create(Ingredients::Bacon));
_ingredients.push_back(factory.Create(Ingredients::Pickles));
_ingredients.push_back(factory.Create(Ingredients::MozarellaCheese));
}