Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Requested files : Matrix.h, Matrix.cpp, Matrix_test.cpp A matrix is a two dimens

ID: 3839346 • Letter: R

Question

Requested files: Matrix.h, Matrix.cpp, Matrix_test.cpp

A matrix is a two dimensional array. In mathematics, a matrix (plural matrices) is a rectangular array[1] of numbers, symbols, or expressions, arranged in rows and columns.[2][3] The dimensions of matrix (1) are 2 × 3 (read "two by three"), because there are two rows and three columns.

Matrices are very useful and represent a fundamental tool for simulating real-world systems. A major branch of numerical analysis is devoted to the development of efficient algorithms for matrix computations, a subject that is centuries old and is today an expanding area of research.

Your program will implement a class that implements a matrix object that stores floats. The matrix can be of any size and will provide the following interfaces:

Matrix() - a constructor that creates a matrix with no rows and no column.

Matrix(x,y) - A constructor that creates a matrix of floats with x rows and y columns. This two dimensional array should be public so it contents are accessible outside the class.

float *setSize(x,y) - a function that will set the size of the matrix object to x rows and y column. If the matrix already has a size, a new matrix will be allocated and the elements of the old matrix copied to the elements of the new matrix. The new size must be larger than the old size. The function return a pointer to element (0,0) of the new matrix. Any storage allocated for the old matrix should be released.

float *getMatrix() - return a pointer to the element at [0,0]

float *getRow(x) - a function that will return a pointer to the beginning of row x in the matrix elementx,[x,0]

float *getColumn(y) - a function that will return a pointer to the beginning of column y in the matrix element[0,y].

~Matrix() - a destructor function that de-allocates any memory used by the matrix.

Your Matrix class should not contain a main method. The main method used to test your program should be in a file named Matrix_test.cpp. The working environment for this assignment should contain 3 files:

Matrix.h - the interface header file where your class is defined.

Matrix.cpp - the implementation file where your class implemented.

Matrix_test.cpp - the test driver file that creates and tests instances of your class.

In order to assure what is called "good test coverage" your Matrix_Test driver should test the following conditions:

Calculate the address of the first position M[0,0] in the Matrix (boundary condition)

Calculate the address of the last position M[n,m] for an n by m matrix (boundary condition)

Calculate the address of an entry inside the matrix M[3,4] where n > 3 and m > 4 (interior condition)

Calculate the address of an entry outside the lower bound M[-1,-1] (out of lower bound)

Calculate the address of an entry outside the upper bound M[n+1,m+1] (out of upper bound)

The out-of-bound values should not return a legitimate address, but a value that clearly indicates there was an error in the indices specified.

Thank you in advance.

Explanation / Answer

class Matrix{

public:
   Matrix();
   Matrix(int x, int y);
   float *setSize(x,y);
   float *getMatrix();
   float *getRow(x);
   float *getColumn(y)
   float *mat;

private:
   int x;
   int y;
};


Matrix::Matrix() {
   mat = NULL;
   x = 0;
   y = 0;
}

Matrix::Matrix(int x, int y) {
   mat = new float[x*y]
   this->x = x;
   this->y = y;
}

Matrix::float *setSize(x,y) {
   float *matCpy = mat;
   mat = new float[x*y];
   for (int i = 0; i < this->x ; i++)
      for (int j = 0; j < this->y; j++)
         mat[i*y + j] = matCpy[i*y + j];
   this->x = x;
   this->y = y;
}

Matrix::float *getMatrix() {
   return mat;
}

Matrix::float *getRow(x) {
   if (x < this->x && x >= 0)
      return &mat[x*y];
   return NULL;
}

Matrix::float *getColumn(y) {
   if(y < this->y && y >= 0)
      return &mat[y];
   return NULL;
}

Here you go champ. I hope this code will help you. If you need any more methods, please let me know, I shall try to resolve all your issues

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote