Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class Matrix
  4. {
  5.     public:
  6.         int matrix[3][3];
  7.         Matrix(int m[3][3])
  8.         {
  9.             for(int i=0;i<3;i++)
  10.             {
  11.                 for(int j=0;j<3;j++)
  12.                 {
  13.                    matrix[i][j] = m[i][j] ;
  14.                 }
  15.             }
  16.         }
  17.         void show()
  18.         {
  19.             for(int i=0;i<3;i++)
  20.             {
  21.                 for(int j=0;j<3;j++)
  22.                 {
  23.                     cout << matrix[i][j] << " " ;
  24.                 }
  25.                 cout << endl ;
  26.             }
  27.         }
  28.  
  29.         void operator+(Matrix &m)
  30.         {
  31.           for(int i=0;i<3;i++)
  32.             {
  33.                 for(int j=0;j<3;j++)
  34.                 {
  35.                    cout << matrix[i][j]+m.matrix[i][j] << " " ;
  36.                 }
  37.                 cout << endl ;
  38.             }
  39.         }
  40.  
  41.         void operator-(Matrix &m)
  42.         {
  43.           for(int i=0;i<3;i++)
  44.             {
  45.                 for(int j=0;j<3;j++)
  46.                 {
  47.                    cout << matrix[i][j]-m.matrix[i][j] << " " ;
  48.                 }
  49.                 cout << endl ;
  50.             }
  51.         }
  52. };
  53. int main(void)
  54. {
  55.     int a[3][3] = {{2,2,2},{2,2,2},{2,2,2}};
  56.     int b[3][3] = {{1,1,1},{1,1,1},{1,1,1}};
  57.     Matrix m1(a), m2(b);
  58.     cout << "m1:" << endl;
  59.     m1.show() ;
  60.     cout << "m2:" << endl;
  61.     m2.show() ;
  62.     cout << "m1+m2:" << endl;
  63.     m1+m2 ;
  64.     cout << "m1-m2:" << endl;
  65.     m1-m2 ;
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement