Question: It is a C++ assignment. I need help to fix the error in Martix.cpp file. Error message Control may reach end of non-void function //Matrix.h

It is a C++ assignment. I need help to fix the error in Martix.cpp file.

Error message "Control may reach end of non-void function"

//Matrix.h

#include using namespace std; class Matrix { int rows, cols; public: float **matrix; Matrix(); Matrix(int r, int col); float *setSize(int x, int y); float *getMatrix(); float *getRow(int r); float *getColumn(int c); ~Matrix(); };

------------------------------------

Matrix.cpp

#include"Matrix.h"

Matrix::Matrix() { matrix = new float*[0]; matrix[0] = new float[0]; }

Matrix::~Matrix() { for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) delete matrix[i]; } delete[] matrix; }

Matrix::Matrix(int r, int c) { rows = r; cols = c; matrix = new float*[rows]; for (int i = 0; i < cols; i++) matrix[0] = new float[i]; }

float *Matrix::setSize(int x, int y) { float **m= NULL ; if (x > rows && y > cols) { //allocate new matrix m = new float*[x]; for(int i = 0; i < y; i++) m[0] = new float[i]; } //now copy elements of to new if (m!=NULL) for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { m[i][j] = matrix[i][j]; } } if (m != NULL) return &m[0][0]; } float *Matrix::getMatrix() { return &matrix[0][0]; } float *Matrix::getRow(int r) { return &matrix[r][0]; } float *Matrix::getColumn(int c) { return &matrix[0][c]; }

---------------------------------------

Matrix_test.cpp

#include"Matrix.h"

int main() { Matrix m(3,4); cout << "Address of the first position M[0,0] in the Matrix : " << m.getMatrix() << endl; cout << "Calculate the address of the last position : " << &m.matrix[2][3] << endl; cout << "Calculate the address of an entry inside the matrix M[3,4]: " << &m.matrix[3][4] << endl;; cout << "Calculate the address of an entry outside the lower bound: " << &m.matrix[-1][-1] << endl; cout << "Calculate the address of an entry outside the lower bound: " << &m.matrix[4+1][4+1] << endl; }

-------------------------------------------------------------------

//utput

Address of the first position M[0,0] in the Matrix : 003EA388 Calculate the address of the last position : CDCDCDD9 Calculate the address of an entry inside the matrix M[3,4]: FDFDFE0D Calculate the address of an entry outside the lower bound: FDFDFDF9 Calculate the address of an entry outside the lower bound: ABABABBF

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 Databases Questions!