ac1dra1n

matrix.h

Sep 19th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. /*
  2.  
  3. Matrix class creation
  4.  
  5. The matrix takes the number of rows and the number of columns upon creation. Each element of the matrix is input using
  6. either the Initialize() or Populate() functions. Initialize() might be removed later since it is not as general as
  7. Populate()
  8.  
  9. */
  10.  
  11. #pragma once
  12. template <class T>
  13. class Matrix {
  14. private:
  15.     int nRow, nCol;
  16.     T* elem;
  17. public:
  18.     Matrix(int a, int b) : nRow(a), nCol(b) {
  19.         elem = new T[nRow * nCol];
  20.     }
  21.     Matrix() : nRow(0), nCol(0) {
  22.         elem = new T[0];
  23.         elem[0] = 0;
  24.     }
  25.     int getRow();   //Returns number of rows in matrix
  26.     int getCol();   //Returns number of columns in matrix
  27.     void Initialize();  //Function for matrix class to handle data input, not as general as Populate
  28.     void Populate(int* nRowPos, int* nColPos, T vals);  //Function inputs given data into matrix; does not handle the input
  29.     void Deinitialize();    //Delete the array in matrix
  30.     void Show();    //Display matrix
  31.     //T Determinant(T n = 1, T det = 0);    //Calculate matrix determinant
  32.     //T Trace();    //Calculate trace of matrix
  33.     T Determinant(T n = 1, T det = 0);
  34.     T Trace();
  35.     Matrix<T> Reduce(int r, int c); //Remove a given row and column from matrix
  36.     Matrix<T> operator+ (const Matrix& rhs);    //Define matrix addition
  37.     //Matrix<T> operator- (const Matrix& rhs);  //Define matrix subtraction(TODO)
  38.     Matrix<T> operator* (const Matrix& rhs);    //Define matrix multiplication
  39.     bool operator== (const Matrix& rhs);    //Define matrix equality
  40.     bool operator!= (const Matrix& rhs);    //Define matrix inequality
  41. };
Advertisement
Add Comment
Please, Sign In to add comment