-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path02_counter.cpp
71 lines (57 loc) · 1.33 KB
/
02_counter.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
// // Implement a class Counter with a static member variable count and a static member function to get value of count.
// // Header files
#include <iostream>
// // use namespace
using namespace std;
// // define class Counter
class Counter
{
private:
// // instance member variable
int counter;
public:
// // constructors
Counter()
{
counter = 0;
}
Counter(int count)
{
counter = count;
}
// // instance member function to set counter
int setCounter(int count)
{
counter = count;
}
// // instance member function to get counter
int getCounter()
{
return counter;
}
// // instance member function to set counter
int incrementCounter()
{
counter++;
}
};
// // Main Function Start
int main()
{
int count;
cout << "\nEnter Number From Which You Want to Start Counter => ";
cin >> count;
Counter c1(count); // create object of Counter
// // show counter
cout << "\nCounter Started From => " << c1.getCounter();
// // increment counter
c1.incrementCounter();
c1.incrementCounter();
c1.incrementCounter();
// // show counter
cout << "\nCounter After Incremented 3 Times => " << c1.getCounter();
cout << endl; // Add new line
cin.ignore();
return 0;
}
// // Main Function End