Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

You are only allowed to use the cstlib and iostream libraries for this task.

You will need to create a main.cpp to test that your class works when used.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

Whats wrong with the following initialization?

Answered: 1 week ago