#include "Matrix.h" using namespace std; int main(int argc, const char * argv[]) { // Do not modify this code srand(time(NULL)); const int max_row = 3, max_col = 3; Matrix m1(max_row, max_col); for (int i = 0; i ------------------------------------------------------------------------------------------------------------------------------------------------
.h file
#ifndef Matrix_h #define Matrix_h
#include
class Matrix{ private: int rows, cols; double** p; public: Matrix(); // a default constructor Matrix(int, int); //a parameterized constructor Matrix(const Matrix &); // a copy constructor void set(int i, int j, double val); //set value at i and j double get(int& i, int & j) const; //get value at i and j //Assigns (copies) a Matrix. Return the same Matrix& assign(const Matrix &);
//Adds two Matrices and returns the result Matrix& add(const Matrix&);
//Subtracts two Matrices and returns the result Matrix& subtract(const Matrix&);
//Returns the dot product of two Matrices. Refer below fig. Matrix& multiply(const Matrix&);
//Element-wise multiplies two Matrices and return the result. //Refer below fig. Matrix& multiplyElement(const Matrix&);
//Add a value to all elements in the Matrix Matrix& add(double);
//Multiply all elements in the Matrix by a value Matrix& multiply(double);
//Displays all elements in the Matrix. //The result should look like a matrix void display();
//destructor ~Matrix();
};
#endif /* Matrix_hpp */
Construct the following class Matrix with corresponding .h and .cpp files and develop all methods including constructors and destructors. Download the main.cpp for test cases. class Matrix private: int rows, cols; double** P; public: Matrix(); // a default constructor Matrix(int, int); //a parameterized constructor Matrix(const Matrix &); 11 a copy constructor void set(int i, int j, double val); //set value at i and j double get(int& i, int & j) const; //get value at i and i //Assigns (copies) a Matrix. Return the same Matrix& assign (const Matrix &); //Adds two Matrices and returns the result Matrix& add(const Matrix&); //Subtracts two Matrices and returns the result Matrix& subtract(const Matrix&); //Returns the dot product of two Matrices. Refer below fig. Matrix& multiply(const Matrix&); //Element-wise multiplies two Matrices and return the result. //Refer below fig. Matrix& multiplyElement(const Matrix&); //Add a value to all elements in the Matrix Matrix& add(double); //Multiply all elements in the Matrix by a value Matrix& multiply(double); //Displays all elements in the Matrix. //The result should look like a matrix void display(); //destructor Dot product vs. element-wise Matrix(); }; Element-wise NE BY CG DH G H ACN AK-N.CO Dot product M .. Ork.E.PO DEFE G H 1 N 0 GUL+N GX+M+TO Construct the following class Matrix with corresponding .h and .cpp files and develop all methods including constructors and destructors. Download the main.cpp for test cases. class Matrix private: int rows, cols; double** P; public: Matrix(); // a default constructor Matrix(int, int); //a parameterized constructor Matrix(const Matrix &); 11 a copy constructor void set(int i, int j, double val); //set value at i and j double get(int& i, int & j) const; //get value at i and i //Assigns (copies) a Matrix. Return the same Matrix& assign (const Matrix &); //Adds two Matrices and returns the result Matrix& add(const Matrix&); //Subtracts two Matrices and returns the result Matrix& subtract(const Matrix&); //Returns the dot product of two Matrices. Refer below fig. Matrix& multiply(const Matrix&); //Element-wise multiplies two Matrices and return the result. //Refer below fig. Matrix& multiplyElement(const Matrix&); //Add a value to all elements in the Matrix Matrix& add(double); //Multiply all elements in the Matrix by a value Matrix& multiply(double); //Displays all elements in the Matrix. //The result should look like a matrix void display(); //destructor Dot product vs. element-wise Matrix(); }; Element-wise NE BY CG DH G H ACN AK-N.CO Dot product M .. Ork.E.PO DEFE G H 1 N 0 GUL+N GX+M+TO