Advertisement
KrimsN

class exc Dor

Apr 9th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <iostream>
  3. #include <iostream>
  4. #include <string>
  5. #include <iomanip>
  6. #include <exception>
  7.  
  8.  
  9.  
  10. namespace labworks
  11. {
  12.     class MyException : public std::exception {
  13.     private:
  14.         int _id;
  15.         std::string msg;
  16.     public:
  17.         MyException(const char *Message, int ID)
  18.         : _id(ID)
  19.         , msg(Message)
  20.         {
  21.         }
  22.         const char*  what() const throw() override
  23.         {
  24.             return msg.c_str();
  25.         }
  26.        
  27.         int ID() const
  28.         {
  29.             return _id;
  30.         }
  31.     };
  32.    
  33.     class Matrix
  34.     {
  35.     private:
  36.         int _rows;
  37.         int _cols;
  38.         int _id;
  39.         double* _elements;
  40.         static int s_count;
  41.     public:
  42.         Matrix();
  43.         Matrix(double Skalar);
  44.         Matrix(const Matrix& A);
  45.         Matrix(Matrix&& A) noexcept;
  46.  
  47.         explicit Matrix(int Rows);
  48.         Matrix(int Rows, double Value);
  49.         Matrix(int Rows, int Cols);
  50.         Matrix(int Rows, int Cols, double Value);
  51.  
  52.         Matrix(int Rows, double(*func) (int, int));
  53.         Matrix(int Rows, int Cols, double(*func) (int, int));
  54.         Matrix(int Rows, const double* Massive, int Size = -1, bool iter = false);
  55.         Matrix(int Rows, int Cols, const double* Massive, int Size = -1, bool iter = false);
  56.  
  57.         int GetRows() const;
  58.         int GetCols() const;
  59.         int GetId() const;
  60.         static int GetCount();
  61.         const double* GetElements() const;
  62.  
  63.         int SetRows(int Rows);
  64.         int SetCols(int Cols);
  65.         int SetSize(int Rows, int Cols);
  66.  
  67.         bool MultCheck(const Matrix& B) const;
  68.         bool SummCheck(const Matrix& B) const;
  69.         double SearchMax() const;
  70.         double SearchMin() const;
  71.  
  72.  
  73.         //operator peregruzki
  74.         Matrix& operator = (const Matrix& A);
  75.         Matrix& operator += (const Matrix& A);
  76.         Matrix& operator -= (const Matrix& A);
  77.         Matrix& operator *= (const Matrix& A);
  78.         Matrix& operator *= (double Skalar);
  79.         Matrix& operator = (double Skalar);
  80.  
  81.         class Pointer
  82.         {
  83.         public:
  84.            
  85.             Pointer(double* A, int Size, int ID) :
  86.                 a(A), size(Size), id(ID)
  87.             {
  88.             }
  89.             double operator [] (int i) const
  90.             {
  91.                 if (size > i)
  92.                     return a[i];
  93.                 else
  94.                     throw MyException("Array index out of bounds!", id);
  95.             }
  96.             double& operator [] (int i)
  97.             {
  98.                 if (size > i)
  99.                     return a[i];
  100.                 else
  101.                     throw MyException("Array index out of bounds!", id);
  102.             }
  103.  
  104.             double* a;
  105.             int size;
  106.             int id;
  107.         };
  108.  
  109.         Pointer operator[] (int index);
  110.         const Pointer operator[] (int index) const;
  111.         double& operator() (int i, int j);
  112.         double operator() (int i, int j) const;
  113.         friend std::ostream& operator <<(std::ostream& s, const Matrix& A);
  114.  
  115.         ~Matrix();
  116.  
  117.     };
  118.  
  119.     Matrix operator + (const Matrix& A, const Matrix& B);
  120.     Matrix operator - (const Matrix& A, const Matrix& B);
  121.     Matrix operator * (const Matrix& A, const Matrix& B);
  122.     Matrix operator * (const Matrix& A, double Skalar);
  123.     Matrix operator * (double Skalar, const Matrix& A);
  124.  
  125.    
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement