4. 3 matrix 1. definition a m*n matrix is a table with m rows and n columns. m and n are the dimensions of the matrix For example: a 5*4 matrix 234 1(7209 36420 48 96
4.3 Matrix 1.definition: a m*n Matrix is a table with m rows and n columns. m and n are the dimensions of the matrix. For example: a 5*4 matrix 7 2 0 9 0 1 0 5 6 4 2 0 8 2 7 3 1 4 9 6 1 2 3 4 5 1 2 3 4
4.3 Matrix 2. Matrix can be implemented with a two dimensional array int x[mn or Array2D<int>x[mn use x(i, j to index the matrix element 1>=1&&i<=m&&=l&&i<=n the private data member is rows, cols element
4.3 Matrix 2.Matrix can be implemented with a two dimensional array . int x[m][n] or Array2D<int>x[m][n] • use x(i,j) to index the matrix element, i>=1&&i<=m&&j>=1&&j<=n the private data member is rows, cols, element
4.3 Matrix Class definition of matrix(program 4-12) template<class t> class Matrix i public Matrix(int r=o,int c=0) Matrix(const Matrix<t>&m) Matrixordeletel element; int Rowsoconst return rows
4.3 Matrix Class definition of Matrix(program 4-12) template<class T> class Matrix { public: Matrix(int r=0,int c=0); Matrix(const Matrix<T>&m); ~Matrix(){delete[] element;} int Rows()const {return rows;}
4.3 Matrix int Columns Oconstreturn cols; 1 T& operator ((int i, int Const Matrix<t>& operator(const Matrix<t>& m) Matrix<t> operator+Const Matrix<t> operator+(const Matrix<t>& m)const Matrix<t> operator-Oconst Matrix<t> operator-(const Matrix<t>& m)const Matrix<t> operator* (const Matrix<T>& m)const Matrix<t>& operator+-(const t& x
4.3 Matrix int Columns ()const{return cols;} T& operator ()(int i,int j)const; Matrix<T>& operator=(const Matrix<T>& m); Matrix<T> operator+()const; Matrix<T> operator+(const Matrix<T>& m)const; Matrix<T> operator-()const; Matrix<T> operator-(const Matrix<T>& m)const; Matrix<T> operator*(const Matrix<T>& m)const; Matrix<T>& operator+=(const T& x);
4.3 Matrix private int rows. cols //matrix dimensions T* element; //element array
4.3 Matrix private: int rows,cols;//matrix dimensions T* element; //element array };