-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamicObj.cpp
More file actions
38 lines (34 loc) · 817 Bytes
/
Copy pathdynamicObj.cpp
File metadata and controls
38 lines (34 loc) · 817 Bytes
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
#include<iostream>
using namespace std;
class Hero{
private:
string name;
int health;
char level;
public:
void getValues(){
cout<<"Enter player name:"<<endl;
cin.ignore();
getline(cin,name);
cout<<"Enter health in percentage:"<<endl;
cin>>health;
cout<<"Enter player level:"<<endl;
cin>>level;
}
void display(){
cout<<"Name: "<<name<<endl;
cout<<"Health: "<<health<<endl;
cout<<"Level: "<<level<<endl<<endl;
}
};
int main(){
//Static Allocation
Hero x;
x.getValues();
x.display();//The dot operator is applied to the actual object.
//Dynamic Allocation
Hero *y=new Hero;
y->getValues();
y->display();/*The arrow operator is used with a pointer to an object*/
return 0;
}