-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic member.cpp
54 lines (46 loc) · 1.36 KB
/
static member.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
/*Problem3: Define a class Complex with members real and imag. Use constructor to construct the objects of
the class Complex. Using static data member and static function, display the total number of object created
before terminating the program.*/
#include <iostream>
using namespace std;
class complex
{
float real;
float imag;
static int count; //static data member
public:
complex(float real1,float imag1)
{
real=real1;
imag=imag1;
count++;
}
void display()
{
cout << "the real part is" << endl;
cout << real << endl;
cout << "the imaginary part is" << endl;
cout << imag << endl;
cout << "In Complex number format :"
<< " " << real << "+" << imag << "j" << endl;
cout << "*******************************************" << endl;
}
static void showcount() //static function
{
cout << "\n.................................." << endl;
cout << "count" << count << endl;
cout << ".................................." << endl;
}
};
int complex::count;
int main()
{
complex c1(2,4);
c1.display();
complex c2(4,8);
c2.display();
complex c3(3,4);
c3.display();
complex::showcount(); ////static function to show total number of object
return 0;
}