Your task is to write a C++ program which computes a set of a target heart rate…

Question:

  1. Your task is to write a C++ program which computes a set of a target heart rate values associated with human exercise research.
    The formulas you will need can be found on the following web page: http://en.wikipedia.org/wiki/Heart rate
  2. Your program should prompt the user for two integers, the subject’s age in years (age) and the subjects resting heart rate in beats per minute (HRrest), then compute and display the integer-valued maximal safe heart rate for this individual using ( HRmax = 205.8 − (0.685 × age) ), the 85% intensity target heart rate (T HR85) based upon the Karvonen method, and the heart rate reserve (HRR).
    NOTE: Your program should conduct a simple validation of the input data (only positive inputs are allowed: the subject must be older than 0 years and have a resting heart rate greater than 0).
  3. To get you started on the program design, we provide a “minimal main(), stubby function/procedure” template for this program as shown at the top of the third page.
    (a) Your job is to complete the implementations (fill in the “stubby bodies”) of the functions.
    (b) You are strongly encouraged to proceed one step at a time in this process, compiling and testing each function implementation before proceeding to the next function.
    GIVEN CODE:
// Compute several exercise-related heart rate targets based upon age and
// resting heart rate.
// Reference: see HRmax, HRR and THR on http://en.wikipedia.org/wiki/Heart_rate
void DisplayIntroduction(void);
int PromptForAge(void);
int PromptForHRrest(void);
int ComputeHRmax(int age);
int ComputeHRR(int age, int HRrest);
int ComputeTHR85(int age, int HRrest);
void DisplayResults(int HRMax, int HRR, int THR85);
int main()
{
int age, HRrest;
int HRmax, HRR, THR85;
DisplayIntroduction();
age = PromptForAge();
HRrest = PromptForHRrest();
HRmax = ComputeHRmax(age);
HRR = ComputeHRR(age, HRrest);
THR85 = ComputeTHR85(age, HRrest);
DisplayResults(HRmax, HRR, THR85);
return 0;
}
// Stubby implementations.
// These need lots of work!
void DisplayIntroduction(void) {return; }
int PromptForAge(void) {return 1;}
int PromptForHRrest(void) {return 1;}
int ComputeHRmax(int age) {return 1;}
int ComputeHRR(int age, int HRrest) {return 1;}
int ComputeTHR85(int age, int HRrest) {return 1;}
void DisplayResults(int HRMax, int HRR, int THR85) {return;}

Answer:

#include<iostream>

using namespace std;

void DisplayIntroduction(void);

int PromptForAge(void);

int PromptForHRrest(void);

int ComputeHRmax(int age);

int ComputeHRR(int age, int HRrest);

int ComputeTHR85(int age, int HRrest);

void DisplayResults(int HRMax, int HRR, int THR85);

int main()

{

int age, HRrest;

int HRmax, HRR, THR85;

DisplayIntroduction();//display introduction of program

  

age = PromptForAge();//get the age

HRrest = PromptForHRrest();//get the heart rate at rest

HRmax = ComputeHRmax(age);//compute the maximum heart rate

HRR = ComputeHRR(age, HRrest);//compute heart rate reserve

THR85 = ComputeTHR85(age, HRrest);//compute the target heart rate

  

DisplayResults(HRmax, HRR, THR85);//display the results

cin.get();//to hold the console screen

return 0;

}

// Stubby implementations.

// These need lots of work!

void DisplayIntroduction(void) {

//display an introductory message

cout<<"Hola User! This program tends to find out the Heart Rate statistics using the data you enter."<<endl;

cout<<"=============================================================================================."<<endl<<endl;

}

int PromptForAge(void)

{

int age;//variable to hold the age value

cout<<"Enter you age."<<endl;//display message to enter age

cin>>age;//read age into the age variable

//invalid condition

while(age<=0)//taker input until the user enters a valid age

{

cout<<"\n\nYou entered an invalid age.Please enter it again!"<<endl;

cout<<"Enter you age."<<endl;//display message to enter age

cin>>age;//read age into the age variable

}

return age;//return age

}

int PromptForHRrest(void)

{

//message to enter the HR Rest

int hr;

cout<<"Enter your heart rate at rest."<<endl;

cin>>hr;//input the hrrate

while(hr<=0)//take input until the user inputs a valid value of heart rate at rest

{

cout<<"\n\nYou entered an invalid value."<<endl;

cout<<"Enter your heart rate at rest."<<endl;

cin>>hr;//input the hrrate

}

return hr;//return the heart rate at rest

}

int ComputeHRmax(int age)

{

int HRmax = 205.8 - (0.685*age);//compute hrmax

return HRmax;//return the value of HRmax

}

int ComputeHRR(int age, int HRrest)

{

//heart rate reserve = HRmax - HRrest

int HRmax=ComputeHRmax(age);//get the maximum heart rate

int HRR=HRmax-HRrest;//compute heart rate reserve

return HRR;//return heart rate reserve

}

int ComputeTHR85(int age, int HRrest)

{

//THR85 = ((HRmax - HRrest) × 85% intensity) + HRrest

int HRmax=ComputeHRmax(age);//get the maximum heart rate

int THR85=((HRmax-HRrest)*(0.85))+HRrest;//compute the target heart rate

return THR85;//retunr the target heart rate

}

void DisplayResults(int HRMax, int HRR, int THR85)

{

cout<<"The results are:"<<endl<<"Maximum Heart Rate : "<<HRMax<<endl<<"Heart Rate Reserve : "<<HRR

<<endl<<"Target Heart Rate at 85% intensity : "<<THR85<<endl<<endl;

}

SCREENSHOTS:

OUTPUT:

INVALID CONDITION HANDLING:

Leave a Comment

Your email address will not be published. Required fields are marked *