Target Heart Rate Calculator
Posted by khan1488
Last Updated: November 17, 2012
Question :

While exercising, you can use a heart rate monitor to see that your heart rate stays within a safe range suggested by your trainer or doctor.  According to the American Heart Association(AHA) the formula for calculating your maximum heart rate in beats per minute is 220 minus your age in years.  Your target heart rate is a range that is 50 – 80% of your maximum heart rate, for this program we will use a target of 65%.  Create a Class called HeartRates.  The class data members should include  the person’s firstname, Lastname, and date of birth(consisting of separate data members for day, month and year).  Provide a function Getdata to allow the user to enter the  persons, firstname, lastname, date of birth( in day, month and year).  Your class should also include a member functions:  getAge that calculates and returns the person’s age (in years); function getMaximumHeartRate that calculates and return the person’s maximum heart rate;  function getTargetHeartRate that calculates and returns the person target heart rate. Since you do not know how to obtain the current date from the computer , function getAge should ask the user for the current year before calculating the person’s age.

Write an application that prompts the user for the relevant information, instantiates an object of the class HeartRates and Print the information from the object including the person’s firstname, Lastname, date of birth, Age in years, maximum heart rate and target heart rate.


Solution:

#include <iostream>
#include <string>

using namespace std;

class Heartrates{
    private:
    string firstname;
    string lastname;
    int birth_day;
    int birth_month;
    int birth_year;
    int current_day;
    int current_month;
    int current_year;
    int age;
    double Maxheartrate;
    double targetRate;



    public:
   void Getdata()
   {
        cout<<"Please Enter your firstname\n";
        getline (cin, firstname);
        cout<<"\n\n";
        cout<<"Please Enter your lastname\n";
        getline (cin, lastname);
        cout<<"\n\n";
        cout<<"Please Enter your date of birth\n";
        cout<<"year:";
        cin >> birth_year;
        cout<<"month:";
        cin>> birth_month;
        cout<<"day:";
        cin >> birth_day;

    cout<<"Data for:"<<firstname<< "  "<<lastname<<endl;
        cout<< "Your date of birth in the format dd/mm/yyyy is:"<<birth_day<<"/"<<birth_month<<"/"<<birth_year<<endl;
        cout<<"\n\n";
    }
   void getAge ()
    {
        cout<<"Enter the current date dd/mm/yyyy \n";
        cout<<"Day: ";
        cin>>current_day;
        cout<<"month:";
        cin>>current_month;
        cout<<"year:";
        cin>> current_year;

         if (current_month >= birth_month and current_day >= birth_day)
    {
        age= current_year- birth_year;
    }
        else
    {
        age= (current_year- birth_year)-1;
    }
        cout<<"Your are currently "<< age<<"  "<<"years old"<<endl;
    }


   void getMaximumHeartRate()
   {
       Maxheartrate= 220-age;
       cout<<"Your Maximum heartrate is:"<<Maxheartrate<<endl;
   }
   void getTargetHeartRate()
   {
        targetRate=  Maxheartrate*0.65;
        cout<< "Your target heartrate is"<<targetRate<<endl;
    }
};







int main()
{
    Heartrates Juanito;

    system ( "color 7c");

    cout<<"Welcome to Heart Rate Systems\n\n\n";
    Juanito.Getdata();

    Juanito.getAge();
    cin.ignore();
    cin.get();
    system ("cls");
    system ("color 0c");
    Juanito.getMaximumHeartRate();

    Juanito.getTargetHeartRate();

    cout<<"\n\n";
    cout<<" Thank You For Choosing Nightfire Inc.'s Heartrate monitor"<<endl;
    cout<<" Please check out other devices we offer"<<endl;


    return 0;
}

Related Content
Simple Calculator using C#
Simple Calculator using C#
Samath | Dec 30, 2020
Calculator Program in Java
Calculator Program in Java
Samath | Jan 07, 2021
Simple C++ Calculator
Simple C++ Calculator
Samath | Jan 05, 2017
Simple Calculator using Python
Simple Calculator using Python
Samath | Jan 09, 2017
GPA Calculator using C#
GPA Calculator using C#
Samath | Jan 01, 2021
Simple GPA calculator in Java
Simple GPA calculator in Java
Samath | Jan 17, 2024
GPA Calculator in C++
GPA Calculator in C++
Samath | Jan 17, 2024
GPA Calculator using Python
GPA Calculator using Python
Samath | Jan 20, 2024
Scientific Calculator using C#
Scientific Calculator using C#
Samath | Jan 08, 2021