This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
151 lines (143 loc) · 4.16 KB
/
main.cpp
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <iostream>
#include "multiplication/Multiplication.h"
#include "PseudoFloat/PseudoFloat.h"
#include "prime/Prime.h"
std::ostream &operator<<(std::ostream &output, const TInteger &a) {
return output << (std::string)a;
}
int charstring_to_int(char s[]) {
int result = 0, i = 0;
bool to_invert = false;
if (s[0] == '-') {
to_invert = true;
i = 1;
}
for (i; s[i] != 0; i++) {
result *= 10;
result += s[i] - '0'; // it is converted from the ASCII character code
}
if (to_invert) {
result *= -1;
}
return result;
}
int main(int argc, char *argv[])
// Check info about executing in README.md
{
if (argc == 1) {
std::cout << "No arguments were given. Aborting execution.";
return 0;
}
if (argc == 2) {
std::cout << "Method " << argv[1] << " was chosen, bun no integers were given. Aborting execution.";
return 0;
}
TInteger a(argv[2]), b;
bool second_integer_exist = argc > 3;
if (second_integer_exist) {
b = TInteger(argv[3]);
}
switch (charstring_to_int(argv[1])) {
case 0: {
std::cout << a;
if (second_integer_exist) {
std::cout << ' ' << b;
}
break;
}
case 1: {
if (! second_integer_exist) {
std::cout << "Second integer is required. Aborting execution.";
} else {
Multiplication* multiply_method = new Karatsuba;
std::cout << multiply_method->multiply(a, b);
}
break;
}
case 2: {
if (! second_integer_exist) {
std::cout << "Second integer is required. Aborting execution.";
} else {
Multiplication* multiply_method = new TomCook;
std::cout << multiply_method->multiply(a, b);
}
break;
}
case 5: {
std::cout << inverse(a);
break;
}
case 7: {
PrimalityCheck* is_prime = new Fermat;
std::cout << is_prime->check(a);
break;
}
case 8: {
PrimalityCheck* is_prime = new RabinMiller;
std::cout << is_prime->check(a);
break;
}
case 9: {
PrimalityCheck* is_prime = new SolovayStrassen;
std::cout << is_prime->check(a);
break;
}
case 10: {
PrimalityCheck* is_prime = new Agrawal;
std::cout << is_prime->check(a);
break;
}
case 11: {
if (! second_integer_exist) {
std::cout << "Second integer is required. Aborting execution.";
} else {
std::cout << a + b;
}
break;
}
case 12: {
if (! second_integer_exist) {
std::cout << "Second integer is required. Aborting execution.";
} else {
std::cout << a - b;
}
break;
}
case 13: {
if (! second_integer_exist) {
std::cout << "Second integer is required. Aborting execution.";
} else {
std::cout << a * b;
}
break;
}
case 14: {
if (! second_integer_exist) {
std::cout << "Second integer is required. Aborting execution.";
} else {
std::cout << a / b;
}
break;
}
case 15: {
if (! second_integer_exist) {
std::cout << "Second integer is required. Aborting execution.";
} else {
std::cout << a % b;
}
break;
}
case 16: {
if (! second_integer_exist) {
std::cout << "Second integer is required. Aborting execution.";
} else {
Multiplication* multiply_method = new RepeatedAddition;
std::cout << multiply_method->multiply(a, b);
}
break;
}
default:
std::cout << "Not implemented!";
}
return 0;
}