forked from oreorider/snu_programming_methodology_project3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartRefrigerator.cpp
More file actions
185 lines (174 loc) · 5.62 KB
/
SmartRefrigerator.cpp
File metadata and controls
185 lines (174 loc) · 5.62 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
#include "SmartRefrigerator.h"
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
#include "Food.h"
#include "Recipe.h"
/**
* A constructor of the class
* SmartController should be initialized in this constructor
*/
SmartRefrigerator::SmartRefrigerator()
{
controller = new SmartController(size, foodList);
};
/**
* add recipes from a text file (.txt)
* This function should add a new recipe object with the given info from the
* file to the private variable recipe (vector)
*/
void SmartRefrigerator::addRecipeFromFile()
{
string recipeFile;
cout << "Enter your file name : ";
cin >> recipeFile;
ifstream recipe_list(recipeFile);
if (!recipe_list)
{
cout << "There is no recipe file!" << endl;
return;
}
/**
* ===============================================
* ======== TODO: Implement this function ========
* ===============================================
*/
recipe_list.close();
}
/**
* show the current recipes of the smart refrigetrator
* e.g. recipe name : [ingredient1, # of ingredient1]...[] / score 7
*
*/
void SmartRefrigerator::showRecipe()
{
recipeVec ::iterator iter;
if (recipes.empty())
cout << "There is no recipe yet." << endl;
else
{
for (iter = recipes.begin(); iter != recipes.end(); ++iter)
{
cout << iter->getName() << " : ";
for (int i = 0; i < iter->getIngredients().size(); i++)
{
cout << '[' << iter->getIngredients()[i].first << ',' << iter->getIngredients()[i].second << ']';
}
cout << " / score " << iter->getScore() << endl;
}
}
}
/**
* recommend the best possible combination (with repetition) of three recipes
* Below are some rules about the recommendation
* 1) the number of each ingredient required by a combination should be less
* than the number of each ingredient in the refrigerator in order to be
* considered as a possible combination 2) the sum of recipe scores of a
* combination should be normalized by the highest score sum of the possible
* combination 3) the exp sum of the foods in the refrigerator considering of a
* combination should be normalized by the longest exp (the greatest number)
* from a possible combination
*/
void SmartRefrigerator::recommendMealCourses() {
/**
* ===============================================
* ======== TODO: Implement this function ========
* ===============================================
*/
}
/**
* base function of the smart refrigerator
* User should type a number between 1 and 4 to call a function of the smart
* regrigerator Then, this function utilizes the other functions of the smart
* refrigerator as the user's input Below is the list of options that menuSelect
* should support 1) display 2) insert food 2-1) insert a list of foods from a
* text file (.txt) 2-2) insert a food directly 3) pop food 4) add recipe 5)
* show recipe 6) recommend meals 7) end program Unless the user ends the
* program ( 7) end program ), this function does not terminate and keeps
* requiring the user to type a number
* @return 0 when the user ends the program by typing else 1
*/
int SmartRefrigerator::menuSelect()
{
int i;
while (1)
{
cout << "************************************************************" << endl;
cout << "************************ Menu **************************" << endl;
cout << "************************************************************" << endl;
cout << "1. display" << endl
<< "2. insert food" << endl
<< "3. pop food" << endl
<< "4. add recipe" << endl
<< "5. show recipe" << endl
<< "6. recommend meal courses" << endl
<< "7. end program" << endl
<< "Select the function you want : ";
cin >> i;
if (i < 1 || i > 7){
cout << "Type an integer from 1 to 7!" << endl;
if (cin.fail())
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
else {break;}
}
if (i == 7)
return 0;
else
{
switch (i)
{
case 1:
display();
break;
case 2:
{
int j;
while (1)
{
cout << "1. Insert a list of foods from a text file" << endl;
cout << "2. Insert a food directly" << endl;
cout << "Enter how to insert your food : ";
cin >> j;
if (!(j == 1 or j == 2))
{
cout << "Type 1 or 2 only" << endl;
if (cin.fail())
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
else
{
break;
}
}
if (j == 1)
insertFoodFromFile();
else
insertFoodDirectly();
break;
}
case 3:
{
popFood();
break;
}
case 4:
addRecipeFromFile();
break;
case 5:
showRecipe();
break;
case 6:
recommendMealCourses();
break;
}
return 1;
}
}