Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
240 lines (219 loc) · 10.7 KB
/
Copy pathmain.cpp
File metadata and controls
240 lines (219 loc) · 10.7 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
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
#include <iostream>
#include <vector>
#include "Matrix.h"
void printAllMatrices(const std::vector<Matrix> &matrices);
void display();
Matrix createMatrix(int numberOfRows, int numberOfColumns);
int main() {
int input, matrixIndex, scalar;
Matrix operandOne, operandTwo;
std::vector<Matrix> matrices;
do {
display();
std::cout << "Enter the option you want to select" << std::endl;
std::cin >> input;
switch (input) {
case 0:
int NumberOfRows, NumberOfColumns;
std::cout << "Enter the number of Rows you want for the matrix" << std::endl;
std::cin >> NumberOfRows;
std::cout << "Enter the number of Column you want for the matrix" << std::endl;
std::cin >> NumberOfColumns;
matrices.push_back(createMatrix(NumberOfRows, NumberOfColumns));
break;
case 1:
printAllMatrices(matrices);
break;
case 2:
printAllMatrices(matrices);
if (matrices.size() > 0) {
std::cout << "Enter the first matrix index you want to add " << std::endl;
std::cin >> matrixIndex;
if (matrices.size() > matrixIndex) {
operandOne = matrices.at(matrixIndex);
std::cout << "Enter the second matrix index you want to add " << std::endl;
std::cin >> matrixIndex;
if (matrices.size() > matrixIndex) {
operandTwo = matrices.at(matrixIndex);
std::cout << operandOne + operandTwo << std::endl;
} else {
std::cout << "Wrong Input" << std::endl;
}
} else {
std::cout << "Wrong Input" << std::endl;
}
} else {
std::cout << "No matrices found" << std::endl;
}
break;
case 3:
printAllMatrices(matrices);
if (matrices.size() > 0) {
std::cout << "Enter the first matrix index you want to subtract " << std::endl;
std::cin >> matrixIndex;
if (matrices.size() > matrixIndex) {
operandOne = matrices.at(matrixIndex);
std::cout << "Enter the second matrix index you want to subtract " << std::endl;
std::cin >> matrixIndex;
if (matrices.size() > matrixIndex) {
operandTwo = matrices.at(matrixIndex);
std::cout << operandOne - operandTwo << std::endl;
} else {
std::cout << "Wrong Input" << std::endl;
}
} else {
std::cout << "Wrong Input" << std::endl;
}
} else {
std::cout << "No matrices found" << std::endl;
}
break;
case 4:
printAllMatrices(matrices);
if (matrices.size() > 0) {
std::cout << "Enter the first matrix index you want to multiply " << std::endl;
std::cin >> matrixIndex;
if (matrices.size() > matrixIndex) {
operandOne = matrices.at(matrixIndex);
std::cout << "Enter the second matrix index you want to multiply " << std::endl;
std::cin >> matrixIndex;
if (matrices.size() > matrixIndex) {
operandTwo = matrices.at(matrixIndex);
std::cout << operandOne * operandTwo << std::endl;
} else {
std::cout << "Wrong Input" << std::endl;
}
} else {
std::cout << "Wrong Input" << std::endl;
}
} else {
std::cout << "No matrices found" << std::endl;
}
break;
case 5:
printAllMatrices(matrices);
if (matrices.size() > 0) {
std::cout << "Enter the matrix index you want to scale " << std::endl;
std::cin >> matrixIndex;
std::cout << "Enter the scalar you want to multiply the matrix" << std::endl;
std::cin >> scalar;
operandOne = matrices.at(matrixIndex);
if (matrixIndex < matrices.size()) {
std::cout << operandOne * scalar << std::endl;
} else {
std::cout << "Wrong input" << std::endl;
}
} else {
std::cout << "No matrices found" << std::endl;
}
break;
case 6:
printAllMatrices(matrices);
if (matrices.size() > 0) {
std::cout << "Enter the matrix index you want to get the transpose of " << std::endl;
std::cin >> matrixIndex;
operandOne = matrices.at(matrixIndex);
if (matrixIndex < matrices.size()) {
std::cout << ~operandOne << std::endl;
} else {
std::cout << "Wrong input" << std::endl;
}
} else {
std::cout << "No matrices found" << std::endl;
}
break;
case 7:
printAllMatrices(matrices);
if (matrices.size() > 0) {
std::cout << "Enter the matrix index you want to get rank of " << std::endl;
std::cin >> matrixIndex;
operandOne = matrices.at(matrixIndex);
if (matrixIndex < matrices.size()) {
operandOne.rank();
} else {
std::cout << "Wrong input" << std::endl;
}
} else {
std::cout << "No matrices found" << std::endl;
}
break;
case 8:
printAllMatrices(matrices);
if (matrices.size() > 0) {
std::cout << "Enter the matrix index you want to get adjoint of " << std::endl;
std::cin >> matrixIndex;
operandOne = matrices.at(matrixIndex);
if (matrixIndex < matrices.size()) {
operandOne.getAdjoint().print();
} else {
std::cout << "Wrong input" << std::endl;
}
} else {
std::cout << "No matrices found" << std::endl;
}
break;
case 9:
printAllMatrices(matrices);
if (matrices.size() > 0) {
std::cout << "Enter the matrix index you want to get the inverse of " << std::endl;
std::cin >> matrixIndex;
operandOne = matrices.at(matrixIndex);
if (matrixIndex < matrices.size()) {
operandOne.inverse().print();
} else {
std::cout << "Wrong input" << std::endl;
}
} else {
std::cout << "No matrices found" << std::endl;
}
break;
}
} while (input != 7);
return 0;
}
void printAllMatrices(const std::vector<Matrix> &matrices) {
int index = 0;
for (auto matrix: matrices) {
std::cout << "Matrix index " << index << std::endl;
matrix.print();
index++;
}
}
void display() {
std::cout << "===============================================================" << std::endl;
std::cout << """"
"███╗░░░███╗░█████╗░████████╗██████╗░██╗░█████╗░███████╗░██████╗\n"
"████╗░████║██╔══██╗╚══██╔══╝██╔══██╗██║██╔══██╗██╔════╝██╔════╝\n"
"██╔████╔██║███████║░░░██║░░░██████╔╝██║██║░░╚═╝█████╗░░╚█████╗░\n"
"██║╚██╔╝██║██╔══██║░░░██║░░░██╔══██╗██║██║░░██╗██╔══╝░░░╚═══██╗\n"
"██║░╚═╝░██║██║░░██║░░░██║░░░██║░░██║██║╚█████╔╝███████╗██████╔╝\n"
"╚═╝░░░░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░░╚═╝╚═╝░╚════╝░╚══════╝╚═════╝░"
"" << std::endl;
std::cout << "===============================================================" << std::endl;
std::cout << "0 - Create a matrix " << std::endl;
std::cout << "1 - Print all saved Matrices" << std::endl;
std::cout << "2 - Add matrices" << std::endl;
std::cout << "3 - Subtract matrices" << std::endl;
std::cout << "4 - Multiply matrices" << std::endl;
std::cout << "5 - Scalar multiplication of matrix" << std::endl;
std::cout << "6 - Transpose of matrix" << std::endl;
std::cout << "7 - Rank of the matrix" << std::endl;
std::cout << "8 - Adjoint of the matrix" << std::endl;
std::cout << "9 - Inverse of the matrix" << std::endl;
std::cout << "===============================================================" << std::endl;
}
Matrix createMatrix(int numberOfRows, int numberOfColumns) {
std::vector<std::vector<double>> matrices(numberOfRows, std::vector<double>(numberOfColumns));
Matrix matrix{matrices};
double value;
for (int i = 0; i < numberOfRows; i++) {
for (int j = 0; j < numberOfColumns; j++) {
std::cout << "Enter the values you want to fill in " << i << "," << j << " location" << std::endl;
std::cin >> value;
matrix.setElement(i, j, value);
matrix.print();
std::cout << std::endl;
}
}
return matrix;
}