Solution
/* Programmer: Bushra Anjum and Clayton Price and Kenneth Fletcher
*/
#include <iostream>
using namespace std;
//Function Prototypes
void greeting(); //welcome greeting message
void signoff(); //good bye sign off message
char present_menu(); //menu options and take user input
int rigorMortis(const float bodyTemp,const bool wasIll,const bool wasCS);
int algorMortis(const float bodyTemp);
int occularMortis(const bool isDiscolored,const bool isBulging);
int vitreousPotassiumMortis(const float potassiumConcentrate);
int stomachMortis(const int noOfShots);
void presentResults(const int tod,const int et); //function displaying TOD
//Helper input function
bool getBool();
//CONSTANTS
const int MIN_TEMP = 32;
const int MAX_TEMP = 120;
const int MIN_POTCONC = 3;
const int MAX_POTCONC = 7;
const int MAX_SHOTS = 30;
const float NORMAL_BODY_TEMP = 98.6;
const float RIGOR_DIVISOR = 2.1;
const float ILLNESS_ADJUSTMENT = 1.5;
const float CSMAJOR_COOLNESS_FACTOR = 2.5;
const float ALGOR_DIVISOR = 1.5;
const float POTCONC_MULTIPLIER = 17.14;
const float POTCONC_ADDEND = 39.1;
const int SHOTS_TO_DEATH = 10;
const int ERROR_TOL_RIGOR = 3;
const int ERROR_TOL_ALGOR = 2;
const int ERROR_TOL_OCCULAR = 5;
const int ERROR_TOL_POTCONC = 4;
const int ERROR_TOL_STOMACH = 0;
int main()
{
char option='0';
float bodyTemp, potConcentrate;
bool illFlag, csFlag, discolorationFlag, bulgingFlag;
int errorTol, numShots, timeOfDeath;
greeting();
while(option!='6')
{
option=present_menu();
switch(option)
{
case '1':
//Gathering Case Data
do
{
cout<<"Please enter Body Temperature: "<<endl;
cin>>bodyTemp;
} while(bodyTemp<MIN_TEMP || bodyTemp>MAX_TEMP);
cout<<"Was the victim ill?";
illFlag=getBool();
cout<<"Was the victim a Computer Scientist?";
csFlag=getBool();
timeOfDeath=rigorMortis(bodyTemp,illFlag, csFlag);
errorTol = ERROR_TOL_RIGOR;
break;
case '2':
//Gathering Case Data
do
{
cout<<"Please enter Body Temperature: "<<endl;
cin>>bodyTemp;
} while(bodyTemp<MIN_TEMP || bodyTemp>MAX_TEMP);
timeOfDeath=algorMortis(bodyTemp);
errorTol = ERROR_TOL_ALGOR;
break;
case '3':
//Gathering Case Data
cout<<"Has Occular Discoloration occuredd?";
discolorationFlag=getBool();
cout<<"Were the eyes bulging?";
bulgingFlag=getBool();
timeOfDeath=occularMortis(discolorationFlag, bulgingFlag);
errorTol = ERROR_TOL_OCCULAR;
break;
case '4':
//Gathering Case Data
do
{
cout<<"Please enter the Potassium Concentration: "<<endl;
cin>>potConcentrate;
} while(potConcentrate<MIN_POTCONC || potConcentrate>MAX_POTCONC);
timeOfDeath=vitreousPotassiumMortis(potConcentrate);
errorTol = ERROR_TOL_POTCONC;
break;
case '5':
//Gathering Case Data
do
{
cout<<"Please enter the number of shots of whiskey: "<<endl;
cin>>numShots;
} while(numShots<0 || numShots>MAX_SHOTS);
timeOfDeath=stomachMortis(numShots);
errorTol = ERROR_TOL_STOMACH;
break;
default:
cout<<"*** Invalid Selection ***\n\n";
}
//Present results if a valid case was selected
if(option>='1' && option<='5')
presentResults(timeOfDeath, errorTol);
}
signoff();
return 0;
}
//Function Definitions
void greeting()
{
cout<<"\n\nWelcome Action Jackson to TOD Determination Program!!\n\n\n";
}
void signoff()
{
cout<<"\n\n\t\tSigning off now ...\n";
}
char present_menu()
{
char option;
cout<<"TOD Determination Options"<<endl;
cout<<"-------------------------"<<endl;
cout<<"\t1. RigorMortis\n";
cout<<"\t2. AlgorMortis\n";
cout<<"\t3. OccularMortis\n";
cout<<"\t4. VirteousPotassiumMortis\n";
cout<<"\t5. StomachMortis\n";
cout<<"\t6. QuitMortis\n";
cin>>option;
return option;
}
int rigorMortis(const float bodyTemp,const bool wasIll,const bool wasCS)
{
float timeOfDeath;
timeOfDeath=(NORMAL_BODY_TEMP - bodyTemp)/RIGOR_DIVISOR
+ wasIll*ILLNESS_ADJUSTMENT
+ wasCS*CSMAJOR_COOLNESS_FACTOR;
return static_cast<int>(timeOfDeath + .5);
}
int algorMortis(const float bodyTemp)
{
float timeOfDeath;
timeOfDeath = (NORMAL_BODY_TEMP-bodyTemp)/ALGOR_DIVISOR;
return static_cast<int>(timeOfDeath+.5);
}
int occularMortis(const bool isDiscolored,const bool isBulging)
{
float timeOfDeath;
if(!isDiscolored && !isBulging)
timeOfDeath=4;
else if(isDiscolored && !isBulging)
timeOfDeath=7;
else if(!isDiscolored && isBulging)
timeOfDeath=16;
else
timeOfDeath=24;
return static_cast<int>(timeOfDeath+.5);
}
int vitreousPotassiumMortis(const float potassiumConcentrate)
{
float timeOfDeath;
timeOfDeath = (POTCONC_MULTIPLIER * potassiumConcentrate) +POTCONC_ADDEND ;
return static_cast<int>(timeOfDeath+.5);
}
int stomachMortis(const int noOfShots)
{
float timeOfDeath;
timeOfDeath = SHOTS_TO_DEATH - noOfShots;
return static_cast<int>(timeOfDeath+.5);
}
void presentResults(const int tod,const int et)
{
cout<<"\n\nTime of Death of the victim is estimated between\n\t";
cout<<((tod-et)<0?0:tod-et);
cout<<" and ";
cout<<((tod+et)<0?0:tod+et);
cout<<" hours before discovery.\n\n\n";
}
//Helper function to take input for a bool
bool getBool()
{
char alpha;
cout<<"(Enter 1 for Yes, 0 for No)";
cin>>alpha;
while(alpha!='1' && alpha!='0')
{
cout<<"\tNo, really, enter 1 for Yes, 0 for No: ";
cin>>alpha;
}
return (alpha=='1'?true:false);
}