-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComplexNumbersClass.cpp
55 lines (50 loc) · 1.06 KB
/
ComplexNumbersClass.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
#include <bits/stdc++.h>
using namespace std;
class CN{
public:
int real;
int img;
CN():real(0), img(0){}
friend ostream& operator<<(ostream &, const CN &);
friend istream& operator>>(istream &, CN &);
CN operator+(const CN &x){
CN ans;
ans.real = real + x.real;
ans.img = img + x.img;
return ans;
}
CN operator-(const CN &x){
CN ans;
ans.real = real - x.real;
ans.img = img - x.img;
return ans;
}
CN operator*(const CN &x){
CN ans;
ans.real = real*x.real - img*x.img;
ans.img = real*x.img + x.real*img;
return ans;
}
};
ostream& operator<<(ostream &Out, const CN &x){
Out<<"("<<x.real<<") + i("<<x.img<<")";
return Out;
}
istream& operator>>(istream &Inp, CN &x){
Inp>>x.real>>x.img;
return Inp;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
CN z1, z2;
cin>>z1>>z2;
cout<<"Complex Number1 is ="<<z1<<"\n";
cout<<"Complex Number2 is ="<<z2<<"\n";
cout<<"z1 + z2 = "<<(z1+z2)<<"\n";
cout<<"z1 - z2 = "<<(z1-z2)<<"\n";
cout<<"z1 * z2 = "<<(z1*z2)<<"\n";
return 0;
}