-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSugarLevels.cpp
316 lines (303 loc) · 8.09 KB
/
SugarLevels.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
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
/*
Name: Sugar Levels
Copyright: 2022
Author: Faizan Khan
Date: 25/09/22 13:03
Description: Using a vector and class to handle
the patient information. It can check, add, edit,
retrieve, display or delete certain information
for the patient.
*/
#include <iostream>
#include <vector>
using namespace std;
// Setting up the info for a sugar patient
class SugarLevel
{
private:
string patientName;
string country;
string gender;
string birthDate;
int sugarConsumption;
int age;
public:
string get_patientName();
int get_sugar();
void retrievePatient();
void showPatient();
void editPatient();
};
// Accessor returns the patient name
string SugarLevel::get_patientName()
{
return patientName;
}
// Retrieve the information for the patient
void SugarLevel::retrievePatient()
{
cout << "\n What is the patient's name: ";
cin.ignore();
getline(cin, patientName);
cout << "\n What is the patient's country: ";
getline(cin, country);
cout << "\n What is the patient's date of birth: ";
getline(cin, birthDate);
cout << "\n What is the patient's age: ";
cin >> age;
cin.ignore(10, '\n');
if ((age < 1) || (age > 100))
{
cout << "\n Invalid input for age.";
cin >> age;
cin.ignore(10, '\n');
}
cout << "\n What is the patient's gender: ";
getline(cin, gender);
if ((gender != "male") && (gender != "female"))
{
cout << " Invalid input for gender.\n";
getline(cin, gender);
}
cout << "\n How much sugar do they consume: ";
cin >> sugarConsumption;
if (sugarConsumption < 1)
{
cout << "Invalid input for sugar consumption\n";
cin >> sugarConsumption;
}
if ((sugarConsumption < 36) && (gender == "male") && (age < 35))
{
cout << "This young male is not at risk for diabetes.\n";
}
else if ((sugarConsumption > 36) && (gender == "male") && (age < 35))
{
cout << "This young male is at risk for diabetes.\n";
}
else if ((sugarConsumption < 36) && (gender == "male") && (age >= 35))
{
cout << "This middle age or older male is not at risk for diabetes.\n";
}
else if ((sugarConsumption > 36) && (gender == "male") && (age >= 35))
{
cout << "This middle age or older male is at risk for diabetes.\n";
}
else if ((sugarConsumption < 24) && (gender == "female") && (age < 35))
{
cout << "This young female is not at risk for diabetes.\n";
}
else if ((sugarConsumption > 24) && (gender == "female") && (age < 35))
{
cout << "This young female is at risk for diabetes.\n";
}
else if ((sugarConsumption < 24) && (gender == "female") && (age >= 35))
{
cout << "This middle age or older female isn't at risk for diabetes.\n";
}
else if ((sugarConsumption > 24) && (gender == "female") && (age >= 35))
{
cout << "This middle age or older female is at risk for diabetes.\n";
}
}
// Display the patient information
void SugarLevel::showPatient()
{
cout << "Patient's name: " << patientName << endl;
cout << "Patient's country: " << country << endl;
cout << "Patient's date of birth: " << birthDate << endl;
cout << "Patient's age: " << age << endl;
cout << "Patient's gender: " << gender << endl;
cout << "Patient's sugar consumption: " << sugarConsumption << endl;
}
// Edit the patient information
void SugarLevel::editPatient()
{
int update;
cout << "\nChanging patient's information...\n";
do
{
cout << "\n 1. Change patient's sugar consumption\n"
<< "\n 2. Change patient's gender\n"
<< "\n 3. Change patient's age\n"
<< "\n 4. Done"
<< "\n Which change would you like to make with the patient: ";
while (!(cin >> update) || update < 1 || update > 4)
{
cout << "Invalid input, please choose 1-4 only: ";
cin.clear();
cin.ignore(10, '\n');
}
if (update == 1)
{
cout << "The sugar consumption has been updated: ";
while (!(cin >> sugarConsumption) || (sugarConsumption < 1))
{
cout << "Invalid input, only positive numbers are accepted.\n";
cin.clear();
cin.ignore(10, '\n');
}
}
else if (update == 2)
{
cout << "The gender has been updated: ";
while (!(cin >> gender) || (gender != "male" && gender != "female"))
{
cout << "Invalid input, only male or female is accepted.\n";
cin.clear();
cin.ignore(10, '\n');
}
}
else if (update == 3)
{
cout << "The patient's age has been update: ";
while (!(cin >> age) || age < 1 || age > 100)
{
cout << "Invalid input, enter a proper age number.\n";
cin.clear();
cin.ignore(10, '\n');
}
}
else if (update != 1 && update != 2 && update != 3 && update != 4)
{
cout << "Invalid input, try to enter the choice again.\n";
}
}
while (update != 4);
cout << "The change is officially completed.\n\n";
}
// Accessor returns the amount of sugar consumed
int SugarLevel::get_sugar()
{
return sugarConsumption;
}
// Main function
int main()
{
vector<SugarLevel> sugarPatient;
int options, i;
int exit = 0;
string patientName;
int sugarConsumption;
cout << "Hello, welcome to the American Diabetes Association.\n";
do
{
// Prompt the user to enter information
cout << " \n 1. Check the patient list "
<< " \n 2. Add a patient "
<< " \n 3. Delete a patient "
<< " \n 4. Display patient information "
<< " \n 5. Update patient information "
<< " \n 6. Display the healthiest patient "
<< " \n 7. Exit";
cin >> options;
switch(options)
{
case 1:
{
if (sugarPatient.size() == 0)
{
cout << "Empty Patient List.\n";
}
else
{
cout << "Full Patient List.\n";
}
break;
}
case 2:
{
SugarLevel ADApatient;
ADApatient.retrievePatient();
sugarPatient.push_back(ADApatient);
cout << "Patient # " << sugarPatient.size() << ": "
<< ADApatient.get_patientName() << endl;
cout << "Patient added to list.\n" << endl;
break;
}
case 3:
{
int numPat = 1;
cout << "Which patient do you want to delete?:\n";
do
{
if (numPat > sugarPatient.size() || numPat < 1)
{
cout << "Invalid input.\n";
}
cin >> numPat;
}
while(numPat > sugarPatient.size() || numPat < 1);
sugarPatient.erase(std::begin(sugarPatient) + numPat - 1);
cout << "Patient " << numPat << " is deleted.\n\n";
break;
}
case 4:
{
if (sugarPatient.size() == 0)
{
cout << "Please enter a patient.\n";
}
else
{
for (int index = 0; index < sugarPatient.size(); index++)
{
sugarPatient[index].showPatient();
}
}
break;
}
case 5:
{
cout << "Which patient do you wish to update.\n";
cin.ignore();
getline(cin, patientName);
if (sugarPatient.size() == 0)
{
cout << "Please enter a patient.\n";
}
else
{
for (int index = 0; index < sugarPatient.size(); index++)
{
if (patientName == sugarPatient[index].get_patientName())
{
sugarPatient[index].editPatient();
}
}
}
break;
}
case 6:
{
int minisugar = 100;
for (int index = 0; index < sugarPatient.size(); index++)
{
if (sugarPatient[index].get_sugar() < minisugar)
{
patientName = sugarPatient[index].get_patientName();
minisugar = sugarPatient[index].get_sugar();
}
if (sugarPatient.size() > 0)
{
cout << "Patient name: " << patientName << " is clean!"
<< endl;
}
else
{
cout << "Empty Patient List.\n";
}
}
}
case 7:
{
exit = 1;
break;
}
default:
cout << "Invalid input selected please select options 1-7: ";
}
} while(exit != 1);
cout << "Thank you for using the American Diabetes Association.\n";
system("PAUSE");
return 0;
}