forked from piyush168713/Core-CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tut_24.cpp
48 lines (41 loc) · 1.01 KB
/
tut_24.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
#include <iostream>
using namespace std;
class employee
{
// private:
int id;
static int count;
public:
void setData(void)
{
cout << "Enter the id " << endl;
cin >> id;
count++;
}
void getData(void)
{
cout << "The id of this employee is " << id << " and this is employee number " << count << endl;
}
static void getCount(void){
// cout<<id; // throws an error
cout<<"The value of count is "<<count<<endl;
}
};
int employee :: count; //Default value is 0
int main()
{
employee piyush, rohan, mohan;
// count is the static data member of class employee
// piyush.id = 1;
// piyush.count = 1; // cannot do this as id and count are private
piyush.setData();
piyush.getData();
employee :: getCount();
rohan.setData();
rohan.getData();
employee :: getCount();
mohan.setData();
mohan.getData();
employee :: getCount();
return 0;
}