Question: Please update my code to answer exercise2. This is the answer for exercise 1: The code: #include using namespace std; template class Matrix { private:


Please update my code to answer exercise2.
This is the answer for exercise 1:
The code:
#include
Matrix(int r = 4, int c = 4) :row(r), col(c) {
arr = new T * [row]; for (int i = 0; i
} Matrix(const Matrix& rhs) { row = rhs.row; col = rhs.col;
arr = new T * [row];
for (int i = 0; i
for (int i = 0; i
}
Matrix operator=(const Matrix& rhs) {
row = rhs.row; col = rhs.col; arr = new T * [row]; for (int i = 0; i
arr[i][j] = rhs.arr[i][j]; } } return *this;
} bool operator == (const Matrix& rhs) { if (row != rhs.row || col != rhs.col) return false; for (int i = 0; i
} Matrix operator += (const Matrix& rhs) { if (row != rhs.row) exit(1); if (col != rhs.col) exit(2); for (int i = 0; i
}
Matrix operator -= (const Matrix& rhs) {
if (row != rhs.row) exit(1); if (col != rhs.col) exit(2); for (int i = 0; i
friend Matrix operator + (const Matrix& m1, const Matrix& m2) { if (m1.row != m2.row) { cout
}
friend Matrix operator - (const Matrix& m1, const Matrix& m2) { if (m1.row != m2.row) { cout
}
friend ostream& operator
friend istream& operator>>(istream& in, const Matrix& rhs) { int value; cout > value; rhs.arr[i][j] = value;
} } return in;
}
T& operator () (const int r_index, const int c_index) {
if (r_index >= 0 && c_index >= 0 && r_index
}
const T& operator () (const int r_index, const int c_index) const { if (r_index >= 0 && c_index >= 0 && r_index
};
int main() {
Matrix //Testing addition + and subtraction - operators. //Testing addition assignment += and subtraction assignment - = operators. cout //Testing comparison operator = cout //Testing operator () cout > index1; cout > index2; cout > value; a(index1, index2) = value; cout cout //Ex2 Bonus return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
