-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut24.cpp
More file actions
43 lines (35 loc) · 1.03 KB
/
tut24.cpp
File metadata and controls
43 lines (35 loc) · 1.03 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
#include<bits/stdc++.h>
using namespace std;
class employee{
private:
int id;
static int count;// static variables have default value as zero
public:
void setData(void){
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 as you can only use static variables in static functions
cout<<"the value of count is "<<count;
}
};
int employee:: count=100;
int main(){
// count is the static data member of the class employee
employee harry ,rohan,lovish;
// harry.id=1; cannnot do this as id and count are private
// harry.count=1;cannnot do this as id and count are private
harry.setData();
harry.getData();
employee::getcount();
harry.setData();
harry.getData();
employee::getcount();
harry.setData();
harry.getData();
return 0;
}