-
Notifications
You must be signed in to change notification settings - Fork 0
/
identify.cpp
596 lines (521 loc) · 15.9 KB
/
identify.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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
// Name: identify.cpp
// Author: Abigail Kennedy
// Date: 11/14/2020
// Description: The cpp file for identify
#include "identify.h"
Identify::Identify(string filename){ // Constructor
m_filename = filename;
}
Identify::~Identify(){ // Destructor
// Destroys all items in m_ID
for (int i = 0; i < int(m_ID.size()); i++){
delete m_ID.at(i); // Vector data deleted
m_ID.at(i) = nullptr; // Set data to null
}
}
void Identify::LoadFile(){
// Opens the file and reads everything in
// Open file
ifstream identity;
identity.open(m_filename);
while(identity){
// Variables
string name = "";
int gram = 0;
char shapeChar = ' ';
string shape = "";
int acidfast = 0;
int catalase = 0;
string morphology = "";
string clusters = "";
bool gramBool = false;
bool acidfastBool = false;
bool catalaseBool = false;
// Read in the file
// For all, read in the name, gram, and shape
getline(identity, name, ','); // Get name
identity >> gram; // Get gram + or - status
if(identity.peek()== ','){
identity.ignore();
}
identity >> shapeChar; // Gets the shape
if(identity.peek()==','){
identity.ignore();
}
// If shape is rods
if (shapeChar == 'r'){
shape = "Rods"; // Update shape
identity >> acidfast; // Acidfast
if (identity.peek() == ','){
identity.ignore();
}
getline(identity, morphology, ','); // Morphology
// Convert gram and acidfast strings to bools
if (gram == 1) {
gramBool = true;
}
if (acidfast == 1) {
acidfastBool = true;
}
if (identity.peek() == '\n') { //End of line
identity.ignore();
}
// Fill in others
catalaseBool = false;
clusters = "Regular clusters";
}
// If shape is cocci
else if (shapeChar == 'c') { // Shape was cocci
shape = "Cocci"; // Update shape
// Catalase, Clusters
identity >> catalase; // Catalaste type
if (identity.peek() == ','){
identity.ignore();
}
getline(identity, clusters, '\n'); // Cluster type
if (identity.peek() == '\n'){
identity.ignore();
}
// Convert gram and acidfast strings to bools
if (gram == 1) {
gramBool = true;
}
if (catalase == 1) {
catalaseBool = true;
}
if (identity.peek() == '\n') { //End of line
identity.ignore();
}
// Fill in others
acidfastBool = false;
morphology = "Regular";
}
//For testing the file status
/*
cout << "Name: " << name << endl
<< "Gram: " << gramBool << endl
<< "Shape: " << shape << endl
<< "Acid fast: " << acidfastBool << endl
<< "Catalse: " << catalaseBool << endl
<< "Morphology: " << morphology << endl
<< "Clusters: " << clusters << endl;
*/
Bacteria* object = new Bacteria(name, gramBool, shape, acidfastBool, catalaseBool, morphology,clusters);
m_ID.push_back(object); // Add to vector
}
// Vector is m_ID
// Close file when done
identity.close();
}
int Identify::Menu(){
// Displays the menu and the choices
int choice = 0;
cout << "What would you like to do?" << endl
<< "1. ID a bacterium" << endl
<< "2. View bacteria available for ID" << endl
<< "3. Exit program" << endl;
cin >> choice;
while (choice < 1 || choice > 3) {
cout << "Please enter a valid choice (1-3)" << endl;
cin >> choice;
}
switch(choice) {
case 1: { // ID a bacterium
IDMenu();
return 3; // End the program
}
case 2: { // Display bacteria
Display();
return 2;
}
case 3: { // Exit
return 3;
}
}
return 0; // We should never reach this
}
void Identify::Start(){
// Starts the ID program
int control = 0; // Controls the program
LoadFile();
// Under game conditions
do {
control = Menu();
} while (control != 3);
cout << "Thank you for using!" << endl;
}
void Identify::IDMenu(){
// The menu from which an item is IDd
int shape = 2;
// Create the unnamed item
Bacteria* object = new Bacteria(); // creates a default
m_ID.push_back(object);
// Add some if statements in here for the rods and cocci
// Get the gram
GramID();
// Get the shape
shape = ShapeID(); // 0 is rods, 1 is cocci
if (shape == 0){
// Get the acid-fast
AcidfastID();
// Get the morphology
MorphologyID();
}
else if (shape == 1) {
// Get the catalase
CatalaseID();
// Get the cluster type
ClusterID();
}
else {
cout << "Something went wrong." << endl;
}
// Call ID
ID();
}
void Identify::GramID(){
string response = "";
bool answered = false;
cout << "Is your bacteria Gram Positive or Gram Negative?" << endl;
cin >> response;
if (response == "positive" ||response == "Positive" ||
response == "Gram Positive" || response == "Gram positive" ||
response == "gram positive") {
for (int i = 0; i < int(m_ID.size()); i++) {// Find Unnamed
if (m_ID.at(i)->GetName() == "Unnamed") {
// Update the gram bool to true
m_ID.at(i)->SetGram(true);
}
}
}
else if (response == "negative" ||response == "Negative" ||
response == "Gram Negative" || response == "Gram negative" ||
response == "gram negative") {
for (int i = 0; i < int(m_ID.size()); i++) {// Find Unnamed
if (m_ID.at(i)->GetName() == "Unnamed") {
// Keep bool as false
m_ID.at(i)->SetGram(false);
}
}
}
else{
while (answered == false) {
cout << "That is not a valid gram type." << endl
<< "Is your bacteria Gram Positive or Gram Negattive?" << endl;
cin >> response;
if (response == "positive" || response == "Positive" ||
response == "Gram Positive" || response == "Gram positive" ||
response == "gram positive") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetGram(true);
answered = true;
}
}
}
else if (response == "negative" ||response == "Negative" ||
response == "Gram Negative" || response == "Gram negative" ||
response == "gram negative") {
for (int i = 0; i < int(m_ID.size()); i++) {// Find Unnamed
if (m_ID.at(i)->GetName() == "Unnamed") {
// Keep bool as false
m_ID.at(i)->SetGram(false);
}
}
}
}
}
}
int Identify::ShapeID() {
string response = "";
bool answered = false;
cout << "What is the shape of your bacteria? Rods or Cocci?" << endl;
cin >> response;
if (response == "rods" || response == "Rods") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetShape("Rods");
return 0;
}
}
}
else if (response == "cocci" || response == "Cocci") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetShape("Cocci");
return 1;
}
}
}
else{
while (answered == false) {
cout << "That is not a valid shape." << endl
<< "Does your bacteria resemble rods or cocci?" << endl;
cin >> response;
if (response == "rods" || response == "Rods") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetShape("Rods");
return 0;
}
}
}
else if (response == "cocci" || response == "Cocci") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetShape("Cocci");
return 1;
}
}
}
}
}
return 2; // Should never reach this
}
void Identify::AcidfastID() {
string response = "";
bool answered = false;
cout << "Is the bacteria acidfast or non-acidfast?" << endl;
cin >> response;
if (response == "acidfast" ||response == "Acidfast") {
for (int i = 0; i < int(m_ID.size()); i++) {// Find Unnamed
if (m_ID.at(i)->GetName() == "Unnamed") {
// Update the gram bool to true
m_ID.at(i)->SetAcidfast(true);
}
}
}
else if (response == "non-acidfast" | response == "Acidfast" ||
response == "Non-acidfast") {
for (int i = 0; i < int(m_ID.size()); i++) {// Find Unnamed
if (m_ID.at(i)->GetName() == "Unnamed") {
// Keep bool as false
m_ID.at(i)->SetAcidfast(false);
}
}
}
else{
while (answered == false) {
cout << "That is not a valid type of acidfast." << endl
<< "Is the bacteria acidfast or non-acidfast?" << endl;
cin >> response;
if (response == "acidfast" ||response == "Acidfast") {
for (int i = 0; i < int(m_ID.size()); i++) {// Find Unnamed
if (m_ID.at(i)->GetName() == "Unnamed") {
// Update the gram bool to true
m_ID.at(i)->SetAcidfast(true);
answered = true;
}
}
}
else if (response == "non-acidfast" | response == "Acidfast" ||
response == "Non-acidfast") {
for (int i = 0; i < int(m_ID.size()); i++) {// Find Unnamed
if (m_ID.at(i)->GetName() == "Unnamed") {
// Keep bool as false
m_ID.at(i)->SetAcidfast(false);
answered = true;
}
}
}
}
}
}
void Identify::CatalaseID() {
string response = "";
bool answered = false;
cout << "Is the bacteria catalase positive or catalase negative?" << endl;
cin >> response;
if (response == "positive" || response == "Positive" ||
response == "Catalase positive" || response == "Catalase Positive" ||
response == "catalase positive") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetCatalase(true);
}
}
}
else if (response == "negative" || response == "Negative" ||
response == "Catalase negative" ||response == "Catalase Negative" ||
response == "catalse negative") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetCatalase(false);
}
}
}
else{
while (answered == false) {
cout << "That is not a valid catalase type." << endl
<< "Is your bacteria catalase positive or negative?" << endl;
cin >> response;
if (response == "positive" || response == "Positive" ||
response == "Catalase positive" || response == "Catalase Positive" ||
response == "catalase positive") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetCatalase(true);
answered = true;
}
}
}
else if (response == "negative" || response == "Negative" ||
response == "Catalase negative" ||
response == "Catalase Negative" ||
response == "catalse negative") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetCatalase(false);
answered = true;
}
}
}
}
}
}
void Identify::MorphologyID() {
string response = "";
bool answered = false;
cout << "Is the bacteria morphology regular or pleomorphic?" << endl;
cin >> response;
if (response == "regular" || response == "Regular") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetMorphology("Regular");
}
}
}
else if (response == "pleomorphic" || response == "Pleomorphic") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetMorphology("Pleomorphic");
}
}
}
else{
while (answered == false) {
cout << "That is not a valid morphology." << endl
<< "Is your bacteria regular or pleomorphic?" << endl;
cin >> response;
if (response == "regular" || response == "Regular") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetMorphology("Regular");
answered = true;
}
}
}
else if (response == "pleomorphic" || response == "Pleomorphic") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetMorphology("Pleomorphic");
answered = true;
}
}
}
}
}
}
void Identify::ClusterID() {
string response = "";
bool answered = false;
cout << "Are your clusters regular or irregular?" << endl;
cin >> response;
if (response == "regular" || response == "Regular") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetClusters("Regular clusters");
}
}
}
else if (response == "irregular" || response == "Irregular") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetClusters("Irregular clusters");
}
}
}
else{
while (answered == false) {
cout << "That is not a valid cluster." << endl
<< "Does your bacteria have regular or irregular clusters?" << endl;
cin >> response;
if (response == "regular" || response == "Regular") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetClusters("Regular clusters");
answered = true;
}
}
}
else if (response == "irregular" || response == "Irregular") {
for (int i = 0; i < int(m_ID.size() ); i++) {
if (m_ID.at(i)->GetName() == "Unnamed") {
m_ID.at(i)->SetClusters("Irregular clusters");
answered = true;
}
}
}
}
}
}
void Identify::ID() {
// Check unnamed against named bacteria and add each one up
// Based on the database, there is a __% chance that it is ...
// Add up for accuracy
int gram = 0;
int shape= 0;
int acidfast = 0;
int catalase = 0;
int morphology = 0;
int clusters = 0;
int unnamedIndex = 6; // The location of our to be IDd bacteria
for (int i = 0; i < int(m_ID.size() - 1 ); i++) {
if ( m_ID.at(i)->GetGram() == m_ID.at( unnamedIndex )->GetGram() ) {
m_ID.at(i)->SetPercentage(int(m_ID.at(i)->GetPercentage()) + 25);
}
// rods
if (m_ID.at(i)->GetShape() == m_ID.at( unnamedIndex )->GetShape() ) { //rods
m_ID.at(i)->SetPercentage(int(m_ID.at(i)->GetPercentage()) + 25);
}
else if(m_ID.at(i)->GetShape() == m_ID.at( unnamedIndex )->GetShape() ){ //cocci
m_ID.at(i)->SetPercentage(int(m_ID.at(i)->GetPercentage()) + 25);
}
// acidfast
if (m_ID.at(i)->GetAcidfast() == m_ID.at( unnamedIndex )->GetAcidfast() ){
m_ID.at(i)->SetPercentage(int(m_ID.at(i)->GetPercentage()) + 25);
}
// morphology
if (m_ID.at(i)->GetMorphology() == m_ID.at( unnamedIndex )->GetMorphology() ) {
m_ID.at(i)->SetPercentage(int(m_ID.at(i)->GetPercentage()) + 25);
}
// catalse
if (m_ID.at(i)->GetCatalase() == m_ID.at( unnamedIndex )->GetCatalase() ) {
m_ID.at(i)->SetPercentage(int(m_ID.at(i)->GetPercentage()) + 25);
}
// clusters
if( m_ID.at(i)->GetClusters() == m_ID.at( unnamedIndex )->GetClusters() ) {
m_ID.at(i)->SetPercentage(int(m_ID.at(i)->GetPercentage()) + 25);
}
}
bool found = false;
for (int i = 0; i < int(m_ID.size()); i++) {
if (m_ID.at(i)->GetPercentage() == 150) {
found = true;
cout << "Your bacteria is " << m_ID.at(i)->GetName() << "!" << endl;
}
}
if (found == false) {
cout << "Your bacteria is not in the program." << endl;
}
}
void Identify::Display() {
// Display all things that have been loaded in
for (int i = 0; i < (m_ID.size()); i++) {
cout << "Name: " << m_ID.at(i)->GetName() << endl
<< m_ID.at(i)->GetGram() << " | " << m_ID.at(i)->GetShape() << endl
<< "Acidfast status: " << m_ID.at(i)->GetAcidfast() << endl
<< "Catalase status: " << m_ID.at(i)->GetCatalase() << endl
<< m_ID.at(i)->GetMorphology() << " morphology, " << m_ID.at(i)->GetClusters() << endl;
}
}