Question

In: Computer Science

A research institute specializing in physiology is conducting a study on the strain and effects of...

A research institute specializing in physiology is conducting a study on the strain and effects of commuting trips done on a bicycle or walking. When the physiological strain of commuting trips has been studied, the results will be used in exercise prescriptions, which can then use commuting as part of an exercise regimen.

In this program you will write a C++ program to analyze a small subset of the data that has been collected.

INPUT: Take the input from the file HR.txt

Input data format:

The file consists of three columns, with six lines of data for each person, test subject.

The first line stores:

i. column 1 - each person’s ID number (integer),

ii. column 2 - clinically measured maximum heart rate (integer), and

iii. column 3 - age (integer).

For the next five lines, each contains:

(a) column 1 - the day’s average commuting heart rate

(b) column 2 - maximum commuting heart rate, and

(c) column 3 - exercise heart rate

for five consecutive working days.

Then, the six-line partition is repeated for the next person.

At times the heart rate monitors reacted to nearby power lines or other signal interference, and gave false readings. These incorrect measurements were rejected and show up in the data file as -1. On the days the person did not exercise, the exercise heart rate value is zero.

PROCESSING: Use precisely six parallel arrays: one for subject ID numbers and five for the calculated values as described below.

Using this information, calculate

  1. Weekly average of the average(daily) commuting heart rates for each person.
  2. Number of days that the person exercised on his/her own.
  3. Estimated maximum heart rate = 220 – age.
  4. Ratio (%) of measured maximum heart rate to estimated maximum heart rate.
    The maximum heart rate for each person has been measured during a maximum oxygen uptake test in the laboratory. During the test, the person exercised with increasing intensity until exhaustion, and then the maximum heart rate was measured close to the end of the test. Using this measured maximum heart rate(column 2 of line 1) and the estimated maximum heart rate(calculation #3 above), calculate the ratio, in percentage, of the measured maximum heart rate to the estimated maximum heart rate. Note that this percentage can exceed 100%.
  5. Ratio (%) of highest commuting heart rate of the week to measured maximum heart rate( lab). Find the highest maximum commuting heart rate of the week(search through each day's maximum commuting heart rate; in column 2) for each person, and then calculate the percentage ratio of this value to the measured maximum heart rate(lab).

OUTPUT: Output should be in the following format, figures aligned in "pretty" columns, and sorted by subject numberfrom low to high

Steps:

  1. Write main() and open file
  2. Write get_data(). At this stage there is a for loop to read data for each of five days and the for loop is nested inside a while(not end of file) loop. Use debug cout statements to check that the data is being input correctly. These cout statements must be removed before final submission of project. Debug.
  3. computations including function as stipulated.
  4. Write function to output heading.
  5. Write output function to output computed data. Debug
  6. Write function to sort the ID using selection method. Debug
  7. Clean up code

Checkpoints:

  1. Develop an input function which fills all five arrays while calling calculation function
  2. One and only one parameterized function must be used to calculate Either a) the percentage of measured maximum to estimated heart rate or b) the percentage of highest commuting heart rate to measure maximum heart rate
  3. Use a selection sort to sort the arrays by the order of subject ID numbers. This needs to be a separate function.
  4. A separate function must be used to output the table heading ONLY
  5. Numerical output is done in a separate output function. Output must be formatted as shown. Output correct. Redirect output to a file

HR.txt

6231 181 28
140.1 170 101.8
128.4 156 0.0
145.2 171 106.2
131.3 165 0.0
144.8 170 0.0

1124 178 36
122.8 139 138.4
119.6 142 0.0
117.8 134 133.4
115.3 145 134.2
87.2 109 120.5

7345 195 36
128.4 151 104.6
120.5 153 0.0
134.5 166 140.4
127.4 156 0.0
150.3 169 158.5

9439 197 21
121.5 143 112.2
128.9 145 0.0
126.1 159 134.5
123.0 152 0.0
131.5 147 0.0

4545 190 52
114.8 130 113.1
102.6 131 0.0
117.4 129 149.1
-1 -1 114.0
114.1 123 119.5

2438 200 26
123.0 165 105.4
118.2 130 122.0
121.7 136 124.5
116.1 130 0.0
111.0 152 103.5

2776 178 45
110.3 120 129.1
107.8 132 0.0
111.5 145 135.0
-1 -1 0.0
95.5 119 0.0

8762 186 28
122.7 146 151.9
116.0 137 0.0
119.9 145 0.0
123.3 148 150.0
121.0 142 156.3

4915 185 27
120.3 169 0.0
130.2 150 0.0
123.0 158 0.0
133.4 152 0.0
131.6 159 0.0

3521 181 51
108.3 133 119.3
-1 -1 0.0
117.6 147 125.3
106.7 131 0.0
122.7 159 0.0

Solutions

Expert Solution

Screenshot

Program

//Header files
#include <iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
#define MAX 10
//Function prototypes
void get_Data(ifstream&, int*, double*, int*, int*, double*, double*);
void sort_Data(int*, double*, int*, int*, double*, double*);
void header(ofstream&);
void output(ofstream&, const int[], const double[], const int[], const int[], const double[], const double[]);
int main()
{
   //Create parallel arrays
   int ids[MAX];
   double wklyAvgs[MAX];
   int daysExercised[MAX];
   int estmatedMaxHeartRate[MAX];
   double heartRateRatio[MAX];
   double highestHeartRateRation[MAX];
   //Input file
   ifstream in("HR.txt");
   //File not open check
   if (!in) {
       cout << "File not found!!!" << endl;
       exit(0);
   }
   //Read data from file to parrallel arrays
   get_Data(in,ids, wklyAvgs, daysExercised, estmatedMaxHeartRate, heartRateRatio, highestHeartRateRation);
   //Close file
   in.close();
   //Sort using parrallel arrays
   sort_Data(ids, wklyAvgs, daysExercised, estmatedMaxHeartRate, heartRateRatio, highestHeartRateRation);
   //Output file path
   ofstream out("output.txt");
   //Write header
   header(out);
   //Write data
   output(out, ids, wklyAvgs, daysExercised, estmatedMaxHeartRate, heartRateRatio, highestHeartRateRation);
   //Close file
   out.close();
}
//Function to get data from file and store ino parallel arrays
void get_Data(ifstream& in, int* ids, double* wAvg,int* days, int* estimate, double* hrate, double* maxHrate) {
   int i = 0;
   while (!in.eof()) {
       int measuredHR, age, wklyCommutingCnt=0, wklyMaxCommuting = 0,exerciseCnt=0, maxCommuting;
       double wklyAvgCommuting = 0,avgCommuting,exercise;
       in >> ids[i]>>measuredHR>>age;
       estimate[i] = 220 - age;
       for (int j = 0; j < 5; j++) {
           in >> avgCommuting >> maxCommuting >> exercise;
           if (avgCommuting != -1) {
               wklyAvgCommuting += avgCommuting;
               wklyCommutingCnt++;
           }
           if (wklyMaxCommuting<maxCommuting) {
               wklyMaxCommuting=maxCommuting;
           }
           if (exercise != 0) {
               exerciseCnt++;
           }
       }
       wAvg[i] = wklyAvgCommuting / wklyCommutingCnt;
       days[i] = exerciseCnt;
       hrate[i] = (double(measuredHR) / estimate[i]) * 100;
       maxHrate[i] = ((double)wklyMaxCommuting / measuredHR) * 100;
       string line;
       getline(in, line);
       i++;
   }
}
//Function to sort array using id
void sort_Data(int* ids, double* wAvg, int* days, int* estimate, double* hrate, double* maxHrate) {
   for (int i = 0; i < MAX; i++)
   {
       for (int j = i + 1; j < MAX; j++)
       {
           if (ids[j] < ids[i])
           {
               int temp = ids[i];
               ids[i] = ids[j];
               ids[j] = temp;
               double tempAvg = wAvg[i];
               wAvg[i] = wAvg[j];
               wAvg[j] = tempAvg;
               int tempDay = days[i];
               days[i] = days[j];
               days[j] = tempDay;
               int tempEstimate = estimate[i];
               estimate[i] = estimate[j];
               estimate[j] = tempEstimate;
               double tempRate = hrate[i];
               hrate[i] = hrate[j];
               hrate[j] = tempRate;
               double tempMax = maxHrate[i];
               maxHrate[i] = maxHrate[j];
               maxHrate[j] = tempMax;
           }
       }
   }
}
//Write header into file
void header(ofstream& out) {
   out << "Person's ID     WeeklyAvgCommuting     DaysExercised     EstimatedMaxHeartRate     PercentageHeartRate     PercentageMaxHeartRate" << endl;
}
//Write data into file
void output(ofstream& out, const int ids[], const double wAvg[], const int days[], const int estimated[], const double hrate[], const double maxHRate[]) {
   for (int i = 0; i < MAX; i++) {
       out << fixed << setprecision(2) << ids[i] << setw(20) << wAvg[i] << setw(20) << days[i] << setw(20)
           << estimated[i] << setw(25) << hrate[i] << setw(26) << maxHRate[i] << endl;
   }
}

---------------------------------------------------------------

Output.txt

Person's ID     WeeklyAvgCommuting     DaysExercised     EstimatedMaxHeartRate     PercentageHeartRate     PercentageMaxHeartRate
1124              112.54                   4                 184                    96.74                     81.46
2438              118.00                   4                 194                   103.09                     82.50
2776              106.28                   2                 175                   101.71                     81.46
3521              113.82                   2                 169                   107.10                     87.85
4545              112.22                   4                 168                   113.10                     68.95
4915              127.70                   0                 193                    95.85                     91.35
6231              137.96                   2                 192                    94.27                     94.48
7345              132.22                   3                 184                   105.98                     86.67
8762              120.58                   3                 192                    96.88                     79.57
9439              126.20                   2                 199                    98.99                     80.71


Related Solutions

__________________________ 1. A researcher is conducting a study on the effects of sleep on creativity. The...
__________________________ 1. A researcher is conducting a study on the effects of sleep on creativity. The creativity scores for three levels of sleep (4 hours of sleep, 8 hours of sleep, and 12 hours of sleep) for n = 5 participants (in each group) are presented below: ***Make sure you also ask SPSS for descriptive statistics of this data. When you are in the one-way ANOVA dialog box where you move variables to Factor and Dependent List, click on options...
The international rice research institute in the Philippines conducted a study of the relationship between and...
The international rice research institute in the Philippines conducted a study of the relationship between and the yield of rice and the amount of nitrogen fertilizer used when growing the rice. A number of small plots of land (all the same size) were used in the study with varying amounts of fertilizer from one plot to the next. When the rice is harvested, the yield (in ounces of rice) was measured and related to the amount (in ounces) of nitrogen...
QUESTION 3 A research firm is conducting a study to determine if there is a relationship...
QUESTION 3 A research firm is conducting a study to determine if there is a relationship between an individual’s age and the individual’s preferred source of news. The research firm asked 1,000 individuals to list their preferred source for news: newspaper, radio and television, or the Internet. The following results were obtained: Individual News Preference Preferred News Source Age of Respondent 20-30 31-40 41-50 Over 50 Newspaper 19 62 95 147 Radio/TV 27 125 168 88 Internet 104 113 37...
Suppose you are conducting a quantitative research study for a major car dealership in the United...
Suppose you are conducting a quantitative research study for a major car dealership in the United States with the objective to rate the importance of typical obstacles in consumers' car purchasing process (such as long wait times, complicated paperwork, aggressive salespeople, or insufficiently trained sales executives). Suppose you came to the conclusion that a random sample is not feasible or cost effective for this study. Which of the following nonprobability sampling designs (convenience sampling, judgment sampling, quota sampling, or snowball...
Research Psychologist A has been conducting a study with human subjects for nearly a year. As...
Research Psychologist A has been conducting a study with human subjects for nearly a year. As a result, A has come to know Participant M quite well. The study is taking longer than expected, and some of the participants are leaving the study. Because of the nature of the working relationship with the participants, Research Psychologist A and Participant M have become interested in an intimate relationship. Since neither one wants to jeopardize the progress of the study, they agree...
You are assigned to work on a research study examining the effects of a new vitamin...
You are assigned to work on a research study examining the effects of a new vitamin D supplement on bone mineral density in post menopausal women. The study duration is 2 months, your sample size is n=100, and you have a large team of researchers. Please justify your answers to the following questions: 1) Which dietary intake assessment method(s) would you use to assess their diet? 2) Which nutritional analysis software would you use? 3) How would you assess the...
consider the following research situation: A group of researchers is interested in study the effects of...
consider the following research situation: A group of researchers is interested in study the effects of caffeine on memory. They plan to use a sample of 25 adults, with the intention of generalizing the findings to the larger population. One of the researchers is concerned, however, because their sample appears to differ from the population in regards to a characteristic that he believes could hinder the generalization of the caffeine and memory study results. This characteristic is cortisol level. A...
what type of research study design should I use if I'm conducting an analysis on level...
what type of research study design should I use if I'm conducting an analysis on level of education completed and if the level of education has an impact on choice of career? I was thinking a cross sectional study but isn't sure. I'm only using those two variables.
Please discuss how you would manage the ethical issues in producing and conducting a research study...
Please discuss how you would manage the ethical issues in producing and conducting a research study (e.g. confidentiality, informed consent, data collection, debriefing of participants).
A psychopharmacologist (a psycholgist interested in the effects of drugs and physiology) is interested in determining...
A psychopharmacologist (a psycholgist interested in the effects of drugs and physiology) is interested in determining the effects of caffeine (from coffee) on performance. Twenty students from a large introductory psychology class volunteered to participate in the study; all were dedicated coffee drinkers and all drank caffeinated coffee. The volunteers were then randomly divided into two groups such that there were ten students in each group. One group of 10 students was asked to study the material while drinking their...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT