-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCocktailSimulator.cpp
More file actions
71 lines (65 loc) · 1.81 KB
/
CocktailSimulator.cpp
File metadata and controls
71 lines (65 loc) · 1.81 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
#include "CocktailSimulator.h"
using namespace std;
void CocktailSimulator::makeCocktail(Cocktail *cocktail)
{
cout << "== CocktailMix | Making Cocktail ==" << endl;
vector<int> dispenserNumber;
vector<int> amount;
for (int i = 0; i < dispensers.size(); i++)
{
for (int k = 0; k < cocktail->getIngredients().size(); k++)
{
if (dispensers[i]->getIngredient()->getName() == cocktail->getIngredients()[k].getName())
{
dispenserNumber.push_back(i); // vector with active dispenser
amount.push_back(cocktail->getIngredients()[k].getAmount()); // vector with ingredients amount
}
}
}
bool while_value = true;
bool value = false;
unsigned int counter_time = 0;
while (while_value)
{
if (value) // if all amounts <= 0
while_value = false;
cout << counter_time << " - ";
for (int i = 0; i < dispensers.size(); i++)
{
int counter = 0;
for (int k = 0; k < dispenserNumber.size(); k++)
{
if (dispenserNumber[k] == i && amount.at(k) > 0) // dispenser is "on"
{
cout << "ON";
break;
}
else
counter++;
if (counter == dispenserNumber.size()) // dispenser is "off"
cout << "OFF";
}
if (i < dispensers.size() - 1) // no "," at end of line
cout << ", ";
}
cout << endl;
int counter = 0;
for (int i = 0; i < amount.size(); i++) // reduce amount of ingredient (amount - 1 ml)
{
int newamount = amount[i];
newamount--;
amount.at(i) = newamount;
if (amount.at(i) <= 0)
counter++;
if (counter == amount.size()) // all amounts <= 0
value = true;
}
usleep(1000000); // wait 1sec.
counter_time++;
}
cout << "Enjoy your cocktail. " << endl;
}
void CocktailSimulator::makeCocktail(int number)
{
this->cocktails[number - 1]->print();
}