Question: C + + pls; Finish the Matrix class below and add a custom copy constructor to perform a deep copy. Contents of Matrix.h: #include Matrix.h

C++ pls;
Finish the Matrix class below and add a custom copy constructor to perform a deep copy.
Contents of Matrix.h:
#include "Matrix.h"
#include
using namespace std;
Matrix::Matrix(int r, int c)
{
rows = r;
cols = c;
data = new int*[rows];
for(int i =0; i < rows; ++i)
{
data[i]= new int[cols]();
}
}
Matrix::Matrix(const Matrix& m)
{
// write code here
}
Matrix::~Matrix()
{
for(int i =0; i < rows; ++i)
{
delete[] data[i];
}
delete[] data;
}
void Matrix::fillMatrix()
{
int value =1;
for (int i =0; i < rows; ++i)
{
for (int j =0; j < cols; ++j)
{
data[i][j]= value++;
}
}
}
void Matrix::printMatrix()
{
for (int i =0; i < rows; ++i)
{
for (int j =0; j < cols; ++j)
{
std::cout << data[i][j]<<"";
}
std::cout << std::endl;
}
}
When you create a new submission, youll notice a template code that includes a partial implementation of the Matrix class. Your task is to implement the missing parts indicated by "your code here".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!