-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
116 lines (102 loc) · 3.04 KB
/
main.cpp
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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include "Hospital.h"
using namespace std;
enum Command {
HIRE_DOCTOR,
FIRE_DOCTOR,
PRINT_DOCTOR,
ADD_PATIENT,
REMOVE_PATIENT,
PRINT_PATIENT,
PRINT_HOSPITAL,
INVALID
};
Command identifyNextCommand(const string& cmdStr)
{
Command command;
if (cmdStr.compare("hire") == 0) {
command = HIRE_DOCTOR;
} else if (cmdStr.compare("fire") == 0) {
command = FIRE_DOCTOR;
} else if (cmdStr.compare("print-doctor") == 0) {
command = PRINT_DOCTOR;
} else if (cmdStr.compare("add-patient") == 0) {
command = ADD_PATIENT;
} else if (cmdStr.compare("remove-patient") == 0) {
command = REMOVE_PATIENT;
} else if (cmdStr.compare("print-patient") == 0) {
command = PRINT_PATIENT;
} else if (cmdStr.compare("print-hospital") == 0) {
command = PRINT_HOSPITAL;
} else {
command = INVALID;
}
return command;
}
int main(int argc, char* argv[])
{
if (argc < 2) {
cerr << "Usage error: ./main input.txt" << endl;
exit(1);
}
string cmdStr;
string doctorFirstname, doctorLastname;
string patientFirstname, patientLastname, age, ailment;
Patient *patient;
Doctor *doctor;
ifstream fin(argv[1]);
Hospital *hospital = new Hospital("KU Hospital");
Command command;
while (fin >> cmdStr) {
command = identifyNextCommand(cmdStr);
/* overloaded the >> operator to fill in each of the variables
* listed. It should fill in the needed information.
*
*/
switch (command) {
case HIRE_DOCTOR:
cmdStr >> doctorFirstname >> doctorLastname;
hospital.hire_doctor ( doctorFirstname, doctorLastname );
break;
case FIRE_DOCTOR:
cmdStr >> doctorFirstname >> doctorLastname;
hospital.fire_doctor ( doctorFirstname, doctorLastname );
break;
case PRINT_DOCTOR:
/* find the doctor and print it */
cmdStr >> doctorFirstname >> doctorLastname;
doctor = hospital.search_doctor ( doctorFirstname, doctorLastname );
cout << *doctor << endl;
break;
case ADD_PATIENT:
cmdStr >> doctorFirstname >> doctorLastname
>> patientFirstname >> patientLastname;
hospital.add_patient ( doctorFirstname, doctorLastname,
patientFirstname, patientLastname );
break;
case REMOVE_PATIENT:
cmdStr >> doctorFirstname >> doctorLastname
>> patientFirstname >> patientLastname;
hospital.delete_patient ( doctorFirstname, doctorLastname,
patientFirstname, patientLastname );
break;
case PRINT_PATIENT:
cmdStr >> patientFirstname >> patientLastname;
patient = hospital.search_patient (patientFirstname, patientLastname );
cout << *patient << endl;
break;
case PRINT_HOSPITAL:
cout << *hospital << endl;
break;
case INVALID:
cout << "Error: invalid command" << endl;
break;
}
}
delete hospital;
fin.close();
exit(0);
}