This repository has been archived by the owner on Mar 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.cpp
352 lines (346 loc) · 13.7 KB
/
client.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#include <cstdio>
#include <windows.h>
#include <iostream>
#include "matrix.hpp"
using namespace std;
int main() {
cout << "Welcome to the matrix computer world!\nLoading: ";
for (int i = 0; i <= 10; ++i) {
if (i == 10) cout << "100% Here we go!" << endl;
else cout << i * 10 << "%, ";
Sleep(300);
}
cout << "\nIn this calculator, you are free to do following things:\n"
<< "(0)Print a stored matrix;\n"
<< "(1)Type in and store a matrix;\n"
<< "(2)Add, (3)Minus, (4)Multiply. in Matrix-Matrix;\n"
<< "(5)Add, (6)Minus, (7)Multiply, (8)divide. in scalar;\n"
<< "(9)Transposition, (10)Conjugation;\n"
<< "(11)Max value, (12)Min value, (13)Sum, (14)Average;\n"
<< "(15)Eigenvalue, (16)Eigenvector, (17)Trace, (18)Inverse, (19)determinant;\n"
<< "(20)Reshape, (21)Slicing, (22)Convolution.\n" << endl;
vector<Matrix<double>> vec;
int choose = 1;
while (true) {
switch (choose) {
case 0: {
if (vec.empty()) cout << "There has no stored matrix now." << endl;
else {
int i = 0;
cout << "There are " << vec.size() - 1 << " matrix now (0-index), choose one:";
cin >> i;
if (i < vec.size()) cout << vec[i] << endl;
else cout << "Out of the bound!" << endl;
}
break;
}
case 1: {
int r, c;
cout << "Type in the integer row and col:" << endl;
cin >> r >> c;
cout << "Type in the element:" << endl;
double t;
vector<vector<double>> t1;
vector<double> t2;
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
cin >> t;
t2.push_back(t);
}
t1.push_back(t2);
t2.resize(0);
}
Matrix<double> m(t1);
vec.push_back(m);
cout << "Your new matrix is ID-" << vec.size() << " (0-index)." << endl;
break;
}
case 2: {
if (vec.size() < 2) cout << "Please first store at least 2 matrix!" << endl;
else {
cout << "Choose two matrix to add:" << endl;
int a, b;
cin >> a >> b;
if (min(a, b) >= 0 && max(a, b) < vec.size())
cout << vec[a] + vec[b] << endl;
else cout << "Out of the bound!";
}
break;
}
case 3: {
if (vec.size() < 2) cout << "Please first store at least 2 matrix!" << endl;
else {
cout << "Choose two matrix to minus:" << endl;
int a, b;
cin >> a >> b;
if (min(a, b) >= 0 && max(a, b) < vec.size())
cout << vec[a] - vec[b] << endl;
else cout << "Out of the bound!";
}
break;
}
case 4: {
if (vec.size() < 2) cout << "Please first store at least 2 matrix!" << endl;
else {
cout << "Choose two matrix to multiply:" << endl;
int a, b;
cin >> a >> b;
if (min(a, b) >= 0 && max(a, b) < vec.size())
cout << vec[a] * vec[b] << endl;
else cout << "Out of the bound!";
}
break;
}
case 5: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to add a scalar, and the scalar:" << endl;
int a, b;
cin >> a >> b;
if (a >= 0 && a < vec.size()) {
vec[a] += b;
cout << vec[a] << endl;
} else cout << "Out of the bound!";
}
break;
}
case 6: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to minus a scalar, and the scalar:" << endl;
int a, b;
cin >> a >> b;
if (a >= 0 && a < vec.size()) {
vec[a] -= b;
cout << vec[a] << endl;
} else cout << "Out of the bound!";
}
break;
}
case 7: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to multiply a scalar, and the scalar:" << endl;
int a, b;
cin >> a >> b;
if (a >= 0 && a < vec.size()) {
vec[a] *= b;
cout << vec[a] << endl;
} else cout << "Out of the bound!";
}
break;
}
case 8: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to divide a scalar, and the scalar:" << endl;
int a, b;
cin >> a >> b;
if (a >= 0 && a < vec.size()) {
vec[a] /= b;
cout << vec[a] << endl;
} else cout << "Out of the bound!";
}
break;
}
case 9: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get transposition:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
cout << vec[a].trans() << endl;
else cout << "Out of the bound!";
}
break;
}
case 10: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get Conjugation:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
// cout << vec[a].conj() << endl; // double itself is conj
cout << vec[a] << endl;
else cout << "Out of the bound!";
}
break;
}
case 11: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get max value:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
cout << vec[a].max() << endl;
else cout << "Out of the bound!";
}
break;
}
case 12: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get min value:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
cout << vec[a].min() << endl;
else cout << "Out of the bound!";
}
break;
}
case 13: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get sum:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
cout << vec[a].sum() << endl;
else cout << "Out of the bound!";
}
break;
}
case 14: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get average value:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
cout << vec[a].mean() << endl;
else cout << "Out of the bound!";
}
break;
}
case 15: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get eigen-value:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
cout << vec[a].eigenValue() << endl;
else cout << "Out of the bound!";
}
break;
}
case 16: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get eigen-vector:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
cout << vec[a].eigenVector() << endl;
else cout << "Out of the bound!";
}
break;
}
case 17: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get trace:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
cout << vec[a].trace() << endl;
else cout << "Out of the bound!";
}
break;
}
case 18: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get inverse:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
cout << vec[a].invert() << endl;
else cout << "Out of the bound!";
}
break;
}
case 19: {
if (vec.empty()) cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to get determinant:" << endl;
int a;
cin >> a;
if (a >= 0 && a < vec.size())
cout << vec[a].determinant() << endl;
else cout << "Out of the bound!";
}
break;
}
case 20: {
if (vec.empty())
cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to be reshaped:" << endl;
int a;
cin >> a;
cout << "Type in the row and column of the matrix after reshaping:" << endl;
int x, y;
cin >> x;
cin >> y;
if (a >= 0 && a < vec.size())
cout << vec[a].reshape(x, y) << endl;
else
cout << "Out of the bound!";
}
break;
}
case 21: {
if (vec.empty())
cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to be sliced:" << endl;
int a;
cin >> a;
cout << "Type in the starting point:" << endl;
int x1, y1;
cin >> x1;
cin >> y1;
cout << "Type in the ending point:" << endl;
int x2, y2;
cin >> x2;
cin >> y2;
if (a >= 0 && a < vec.size())
cout << vec[a].slice(x1, x2, y1, y2) << endl;
else
cout << "Out of the bound!";
}
break;
}
case 22: {
if (vec.empty())
cout << "Please first store at least 1 matrix!" << endl;
else {
cout << "Choose the matrix to be convolution:" << endl;
int a;
cin >> a;
cout << "Choose the matrix to convolution:" << endl;
int b;
cin >> b;
if (a >= 0 && a < vec.size())
cout << vec[a].convolution(vec[b]) << endl;
else
cout << "Out of the bound!";
}
break;
}
default:
break;
}
cout << "Please type in num(0~22) to choose operation next, or others to quit:";
cin >> choose;
if (choose <= 0 or choose > 23) {
cout << "Calculator detect you type in the wrong num. THE END! Bye" << endl;
break;
}
}
}