Untitled
unknown
plain_text
a year ago
1.8 kB
4
Indexable
Never
#include <iostream> #include "Matrix.h" using namespace std; int main() { Matrix matrix; matrix.SetSizeArray(3, 3); matrix.MatrixMultNum(3); matrix.MatrixMultMatrix(); //Only square matrix } ----------------------------------------------------------------------------------- #include <iostream> #include <vector> #include <random> using namespace std; class Matrix { private: int row; int column; int number; vector<vector<int>> array; public: void Set_and_ShowArray(int row_amount, int column_amount) { srand(time(NULL)); for (int i = 0; i < row_amount; i++) { vector<int> line; for (int j = 0; j < column_amount; j++) { line.push_back((rand() % 201) - 100); cout << line[j] << '\t'; } array.push_back(line); cout << '\n'; } cout << "-------------------" << '\n'; } void SetSizeArray(int x, int y) { row = x; column = y; Set_and_ShowArray(row, column); } void MatrixMultMatrix() { vector<vector<int>> mult_matr_array; for (int i = 0; i < row; i++) { vector<int> line; for (int j = 0; j < column; j++) { int num = 0; for (int k = 0; k < row; k++) num += array[i][k] * array[k][j]; line.push_back(num); cout << line[j] << '\t'; } mult_matr_array.push_back(line); cout << '\n'; } cout << "-------------------" << '\n'; } void MatrixMultNum(int number) { vector<vector<int>> mult_num_array; for (int i = 0; i < row; i++) { vector<int> line; for (int j = 0; j < column; j++) { line.push_back(array[i][j] * number); cout << line[j] << '\t'; } mult_num_array.push_back(line); cout << '\n'; } cout << "-------------------" << '\n'; } };