Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
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...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