-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexNumber.cpp
More file actions
64 lines (64 loc) · 1.24 KB
/
ComplexNumber.cpp
File metadata and controls
64 lines (64 loc) · 1.24 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
#include<iostream>
using namespace std;
class ComplexFraction
{
private: int real;
int imginary;
public:
ComplexFraction(int x, int y)
{
real=x;
imginary=y;
}
void add(ComplexFraction const &c)
{
real=real+c.real;
imginary=imginary+c.imginary;
}
void print()
{
cout<<real<<" + "<<imginary<<"i"<<endl;
}
void multiply(ComplexFraction const &c)
{
int w=real*c.real;
int x=real*c.imginary;
int y=imginary*c.real;
int z=imginary*c.imginary;
real=w+z;
imginary=x+y;
}
void simplify()
{
int gcd=1;
int n=min(real,imginary);
for(int i=2;i<=n;i++)
{
if(real%i==0 && imginary%i==0)
{
gcd=i;
}
}
real=real/gcd;
imginary=imginary/gcd;
}
};
int main()
{
ComplexFraction cn1(10,20);
ComplexFraction cn2(2,5);
cn1.print();
cn2.print();
cn1.add(cn2);
cout<<"After Addition = "<<endl;
cn1.print();
cn2.print();
//Multiption
cn1.print();
cn2.print();
cn1.multiply(cn2);
cout<<"After Multipication = "<<endl;
cn1.print();
cn2.print();
return 0;
}