Students are expected to write, run, test, and debug a fully-working C++ program for the following computing problem:
In mathematics, a matrix is a rectangular array of numbers, arranged in rows and columns. For example, the dimension of the below matrix is 2 x 3 (read “two by three”), because there are two rows and 3 columns:
? = [ 1 2 −1 −1 0 3
]
Matrices can be called sparse or dense depending on the number of zero elements. A sparse matrix is a matrix in which most of the elements are zero. By contrast, if most of the elements are nonzero, then the matrix is considered dense. For dense matrices, all values need to be stored in the system. However, for sparse matrices, since the number of non-zero values is less, instead of unnecessarily occupying memory for zero values, we may store the corresponding row and column information of the non-zero values in the system. To be more specific, for a dense matrix, every cell of the matrix needs to occupy memory, however, for a sparse matrix, only row, column, and value information needs to be stored.
Both sparse and dense matrices are to be derived from the general matrix class. The general matrix class should contain a couple of pure virtual functions, namely, the get, set, and resize, to be overridden by the sparse/dense matrices to meet their specific needs. Also note that, for a sparse matrix, get function needs to apply a kind of search operation since we are not storing the whole n x m system.
Some mathematical operations that need to be defined are the matrix addition, subtraction, and multiplication. Matrix transpose, multiplying by a constant, and testing whether two matrices commute (equal) or not, are the other functions that should be defined. Moreover, inputting and outputting of the matrices should be presented in such a way that a user may specify values into the matrices. Remember, when possible, operator functions need to be overloaded.
Get Free Quote!
362 Experts Online