-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFood.cpp
More file actions
32 lines (26 loc) · 852 Bytes
/
Copy pathFood.cpp
File metadata and controls
32 lines (26 loc) · 852 Bytes
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
#include "Food.h"
namespace food {
Food::Food(std::string name, int calories, std::vector<std::string> flavors) {
this->name = name;
this->calories = calories;
this->flavors = flavors;
}
int Food::calorieCount() {
return this->calories;
}
bool Food::hasFlavor(std::string flavor) {
for (std::string f : this->flavors) {
if (f == flavor) {
return true;
}
}
return false;
}
Food Food::operator+(const Food& other) const {
std::string combinedName = this->name + " and " + other.name;
int combinedCalories = this->calories + other.calories;
std::vector<std::string> combinedFlavors = this->flavors;
combinedFlavors.insert(combinedFlavors.end(), other.flavors.begin(), other.flavors.end());
return Food(combinedName, combinedCalories, combinedFlavors);
}
} // namespace food