-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeartRates.cpp
More file actions
103 lines (83 loc) · 2.88 KB
/
HeartRates.cpp
File metadata and controls
103 lines (83 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Implementation of the class HeartRates
#include<string>
#include<iostream>
#include "HeartRates.h"
#include "Date.h"
using namespace std;
HeartRates::HeartRates(string givenFirstName, string givenLastName, Date givenDateOfBirth){
// TODO: Figure out why we need default consructor for Date class for this
setFirstName(givenFirstName);
setLastName(givenLastName);
dateOfBirth = givenDateOfBirth;
}
HeartRates::HeartRates(){
setFirstName("");
setLastName("");
}
// get function for firstName
string HeartRates::getFirstName(){
return firstName;
}
// set function for firstName
void HeartRates::setFirstName(string givenFirstName){
firstName = givenFirstName;
}
// get function for lastName
string HeartRates::getLastName(){
return lastName;
}
// set function for lastName
void HeartRates::setLastName(string givenLastName){
lastName = givenLastName;
}
// get function for dateOfBirth
Date HeartRates::getDateOfBirth(){
return dateOfBirth;
}
// set function for dateOfBirth
void HeartRates::setDateOfBirth(Date givenDateOfBirth){
dateOfBirth = givenDateOfBirth;
}
/* function to return age in years - NOT HANDLING LEAP YEARS -
DAYS/MONTH APPROXIMATED TO 30 DAYS*/
int HeartRates::getAge(){
int currentDay, currentMonth, currentYear;
cout << "Enter current day: " << endl;
cin >> currentDay;
cout << "Enter current month: " << endl;
cin >> currentMonth;
cout << "Enter current year: " << endl;
cin >> currentYear;
/* If number of days passed in currentYear is >= number of days
passed in the birthYear, birthday has passed/is today. Otherwise,
age will be 1 year less than the difference of years.*/
//TODO: Implement leap year check and month->day mapping
// compute days in birth year
Date dateOfBirth = getDateOfBirth();
int birthYearDays = dateOfBirth.getMonth() * 30 + dateOfBirth.getDay();
// compute days in current year
int currentYearDays = currentMonth*30 + currentDay;
// if birthday hasn't passed yet
if (currentYearDays < birthYearDays){
// age is 1 year less
return currentYear - dateOfBirth.getYear() -1;
}else {
// otherwise, age is simply the difference of years
return currentYear - dateOfBirth.getYear();
}
}
// function to get maximum heart rate in Beats per Minute
int HeartRates::getMaximumHeartRate(){
return 220 - getAge();
}
// function to get target heart rate in Beats per Minute
TargetHeartRateRange HeartRates::getTargetHeartRate(){
TargetHeartRateRange calculatedRange;
int maximumHeartRate = getMaximumHeartRate();
//TODO: FIX THIS TO ADD FLOATING POINTS IN THE STRUCT
// minimum target range is 50% of maximum
calculatedRange.minTargetHeartRate = 0.5*maximumHeartRate;
// maximum target rate is 85% of maximum
calculatedRange.maxTargetHeartRate = 0.85*maximumHeartRate;
return calculatedRange;
}