Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- class Vector;
- class Matrix
- {
- public:
- int matrix[100][100], // статический массив
- rows = 0, // строки
- columns = 0; // столбцы
- friend void mulData(Matrix& m, Vector& v);
- Matrix()
- {
- rows = 5;
- columns = 5;
- srand(time(0));
- for (int ix = 0; ix < rows; ix++)
- for (int jx = 0; jx < columns; jx++)
- matrix[ix][jx] = rand() % 10 + 1;
- }
- Matrix(int r, int c)
- {
- rows = r;
- columns = c;
- srand(time(0));
- for (int ix = 0; ix < rows; ix++)
- for (int jx = 0; jx < columns; jx++)
- matrix[ix][jx] = rand() % 10 + 1;
- }
- Matrix(const Matrix& m)
- {
- rows = m.rows;
- columns = m.columns;
- for (int ix = 0; ix < rows; ix++)
- for (int jx = 0; jx < columns; jx++)
- matrix[ix][jx] = m.matrix[ix][jx];
- }
- void cout_m()
- {
- for (int ix = 0; ix < rows; ix++)
- {
- for (int jx = 0; jx < columns; jx++)
- {
- cout << setw(4) << matrix[ix][jx];
- }
- cout << endl;
- }
- cout << endl;
- }
- ~Matrix()
- {
- }
- };
- class Vector
- {
- public:
- int vector[100];
- int vector_size = 0;
- friend void mulData(Matrix& m, Vector& v);
- Vector()
- {
- vector_size = 5;
- for (int jx = 0; jx < vector_size; jx++)
- vector[jx] = rand() % 10 + 1;
- }
- Vector(int v_sz)
- {
- vector_size = v_sz;
- for (int jx = 0; jx < vector_size; jx++)
- vector[jx] = rand() % 10 + 1;
- }
- Vector(const Vector& vec)
- {
- vector_size = vec.vector_size;
- for (int jx = 0; jx < vector_size; jx++)
- vector[jx] = vec.vector[jx];
- }
- void cout_v()
- {
- for (int ix = 0; ix < vector_size; ix++)
- {
- cout << setw(4) << vector[ix] << endl;
- }
- cout << endl;
- }
- ~Vector()
- {
- }
- };
- void mulData(Matrix& m, Vector& v)
- {
- int out[100]; // выходной вектор
- // умножение элементов матрицы на вектор
- for (int ix = 0; ix < m.rows; ix++)
- {
- out[ix] = 0;
- for (int jx = 0; jx < m.columns; jx++)
- out[ix] += m.matrix[ix][jx] * v.vector[jx];
- }
- m.cout_m();
- v.cout_v();
- for (int ix = 0; ix < m.rows; ix++)
- {
- cout << out[ix] << " ";
- }
- cout << endl;
- }
- int main()
- {
- Matrix m;
- Vector v;
- mulData(m, v);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement