Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Kevin Tancho
- kevintancho@gmail.com
- LAB 7
- */
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- using namespace std;
- //Prototypes
- void sortSelect(int arr[], int num, double average[10],
- int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]);
- void getData(int maxHR, int age, int subject[], double day1Avg, double day1MaxCommute, double day1exerciseHR,
- double day2Avg, double day2MaxCommute, double day2exerciseHR,
- double day3Avg, double day3MaxCommute, double day3exerciseHR,
- double day4Avg, double day4MaxCommute, double day4exerciseHR,
- double day5Avg, double day5MaxCommute, double day5exerciseHR, double average[10],
- int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]);
- void calculation(int maxHR, int age, int i, double day1Avg, double day1MaxCommute, double day1exerciseHR,
- double day2Avg, double day2MaxCommute, double day2exerciseHR,
- double day3Avg, double day3MaxCommute, double day3exerciseHR,
- double day4Avg, double day4MaxCommute, double day4exerciseHR,
- double day5Avg, double day5MaxCommute, double day5exerciseHR, double average[10],
- int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]);
- void headerOutput();
- void resultOutput(int subject[], double average[10], int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]);
- int main()
- {
- //Declare variables
- int subjectID[10], maxHR = 0, age = 0, daysExercised[10];
- double average[10], estMaxHR[10], ratioMaxToEst[10], ratioHighToMax[10];
- double day1Avg = 0, day1MaxCommute = 0, day1exerciseHR = 0;
- double day2Avg = 0, day2MaxCommute = 0, day2exerciseHR = 0;
- double day3Avg = 0, day3MaxCommute = 0, day3exerciseHR = 0;
- double day4Avg = 0, day4MaxCommute = 0, day4exerciseHR = 0;
- double day5Avg = 0, day5MaxCommute = 0, day5exerciseHR = 0;
- cout << "Kevin Tancho" << endl;
- cout << "kevintancho@gmail.com" << endl;
- cout << "LAB 7" << endl;
- getData(maxHR, age, subjectID, day1Avg, day1MaxCommute, day1exerciseHR, day2Avg, day2MaxCommute, day2exerciseHR,
- day3Avg, day3MaxCommute, day3exerciseHR, day4Avg, day4MaxCommute, day4exerciseHR, day5Avg, day5MaxCommute, day5exerciseHR,
- average, daysExercised, estMaxHR, ratioMaxToEst, ratioHighToMax);
- sortSelect(subjectID, 10, average, daysExercised, estMaxHR, ratioMaxToEst, ratioHighToMax);
- headerOutput();
- resultOutput(subjectID, average, daysExercised, estMaxHR, ratioMaxToEst, ratioHighToMax);
- }
- //getdata
- /*
- maxHR - reference to number of maximum heart rate
- age - reference to number of age of the subject
- subject - reference to subject number
- day'n'Avg - reference to the average commuting heart rate on day 'n'
- day'n'MaxCommute - reference to the maximum commuting heart on day 'n'
- day'n'exerciseHR - reference to the number of exercise heart rate on day 'n'
- */
- void getData(int maxHR, int age, int subject[],
- double day1Avg, double day1MaxCommute, double day1exerciseHR,
- double day2Avg, double day2MaxCommute, double day2exerciseHR,
- double day3Avg, double day3MaxCommute, double day3exerciseHR,
- double day4Avg, double day4MaxCommute, double day4exerciseHR,
- double day5Avg, double day5MaxCommute, double day5exerciseHR, double average[10],
- int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10])
- {
- ifstream inFile;
- //Open file
- inFile.open("HR.txt");
- if (inFile.fail())
- {
- cout << "No Such File" << endl;
- exit(100);
- }
- while (!inFile.eof())
- {
- for (int i = 0; i < 10; i++) {
- inFile >> subject[i];
- inFile >> maxHR;
- inFile >> age;
- inFile >> day1Avg >> day1MaxCommute >> day1exerciseHR >> day2Avg >> day2MaxCommute >> day2exerciseHR >> day3Avg >> day3MaxCommute >> day3exerciseHR
- >> day4Avg >> day4MaxCommute >> day4exerciseHR >> day5Avg >> day5MaxCommute >> day5exerciseHR;
- calculation(maxHR, age, i, day1Avg, day1MaxCommute, day1exerciseHR, day2Avg, day2MaxCommute, day2exerciseHR, day3Avg, day3MaxCommute, day3exerciseHR,
- day4Avg, day4MaxCommute, day4exerciseHR, day5Avg, day5MaxCommute, day5exerciseHR, average, daysExercised, estMaxHR, ratioMaxToEst, ratioHighToMax);
- }
- }
- }
- //calculation
- /*Pre: maxHR - number of maximum heart rate
- age - number of age of the subject
- i - order number of the arrays
- day'n'Avg - the average commuting heart rate on day 'n'
- day'n'MaxCommute - maximum commuting heart on day 'n'
- day'n'exerciseHR - the number of exercise heart rate on day 'n'
- average - number of average commuting heart rate in 5 days
- daysExercised - number of days exercised
- extMaxHR - number of estimated heart rate
- ratioMaxToEst - ratio in percentage of measured maximum heart rate to calculated estimate maximum heart rate
- ratioHighToMax - ratio in percentage of measured maximum commuting heart rate to measured maximum heart rate
- Post: none
- Purpose: to calculate the average of commuting heart rate in 5 days
- to calculate the number of days exercised
- to calculate the number of estimated heart rate
- to calculate the ratio of measured maximum heart rate to calculated estimate maximum heart rate in percentage
- to calculate the ratio of measured maximum commuting heart rate to measured maximum heart rate in percentage
- */
- void calculation(int maxHR, int age, int i, double day1Avg, double day1MaxCommute, double day1exerciseHR,
- double day2Avg, double day2MaxCommute, double day2exerciseHR,
- double day3Avg, double day3MaxCommute, double day3exerciseHR,
- double day4Avg, double day4MaxCommute, double day4exerciseHR,
- double day5Avg, double day5MaxCommute, double day5exerciseHR, double average[10],
- int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]) {
- if (day1Avg > 0 && day2Avg > 0 && day3Avg > 0 && day4Avg > 0 && day5Avg > 0) {
- average[i] = (day1Avg + day2Avg + day3Avg + day4Avg + day5Avg) / 5;
- }
- else {
- if (day1Avg <= 0) {
- average[i] = (day2Avg + day3Avg + day4Avg + day5Avg) / 4;
- }
- if (day2Avg <= 0) {
- average[i] = (day1Avg + day3Avg + day4Avg + day5Avg) / 4;
- }
- if (day3Avg <= 0) {
- average[i] = (day2Avg + day1Avg + day4Avg + day5Avg) / 4;
- }
- if (day4Avg <= 0) {
- average[i] = (day2Avg + day3Avg + day1Avg + day5Avg) / 4;
- }
- if (day5Avg <= 0) {
- average[i] = (day2Avg + day3Avg + day4Avg + day1Avg) / 4;
- }
- }
- int days = 5;
- if (day1exerciseHR == 0) {
- days--;
- }
- if (day2exerciseHR == 0) {
- days--;
- }
- if (day3exerciseHR == 0) {
- days--;
- }
- if (day4exerciseHR == 0) {
- days--;
- }
- if (day5exerciseHR == 0) {
- days--;
- }
- daysExercised[i] = days;
- estMaxHR[i] = 220 - age;
- ratioMaxToEst[i] = maxHR / estMaxHR[i] * 100;
- double highestCommute = 0;
- if (day1MaxCommute > highestCommute) {
- highestCommute = day1MaxCommute;
- }
- if (day2MaxCommute > highestCommute) {
- highestCommute = day2MaxCommute;
- }
- if (day3MaxCommute > highestCommute) {
- highestCommute = day3MaxCommute;
- }
- if (day4MaxCommute > highestCommute) {
- highestCommute = day4MaxCommute;
- }
- if (day5MaxCommute > highestCommute) {
- highestCommute = day5MaxCommute;
- }
- ratioHighToMax[i] = highestCommute / maxHR * 100;
- }
- /*
- Pre:
- */
- void sortSelect(int arr[], int num, double average[10],
- int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10])
- {
- int current; int walker;
- int smallestIndex;
- int temp, temp2;
- double temp1, temp3, temp4, temp5;
- for (current = 0; current < num - 1; current++)
- {
- smallestIndex = current;
- for (walker = current; walker < num; walker++)
- {
- if (arr[walker] < arr[smallestIndex])
- smallestIndex = walker;
- }//for walker
- //Swap to position smallest at what is the current position
- temp = arr[current];
- arr[current] = arr[smallestIndex];
- arr[smallestIndex] = temp;
- temp1 = average[current];
- average[current] = average[smallestIndex];
- average[smallestIndex] = temp1;
- temp2 = daysExercised[current];
- daysExercised[current] = daysExercised[smallestIndex];
- daysExercised[smallestIndex] = temp2;
- temp3 = estMaxHR[current];
- estMaxHR[current] = estMaxHR[smallestIndex];
- estMaxHR[smallestIndex] = temp3;
- temp4 = ratioMaxToEst[current];
- ratioMaxToEst[current] = ratioMaxToEst[smallestIndex];
- ratioMaxToEst[smallestIndex] = temp4;
- temp5 = ratioHighToMax[current];
- ratioHighToMax[current] = ratioHighToMax[smallestIndex];
- ratioHighToMax[smallestIndex] = temp5;
- }//for current
- return;
- }
- /*
- pre: none
- post: output of the header
- purpose: to post output of the header
- */
- //header output
- void headerOutput() {
- cout << "COMMUTING AND EXERCISE HEART RATE SUMMARY" << endl << endl;
- cout << "SUBJECT AVERAGE DAYS ESTIMATED %MEASURED %MAX" << endl;
- cout << "NUMBER COMMUTING EXERCISED MAX HR TO COMMUTING" << endl;
- cout << " HR ESTIMATED HR TO" << endl;
- cout << " MAX HR MEASURED" << endl;
- }
- /*
- pre: subjectID - the number of subject ID
- average - number of average commuting heart rate in 5 days
- daysExercised - number of days exercised
- extMaxHR - number of estimated heart rate
- ratioMaxToEst - ratio in percentage of measured maximum heart rate to calculated estimate maximum heart rate
- ratioHighToMax - ratio in percentage of measured maximum commuting heart rate to measured maximum heart rate
- post: calculation from the given data
- purpose: to post the summary result from the calculated data
- */
- //result calculation output
- void resultOutput(int subjectID[], double average[10], int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]) {
- for (int i = 0; i < 10; i++) {
- cout << setprecision(1) << fixed << right << setw(5);
- cout << subjectID[i] << "\t " << average[i] << "\t " << daysExercised[i] << "\t\t" << estMaxHR[i] << "\t\t" << ratioMaxToEst[i] << "\t\t " << ratioHighToMax[i] << endl;
- }
- }
- /*
- Kevin Tancho
- kevintancho@gmail.com
- LAB 7
- COMMUTING AND EXERCISE HEART RATE SUMMARY
- SUBJECT AVERAGE DAYS ESTIMATED %MEASURED %MAX
- NUMBER COMMUTING EXERCISED MAX HR TO COMMUTING
- HR ESTIMATED HR TO
- MAX HR MEASURED
- 1124 112.5 4 184.0 96.7 81.5
- 2438 118.0 4 194.0 103.1 82.5
- 2776 106.3 2 175.0 101.7 81.5
- 3521 113.8 2 169.0 107.1 87.8
- 4545 112.2 4 168.0 113.1 68.9
- 4915 127.7 0 193.0 95.9 91.4
- 6231 138.0 2 192.0 94.3 94.5
- 7345 132.2 3 184.0 106.0 86.7
- 8762 120.6 3 192.0 96.9 79.6
- 9439 126.2 2 199.0 99.0 80.7
- Press any key to continue . . .
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement