Matrix Class C++ Example
Define matrix class with dynamic memory allocation for 2-D matrix. Include constructors, destructor, overload + (m1+m2, m1+3 & 4+m2), -, << and >> operators. Also overload new and delete operators by using malloc & free functions internally #include<iostream> using namespace std; #include<cstdlib> #include<new> class matrix { int **array; int row; int column; public: //default constructor matrix() { array=NULL; row=0; column=0; } //single parameter constructor(square matrix) matrix(int length) { int i,j; array=(int **)new int[length]; row=length; column=length; for(i=0;i<length;i++) array[i]=new int[length]; for(i=0;i<length;i++) for(j=0;j<length;j++) array[i][j]=0; } //double parameterized constructor(rectangular matrix) matrix(int r,int c) { int i,j; row=r; column=c; array=(int **)new int[r]; for(i=0;