Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.25 KB | None | 0 0
  1. /*
  2. Kevin Tancho
  3. kevintancho@gmail.com
  4. LAB 7
  5. */
  6.  
  7. #include <iostream>
  8. #include <fstream>
  9. #include <iomanip>
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14. //Prototypes
  15. void sortSelect(int arr[], int num, double average[10],
  16. int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]);
  17.  
  18. void getData(int maxHR, int age, int subject[], double day1Avg, double day1MaxCommute, double day1exerciseHR,
  19. double day2Avg, double day2MaxCommute, double day2exerciseHR,
  20. double day3Avg, double day3MaxCommute, double day3exerciseHR,
  21. double day4Avg, double day4MaxCommute, double day4exerciseHR,
  22. double day5Avg, double day5MaxCommute, double day5exerciseHR, double average[10],
  23. int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]);
  24.  
  25. void calculation(int maxHR, int age, int i, double day1Avg, double day1MaxCommute, double day1exerciseHR,
  26. double day2Avg, double day2MaxCommute, double day2exerciseHR,
  27. double day3Avg, double day3MaxCommute, double day3exerciseHR,
  28. double day4Avg, double day4MaxCommute, double day4exerciseHR,
  29. double day5Avg, double day5MaxCommute, double day5exerciseHR, double average[10],
  30. int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]);
  31.  
  32. void headerOutput();
  33.  
  34. void resultOutput(int subject[], double average[10], int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]);
  35.  
  36. int main()
  37. {
  38. //Declare variables
  39. int subjectID[10], maxHR = 0, age = 0, daysExercised[10];
  40. double average[10], estMaxHR[10], ratioMaxToEst[10], ratioHighToMax[10];
  41. double day1Avg = 0, day1MaxCommute = 0, day1exerciseHR = 0;
  42. double day2Avg = 0, day2MaxCommute = 0, day2exerciseHR = 0;
  43. double day3Avg = 0, day3MaxCommute = 0, day3exerciseHR = 0;
  44. double day4Avg = 0, day4MaxCommute = 0, day4exerciseHR = 0;
  45. double day5Avg = 0, day5MaxCommute = 0, day5exerciseHR = 0;
  46.  
  47. cout << "Kevin Tancho" << endl;
  48. cout << "kevintancho@gmail.com" << endl;
  49. cout << "LAB 7" << endl;
  50. getData(maxHR, age, subjectID, day1Avg, day1MaxCommute, day1exerciseHR, day2Avg, day2MaxCommute, day2exerciseHR,
  51. day3Avg, day3MaxCommute, day3exerciseHR, day4Avg, day4MaxCommute, day4exerciseHR, day5Avg, day5MaxCommute, day5exerciseHR,
  52. average, daysExercised, estMaxHR, ratioMaxToEst, ratioHighToMax);
  53.  
  54. sortSelect(subjectID, 10, average, daysExercised, estMaxHR, ratioMaxToEst, ratioHighToMax);
  55.  
  56. headerOutput();
  57.  
  58. resultOutput(subjectID, average, daysExercised, estMaxHR, ratioMaxToEst, ratioHighToMax);
  59.  
  60. }
  61.  
  62. //getdata
  63. /*
  64. maxHR - reference to number of maximum heart rate
  65. age - reference to number of age of the subject
  66. subject - reference to subject number
  67. day'n'Avg - reference to the average commuting heart rate on day 'n'
  68. day'n'MaxCommute - reference to the maximum commuting heart on day 'n'
  69. day'n'exerciseHR - reference to the number of exercise heart rate on day 'n'
  70. */
  71. void getData(int maxHR, int age, int subject[],
  72. double day1Avg, double day1MaxCommute, double day1exerciseHR,
  73. double day2Avg, double day2MaxCommute, double day2exerciseHR,
  74. double day3Avg, double day3MaxCommute, double day3exerciseHR,
  75. double day4Avg, double day4MaxCommute, double day4exerciseHR,
  76. double day5Avg, double day5MaxCommute, double day5exerciseHR, double average[10],
  77. int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10])
  78. {
  79. ifstream inFile;
  80.  
  81. //Open file
  82. inFile.open("HR.txt");
  83. if (inFile.fail())
  84. {
  85. cout << "No Such File" << endl;
  86. exit(100);
  87. }
  88.  
  89.  
  90. while (!inFile.eof())
  91. {
  92. for (int i = 0; i < 10; i++) {
  93. inFile >> subject[i];
  94. inFile >> maxHR;
  95. inFile >> age;
  96. inFile >> day1Avg >> day1MaxCommute >> day1exerciseHR >> day2Avg >> day2MaxCommute >> day2exerciseHR >> day3Avg >> day3MaxCommute >> day3exerciseHR
  97. >> day4Avg >> day4MaxCommute >> day4exerciseHR >> day5Avg >> day5MaxCommute >> day5exerciseHR;
  98. calculation(maxHR, age, i, day1Avg, day1MaxCommute, day1exerciseHR, day2Avg, day2MaxCommute, day2exerciseHR, day3Avg, day3MaxCommute, day3exerciseHR,
  99. day4Avg, day4MaxCommute, day4exerciseHR, day5Avg, day5MaxCommute, day5exerciseHR, average, daysExercised, estMaxHR, ratioMaxToEst, ratioHighToMax);
  100. }
  101.  
  102. }
  103.  
  104. }
  105. //calculation
  106. /*Pre: maxHR - number of maximum heart rate
  107. age - number of age of the subject
  108. i - order number of the arrays
  109. day'n'Avg - the average commuting heart rate on day 'n'
  110. day'n'MaxCommute - maximum commuting heart on day 'n'
  111. day'n'exerciseHR - the number of exercise heart rate on day 'n'
  112. average - number of average commuting heart rate in 5 days
  113. daysExercised - number of days exercised
  114. extMaxHR - number of estimated heart rate
  115. ratioMaxToEst - ratio in percentage of measured maximum heart rate to calculated estimate maximum heart rate
  116. ratioHighToMax - ratio in percentage of measured maximum commuting heart rate to measured maximum heart rate
  117.  
  118. Post: none
  119.  
  120. Purpose: to calculate the average of commuting heart rate in 5 days
  121. to calculate the number of days exercised
  122. to calculate the number of estimated heart rate
  123. to calculate the ratio of measured maximum heart rate to calculated estimate maximum heart rate in percentage
  124. to calculate the ratio of measured maximum commuting heart rate to measured maximum heart rate in percentage
  125. */
  126.  
  127.  
  128. void calculation(int maxHR, int age, int i, double day1Avg, double day1MaxCommute, double day1exerciseHR,
  129. double day2Avg, double day2MaxCommute, double day2exerciseHR,
  130. double day3Avg, double day3MaxCommute, double day3exerciseHR,
  131. double day4Avg, double day4MaxCommute, double day4exerciseHR,
  132. double day5Avg, double day5MaxCommute, double day5exerciseHR, double average[10],
  133. int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]) {
  134. if (day1Avg > 0 && day2Avg > 0 && day3Avg > 0 && day4Avg > 0 && day5Avg > 0) {
  135. average[i] = (day1Avg + day2Avg + day3Avg + day4Avg + day5Avg) / 5;
  136. }
  137. else {
  138. if (day1Avg <= 0) {
  139. average[i] = (day2Avg + day3Avg + day4Avg + day5Avg) / 4;
  140. }
  141. if (day2Avg <= 0) {
  142. average[i] = (day1Avg + day3Avg + day4Avg + day5Avg) / 4;
  143. }
  144. if (day3Avg <= 0) {
  145. average[i] = (day2Avg + day1Avg + day4Avg + day5Avg) / 4;
  146. }
  147. if (day4Avg <= 0) {
  148. average[i] = (day2Avg + day3Avg + day1Avg + day5Avg) / 4;
  149. }
  150. if (day5Avg <= 0) {
  151. average[i] = (day2Avg + day3Avg + day4Avg + day1Avg) / 4;
  152. }
  153. }
  154. int days = 5;
  155. if (day1exerciseHR == 0) {
  156. days--;
  157. }
  158. if (day2exerciseHR == 0) {
  159. days--;
  160. }
  161. if (day3exerciseHR == 0) {
  162. days--;
  163. }
  164. if (day4exerciseHR == 0) {
  165. days--;
  166. }
  167. if (day5exerciseHR == 0) {
  168. days--;
  169. }
  170. daysExercised[i] = days;
  171. estMaxHR[i] = 220 - age;
  172. ratioMaxToEst[i] = maxHR / estMaxHR[i] * 100;
  173. double highestCommute = 0;
  174. if (day1MaxCommute > highestCommute) {
  175. highestCommute = day1MaxCommute;
  176. }
  177. if (day2MaxCommute > highestCommute) {
  178. highestCommute = day2MaxCommute;
  179. }
  180. if (day3MaxCommute > highestCommute) {
  181. highestCommute = day3MaxCommute;
  182. }
  183. if (day4MaxCommute > highestCommute) {
  184. highestCommute = day4MaxCommute;
  185. }
  186. if (day5MaxCommute > highestCommute) {
  187. highestCommute = day5MaxCommute;
  188. }
  189. ratioHighToMax[i] = highestCommute / maxHR * 100;
  190. }
  191.  
  192. /*
  193. Pre:
  194. */
  195. void sortSelect(int arr[], int num, double average[10],
  196. int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10])
  197. {
  198. int current; int walker;
  199. int smallestIndex;
  200. int temp, temp2;
  201. double temp1, temp3, temp4, temp5;
  202.  
  203. for (current = 0; current < num - 1; current++)
  204. {
  205. smallestIndex = current;
  206. for (walker = current; walker < num; walker++)
  207. {
  208. if (arr[walker] < arr[smallestIndex])
  209. smallestIndex = walker;
  210. }//for walker
  211.  
  212. //Swap to position smallest at what is the current position
  213. temp = arr[current];
  214. arr[current] = arr[smallestIndex];
  215. arr[smallestIndex] = temp;
  216. temp1 = average[current];
  217. average[current] = average[smallestIndex];
  218. average[smallestIndex] = temp1;
  219. temp2 = daysExercised[current];
  220. daysExercised[current] = daysExercised[smallestIndex];
  221. daysExercised[smallestIndex] = temp2;
  222. temp3 = estMaxHR[current];
  223. estMaxHR[current] = estMaxHR[smallestIndex];
  224. estMaxHR[smallestIndex] = temp3;
  225. temp4 = ratioMaxToEst[current];
  226. ratioMaxToEst[current] = ratioMaxToEst[smallestIndex];
  227. ratioMaxToEst[smallestIndex] = temp4;
  228. temp5 = ratioHighToMax[current];
  229. ratioHighToMax[current] = ratioHighToMax[smallestIndex];
  230. ratioHighToMax[smallestIndex] = temp5;
  231. }//for current
  232. return;
  233. }
  234. /*
  235. pre: none
  236. post: output of the header
  237. purpose: to post output of the header
  238. */
  239. //header output
  240. void headerOutput() {
  241. cout << "COMMUTING AND EXERCISE HEART RATE SUMMARY" << endl << endl;
  242. cout << "SUBJECT AVERAGE DAYS ESTIMATED %MEASURED %MAX" << endl;
  243. cout << "NUMBER COMMUTING EXERCISED MAX HR TO COMMUTING" << endl;
  244. cout << " HR ESTIMATED HR TO" << endl;
  245. cout << " MAX HR MEASURED" << endl;
  246. }
  247.  
  248. /*
  249. pre: subjectID - the number of subject ID
  250. average - number of average commuting heart rate in 5 days
  251. daysExercised - number of days exercised
  252. extMaxHR - number of estimated heart rate
  253. ratioMaxToEst - ratio in percentage of measured maximum heart rate to calculated estimate maximum heart rate
  254. ratioHighToMax - ratio in percentage of measured maximum commuting heart rate to measured maximum heart rate
  255. post: calculation from the given data
  256. purpose: to post the summary result from the calculated data
  257. */
  258. //result calculation output
  259. void resultOutput(int subjectID[], double average[10], int daysExercised[10], double estMaxHR[10], double ratioMaxToEst[10], double ratioHighToMax[10]) {
  260. for (int i = 0; i < 10; i++) {
  261. cout << setprecision(1) << fixed << right << setw(5);
  262. cout << subjectID[i] << "\t " << average[i] << "\t " << daysExercised[i] << "\t\t" << estMaxHR[i] << "\t\t" << ratioMaxToEst[i] << "\t\t " << ratioHighToMax[i] << endl;
  263. }
  264. }
  265.  
  266. /*
  267. Kevin Tancho
  268. kevintancho@gmail.com
  269. LAB 7
  270. COMMUTING AND EXERCISE HEART RATE SUMMARY
  271.  
  272. SUBJECT AVERAGE DAYS ESTIMATED %MEASURED %MAX
  273. NUMBER COMMUTING EXERCISED MAX HR TO COMMUTING
  274. HR ESTIMATED HR TO
  275. MAX HR MEASURED
  276. 1124 112.5 4 184.0 96.7 81.5
  277. 2438 118.0 4 194.0 103.1 82.5
  278. 2776 106.3 2 175.0 101.7 81.5
  279. 3521 113.8 2 169.0 107.1 87.8
  280. 4545 112.2 4 168.0 113.1 68.9
  281. 4915 127.7 0 193.0 95.9 91.4
  282. 6231 138.0 2 192.0 94.3 94.5
  283. 7345 132.2 3 184.0 106.0 86.7
  284. 8762 120.6 3 192.0 96.9 79.6
  285. 9439 126.2 2 199.0 99.0 80.7
  286. Press any key to continue . . .
  287. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement