Operator so assignment works for matrix


// The following provides starter code for a 2D matrix template
// have a constructor for a NxM matrix, and overloads the () operator
// for indexing (see example in main)

// add the following:
// copy constructor
// destructor
// overload the = operator so assignment works for Matrix 
// (note in sample code that = works for single elements)
// a member function that prints the matrix to standard output
// a member function that inputs a Matrix from standard input
// overload the >> and << operators so they read/write a matrix

// add calls to main demonstrating that your copy constructor, output
// and input functions work 

// starter matrix template ( from Professor Botting )

#include
#include

using namespace std;

template class Matrix
{
private:
int R; // row
int C; // column
T *m; // pointer to T
public:
T &operator()(int r, int c){ return m[r+c*R];}
Matrix(int R0, int C0){ R=R0; C=C0; m=new T[R*C]; }

};


int main()
{
Matrix a(3,3);
a(1,1)=1;
cout << a(1,1);

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Operator so assignment works for matrix
Reference No:- TGS092527

Expected delivery within 24 Hours