-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexNo.cpp
More file actions
97 lines (69 loc) · 1.55 KB
/
Copy pathComplexNo.cpp
File metadata and controls
97 lines (69 loc) · 1.55 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<iostream>
using namespace std;
class complex
{
private:
int real;
int imag;
public:
complex()
{
real = 0;
imag = 0;
}
complex(int r, int i)
{
real = r;
imag = i;
}
complex operator +(complex c)
{
complex temp;
temp.real = real + c.real;
temp.imag = imag + c.imag;
return temp;
}
complex operator *(complex c)
{
complex temp;
temp.real = (real * c.real ) - (imag * c.imag);
temp.imag = (real * c.imag ) + (imag * c.real);
return temp;
}
friend istream& operator >>(istream& in, complex& c);
friend ostream& operator <<(ostream& out, complex& c);
};
istream& operator >>(istream& in, complex& c)
{
cout <<"Enter Real Part :";
cin >> c.real;
cout <<"Enter Imaginary Part:";
cin >> c.imag;
return in;
}
ostream& operator <<(ostream& out, complex& c)
{
out << c.real;
if(c.imag >= 0)
cout<<"+"<< c.imag <<"i";
else
cout<< c.imag << "i";
return out;
}
int main()
{
complex c1, c2, sum, product;
cout<<"------------Enter First Complex Number------------"<<endl;
cin>>c1;
Output
cout<<"\n------------Enter Second Complex Number:------------"<<endl;
cin>>c2;
sum = c1 + c2;
Output
product = c1* c2;
cout<<"\nFirst Complex Number = "<< c1 << endl;
cout<<"\nSecond Complex Number = "<< c2 << endl;
cout<<"\nAddition = "<< sum << endl;
cout<<"\nMultiplication = "<< product << endl;
return 0;
}