-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathAll_Operations_of_Complex_Numbers.cpp
More file actions
89 lines (72 loc) · 1.4 KB
/
All_Operations_of_Complex_Numbers.cpp
File metadata and controls
89 lines (72 loc) · 1.4 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
#include <iostream>
using namespace std;
class comp
{
int r, i;
public:
void input()
{
cout << "Enter real & imaginary parts : ";
cin >> r >> i;
}
void display()
{
cout << "Result : " << r << "+i" << i << endl;
}
comp operator + (comp c2)
{
comp c3;
c3.r = r + c2.r;
c3.i = i + c2.i;
return c3;
}
comp operator - (comp c2)
{
comp c3;
c3.r = r - c2.r;
c3.i = i - c2.i;
return c3;
}
comp operator * (comp c2)
{
comp c3;
c3.r = r*c2.r + i*c2.i;
c3.i = i*c2.r + r*c2.i;
return c3;
}
comp operator / (comp c2)
{
comp c3;
c3.r = ( r*c2.r + i*c2.i ) / ( c2.r*c2.r + c2.i*c2.i );
c3.i = ( r*c2.i - i*c2.r ) / ( c2.r*c2.r + c2.i*c2.i );
return c3;
}
};
void option ( comp b1, comp b2, comp &b3 )
{
int n;
cout << endl << "Options:" << endl << endl;
cout << "1.Addition" << endl;
cout << "2.Subtraction" << endl;
cout << "3.Multiplication" << endl;
cout << "4.Division" << endl;
cout << "Enter your option : ";
cin >> n;
switch ( n )
{
case 1 : b3 = b1+b2; break;
case 2 : b3 = b1-b2; break;
case 3 : b3 = b1*b2; break;
case 4 : b3 = b1/b2; break;
}
return ;
}
int main()
{
comp b1,b2,b3;
b1.input();
b2.input();
option(b1,b2,b3);
b3.display();
return 0;
}