Question: matrix class Replace the ?????s #include #include #include #include using namespace std; //This forward declaration of Matrix class is necessary because the following operator>> and

matrix class

Replace the ?????s

#include #include #include #include using namespace std;

//This forward declaration of Matrix class is necessary because the following operator>> and << are using Matrix as a parameter template class Matrix;

//This forward declaration of operator>> is necessary Since operator<< is a template function. template ifstream& operator>>(ifstream& o, Matrix& m);

//This forward declaration of operator<< is necessary Since operator<< is a template function. template ostream& operator<<(ostream& o, const Matrix & m);

//Template class so we can have a matrix of any data types, int or double template class Matrix { //friend functions so they can access the private members friend ostream& operator<< (ostream& o, const Matrix & m); friend ifstream& operator>> (ifstream& o, Matrix& m);

private: T** m; //2 dimensional dynamic array const int R; //number of rows const int C; //number of columns

public: Matrix(int R, int C); Matrix(); ~Matrix(); void fill(); //filling the matrix Matrix operator*(const Matrix& other);// matrix multiplication class size_error{};//exception class };

//default constructor template Matrix::Matrix() : R(0), C(0) //setting const R and C to initial value, 0. { m = NULL; }

//constructor to create a matrix, row x col template Matrix::Matrix(int row, int col) : R(row), C(col) //setting const R and C { if(row <= 0 || col <= 0) { m = NULL; return; }

//m = new T[R][C]; //this doesn't compile m = new T*[R]; //create a single dimensional array of pointers of the T type for (int i=0; i

//initialize each element to 0 for(int row = 0; row < R; row++) for(int col = 0; col < C; col++) m[row][col] = 0; }

//fill a matrix using an input file template ifstream& operator>>(ifstream& fin, Matrix& mrx) { /* for(????????????????) for(????????????????) ??? >> ?????[??][??]; return fin; */ }

/*output the matrix to screen in the following format. Allocate 5 spaces for each value. 1 1 1 2 2 2 3 3 3 4 4 4 */ template ostream& operator<<(ostream& o, const Matrix& mrx) { /* ????? //multiple lines of code here //use setw(5) to allocate 5 spaces to show each value */ return o; }

//matrix multiplication template Matrix Matrix::operator*(const Matrix& other) { /* //check if the 2 matrices are comparable. If m1 is mxn, m2 has to be nxk. if(??????????) //cannot compute because of incomparable sizes ?????????; //throw an exception ???? //multiple lines of code */ }

//destructor template Matrix::~Matrix() { //destroy what is created in heap memory //if m is not NULL do the following //HINT: delete each dynamic array pointed to by each slot of m //delete m (m contains all rows) }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!