// Programmer: Jennifer Leopold date: September 12, 2014
// File: hw3.cpp
// Purpose: Determine which of 2 patients should be seen
// next by a doctor by computing injury severity
// score (which is based on region of body affected,
// subregion of body affected, and type of injury,
// all of which are user inputs)
//
// To compile: fg++ hw3.cpp -o hw3
//
// To execute: ./hw3
#include <iostream>
using namespace std;
int main()
{
const short HEAD_NECK = 10; // body region codes
const short TORSO = 20;
const short EXTREMITY = 30;
const short HEAD = 11; // HEAD_NECK subregion codes
const short NECK = 12;
const short FACE = 13;
const short BACK = 21; // TORSO subregion codes
const short ABDOMEN = 22;
const short CHEST = 23;
const short ARM = 31; // EXTREMITY subregion codes
const short LEG = 32;
const short CONTUSION = 111; // HEAD injuries
const short EARLOBE_GAS = 112;
const short ALTERED_EGO = 113;
const short BROKEN_NECK = 121; // NECK injuries
const short SMILEY_FACE = 131; // FACE injuries
const short PLASTIC_SURGERY = 132;
const short DISK_RUPTURE = 211; // BACK injuries
const short BBQ_RIBS = 212;
const short GUT_DISTRESS = 221; // ABDOMEN injuries
const short ALCOHOL_POISON = 222;
const short FLAIL_CHEST = 231; // CHEST injuries
const short ALIEN_IMPLANT = 232;
const short RADIUS_BREAK = 311; // ARM injuries
const short NAIL_FUNGUS = 312;
const short FEMUR_BREAK = 321; // LEG injuries
const short TOE_BURN = 322;
const short INVALID_INJURY = -1;
string patientName1, // patient names
patientName2,
patientName;
short patientCount = 1; // count of patients seen
short injurySeverityScore1 = INVALID_INJURY,
injurySeverityScore2 = INVALID_INJURY,
injurySeverityScore; // patient injury severity
// scores to be calculated
short bodyRegion, // menu inputs
bodySubRegion,
injury;
short numMenuEntries; // # entries on a menu
bool invalidEntry; // true if invalid menu entry
do // get information for 2 patients
{
// greet and get patient's name
cout << endl << "Welcome to the ER!" << endl;
cout << "Enter patient's name: ";
cin >> patientName;
// initialize severity score
injurySeverityScore = INVALID_INJURY;
// find out which body region is affected
numMenuEntries = 4;
do
{
cout << endl
<< "Affected body region" << endl
<< "1. Head and neck" << endl
<< "2. Torso" << endl
<< "3. Extremity" << endl
<< "4. None of the above" << endl
<< "Enter 1-4: ";
cin >> bodyRegion;
invalidEntry = (bodyRegion < 1) ||
(bodyRegion > numMenuEntries);
if (invalidEntry)
cout << endl << "Invalid entry!" << endl;
} while (invalidEntry);
// if 'none of the above' wasn't selected, continue
// with next menu; otherwise, do not continue asking
// for more info
if (bodyRegion != numMenuEntries)
{
// find out which body subregion is affected
do
{
cout << endl
<< "Affected body subregion" << endl;
switch (bodyRegion*10)
{
case HEAD_NECK : cout << "1. Head" << endl
<< "2. Neck" << endl
<< "3. Face" << endl
<< endl;
numMenuEntries = 3;
break;
case TORSO : cout << "1. Back" << endl
<< "2. Abdomen" << endl
<< "3. Chest" << endl
<< endl;
numMenuEntries = 3;
break;
case EXTREMITY : cout << "1. Arm" << endl
<< "2. Leg" << endl
<< endl;
numMenuEntries = 2;
break;
}
cout << "Enter 1-" << numMenuEntries << ": ";
cin >> bodySubRegion;
invalidEntry = (bodySubRegion < 1) ||
(bodySubRegion > numMenuEntries);
if (invalidEntry)
cout << endl << "Invalid entry!" << endl;
} while (invalidEntry);
// find out injury
do
{
cout << endl << "Injury" << endl;
switch ((bodyRegion*10)+bodySubRegion)
{
case HEAD : cout << "1. Cerebral contusion"
<< endl
<< "2. Earlobe gastrophilology"
<< endl
<< "3. Altered ego" << endl;
numMenuEntries = 3;
break;
case BACK : cout << "1. Disk rupture" << endl
<< "2. BBQ'd ribs" << endl;
numMenuEntries = 2;
break;
case ARM : cout << "1. Broken radius" << endl
<< "2. Finger nail fungus"
<< endl;
numMenuEntries = 2;
break;
case ABDOMEN : cout << "1. Intestinal distress"
<< endl
<< "2. Alcohol poisoning"
<< endl;
numMenuEntries = 2;
break;
case NECK : cout << "1. Broken" << endl;
numMenuEntries = 1;
break;
case FACE : cout << "1. Smiley face" << endl
<< "2. Deformed plastic surgery"
<< endl;
numMenuEntries = 2;
break;
case CHEST : cout << "1. Flailed chest" << endl
<< "2. Alien implantation"
<< endl;
numMenuEntries = 2;
break;
case LEG : cout << "1. Fractured femur" << endl
<< "2. Burned toe hair" << endl;
numMenuEntries = 2;
break;
}
cout << "Enter 1-" << numMenuEntries << ": ";
cin >> injury;
invalidEntry = (injury < 1) ||
(injury > numMenuEntries);
if (invalidEntry)
cout << endl << "Invalid entry!" << endl;
} while (invalidEntry);
// my own encoding scheme (see values of constants)
injury += ((bodyRegion*10)+bodySubRegion) * 10;
switch (injury)
{
case CONTUSION : injurySeverityScore = 9;
break;
case EARLOBE_GAS : injurySeverityScore = 5;
break;
case ALTERED_EGO : injurySeverityScore = 4;
break;
case BROKEN_NECK : injurySeverityScore = 6;
break;
case SMILEY_FACE : injurySeverityScore = 3;
break;
case PLASTIC_SURGERY: injurySeverityScore = 1;
break;
case DISK_RUPTURE : injurySeverityScore = 7;
break;
case BBQ_RIBS : injurySeverityScore = 7;
break;
case GUT_DISTRESS : injurySeverityScore = 2;
break;
case ALCOHOL_POISON : injurySeverityScore = 2;
break;
case FLAIL_CHEST : injurySeverityScore = 4;
break;
case ALIEN_IMPLANT : injurySeverityScore = 8;
break;
case RADIUS_BREAK : injurySeverityScore = 3;
break;
case NAIL_FUNGUS : injurySeverityScore = 0;
break;
case FEMUR_BREAK : injurySeverityScore = 3;
break;
case TOE_BURN : injurySeverityScore = 0;
break;
default : injurySeverityScore = INVALID_INJURY;
}
} // else no body region selected for this patient
if (patientCount == 1)
{
injurySeverityScore1 = injurySeverityScore;
patientName1 = patientName;
}
else
{
injurySeverityScore2 = injurySeverityScore;
patientName2 = patientName;
};
patientCount++;
} while (patientCount <= 2);
// output results
cout << endl << patientName1 << " has injury severity score "
<< injurySeverityScore1 << endl;
cout << patientName2 << " has injury severity score "
<< injurySeverityScore2 << endl;
// patient with highest score will be seen first;
// if scores equal, patient with "smallest" name will be
// seen first; if scores and names are equal, first patient
// will be seen first
if (injurySeverityScore1 > injurySeverityScore2)
patientName = patientName1;
else if (injurySeverityScore2 > injurySeverityScore1)
patientName = patientName2;
else if (patientName1 < patientName2)
patientName = patientName1;
else if (patientName2 < patientName1)
patientName = patientName2;
else patientName = patientName1;
cout << "Dr. Eloe will see " << patientName
<< " first." << endl;
cout << "Goodbye!" << endl;
return 0;
}