Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <windows.h>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- typedef unsigned short int USI;
- class Matrix
- {
- private:
- USI Matrix_Size;
- int**m;
- static USI HOW_MUCH;
- USI numb;
- public:
- Matrix();
- Matrix(USI M_S);
- Matrix(USI M_S,int** m);
- ~Matrix();
- friend ostream& operator<< (ostream&, const Matrix&);
- bool operator==(const Matrix&);
- const Matrix& operator= (const Matrix&);
- Matrix& operator+ (const Matrix&);
- };
- Matrix::Matrix()
- {
- HOW_MUCH++;
- numb = HOW_MUCH;
- cout << "ds";
- cin >> Matrix_Size;
- m = new int*[Matrix_Size];
- for (USI l = 0; l < Matrix_Size; l++) m[l] = new int[Matrix_Size];
- for (USI s = 0; s < Matrix_Size; s++)
- {
- for (USI j = 0; j < Matrix_Size; j++)
- {
- *(*(m + s) + j) = rand() % 120;
- }
- }
- }
- Matrix::~Matrix()
- {
- for (USI l = 0; l < Matrix_Size; l++) delete[]m[l];
- delete m;
- }
- bool Matrix::operator==(const Matrix& s)
- {
- if (Matrix_Size == s.Matrix_Size)
- {
- for (USI i = 0; i < Matrix_Size; i++)
- {
- for (USI j = 0; j < Matrix_Size; j++)
- {
- if (!(*(*(s.m) + i) + j == *(*(m + i) + j))) return false;
- }
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- const Matrix& Matrix::operator=(const Matrix& s)
- {
- for (USI l = 0; l < Matrix_Size; l++) delete[]m[l];
- delete m;
- m = new int*[Matrix_Size];
- for (USI l = 0; l < Matrix_Size; l++) m[l] = new int[Matrix_Size];
- Matrix_Size = s.Matrix_Size;
- for (USI i = 0; i < s.Matrix_Size; i++)
- {
- for (USI j = 0; j < s.Matrix_Size; j++)
- {
- m[i][j] = s.m[i][j];
- }
- }
- return *this;
- }
- Matrix& Matrix::operator+ (const Matrix& s)
- {
- if (s.Matrix_Size == Matrix_Size)
- {
- Matrix buff(Matrix_Size);
- for (USI i = 0; i < Matrix_Size; i++)
- {
- for (USI j = 0; j < Matrix_Size; j++)
- {
- *(*(buff.m + i) + j) = *(*(s.m + i) + j) + *(*(m + i) + j);
- }
- }
- cout << "suck my eldak" << endl;
- cout << buff;
- return buff;
- }
- else
- {
- Matrix buff(5);
- cout << "Sorry, but you can't sum this matrix! RANDOM MATRIX FOR YOU!" << endl;
- return buff;
- }
- }
- USI Matrix::HOW_MUCH = 0;
- int main()
- {
- Matrix z,g,y;
- cout << z << endl << g << endl;
- Matrix ty = g + z;
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement