Question: C++ // please solve Complete the code: #include using namespace std; template class Matrix { private: T **arr; int rows; int cols; public: Matrix(int r
C++ // please solve

Complete the code:
#include
private: T **arr; int rows; int cols; public: Matrix(int r = 4, int c = 4): rows(r), cols(c) { } Matrix(const Matrix &rhs) {
} Matrix operator=(const Matrix &rhs) {
} bool operator == (const Matrix& rhs) {
}
friend Matrix operator + (const Matrix& m1, const Matrix& m2) { } friend Matrix operator - (const Matrix& m1, const Matrix& m2) { }
friend ostream& operator>(istream& ins, Matrix& rhs) { }
T& operator () (const int r_index, const int c_index) { } const T& operator () (const int r_index, const int c_index) const { } Matrix& operator++(){ // Pre increment. } Matrix operator++(int)//post increment { } ~Matrix() { } };
int main() {
Matrix //Testing addition + and subtraction - operators. cout //Testing comparison operator = cout //Testing operator () cout > index1; cout > index2; cout > value; a(index1, index2) = value; cout Exercise 1: Create a template class Matrix that has two-dimensional array of any number of rows (with a default of 4 rows) and any number of columns (with a default of 4 columns). Matrix should make use of a standard C++, dynamically allocated two-dimensional array to store its elements. Design, implement and test the Matrix class. Your class should contain at least the following features, namely: A default constructor and parametrized constructor with two arguments m (the number of rows) and n (the number of columns). It initializes all elements to zeros. A destructor A copy constructor and an assignment operator "=". A comparison operator "=". Matrix addition "+" and subtraction operators. Matrix insertion ">" operators (using row-col format). operator () to provide indexing. For example, in a 3-by-5 Matrix called A, the programmer could write A (1,3) to access the element at row 1 and column 3. There should be two versions of operator(), one that returns int & so an element of a Matrix can be used as an Ivalue and one that returns const int & so an element of a Matrix can be used as an evalue. Two versions of operator ++: post and pre increment operators that adds 1 to every element of the matrix. . Note: You must create an array of pointers to implement Matrix
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
