Using C++, Write a matrix class. You need to write a matrix class (Mat) that imp
ID: 3848470 • Letter: U
Question
Using C++,
Write a matrix class.
You need to write a matrix class (Mat) that implements common matrix functionality. You need use the Mat.h and Mat.cpp files to write this class. Your Mat class should meet the following requirements.
Dynamic Matrix Allocation:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Read and write from istream and ostream, respectively.
Reading from a istream:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Write from a istream
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Copy constructor and assignment operator with error checking
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Scalar arithmatic
Overload the following operators for matrix-scalar (double) addition/subtraction/multiplication/division: +, -, *, /, +=, -=, *= and /=.
Matrix arithmatic
Overload the following operators for matrix-matrix addition/subtraction/multiplication: +, -, *, +=, -= and *=. Don’t forget to error check. E.g., for addition or subtraction the two matrices must be the same size, and for multiplication the number of columns of the first matrix should be equal to the number of rows of the second matrix.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Indexing
Overload [] operator to support the following functionality:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Fill up
Develop the following functions:
Destructor to deallocate the memory;
Mat::ones() to initialize a matrix to all 1s;
Mat::zeros() to initialize a matrix to all 0s; and
Mat::rand() to intialize a matrix to random values between 0 and 1.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Explanation / Answer
#include using namespace std; main() { int m, n, c, d, first[10][10], second[10][10], sum[10][10]; cout > m >> n; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.