forked from ajinkya48765/Academic_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.cpp
More file actions
64 lines (46 loc) · 813 Bytes
/
Copy pathcomplex.cpp
File metadata and controls
64 lines (46 loc) · 813 Bytes
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
//I have written this complex number code only to practice operator overloading.
// Please understand the code before using it as it is.
#include<iostream>
using namespace std;
class complex
{
public:
int a, b;
int getdata(int i)
{
cout<<"Enter real and imaginary parts of complex number : "<<i<<endl;
cin>>a>>b;
return 0;
}
int putdata(int i)
{
cout<<"\ncomplex number : "<<i<<" is "<<a<<"+"<<b<<"i"<<endl;
return 0;
}
complex operator + (complex ob)
{
complex temp;
temp.a=a+ob.a;
temp.b=b+ob.b;
return temp;
}
complex operator * (complex ob)
{
complex temp;
temp.a= a*ob.a-b*ob.b;
temp.b= a*ob.b+ob.a*b;
return temp;
}
};
int main()
{
complex k1,k2,k3,k4;
k1.getdata(1);
k2.getdata(2);
k1.putdata(1);
k2.putdata(2);
k3=k1+k2;
k4=k1*k2;
k3.putdata(3);
k4.putdata(4);
}