Advertisement
Guest User

Untitled

a guest
May 17th, 2016
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4. #include <ctime>
  5. #include <iomanip>
  6. using namespace std;
  7.  
  8. typedef unsigned short int USI;
  9.  
  10. class Matrix
  11. {
  12. private:
  13.     USI Matrix_Size;
  14.     int**m;
  15.     static USI HOW_MUCH;
  16.     USI numb;
  17. public:
  18.     Matrix();
  19.     Matrix(USI M_S);
  20.     Matrix(USI M_S,int** m);
  21.     ~Matrix();
  22.     friend ostream& operator<< (ostream&, const Matrix&);
  23.     bool operator==(const Matrix&);
  24.     const Matrix& operator= (const Matrix&);
  25.     Matrix& operator+ (const Matrix&);
  26. };
  27. Matrix::Matrix()
  28. {
  29.     HOW_MUCH++;
  30.     numb = HOW_MUCH;
  31.     cout << "ds";
  32.     cin >> Matrix_Size;
  33.     m = new int*[Matrix_Size];
  34.     for (USI l = 0; l < Matrix_Size; l++) m[l] = new int[Matrix_Size];
  35.     for (USI s = 0; s < Matrix_Size; s++)
  36.     {
  37.         for (USI j = 0; j < Matrix_Size; j++)
  38.         {
  39.             *(*(m + s) + j) = rand() % 120;
  40.         }
  41.     }
  42. }
  43.  
  44. Matrix::~Matrix()
  45. {
  46.     for (USI l = 0; l < Matrix_Size; l++) delete[]m[l];
  47.     delete m;
  48. }
  49.  
  50. bool Matrix::operator==(const Matrix& s)
  51. {
  52.     if (Matrix_Size == s.Matrix_Size)
  53.     {
  54.         for (USI i = 0; i < Matrix_Size; i++)
  55.         {
  56.             for (USI j = 0; j < Matrix_Size; j++)
  57.             {
  58.                 if (!(*(*(s.m) + i) + j == *(*(m + i) + j))) return false;
  59.             }
  60.         }
  61.         return true;
  62.     }
  63.     else
  64.     {
  65.         return false;
  66.     }
  67. }
  68.  
  69. const Matrix& Matrix::operator=(const Matrix& s)
  70. {
  71.     for (USI l = 0; l < Matrix_Size; l++) delete[]m[l];
  72.     delete m;
  73.     m = new int*[Matrix_Size];
  74.     for (USI l = 0; l < Matrix_Size; l++) m[l] = new int[Matrix_Size];
  75.         Matrix_Size = s.Matrix_Size;
  76.         for (USI i = 0; i < s.Matrix_Size; i++)
  77.         {
  78.             for (USI j = 0; j < s.Matrix_Size; j++)
  79.             {
  80.                 m[i][j] = s.m[i][j];
  81.             }
  82.         }
  83.         return *this;
  84. }
  85.  
  86. Matrix& Matrix::operator+ (const Matrix& s)
  87. {
  88.     if (s.Matrix_Size == Matrix_Size)
  89.     {
  90.         Matrix buff(Matrix_Size);
  91.         for (USI i = 0; i < Matrix_Size; i++)
  92.         {
  93.             for (USI j = 0; j < Matrix_Size; j++)
  94.             {
  95.                 *(*(buff.m + i) + j) = *(*(s.m + i) + j) + *(*(m + i) + j);
  96.             }
  97.         }
  98.         cout << "suck my eldak" << endl;
  99.         cout << buff;
  100.         return buff;
  101.     }
  102.     else
  103.     {
  104.         Matrix buff(5);
  105.         cout << "Sorry, but you can't sum this matrix! RANDOM MATRIX FOR YOU!" << endl;
  106.         return buff;
  107.     }
  108. }
  109.  
  110. USI Matrix::HOW_MUCH = 0;
  111.  
  112. int main()
  113. {
  114.     Matrix z,g,y;
  115.     cout << z << endl << g << endl;
  116.     Matrix ty = g + z;
  117.     _getch();
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement