Question

C++

Your solution will consist of the following four files: HeartRates.h (class specification file) HeartRates.cpp (class impleme

For your fourth programming assignment you will be writing the following C++ program: The formula for calculating your maximu

Please enter first and last name (separated by spaces): Optimus Prime Please enter month, day, and year of birth (separated b

Sample run 2: Please enter first and last name (separated by spaces): Han Solo Please enter month, day, and year of birth (se

0 0
Add a comment Improve this question Transcribed image text
Answer #1


/*C++ program that prompts user to enter the first and last names
then day, month and year values and then display the name ,date of birth
and then prompt current date and then find age and the find
maximum heart rate and target heart rate range*/
//200_assign4.cpp
#include<iostream>
#include<string>
//include header file , HeartRates.h
#include"HeartRates.h"
using namespace std;
//start of main function
int main()
{
   string fname;
   string lname;
   int month;
   int day;
   int year;

   cout<<"Please enter first and last name (separatead by spaces):\n";
   //read first name and last name
   cin>>fname>>lname;
   cout<<"Please enter today's month, day, and year:"<<endl;
   //read month ,day and year
   cin>>month>>day>>year;
   //create class object, HeartRates
   HeartRates hrate(fname,lname,day,month,year);

   cout<<"First Name: "<<hrate.getFirstName()<<endl;
   cout<<"Last Name: "<<hrate.getFirstName()<<endl;
   cout<<"Date of Birth: "<<hrate.getmonth()<<"/"
                                           <<hrate.getday()<<"/"
                                           <<hrate.getyear()<<endl;


   int age=hrate.getAge();

   cout<<"Age : "<<age<<endl;
   cout<<"Maximum Heart Rate : "<<hrate.getMaximumHeartRate(age)<<endl;
   hrate.getTargetHeartRate(age);

   system("pause");
   return 0;
}

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

//HeartRates.h
#ifndef HEART_RATE_H
#define HEART_RATE_H
#include<iostream>
#include<string>
using namespace std;
class HeartRates
{
private:
   string fname;
   string lname;
   int month;
   int day;
   int year;

public:
   HeartRates(string, string, int ,int , int);

   void setFirstName(string);
   string getFirstName();

   void setLastName(string);
   string getLastName();

   void setday(int);
   int getday();

   void setmonth(int);
   int getmonth();


   void setyear(int);
   int getyear();

   int getAge();
   int getMaximumHeartRate(int);
   void getTargetHeartRate(int);

};
#endif HEART_RATE_H

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

//HeartRates.cpp
#include<iostream>
#include "HeartRates.h"
using namespace std;
HeartRates::HeartRates(string fname,
   string lname, int d,int m, int y)
{
   this->fname=fname;
   this->lname=lname;
   this->day=d;
   this->month=m;
   this->year=y;
}

void HeartRates::setFirstName(string fname)
{
   this->fname=fname;
}
string HeartRates::getFirstName()
{
   return fname;
}
void HeartRates::setLastName(string)
{
       this->lname=lname;
}
string HeartRates::getLastName()
{
   return lname;
}
void HeartRates::setday(int d)
{
   this->day=d;
}
  
int HeartRates::getday()
{
   return day;
}

void HeartRates::setmonth(int m)
{
   this->month=m;
}
int HeartRates::getmonth()
{
   return month;
}

void HeartRates::setyear(int y)
{
       this->year=y;
}
int HeartRates::getyear()
{
   return year;
}

int HeartRates::getAge()
{
   int cur_day;
   int cur_month;
   int cur_year;
   int age=0;
   cout<<"Please enter today's month, day, and year:"<<endl;
   cin>>cur_day>>cur_month>>cur_year;
   //calculate age
   if(day==cur_day && month==cur_month)
       age=cur_year-year;
   else
       age=(cur_year-year)-1;
   return age;
}
int HeartRates::getMaximumHeartRate(int age)
{
   int maxHeartRate = 220 - age;
return maxHeartRate;
}
void HeartRates::getTargetHeartRate(int age)
{
   int targetHeartRateMin = (0.5) * getMaximumHeartRate(age);
int targetHeartRateMax = (0.85) * getMaximumHeartRate(age);
cout<<"Target Heart Rate : "<<targetHeartRateMin
       <<"-"<<targetHeartRateMax<<endl;
}

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

Sample Output:

Please enter first and last name (separatead by spaces): Optimus Prime Please enter todays month, day, and year: 12 11 1946

Add a comment
Know the answer?
Add Answer to:
C++ Your solution will consist of the following four files: HeartRates.h (class specification file) HeartRates.cpp (class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and...

    Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and please add comments for the whole code. Include a class diagrams, and explain the approach you used for the project and how you implemented that, briefly in a few sentences. Please note the following: -Names chosen for classes, functions, and variables should effectively convey the purpose and meaning of the named entity. - Code duplication should be avoided by factoring out common code into...

  • HW_8b - Famous People - One class used by another class - This exercise requires the...

    HW_8b - Famous People - One class used by another class - This exercise requires the declaration of two classes: o Famous People O Date - 5 Files are required: o Date.h o Date.cpp o Famous People.h o Famous People.cpp o main.cpp File: Date.h Private data members: O _month o _day 0 year - Public member functions: o Default constructor • Assign O's to all three data members. o Overloaded constructor • Three integer values are passed as arguments from...

  • COSC 600 Programming Assignment 1 Due D ate : September 1 3 ( Tuesday ) by...

    COSC 600 Programming Assignment 1 Due D ate : September 1 3 ( Tuesday ) by 7 pm NOTE: Please submit a soft copy to the blackboard c ontaining your source codes and hand in the hard copies of source codes with your outputs together in class . We will run your p rogram for grading your program assignments. Problem 1 . Introduce Yourself W rite a Java program that interactively request s the following information: • Your first name...

  • Use C++ to create a class called Student, which represents the students of a university. A...

    Use C++ to create a class called Student, which represents the students of a university. A student is defined with the following attributes: id number (int), first name (string), last name (string), date of birth (string), address (string). and telephone (area code (int) and 7-digit telephone number(string). The member functions of the class Student must perform the following operations: Return the id numb Return the first name of the student Modify the first name of the student. . Return the...

  • Write a C program which creates a template for a structure to store somebody's date of...

    Write a C program which creates a template for a structure to store somebody's date of birth (day, month, and year). Then write a C function that takes two such structure, one which represents the date of birth, and the other today's date, and returns the age of the user in years. Your function can either provide the full year only (integer) or the floating point age (bonus marks). Next, write a C program which asks the user to enter...

  • I need to create a Java class file and a client file that does the following:  Ask user to enter Today’s date in the fo...

    I need to create a Java class file and a client file that does the following:  Ask user to enter Today’s date in the form (month day year): 2 28 2018  Ask user to enter Birthday in the form (month day year): 11 30 1990  Output the following: The date they were born in the form (year/month/day). The day of the week they were born (Sunday – Saturday). The number of days between their birthday and today’s...

  • (JAVA) Using classes and inheritance, design an online address book to keep track of the names

    (JAVA)Using classes and inheritance, design an online address book to keep track of the names, addresses, phone numbers and birthdays of family members, friends and business associates. Your program should be able to handle a maximum of 500 entries.Define the following classes: Class Address to store a street name, city, state and zip code. Class Date to store the day, month and year. Class Person to store a person's last name and first name. Class ExtPerson that extends the class...

  • Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date....

    Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date. You will make some modific ation to the Date class so that it mccts the folowing specific ations: The Date class consists of three private member variables: Member Variable year month day Description An int variable that hokls the value of a year. An int variable that hokds the value of a month An int variable that hokis the value of a day. The...

  •    Lab/HW 3   Write a program that reads in the following data, all entered on one...

       Lab/HW 3   Write a program that reads in the following data, all entered on one line with at least one space separating them: a) an integer representing a month b) an integer representing the day of the month c) an integer representing a year 1. Check that the month is between 1 and 12. If it’s not print an error message. 2. Day cannot be 0 or less nor can it be more than 31 for all months. Print...

  • Amend the Date.java file on p. 77 (also available on the lab drive) so that the...

    Amend the Date.java file on p. 77 (also available on the lab drive) so that the Date class: a. Has a month field that is a String instead of an int. b. Has a third constructor that will take in a String parameter (only.) This constructor will parse the String into the month, day, and year fields. The String is provided in the following format: “Month Day, Year”. If the tokenizing and/or parsing generates an exception, the date defaults to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT