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...

  • 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...

  • 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...

  • Introduction to Data Structures programming assignments can be completed either in C++ (preferred) or in Java....

    Introduction to Data Structures programming assignments can be completed either in C++ (preferred) or in Java. In both cases you cannot use libraries or packages that contain pre-built data structures, other than built-in support for objects, arrays, references, and pointers. Classes in C++ and Java can represent anything in the real world. This assignment is to write a class to represent a Date in a Calendar. Date Class Member Variables The following table identifies and describes the purpose of each...

  • 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 in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person...

    Write in C++ 1. Use the following Person class (Person.cpp, Person.h). You will be writing Person objects to a random access file. --------------------- Person.cpp--------------------------------- // Class Person stores customer's credit information. #include <string> #include "Person.h" using namespace std; // default Person constructor Person::Person( int idValue, string lastNameValue, string firstNameValue, int AgeValue ) { setID( idValue ); setLastName( lastNameValue ); setFirstName( firstNameValue ); setAge( AgeValue ); } // end Person constructor // get id value int Person::getID() const { return id;...

  • 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...

  • Lab 1: InheritanceTest Write a program called InheritanceTest1.java to support an inheritance hierarchy for class Point–Square–Cube....

    Lab 1: InheritanceTest Write a program called InheritanceTest1.java to support an inheritance hierarchy for class Point–Square–Cube. Use Point as the superclass of the hierarchy. Specify the instance variables and methods for each class. The private data of Point should be the x-y coordinates, the private data of Square should be the sideLength, and the private data of Cube should be depth. Provide applicable accessor methods, mutator methods, toString() methods, area() method, and volume() method to all classes. Write a program...

  • (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...

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