-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
338 lines (302 loc) · 7.76 KB
/
Menu.cpp
File metadata and controls
338 lines (302 loc) · 7.76 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*******************************************************************************************************
* @file Menu.c
*
* @brief Menu driver for Menu.h file
*
* @details Menu file is created to simplify the menu operations. It asks to the user that what he/she wants to do
* and the type of the product. Then, it provides adding new products to the inventory, changing the number
* of available products and listing the products in the inventory.
*
* @author Aysenur Bolat
*
* @version V1.0
*
* @date 28. December 2018
********************************************************************************************************/
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
#include "Refrigerator.h"
#include "Dishwasher.h"
#include "Washing_Machine.h"
#include "Menu.h"
using namespace std;
vector<Refrigerator>::iterator refIt;
vector<Dishwasher>::iterator dishIt;
vector<Washing_Machine>::iterator washIt;
/**
* @brief Constructor for Menu class
*
* @details This constructor calls main menu that start the menu operations.
*
* @param void
*
*/
Menu::Menu()
{
this->mainMenu();
}
Menu::~Menu()
{
}
/**
* @brief Print refrigerator properties that is stored in a vector
* @param void
* @retval void
*/
void Menu::printRefrigerator()
{
cout <<"Refrigerator\n";
for(refIt = vecOfRefrigerator.begin(); refIt != vecOfRefrigerator.end(); refIt++){
refIt->printProperties();
cout <<endl;
}
}
/**
* @brief Print dishwasher properties that is stored in a vector
* @param void
* @retval void
*/
void Menu::printDishwasher()
{
cout<<"Dishwasher\n";
for(dishIt = vecOfDishwasher.begin(); dishIt != vecOfDishwasher.end(); dishIt++){
dishIt->printProperties();
cout <<endl;
}
}
/**
* @brief Print washing machine properties that is stored in a vector
* @param void
* @retval void
*/
void Menu::printWashingMachine()
{
cout <<"Washing Machine\n";
for(washIt = vecOfWashingMachine.begin(); washIt != vecOfWashingMachine.end(); washIt++ ){
washIt->printProperties();
cout <<endl;
}
}
/**
* @brief Print all properties that is stored in vectors
* @param void
* @retval void
*/
void Menu::printVector()
{
printRefrigerator();
printDishwasher();
printWashingMachine();
}
/**
* @brief Print all refrigerator IDs when change mode is selected
* @param void
* @retval void
*/
void Menu::refrigeratorID()
{
for(refIt = vecOfRefrigerator.begin(); refIt != vecOfRefrigerator.end(); refIt++){
cout <<refIt->getIdentificationCode();
cout <<endl;
}
}
/**
* @brief Print all dishwasher IDs when change mode is selected
* @param void
* @retval void
*/
void Menu::dishwasherID()
{
for(dishIt = vecOfDishwasher.begin(); dishIt != vecOfDishwasher.end(); dishIt++){
cout <<dishIt->getIdentificationCode();
cout <<endl;
}
}
/**
* @brief Print all washing machine IDs when change mode is selected
* @param void
* @retval void
*/
void Menu::washingmachineID()
{
for(washIt = vecOfWashingMachine.begin(); washIt != vecOfWashingMachine.end(); washIt++ ){
cout <<washIt->getIdentificationCode();
cout <<endl;
}
}
/**
* @brief When user wants to change the number of product of refrigerator, the ID entered is found in vector
* @param string ID value
* @retval void
*/
void Menu::findRefID(string ID)
{
int newNumberOfProd;
for(refIt = vecOfRefrigerator.begin(); refIt != vecOfRefrigerator.end(); refIt++){
if(refIt->getIdentificationCode() == ID)
{
cin >>newNumberOfProd;
refIt->setNumberOfProduct(newNumberOfProd);
}
}
}
/**
* @brief When user wants to change the number of product of dishwasher, the ID entered is found in vector
* @param string ID value
* @retval void
*/
void Menu::findDishID(string ID)
{
int newNumberOfProd;
for(dishIt = vecOfDishwasher.begin(); dishIt != vecOfDishwasher.end(); dishIt++){
if(dishIt->getIdentificationCode() == ID)
{
cin >>newNumberOfProd;
dishIt->setNumberOfProduct(newNumberOfProd);
}
}
}
/**
* @brief When user wants to change the number of product of washing machine, the ID entered is found in vector
* @param string ID value
* @retval void
*/
void Menu::findWashID(string ID)
{
int newNumberOfProd;
for(washIt = vecOfWashingMachine.begin(); washIt != vecOfWashingMachine.end(); washIt++ ){
if(washIt->getIdentificationCode() == ID)
{
cin >>newNumberOfProd;
washIt->setNumberOfProduct(newNumberOfProd);
}
}
}
/**
* @brief If user wants to change number of products, this function is used
* first type is entered and then all IDs of this type listed, then user
* enters ID and new number of prodcut to change.
* @param void
* @retval void
*/
void Menu::changeNumberOfProduct()
{
string userID;
cout <<"To change number, choose the type below\n";
cout << "\nPress 1, for Refrigerator";
cout << "\nPress 2, for Dishwasher";
cout << "\nPress 3, for Washing Machine" << endl;
int select;
cin >>select;
switch(select){
case 1:
{
refrigeratorID();
cout <<"Enter ID and a new number of product to change\n";
cin >>userID;
findRefID(userID);
break;
}
case 2:
{
dishwasherID();
cout<<"Enter ID and a new number of product to change\n";
cin >>userID;
findDishID(userID);
break;
}
case 3:
{
washingmachineID();
cout <<"Enter ID and a new number of product to change\n";
cin >>userID;
findWashID(userID);
break;
}
}
}
/**
* @brief Here, the menu is shown to user and user should define which action
* he or she wants to do. For listing press'l' or 'L', for changing number
* of products press 'c' or 'C' and for adding new product press 'a' or
* or 'A'. For listing, all available items list shown. For changing the
* the number of product user must choose which type of appliance
* then all IDs are listed and then user enters new nmber. For adding
* user again selects type of appliance and then bunch of data is written.
* @param void
* @retval void
*/
void Menu::mainMenu()
{
bool enterMenu = true;
char exitOrContinue;
while(enterMenu){
int request;
char type;
cout << "Welcome to the inventory." << endl;
cout << "\n\nType the process" << endl;
cout << "Press 'l' or 'L', to list the inventory details" <<endl;
cout << "Press 'c' or 'C', to change the number of products" << endl;
cout << "Press 'a' or 'A', to add a new product" << endl;
cin >> type;
switch(type){
case 'l' :
case 'L' :
{
printVector();
break;
}
case 'c':
case 'C':
{
changeNumberOfProduct();
break;
}
case 'a':
case 'A':
{
cout << "\nPress 1, for Refrigerator";
cout << "\nPress 2, for Dishwasher";
cout << "\nPress 3, for Washing Machine" << endl;
cin >> request;
Engine eng(0.0, 0, 0);
switch(request){
case 1:
{
Refrigerator r(" ", 0, 0, 0, " ", 0, 0, 0, ' ',eng,0);
r.printProperties();
vecOfRefrigerator.push_back(r);
break;
}
case 2:
{
Dishwasher d(" ", 0, 0, 0, " ", 0, 0, 0, 0, eng,0);
d.printProperties();
vecOfDishwasher.push_back(d);
break;
}
case 3:
{
Washing_Machine w(" ", 0, 0, 0, " ", 0, 0, 0, 0, eng,0);
w.printProperties();
vecOfWashingMachine.push_back(w);
break;
}
}
break;
}
}
cout <<"\nIf you want to exit press 'e' or 'E', for continuing press any except exit..";
cin >>exitOrContinue;
if(exitOrContinue=='e' || exitOrContinue == 'E')
{
enterMenu = false;
cout << "Closing Inventory..." << endl;
}
else{
enterMenu = true;
}
}
}