-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_classes.cpp
44 lines (38 loc) · 976 Bytes
/
04_classes.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
#include <iostream>
using namespace std;
class student
{
int id;
static int count; // Default value 0
//count is the static member of the class
public:
void setdata(void){
cout<< "Enter the id of the student ";
cin >> id;
count++;
}
void getdata(void){
cout<<"The id number of student "<<count<<" is "<< id <<endl;
}
static void getcount(void){
cout<<"The value of count is "<<count<<endl;
//isme sirf yehi print hoga
//cout<<id; throws error
}
};
int student :: count;// count is int so declare student as int
// here count value can be change
int main()
{
student hardik,mohit,sahil;
hardik.setdata();
hardik.getdata();
student :: getcount();
mohit.setdata();
mohit.getdata();
student :: getcount();
sahil.setdata();
sahil.getdata();
student :: getcount();
return 0;
}