-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2018_February_04_TaskA
109 lines (90 loc) · 2.7 KB
/
2018_February_04_TaskA
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
#include <iostream>
#include <cmath>
using namespace std;
class IrRat {
public:
double normal;
double awful;
void onCreate(double n, double a){
normal = n;
awful = a;
}
IrRat operator+ (IrRat scnd){
IrRat result;
result.normal = normal + scnd.normal;
result.awful = pow(awful, 2) + 2*awful*scnd.awful + pow(scnd.awful, 2);
if(fmod(sqrt(result.awful), 1) == 0) {
result.normal += result.awful;
result.awful = 0;
}
return result;
}
IrRat operator- (IrRat scnd){
IrRat result;
result.normal = normal - scnd.normal;
result.awful = pow(awful, 2) - 2*awful*scnd.awful + pow(scnd.awful, 2);
if(fmod(sqrt(result.awful), 1) == 0) {
result.normal += result.awful;
result.awful = 0;
}
return result;
}
IrRat operator* (IrRat scnd){
IrRat result;
result.normal = normal * normal;
result.awful = awful*scnd.awful + awful*scnd.normal + normal*scnd.awful;
if(fmod(sqrt(result.awful), 1) == 0) {
result.normal = result.awful;
result.awful = 0;
}
return result;
}
IrRat operator/ (IrRat scnd){
IrRat val;
int znamenatel = (pow(scnd.normal, 2) - scnd.awful);
val.normal = normal * scnd.normal / znamenatel;
val.awful = awful*scnd.normal - awful*scnd.awful - normal*scnd.awful / znamenatel;
return val;
}
void print(){
cout << normal << " + sqrt(" << awful << ")";
}
};
class ComplX{
public:
IrRat normal;
IrRat evenMoreAwful;
ComplX(IrRat n, IrRat e){
normal = n;
evenMoreAwful = e;
}
ComplX operator+ (ComplX scnd){
ComplX result(normal + scnd.normal, evenMoreAwful + scnd.evenMoreAwful);
return result;
}
ComplX operator- (ComplX scnd){
ComplX result(normal - scnd.normal, evenMoreAwful - scnd.evenMoreAwful);
return result;
}
ComplX operator* (ComplX scnd){
ComplX result(normal * normal - evenMoreAwful*scnd.evenMoreAwful, evenMoreAwful*scnd.normal + normal*scnd.evenMoreAwful);
return result;
}
ComplX operator/ (ComplX scnd){
IrRat a;
ComplX val(a, a);
IrRat znamenatel = (scnd.normal*scnd.normal - scnd.evenMoreAwful);
val.normal = normal * scnd.normal / znamenatel;
val.evenMoreAwful = evenMoreAwful*scnd.normal - evenMoreAwful*scnd.evenMoreAwful - normal*scnd.evenMoreAwful / znamenatel;
return val;
}
void print(){
normal.print();
cout << " + sqrt(";
evenMoreAwful.print();
cout << ")";
}
};
int main() {
return 0;
}