-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal project.cpp
More file actions
124 lines (95 loc) · 2.08 KB
/
final project.cpp
File metadata and controls
124 lines (95 loc) · 2.08 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using namespace std;
#include<iomanip>
#include<iostream>
#include<cmath>
typedef struct {
// complex struct
double real;
double imag;
}complex;
complex Division(complex A, complex B); // sign
complex multyply(complex q, complex w);
void Add(complex c1, complex c2);
void Minus(complex m1, complex m2);
complex multyply(complex q, complex w);
void print(complex P) {
cout << P.real;
if (P.imag != 0) {
if (P.imag > 0) cout << "+";
cout << P.imag << "i" << endl;
}
}
void polar(complex a) { //polar
float r;
r = sqrt(pow(a.real, 2) + pow(a.imag, 2));
float e;
float y;
float teta;
y = a.imag / a.real;
e = atan(y);
teta = atan(y) * 180 / 3.14159265;
cout << "z = " << r << "e^(" << teta << ")i" ;
}
complex Division(complex A, complex B) { //division
complex C;
C.real = A.real / pow(A.imag, 2) + pow(B.imag, 2);
C.imag = B.real / pow(A.imag, 2) + pow(B.imag, 2);
print(C);
return C;
}
void Add(complex c1, complex c2) { //add
complex c3;
c3.real = c1.real + c2.real;
c3.imag = c1.imag + c2.imag;
print(c3);
}
void Minus(complex m1, complex m2) { //minus
complex m3;
m3.real = m1.real - m2.real;
m3.imag = m1.imag - m2.imag;
print(m3);
}
complex multyply(complex q, complex w) { //multiplication
complex d4;
d4.real = (q.real * w.real) - (q.imag * w.imag);
d4.imag = (q.real * w.imag) + (q.imag * w.real);
print(d4);
return d4;
}
int main() {
char value;
complex a;
complex b;
cout << "enter real number complex1: ";
cin >> a.real;
cout << "enter imag number complex1: ";
cin >> a.imag;
cout << "enter your operation:";
cin >> value;
if (value == '^')
polar(a);
else
{
cout << "enter real number complex2: ";
cin >> b.real;
cout << "enter imag number complex2: ";
cin >> b.imag;
switch (value) {
case '+':
Add(a, b);
break;
case '-':
Minus(a, b);
break;
case '*':
multyply(a, b);
break;
case'/':
Division(a, b);
break;
default:
cout << "your operator invlaid.";
break;
}
}
}