forked from joshua840/snu_programming_methodology_project3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulator.cpp
More file actions
68 lines (66 loc) · 2.12 KB
/
Simulator.cpp
File metadata and controls
68 lines (66 loc) · 2.12 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
#include <iostream>
#include <string>
#include "Refrigerator.h"
#include "SmartRefrigerator.h"
#include "Simulator.h"
using namespace std;
/**
* This function chooses a type of a refrigerator,
* then should call menuSelect of the refrigerator
* Function terminates when the menuSelect returns 0 (program ends)
*/
void Simulator::start()
{
int ref_type;
Refrigerator *ref;
// Initialize a refrigerator
cout << "************************************************************" << endl;
cout << "************************************************************" << endl;
cout << "************************************************************" << endl;
cout << "************* Let's start the Project 3 ****************" << endl;
cout << "************************************************************" << endl;
cout << "************************************************************" << endl;
cout << "************************************************************" << endl
<< endl;
while (1)
{
cout << "1. Normal refrigerator" << endl;
cout << "2. Smart refrigerator" << endl;
cout << "What type of refrigerator do you have? : ";
// ref_type = 1; //TODO: remove this line and restore the below comment before commit.
cin >> ref_type;
if (ref_type == 1)
{
ref = new Refrigerator();
cout << "You have a normal refrigerator!" << endl
<< endl;
break;
}
else if (ref_type == 2)
{
ref = new SmartRefrigerator();
cout << "You have a smart refrigerator!" << endl
<< endl;
break;
}
else
{
cout << "Please insert 1 or 2" << endl;
if (cin.fail())
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
}
// Simulate
while (1)
{
int result = ref->menuSelect();
if (result == 0)
{
cout << "Program finished!" << endl;
break;
}
}
}