get and set

iam so lost with the get and set functions . please someone help!

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
 #include<iostream>
#include<iomanip>
using namespace std; 

class HealthProfile
{
 public:
void SetName();
void setAge();
void setWeight();
void setHeight();
double getName();
double getAge();
double getWeight();
double getHeight();
double getBMI();
double getCategory();
double getMaxHR();
void printProfile();


	




 private:
double age; 
	double weight ;
	double feet;
	double inches;
	double height;
	double bmi;
	double MaxHR;
    
};
  
int main() { 
	
	
	
	 string name;
	double age; 
	double weight ;
	double feet;
	double inches;
	double height;
	double bmi;
	double MaxHR;
	
    cout<<"what is the name of the patient?\n";
    cin>>name;
    cout<<"what is the age of the patient?\n";
    cin>>age;
	cout<<"What is the weight of the patient?\n";
	cin>>weight;
	cout<<"what is the height in feet of the patient?\n";
	cin>>feet;
	cout<<"what is the height in inches of the patient?\n";
	cin>>inches;
 

height = feet * 12 + inches;
bmi= (weight*703) / (height * height);
MaxHR = 220 - age;
cout<<"Your BMI is "<< setprecision(4)<<bmi<<endl;
cout<<"Your Maximum heart rate is " <<MaxHR<<endl;


/*Category BMI Range
Underweight less than 18.5
Normal 18.5 to less than 25
Overweight 25 to less than 30
Obese 30 or more

*/
if(bmi<18.5)
cout<<"You are underweight, please see a nutritionist for more info\n";
else if(bmi=18.5 && bmi<24.9)
cout<<"You are normal weight, good job!\n";
else if(bmi= 25 && bmi<29.9)
cout<<"Your are overweight, please see a nutritionist for more info\n";
else if(bmi>=30)
cout<<"You are obese, please see a nutritionist for more info\n";

} 

void HealthProfile::SetName (string name)
{
 	
	string name;
}	

void HealthProfile :: setAge( double Age)
{
	double age;
	
}
void HealthProfile ::setWeight(double weight)
{
		double weight;
}	
void HealthProfile ::setHeight(double height)
{
	double height;
}
double HealthProfile ::getName()
{
	return Name;
}	
double HealthProfile ::getWeight()
{
	return weight;
}
double HealthProfile ::getHeight()
{
	return height;
}
double HealthProfile ::getBMI()
{
	return bmi;
}
double HealthProfile :: getCategory()
{
	return Category;
}

double HealthProfile getMaxHR();
{
	return MaxHR;
}
void HealthProfile printProfile();
{
	return printProfile;
}
first of all, as their names imply,

Getters are public methods used to retrieve some value from the class: either a property or a calculated value. These functions are 'const' and do not alter the property of an instance.

Setters are public methods used to directly set(may validate) the value of an instance property. They usually accept only one argument whose type matches the that of the property to be set. Return types are not needed(ie: void).

eg:
1
2
3
4
5
6
7
8
9
10
11
12
13
class Apple{
  string color;
  float mass;

public:
  // setters
  void setColor(string c);
  void setMass(float m);
  
  // getters
  string getColor() const;
  float getMass() const;
}
Topic archived. No new replies allowed.