Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HeartRates.h (class specification file) HeartRates.cpp (class implementation fil

ID: 3756561 • Letter: H

Question

HeartRates.h

(class specification file)

HeartRates.cpp

(class implementation file)

application.cpp

(application program)

Your solution should use all three files listed above.

=====================================================

For your fourth programming assignment you will be writing the following C++ program:
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–85% of your maximum heart rate. Create a class called HeartRates. The class attributes should include the person’s first name, last name and date of birth (consisting of separate attributes for the month of birth, day of birth, and year of birth). Your class should have a constructor that receives this data as parameters. For each attribute provide set and get functions.

The class also should include a function getAge that calculates and returns the person’s age (in years), a function getMaxiumumHeartRate that calculates and returns the person’s maximum heart rate and a function getTargetHeartRate that calculates and returns the person’s target heart rate. Function getAgeshould prompt the user to enter the current month, day and year before calculating the person’s age. Write an application program that prompts for the person’s information, creates an object of classHeartRatesand prints the information from that object—including the person’s first name, last name and date of birth—then calculates and prints the person’s age in (years), maximum heart rate and target-heart-rate range.

Sample run 2: Please enter first and last name (separated by spaces): Han Solo Please enter month, day, and year of birth (separated by spaces): 4 1 1980 First Name: Han Last Name: Solo Date of Birth: 4/1/1980 Please enter today's month, day, and year: 9 6 2017 Age: 37 Maximum Heart Rate: 183 Target Heart Rate: 91-155 Sample run 3: Please enter first and last name (separated by spaces): James Bond Please enter month, day, and year of birth (separated by spaces): 7 7 1977 First Name: James Last Name: Bond Date of Birth: 7/7/1977 Please enter today's month, day, and year: 9 6 2017 Age: 39 Maximum Heart Rate: 181 Target Heart Rate: 90-153

Explanation / Answer

Here are the three code files of the given problem. In case of any query do write me in the comments:

HeartRates.h
===============================================================================

#include <string>

using namespace std;

class HeartRates{

private:

string firstName;

string lastName;

string birthDate;

public:

HeartRates(const string &name, const string &dateofbirth);

void SplitName(string &fName, string &lName, string fullName);

string formatDOB(string inDOB);

int getAge();

string getFirstName();

string getLastName();

string getDateofBirth();

int getMaximumHeartRate(int age);

string getTargetHeartRate(int maxHrtRate);

};

==============================================================================

HeartRates.cpp

#include "HeartRates.h"

#include <iostream>

#include <sstream>

#include <string>

using namespace std;

HeartRates::HeartRates(const string &name, const string &dateofbirth){

SplitName(this->firstName, this->lastName, name);

this->birthDate = formatDOB(dateofbirth);

}

void HeartRates::SplitName(string &fName, string &lName, string fullName){

int i;

for(i=0; i<fullName.length(); i++){

if(fullName[i] == ' '){

break;

}

}

fName = fullName.substr(0,i);

lName = fullName.substr(i+1);

}

string HeartRates::formatDOB(string inDOB){

for(int i=0; i<inDOB.length(); i++){

if(inDOB[i] == ' '){

inDOB[i] = '/';

}

}

return inDOB;

}

string HeartRates::getFirstName(){

return firstName;

}

string HeartRates::getLastName(){

return lastName;

}

string HeartRates::getDateofBirth(){

return birthDate;

}

int HeartRates::getAge(){

int i,space,bYear,currYear,count=0;

string currDate;

string bDate=this->birthDate;

cout<<" Please enter today's month, day and year: ";

getline(cin, currDate);

for(i=0 ; i<currDate.length(); i++ ){

if(currDate[i] == ' '){

count++;

}

if(count==2){

break;

}

}

stringstream a(currDate.substr(i+1)); //This function first cuts out the year part from currDate string and then converts it into an int value

count=0;

a>>currYear;

for(i=0 ; i<bDate.length(); i++ ){

if(bDate[i] == '/'){

count++;

}

if(count==2){

break;

}

}

stringstream b(bDate.substr(i+1));

b>>bYear;

return currYear-bYear;

}

int HeartRates::getMaximumHeartRate(int age){

return 220-age;

}

string HeartRates::getTargetHeartRate(int maxHrtRate){

int lower = (maxHrtRate)*0.5;

int upper = (maxHrtRate)*0.85;

stringstream ss;

ss<<lower;

string s_lower = ss.str();

stringstream ssU;

ssU<<upper;

string s_upper = ssU.str();

return s_lower +" - "+ s_upper;

}

========================================================================

application.cpp

#include "HeartRates.cpp"

#include <string>

using namespace std;

int main(){

int age,mxHrtRate;

string name, birth_date, targetHR;

cout<<" Please enter first and last name (separated by spaces):"<<endl;

getline(cin, name);

cout<<" Please enter month, date and year of birth (separated by spaces):"<<endl;

getline(cin, birth_date);

HeartRates hr(name, birth_date);

cout<<" First Name: "<<hr.getFirstName();

cout<<" Last Name: "<<hr.getLastName();

cout<<" Date of Birth: "<<hr.getDateofBirth();

age = hr.getAge();

mxHrtRate=hr.getMaximumHeartRate(age);

targetHR=hr.getTargetHeartRate(mxHrtRate);

cout<<" Age: "<<age;

cout<<" Maximum Heart Rate: "<<mxHrtRate;

cout<<" Target Heart Rate: "<<targetHR;

return 0;

}

============================================================================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote