hw7fncts.cpp
// Programmer: Jennifer Leopold date: October 20, 2014
// File: hw7fncts.cpp
// Purpose: This file contains the definitions of the functions
// for the program that compares two tests for
// diagnosing zombie-ism.
#include <string>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "hw7.h"
using namespace std;
void greeting()
{
cout << "Welcome to Dr. Eloe's research "
<< "study on zombie-ism!\n\n";
return;
};
void goodbye()
{
cout << "\nWe hope you found this research study "
<< "interesting.\n";
cout << "Goodbye!\n";
return;
};
void getData(patientData p[], const short numPatients)
{
char dnaChar; // 1 of the 4 nucleobase chars
short dnaCode; // represents a randomly gen'd nucleobase
for (short i = 0; i < numPatients; i++)
{
p[i].wantsToEatBrains = rand() % 2; // bool, so 0..1
p[i].bodyOdor = rand() % NUM_ODOR_CODES;
p[i].gait = rand() % NUM_GAIT_CODES;
for (short j = 0; j < DNA_SEQUENCE_LENGTH; j++)
{
dnaCode = rand() % 100;
if (dnaCode <= GUANINE_FREQUENCY)
dnaChar = GUANINE;
else if (dnaCode <= (GUANINE_FREQUENCY +
THYMINE_FREQUENCY))
dnaChar = THYMINE;
else if (dnaCode <= (GUANINE_FREQUENCY +
THYMINE_FREQUENCY +
ADENINE_FREQUENCY))
dnaChar = ADENINE;
else dnaChar = CYTOSINE;
p[i].dnaSequence[j] = dnaChar;
}
}
return;
}
void testByCharacteristics(patientData p[],
const short numPatients)
{
for (short i = 0; i < numPatients; i++)
p[i].isZombieByCharTest =
(p[i].wantsToEatBrains) &&
((p[i].bodyOdor == SMELL_SLIGHTLY_RIPE) ||
(p[i].bodyOdor == SMELL_ROTTING_STENCH)) &&
(p[i].gait != GAIT_NORMAL);
return;
}
void testByDNA(patientData p[],
const short numPatients)
{
bool subsequenceFound;
short j;
for (short i = 0; i < numPatients; i++)
{
j = 0;
subsequenceFound = false;
while ((j <= DNA_SEQUENCE_LENGTH-4) &&
(!subsequenceFound))
if ((p[i].dnaSequence[j] == GUANINE) &&
(p[i].dnaSequence[j+1] == ADENINE) &&
(p[i].dnaSequence[j+2] == THYMINE) &&
(p[i].dnaSequence[j+3] == CYTOSINE))
subsequenceFound = true;
else j++;
p[i].isZombieByDNATest = subsequenceFound;
}
return;
}
void collectStatistics(const patientData p[],
const short numPatients,
short &numWantBrains,
short &numStinky,
short &numAbnormalGait,
short &numZombiesOnlyByDNATest,
short &numZombiesOnlyByCharTest,
short &numZombiesByBothTests)
{
numWantBrains = 0;
numStinky = 0;
numAbnormalGait = 0;
numZombiesOnlyByDNATest = 0;
numZombiesOnlyByCharTest = 0;
numZombiesByBothTests = 0;
for (int i = 0; i < numPatients; i++)
{
if (p[i].wantsToEatBrains)
numWantBrains++;
if ((p[i].bodyOdor == SMELL_SLIGHTLY_RIPE) ||
(p[i].bodyOdor == SMELL_ROTTING_STENCH))
numStinky++;
if (p[i].gait != GAIT_NORMAL)
numAbnormalGait++;
if (p[i].isZombieByDNATest &&
!p[i].isZombieByCharTest)
numZombiesOnlyByDNATest++;
else if (!p[i].isZombieByDNATest &&
p[i].isZombieByCharTest)
numZombiesOnlyByCharTest++;
else if (p[i].isZombieByDNATest &&
p[i].isZombieByCharTest)
numZombiesByBothTests++;
}
return;
}
void outputResults(const short numPeople,
const short numWantBrains,
const short numStinky,
const short numAbnormalGait,
const short numZombiesOnlyByDNATest,
const short numZombiesOnlyByCharTest,
const short numZombiesByBothTests)
{
cout << "\nOut of a total of " << numPeople
<< " people tested:\n";
cout << " " << percent(numWantBrains, numPeople)
<< "% want to eat brains.\n";
cout << " " << percent(numStinky, numPeople)
<< "% have a slightly ripe or rotting stench "
<< "smell.\n";
cout << " " << percent(numAbnormalGait, numPeople)
<< "% do not walk normally.\n\n";
cout << " "
<< percent(numZombiesOnlyByCharTest, numPeople)
<< "% qualify as zombies only by how they smell,\n"
<< " how they walk, and what they want to eat.\n\n";
cout << " "
<< percent(numZombiesOnlyByDNATest, numPeople)
<< "% qualify as zombies only by the DNA test.\n\n";
cout << " "
<< percent(numZombiesByBothTests, numPeople)
<< "% qualify as zombies by both "
<< "the DNA test and how they \n"
<< " walk, how they smell, and what "
<< "they want to eat.\n";
return;
}
float percent(const short numerator, const short denominator)
{
return(denominator == 0? 0 :
(static_cast<float>(numerator)/denominator)*100);
}
short getNumPeopleTested()
{
short numPeopleTested;
bool invalidInput;
do
{
cout << "Enter the number of people in the test (1-"
<< MAX_NUM_PATIENTS << "): ";
cin >> numPeopleTested;
invalidInput = ((numPeopleTested < 1) ||
(numPeopleTested > MAX_NUM_PATIENTS));
if (invalidInput)
cout << "Invalid input!\n\n";
} while (invalidInput);
return(numPeopleTested);
}