-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog5.cpp
More file actions
39 lines (27 loc) · 766 Bytes
/
prog5.cpp
File metadata and controls
39 lines (27 loc) · 766 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
/*
Write a C++ Program to design a class called IntegerDisplay with both an integer
variable and a static integer variable and member function. Display both data
using corresponding member functions namely print_i() and print_si()
*/
#include <iostream>
using namespace std;
class IntegerDisplay {
private:
int i;
static int si;
public:
void set_i(int i) { this->i = i; }
static void set_si(int si) { IntegerDisplay::si = si; }
void print_i() { cout << "Value of i: " << i << endl; }
static void print_si() { cout << "Value of si: " << si << endl; }
};
int IntegerDisplay::si = 77;
int main() {
IntegerDisplay obj;
obj.set_i(11);
obj.print_i();
IntegerDisplay::print_si();
IntegerDisplay::set_si(21);
obj.print_si();
return 0;
}