-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintro.cpp
More file actions
69 lines (53 loc) · 1.24 KB
/
Copy pathintro.cpp
File metadata and controls
69 lines (53 loc) · 1.24 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
#include<iostream>
using namespace std;
class Hero{
//properties
private:
int health;
public:
char level;
void print(){
cout<< level <<endl;
}
// getters && setters
int getHealth(){
return health;
}
int getLevel(){
return level;
}
void setHealth(int h){
health = h;
}
void setLevel(char ch){
level = ch;
}
};
int main(){
//STATIC ALLOCATION
Hero a;
a.setHealth(80);
a.setLevel('B');
cout<<"Level is "<<a.level<<endl;
cout<<"Health is "<<a.getHealth()<<endl;
//Dynamically
Hero *b = new Hero;
b->setHealth(70);
b->setLevel('A');
cout<<"Level is "<<(*b).level<<endl;
cout<<"Health is "<<(*b).getHealth()<<endl;
//or
cout<<"Level is "<<b->level<<endl;
cout<<"Health is "<<b->getHealth()<<endl;
/*
//creation of a object
Hero hula;
cout<<"hula health is "<<hula.getHealth()<<endl;
hula.setHealth(70);
// hula.health = 70;
hula.level ='A';
cout<<"Health is : "<<hula.getHealth()<<endl;
cout<<"level is : "<<hula.level<<endl;
// cout<<"Size : "<<sizeof(h1)<<endl;
*/
}