(Target-Heart-Rate Calculator) While exercising, you can use a heart-rate monito
ID: 3674782 • Letter: #
Question
(Target-Heart-Rate Calculator) While exercising, you can use a heart-rate monitor to seethat your heart rate stays within a safe range suggested by your trainers and doctors. According to theAmerican Heart Association (AHA),the formula for calculating your maximum heart rate in beats per minute is 220 minus your age inyears. Your target heart rate is a range that is 50–85% of your maximum heart rate. [Note: These formulasare estimates provided by the AHA. Maximum and target heart rates may vary based on the health,fitness and gender of the individual. Always consult a physician or qualified health care professional beforebeginning or modifying an exercise program.] Create a class called HeartRates. The class attributesshould include the person’s first name, last name and date of birth (consisting of separate attributesfor the month, day and year of birth). Your class should have a constructor that receives this data asparameters. For each attribute provide set and get functions. The class also should include a functiongetAge that calculates and returns the person’s age (in years), a function getMaxiumumHeartRate thatcalculates and returns the person’s maximum heart rate and a function getTargetHeartRate that calculatesand returns the person’s target heart rate. Since you do not yet know how to obtain the currentdate from the computer, function getAge should prompt the user to enter the current month, dayand year before calculating the person’s age. Write an application that prompts for the person’s information,instantiates an object of class HeartRates and prints the information from that objectincluding the person’s first name, last name and date of birththen calculates and prints the person’sage in (years), maximum heart rate and target-heart-rate range
Explanation / Answer
Please find the required program below :
// Example program
#include <iostream>
#include <string.h>
using namespace std;
class HeartRates {
private :
string fname;
string lname;
int day;
int month;
int year;
public :
HeartRates(string fname1, string lname1, int day1, int month1, int year1) {
fname = fname1;
lname = lname1;
day = day1;
month = month1;
year = year1;
}
string getfname() { return fname;}
string getlname() { return lname;}
int getday() { return day;}
int getmonth() { return month;}
int getyear() { return year;}
void setfname(string f) { fname = f;}
void setlname(string l) { lname = l;}
void setday(int d) { day = d;}
void setmonth(int m) { month = m;}
void setyear(int y) { year = y;}
int getAge (){
int cd,cm,cy, dm=0;
cout << "Enter current day, month, and year " << endl;
cin >> cd;
cin >> cm;
cin >> cy;
if(cm-month>5)
dm = 1;
return (cy-year + dm);
}
int getMaxiumumHeartRate(){
int max = 220 - getAge();
return max;
}
string getTargetHeartRate() {
int maxRate = getMaxiumumHeartRate();
double min = maxRate * 0.5;
double max = maxRate * 0.85;
string target = to_string(max) + " - " + to_string(min);
return target;
}
};
int main()
{
HeartRates hr("rishi","pp",11,7,1990);
cout << hr.getTargetHeartRate() << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.