-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWolframAlphaFormatter.cpp
45 lines (39 loc) · 1.55 KB
/
WolframAlphaFormatter.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
#include "WolframAlphaFormatter.hpp"
#include <sstream>
std::string WolframAlphaFormatter::matrixString(Matrix* matrix) {
std::string output = "[";
for (int i = 0; i < matrix->getI(); i++) {
output += "[";
for (int j = 0; j < matrix->getJ(); j++) {
// Transforma o número em string
std::ostringstream strs;
strs << matrix->getAt(i, j);
output += strs.str();
// Verifica se não é o último elemento da linha
if (j != (matrix->getJ() - 1)) {
output += ",";
}
}
output += "]";
if (i != matrix->getI() - 1) {
output += ",";
}
}
output += "]";
return output;
}
std::string WolframAlphaFormatter::transposedMatrixString(Matrix *matrix) {
return "transpose" + WolframAlphaFormatter::matrixString(matrix);
}
std::string WolframAlphaFormatter::matrixSumString(Matrix *m1, Matrix *m2) {
return WolframAlphaFormatter::matrixString(m1) + "+" + WolframAlphaFormatter::matrixString(m2);
}
std::string WolframAlphaFormatter::matrixSubtractionString(Matrix* m1, Matrix* m2) {
return WolframAlphaFormatter::matrixString(m1) + "-" + WolframAlphaFormatter::matrixString(m2);
}
std::string WolframAlphaFormatter::matrixProductString(Matrix *m1, Matrix *m2) {
return WolframAlphaFormatter::matrixString(m1) + "*" + WolframAlphaFormatter::matrixString(m2);
}
std::string WolframAlphaFormatter::matrixDeterminantString(Matrix* matrix) {
return "det" + WolframAlphaFormatter::matrixString(matrix);
}