Create an implement a simple matrix class called baseMatrix. This will consist of baseMatrix.h and baseMatrix.cpp which
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 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.
Elementary Linear Algebra with Applications
ISBN: 978-0132296540
9th edition
Authors: Bernard Kolman, David Hill