Question: Create an implement a simple matrix class called baseMatrix. This will consist of baseMatrix.h and baseMatrix.cpp which will define and implement the class respectively. The

Create an implement a simple matrix class called baseMatrix. This will consist of baseMatrix.h and baseMatrix.cpp which will define and implement the class respectively. The purpose of this class is to provide matrix operations for a single matrix that will be contained within. The class has the following features based on this simple UML class diagram:

baseMatrix

-numRows: int

-numCols: int

-matrix: int**

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

+setRows(a:int):void

+setCols(a:int):void

+getRows():int

+getCols():int

+createMatrix():void 2

+randomiseMatrix(seed:int,min:int,max:int):void

+getElement(r:int, c:int):int

+sumMatrix():int

+displayMatrix():void

The variables are as follows:

• numRows: the number of rows in the current matrix to construct

• numCols: the number of columns in the current matrix to construct

• matrix: a 2D integer matrix

The methods have the following behaviour:

• setRows, setCols: Two methods that are used set the rows and columns respectively

• getRows, getCols: Two methods used to fetch the values stored for the rows and columns

• createMatrix: This will allocate the matrix as determined by the row and column values. The initial matrix must contain only 0s after construction.

• randomiseMatrix: This function will take a seed and then use it to generate random numbers in the range defined between the max and min arguments, inclusive. The entire matrix should be populated with random numbers in this way.

• getElement: This returns the value stored in the matrix at the given row, r, and column, c, respectively. If the value is unavailable, because the given row and column is outside the bounds of the matrix or not allocated, then return -1.

• sumMatrix: This function will compute the sum of all of the elements in the matrix and return the value. Should the matrix be not constructed, it must return -1.

• displayMatrix: This will print out the current matrix as stored using commas to delineate the columns and every row appearing on a new line. For example

1,2,3

4,5,6

7,8,9

Use the cstlib and iostream libraries for this task. Create a main.cpp to test that your class works when used.

Step by Step Solution

3.39 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the baseMatrix class in C follow the steps below to create and define the methods outlined in the UML diagram This will involve creating two files baseMatrixh for the class definition and ... View full answer

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

Document Format (2 attachments)

PDF file Icon

60920cd7f2926_22746.pdf

180 KBs PDF File

Word file Icon

60920cd7f2926_22746.docx

120 KBs Word File

Students Have Also Explored These Related Databases Questions!