-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplex.cpp
More file actions
78 lines (66 loc) · 1.41 KB
/
Complex.cpp
File metadata and controls
78 lines (66 loc) · 1.41 KB
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
72
73
74
75
76
77
78
#include<iostream>
using namespace std;
class complex
{
private:
int real,imag;
public:
complex()
{
real=0;
imag=0;
}
complex(int a, int b)
{
real=a;
imag=b;
}
complex(complex &c)
{
real=c.real;
imag=c.imag;
}
void set_data()
{
cout<<real<<"+"<<imag<<"i"<<endl;
}
void get_data()
{
cout<<"Enter real and imaginary part of the complex number :"<<endl;
cin>>real>>imag;
cout<<"the complex number are: "<<real<<"+"<<imag<<"i"<<"\t";
}
void display()
{
cout<<real<<"+"<<imag<<"i"<<endl;
}
complex add(complex x)
{
complex temp;
temp.real=x.real+real;
temp.imag=x.imag+imag;
return temp;
}
complex sub(complex x)
{
complex temp;
temp.real=x.real-real;
temp.imag=x.imag-imag;
return temp;
}
};
int main()
{
complex c2(7,10),c3(c2),c1,c4;
c3.get_data();
c2.set_data();
cout<<"**********************************************"<<endl;
cout<<"Sum of two complex numbers is :"<<endl;
c1=c2.add(c3);
c1.display();
cout<<"**********************************************"<<endl;
cout<<"Subtraction of two complex numbers is :"<<endl;
c4=c2.sub(c3);
c4.display();
return 0;
}