Can you please help me solve this for C++? files needed are below, Names of file
ID: 3915898 • Letter: C
Question
Can you please help me solve this for C++? files needed are below, Names of files are in yellow in top left corner
ie: Section You are given a DynamicMatrix.h header file and an incomplete DynamicMatrix.cpp source file. You are required to implement a Parametrized Constructor and a Destructor for this class, such that: a) the Constructor allocates a dynamic 2D array to be used by the data member m_matrix of the class. It takes in only 2 parameters, the desired rows and columns of the matrix You are not required (but you are encouraged) to implement this with allocation checking) b) the Destructor deallocates the dynamic 2D array data (the m_matrix). The insertion operator overload implementation is already given. You are also give a lab8.cpp test source code file (and a Makefile) to test your code. 1. Sample input and output Please input the rows and then the columns of the DynamicMatrix object: Dynamic Matrix of 3 rows and 6 cols: (zeros here can also be any randomly initialized integer numbers)Explanation / Answer
Update your DynamicMatrix.cpp file as follows (Giving you the implementation for the constructor and Destructor. .. rest of code in file will not change). Please do rate the answer if it helped. Thank you
//constructor
DynamicMatrix::DynamicMatrix(int rows, int cols)
: m_rows(rows),
: m_cols(cols)
{
m_matrix = new int*[m_rows]; //create rows
for(int r = 0; r < m_rows; r++)
{
//for each row, create columns
m_matrix[r] = new int[m_cols];
//initialize the values
for(int c = 0; c < m_cols; c++)
m_matrix[r][c] = 0;
}
}
//-----------------------------
//destructor
DynamicMatrix::~DynamicMatrix()
{
//first deallocate each row
for(int i = 0; i < m_rows; i++)
delete []m_matrix[i];
//now deallocate the 2d array pointer
delete []m_matrix;
}