Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. class matrix
  7. {
  8. public:
  9.     int n, m;
  10.     int a[100][100];
  11.     void enter_the_matrix()
  12.     {
  13.         cout << "Enter size of matrix: " << endl; //введите размер матрицы
  14.        
  15.         cin >> n >> m;
  16.         cin.ignore();
  17.         cout << "Enter the matrix: " << endl; //введите матрицу
  18.         for (int i = 0; i < n; i++)
  19.         {
  20.             for (int j = 0; j < m; j++)
  21.             {
  22.                
  23.                 cin >> a[i][j];
  24.                 cin.ignore();
  25.             }
  26.         }
  27.     }
  28.     void addition_matrix(matrix A, matrix B)
  29.     {
  30.         if (A.n != B.n || A.m != B.m)
  31.         {
  32.             cout << "addition imposible" << endl; //cложение невозможно
  33.             return;
  34.         }
  35.         for (int i = 0; i < A.n; i++)
  36.         {
  37.             for (int j = 0; j < A.m; j++)
  38.             {
  39.                 a[i][j] = A.a[i][j] + B.a[i][j];
  40.                 cout << a[i][j] << " ";
  41.             }
  42.             cout << endl;
  43.         }
  44.     }
  45.     void multiplication_matrix(matrix A, matrix B)
  46.     {
  47.         if (A.m != B.n)
  48.         {
  49.             cout << "multiplication imposible" << endl; //умножение невозможно
  50.             return;
  51.         }
  52.         for (int i = 0; i < A.n; i++)
  53.         {
  54.             for (int j = 0; j < B.m; j++)
  55.             {
  56.                 int s = 0;
  57.                 for (int k = 0; k < B.n; k++)
  58.                 {
  59.                     s += A.a[i][k] * B.a[k][j];
  60.                 }
  61.                 a[i][j] = s;
  62.                 cout << s << " ";
  63.             }
  64.             cout << endl;
  65.         }
  66.     }
  67.     void out_matrix()
  68.     {
  69.         for (int i = 0; i < n; i++)
  70.         {
  71.             for (int j = 0; j < m; j++)
  72.             {
  73.                 cout << a[i][j] << " ";
  74.             }
  75.             cout << endl;
  76.         }
  77.     }
  78. };
  79.  
  80. int main()
  81. {
  82.     matrix A, B;
  83.     A.enter_the_matrix();
  84.     B.enter_the_matrix();
  85.     matrix C;
  86.     cout << " Summ of matrixes" << endl; //cумма матриц
  87.     C.addition_matrix(A, B);
  88.     cout << " Composition of matrixes" << endl; //произведение матриц
  89.     C.multiplication_matrix(A, B);
  90.     system("pause");
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement