Question: Write a class named as Matrix with data members: Int **ptr, Int rows; Int cols; Default Constructor will initialize rows cols=2 and allocate memory
Write a class named as Matrix with data members: Int **ptr, Int rows; Int cols; Default Constructor will initialize rows cols=2 and allocate memory to ptr. Overloaded constructor Matrix Add(Matrix m) Matrix(int r, int c) o It will initialize rows=r, cols-c and allocate memory to ptr Matrix Subtract(Matrix m) Input() . o It will add this Matrix to m and return resultant object. o It will subtract m from this Matrix and return resultant object. Also write checks for same rows and cols for add and subtract functions. If size of two matrices is different, then addition or subtraction can not perform, o This function will input the elements of matrix from user PrintMatrix() o This function will display the elements of matrix on console in matrix form in Main: Write a destructor to allocate the memory. Matrix A(3,3); Matrix B(3,3), C(3,3); A.Input()); B.Input(): C = A.Add(B); C. PrintMatrix():
Step by Step Solution
There are 3 Steps involved in it
include class Matrix private int ptr int rows int cols public Matrixint r 2 int c 2 rowsr colsc ptr new introws cols Matrix AddMatrix m if rows mrows cols mcols stdcout Size of two matrices is differe... View full answer
Get step-by-step solutions from verified subject matter experts
