-
Notifications
You must be signed in to change notification settings - Fork 0
/
OOPS.cpp
54 lines (37 loc) · 864 Bytes
/
OOPS.cpp
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
#include<iostream>
using namespace std;
class Hero{
//properties
int health; // by default - Private
public:
char level;
int gethealth(){
return health;
}
int getlevel(){
return level;
}
void sethealth(int h){
health = h;
}
void setlevel(char ch){
level = ch;
}
};
int main(){
Hero royce;
// cout<<"Before - any garbage value "<<endl;
// cout<<"After put in the values"<<endl;
// cout<<"Health is "<< royce.health<<endl;
// cout<<"Level is "<<royce.level<<endl;
// //put in the values
// royce.health = 80;
// royce.level = 'A';
cout<<"Using getter and setter method "<<endl;
cout<<"Health is (any garbage value)"<< royce.gethealth()<<endl;
cout<<"setter use"<<endl;
royce.sethealth(60);
royce.setlevel('B');
cout<<"Health now is "<<royce.gethealth()<<endl;
cout<<"Level now is "<<royce.getlevel()<<endl;
}