/*********************************************************************** * Matrix.h * * Header file for an implementation of a matrix of doubles. * Features overloading of basic arithmetic and comparison operators. * * Written by Paul Bonamy - 16 Feburary 2010 ************************************************************************/ #ifndef MATRIX_H #define MATRIX_H #include using namespace std; /*********************************************************************** * Relatively simple matrix class ***********************************************************************/ class Matrix { public: // constructors Matrix(); // default constructor - matrix of size 0 Matrix(int r, int c); // 0 - filled matrix of given size Matrix(const Matrix &m); // copy constructor Matrix(double **a, int r, int c); // matrix from array and size // destructor ~Matrix(); // support functions int getRows(); // returns number of rows int getCols(); // returns number of columns // operators overloaded as global functions friend ostream& operator<< ( ostream & out, const Matrix & m); // output operator // operators overloaded as member functions Matrix& operator= ( const Matrix & m); // assignment const Matrix operator+ ( const Matrix & m) const; // matrix addition Matrix operator+= ( const Matrix & m); // matrix addition const Matrix operator- ( const Matrix & m) const; // matrix subtraction Matrix operator-= ( const Matrix & m); // matrix subtraction const Matrix operator* ( const Matrix & m) const; // matrix multiplication const Matrix operator* ( const double & d) const; // scalar multiplication Matrix operator*= ( const Matrix & m); // matrix multiplication Matrix operator*= ( const double & d); // scalar multiplication const Matrix operator/ ( const double & d) const; // scalar division Matrix operator/= ( const double & d); // scalar division bool operator== (const Matrix &m) const; // equality bool operator!= (const Matrix &m) const; // inequality double& operator() (const int & r, const int & c); // subscript-like private: double **array; // array in which to store matrix values int rows, cols; // number of rows, cols in matrix }; #endif