jaredec18

Untitled

Sep 29th, 2019
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. copy to code:
  2.  
  3. HeartRate.h
  4.  
  5. #include <string>
  6.  
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. #ifndef HEARTRATE_H_
  12.  
  13. #define HEARTRATE_H_
  14.  
  15. class HeartRates{
  16.  
  17. private:
  18.  
  19. string firstName,lastName;
  20.  
  21. int month,day,year;
  22.  
  23. public:
  24.  
  25. HeartRates(string firstname, string lastname,int monthIn,int dayIn,int yearIn);
  26.  
  27. string getFirstName() const;
  28.  
  29. void setFirstName(string firstName);
  30.  
  31. int getMonth() const;
  32.  
  33. void setMonth(int month);
  34.  
  35. string getLastName()const;
  36.  
  37. void setLastName(string lastName);
  38.  
  39. int getDay() const;
  40.  
  41. void setDay(int day);
  42.  
  43. int getYear() const;
  44.  
  45. int getAge(int currDay, int currMonth,int currYear) const;
  46.  
  47. void setYear(int year);
  48.  
  49. void printDetails();
  50.  
  51. string getTargetHeartRate(int age) const;
  52.  
  53. int getMaximumHeartRate(int age)const;
  54.  
  55. };
  56.  
  57. #endif /* HEARTRATE_H_ */
  58.  
  59. HeartRates.cpp
  60.  
  61. #include "HeartRate.h"
  62.  
  63. HeartRates::HeartRates(string firstnameIn, string lastnameIn,int monthIn,int dayIn,int yearIn){
  64.  
  65. firstName = firstnameIn;
  66.  
  67. lastName = lastnameIn;
  68.  
  69. month = monthIn;
  70.  
  71. day = dayIn;
  72.  
  73. year = yearIn;
  74.  
  75. }
  76.  
  77. void HeartRates::printDetails(){
  78.  
  79. cout<<"First name :"<<firstName<<endl;
  80.  
  81. cout<<"Last name :"<<lastName<<endl;
  82.  
  83. cout<<"Date of birth : "<<month<<"/"<<day<<"/"<<year<<endl;
  84.  
  85. }
  86.  
  87. string HeartRates::getFirstName() const
  88.  
  89. {
  90.  
  91. return firstName;
  92.  
  93. }
  94.  
  95. void HeartRates::setFirstName(string firstName)
  96.  
  97. {
  98.  
  99. this->firstName = firstName;
  100.  
  101. }
  102.  
  103. string HeartRates::getLastName() const
  104.  
  105. {
  106.  
  107. return lastName;
  108.  
  109. }
  110.  
  111. void HeartRates::setLastName(string lastName)
  112.  
  113. {
  114.  
  115. this->lastName = lastName;
  116.  
  117. }
  118.  
  119. int HeartRates::getMonth() const
  120.  
  121. {
  122.  
  123. return month;
  124.  
  125. }
  126.  
  127. void HeartRates::setMonth(int month)
  128.  
  129. {
  130.  
  131. this->month = month;
  132.  
  133. }
  134.  
  135. int HeartRates::getDay() const
  136.  
  137. {
  138.  
  139. return day;
  140.  
  141. }
  142.  
  143. int HeartRates::getMaximumHeartRate(int age) const
  144.  
  145. {
  146.  
  147. return 220-age;
  148.  
  149. }
  150.  
  151. string HeartRates::getTargetHeartRate(int age) const
  152.  
  153. {
  154.  
  155. string result="";
  156.  
  157. int minRate = age*50/100;
  158.  
  159. int maxRate = age*85/100;
  160.  
  161. result= to_string(minRate)+" - "+to_string(maxRate);
  162.  
  163. return result;
  164.  
  165. }
  166.  
  167. void HeartRates::setDay(int day)
  168.  
  169. {
  170.  
  171. this->day = day;
  172.  
  173. }
  174.  
  175. int HeartRates::getYear() const
  176.  
  177. {
  178.  
  179. return year;
  180.  
  181. }
  182.  
  183. void HeartRates::setYear(int year)
  184.  
  185. {
  186.  
  187. this->year = year;
  188.  
  189. }
  190.  
  191. int HeartRates::getAge(int currDay, int currMonth,int currYear) const
  192.  
  193. {
  194.  
  195. int yearDiff = currYear - year;
  196.  
  197. int monthDiff = currMonth - month;
  198.  
  199. int dayDiff = currDay - day;
  200.  
  201. int totalDayDiff = dayDiff + monthDiff*30 + yearDiff *365;
  202.  
  203. int yearTotalDiff = totalDayDiff/365;
  204.  
  205. return yearTotalDiff;
  206.  
  207. }
  208.  
  209. main.cpp
  210.  
  211. #include "HeartRate.h"
  212.  
  213. using namespace std;
  214.  
  215. int main()
  216.  
  217. {
  218.  
  219. //for user input
  220.  
  221. string firstName,lastName;
  222.  
  223. int month,day,year;
  224.  
  225. cout<<"Please enter first name and last name(separated by spaces) : ";
  226.  
  227. cin>>firstName>>lastName;
  228.  
  229. cout<<"Please enter month day and year of birth(separated by spaces) : ";
  230.  
  231. cin>>month>>day>>year;
  232.  
  233. HeartRates heart(firstName,lastName,month,day,year);
  234.  
  235. //print person details
  236.  
  237. heart.printDetails();
  238.  
  239. cout<<"Please enter today's month day and year of birth(separated by spaces) : ";
  240.  
  241. cin>>month>>day>>year;
  242.  
  243. //get age
  244.  
  245. int personAge = heart.getAge(month,day,year);
  246.  
  247. //get max heart rate
  248.  
  249. int maxHeartRate = heart.getMaximumHeartRate(personAge);
  250.  
  251. //get target rate as string
  252.  
  253. string targetheartRate = heart.getTargetHeartRate(maxHeartRate);
  254.  
  255. cout<<"Age : "<<personAge<<endl;
  256.  
  257. cout<<"Maximum Heart Rate : "<<maxHeartRate<<endl;
  258.  
  259. cout<<"Target Heart Rate : "<<targetheartRate;
  260.  
  261. return 0;
  262.  
  263. }
  264.  
  265. https://d2vlcm61l7u1fs.cloudfront.net/media%2F702%2F702dc073-4195-46ff-9f6f-1866fab53ba0%2FphptUrmwp.png
Advertisement
Add Comment
Please, Sign In to add comment