-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog6.cpp
More file actions
44 lines (30 loc) · 671 Bytes
/
prog6.cpp
File metadata and controls
44 lines (30 loc) · 671 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
39
40
41
42
43
44
/*
Write a Program to design a class having a static member function named
ShowCount() which has the property of displaying the number of objects created
for the class.
*/
#include <iostream>
using namespace std;
class test {
private:
int code;
static int count;
public:
void setCode() { code = ++count; }
void showCode() { cout << "Object No: " << code << endl; }
static void showCount() { cout << "Count : " << count << endl; }
};
int test::count = 0;
int main() {
test t1, t2;
t1.setCode();
t2.setCode();
test::showCount();
test t3;
t3.setCode();
test::showCount();
t1.showCode();
t2.showCode();
t3.showCode();
return 0;
}