-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut24.cpp
90 lines (75 loc) · 2.11 KB
/
tut24.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
using namespace std;
void name()
{
cout << 'Author: Varun Gupta' << endl;
}
class employee
{
int a;
static int count;
//***********STATIC VARIABLES***********//
/* * Static variables are accessed outside the class.
* Whenever a static variables is declared , it is by default initialized with zero
* Static variable gets joined with class ,that's why they are known as class variables.
* Life span of a static variable: Start ---->Till----> Termination of the program
* Once it is declared inside the class, every object can share the same static value.
* Syntax:
class emp{
static int stats;
public:
static void show()
{
cout<<stats;
}
};
emp::stats; //Here we can assign the value also to the static variable stats.
* */
public:
void endata()
{
cout << "Enter the value " << endl;
cin >> a;
count++;
}
void outdata()
{
cout << "Your entered value is " << a << " with ID " << count << endl;
}
static void show()
{
/****************STATIC MEMEBER FUNCTION************/
/* A funtion that can only access the static variables/members declared inside the class.
It doesn't require objects to call, but it can be following the below syntax:
Syntax:
class emp{
static int stats;
public:
static void show()
{
cout<<stats;
}
};
*/
cout <<"The value of ID is "<<count<<endl;
}
};
int employee ::count; //Default value is 0.
int main()
{
name();
employee lebra, varun, harry, john;
varun.endata();
varun.outdata();
employee::show();
harry.endata();
harry.outdata();
employee ::show();
john.endata();
john.outdata();
employee ::show();
lebra.endata();
lebra.outdata();
employee::show();
return 0;
}