-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSandwich.cpp
87 lines (71 loc) · 2 KB
/
Sandwich.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "Sandwich.h"
#include <sstream>
#include <iomanip>
using namespace std;
Sandwich::Sandwich() {
}
//base constructor to create a sandwich
Sandwich::Sandwich(string meat, vector<string> toppings, bool toasted, double price) {
set_ingredients(meat, toppings);
this->toasted = toasted;
this->price = price;
}
//changes the sandwiches ingredients
void Sandwich::set_ingredients(string meat, vector<string> toppings) {
this->meat = meat;
this->toppings = toppings;
}
//changes the sandwiches meat parameter
void Sandwich::set_meat(string meat) {
this->meat = meat;
}
//adds a topping to the sandwich
void Sandwich::add_topping(string topping) {
toppings.push_back(topping);
}
//changes the sandwiches is toasted parameter
void Sandwich::set_toasted(bool toasted) {
this->toasted = toasted;
}
//changes the sandwiches price parameter
void Sandwich::set_price(double price) {
this->price = price;
}
//returns string of the meat
string Sandwich::get_meat() {
return meat;
}
//returns vector representing sandwiches toppings
vector<string> Sandwich::get_toppings() {
return toppings;
}
//returns bool of if sandwich is toasted
bool Sandwich::get_toasted() const{
return toasted;
}
//returns double of sandwich's price
double Sandwich::get_price() const {
return price;
}
//returns a vector of strings representing the ingredients
vector<string> Sandwich::get_ingredients() {
vector<string> ingredients;
for (int i=0;i<toppings.size();i++) {
ingredients.push_back(toppings[i]);
}
ingredients.push_back(meat);
return ingredients;
}
//returns a string representing the sandwich chosen
string Sandwich::get_sandwich(){
string sandwich = "";
if(toasted)
sandwich.append("Toasted");
sandwich.append(meat+" Sandwich with:\n");
for (int i=0;i<toppings.size();i++)
sandwich.append(toppings[i]+"\n");
stringstream ss;
ss << fixed << setprecision(2) << price;
sandwich.append("\n$"+to_string(price));
return sandwich;
}