-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeal.cpp
More file actions
100 lines (85 loc) · 2.71 KB
/
Meal.cpp
File metadata and controls
100 lines (85 loc) · 2.71 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
#include "IIKH.h"
#include <random>
#include <vector>
#include <deque>
#include <iostream>
#include <numeric>
#include <algorithm>
using namespace std;
// Constructor that recommends a meal randomly
Meal::Meal(deque<Recipe> mealRecipeDB) {
productMeal(mealRecipeDB);
}
// Constructor that takes main and side recipe databases
Meal::Meal(deque<Recipe> mainRecipeDB, deque<Recipe> sideRecipeDB) {
inputHumanNum();
productMeal(mainRecipeDB, sideRecipeDB);
}
// Recommend a meal randomly from a single recipe database
void Meal::productMeal(deque<Recipe> mealRecipeDB) {
// Initialize random device
random_device rd;
mt19937 gen(rd());
// Save the size of deque
size_t Deque_size = mealRecipeDB.size();
// Generate a random index
int randnum = rd() % Deque_size;
cout << mealRecipeDB[randnum].foodName << endl;
meal.push_back(mealRecipeDB[randnum]);
}
// Recommend meals randomly from main and side recipes
void Meal::productMeal(deque<Recipe> mainRecipeDB, deque<Recipe> sideRecipeDB) {
// Main dishes
random_device rd;
mt19937 gen(rd());
size_t mainDeque_size = mainRecipeDB.size();
// Create an index list for random selection
vector<int> indices(mainDeque_size);
iota(indices.begin(), indices.end(), 0); // Fill index from 0 to deque_size-1
shuffle(indices.begin(), indices.end(), gen); // Shuffle the indices
cout << "\n[MAIN]\n";
// Print main dishes randomly
for (int i = 0; i < mainMealNum; ++i) {
cout << mainRecipeDB[indices[i]].foodName;
if (i < mainMealNum - 1) {
cout << ", ";
}
meal.push_back(mainRecipeDB[indices[i]]);
}
cout << endl;
// Side dishes
random_device rd2;
mt19937 gen2(rd2());
size_t sideDeque_size = sideRecipeDB.size();
vector<int> indices2(sideDeque_size);
iota(indices2.begin(), indices2.end(), 0);
shuffle(indices2.begin(), indices2.end(), gen2);
cout << "[SIDE]\n";
for (int i = 0; i < sideMealNum; ++i) {
cout << sideRecipeDB[indices2[i]].foodName;
if (i < sideMealNum - 1) {
cout << ", ";
}
meal.push_back(sideRecipeDB[indices2[i]]);
}
cout << endl;
}
// Input the number of people and determine main and side meal quantities
void Meal::inputHumanNum() {
cout << "NUMBER OF PEOPLE: ";
cin >> humanNum;
if (humanNum > 0) {
if (humanNum % 2 == 0) { // Even number
mainMealNum = humanNum / 2;
sideMealNum = humanNum / 2;
}
else { // Odd number
mainMealNum = (humanNum - 1) / 2 + 1;
sideMealNum = (humanNum - 1) / 2;
}
}
else {
cout << "NUMBER OF PEOPLE ERROR";
return;
}
}