Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Fill in the code needed for the operator * as well as the deconstructor ~Matrix. This is the code at the bottom included in the
Fill in the code needed for the operator as well as the deconstructor ~Matrix. This is the code at the bottom included in the image. Please use the remaining code here as a foundation to finish the rest #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& operatorifstream& o Matrix& m;
This forward declaration of operator is necessary Since operator is a template function.
template
ostream& operatorostream& 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& operatorostream& o const Matrix & m;
friend ifstream& operatorifstream& o Matrix& m;
private:
T m; dimensional dynamic array
const int R; number of rows
const int C; number of columns
public:
Matrixint R int C;
Matrix;
~Matrix;
Matrix operatorconst Matrix& other; matrix multiplication
class sizeerror;exception class
; default constructor
template
Matrix::Matrix : R Csetting const R and C to initial value,
m NULL;
constructor to create a matrix, row x col
template
Matrix::Matrixint row, int col : Rrow Ccolsetting const R and C
ifrow col
m NULL;
return;
m new TRC; this doesn't compile
m new TR; create a single dimensional array of pointers of the T type
for int i; i
ifstream& operatorifstream& fin, Matrix& mrx
for int i ; i mrxR; i
for int j ; j mrxC; j
fin mrxmij;
return fin;
output the matrix to screen in the following format. Allocate spaces for each value.
template
ostream& operatorostream& o const Matrix& mrx
for int i ; i mrxR; i
for int j ; j mrxC; j
o setw mrxmij;
o endl; move to the next line after printing each row
return o;
matrix multiplication
template
Matrix Matrix::operatorconst Matrix& other
check if the matrices are comparable. If m is mxn m has to be nxk
ifcannot 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started