Question: Description: A rectangular array of numbers is called a matrix. Sometimes, a matrix is referred to as a table, 2 - dimensional array, or array
Description: A rectangular array of numbers is called a matrix. Sometimes, a matrix is referred to as a table,
dimensional array, or array of arrays. Consider the following matrix below. It has rows denoted n and
columns denoted m As you can see the row and column numbers start with a Many entries might be
zero in matrix computations, especially with large matrices. Storing all elements, including zeros, would be
inefficient regarding memory and computational resources. The Sparse Matrix Representation SMR
efficiently stores and operates on matrices where most the elements are zero. Instead of storing every
element, we only store the nonzero elements along with their positions in the matrix, which reduces the
amount of memory used and can make certain operations more efficient. This project will help you learn
how to implement and work with this data structure using objectoriented principles by encapsulating it
within a class and relevant operations.
This project focuses on manipulating and storing matrices using a specific data structure called Sparse Matrix
Representation SMR We will encapsulate the SMR within a class, including a set of methods designed to
operate on matrices stored in this format.
The empty cells have the same common value for example, it can be The above matrix is said to be sparse
because the total number of common values is significantly large in comparison to other values in the matrix.
In the example above, we have a total of values in the matrix noncommon values, and
common values.
A sparse matrix can be represented using sparse matrix representation. In a table format, the sparse matrix
representation for the above matrix looks like the following
Row# Column# Value
In this project, you will create appropriate C classes see below to create the sparse matrix representation
data structure along with matrix operations on the sparse matrix.
Your Project Implementation: As part of this project, you will create two classes as described below. The
first class that you will create will be a SparseRow class. The second class that you will create will be the
SparseMatrix class. A partial you are responsible for completing this and writing all the methods class
definition for both classes is given below.
You will create two classes for this project, as described below. The first class that you will create will be a
SparseRow class. The second class that you will create will be the SparseMatrix class. A partial you are
responsible for completing this along with writing all the methods class definition for both classes is given
below.
Programming Objectives:
All code must be in CYou will create a class given below with appropriate fields.
The class will have several methods, including matrix addition, transpose, and matrixmatrix
multiplication.
All input will be read via redirected input. That is you will not open a file inside the program.
The class structure is shown below you are responsible for fixing any syntax errors
The structure for your main program is also provided. You will use that for your project.
class SparseRow
protected:
int row; Row#
int col; Column#
int value; We will assume that all our values will be integers
public:
SparseRow ; default constructor; row;col;value
display; print Row# Column# value
ostream& operatorostream& s const SparseRow;
other methods that are necessary such as get and set
;
class SparseMatrix
protected:
int noRows; Number of rows of the original matrix
int noCols; Number of columns of the original matrix
int commonValue; read from input
int noNonSparseValues;
SparseRow myMatrix; Array
public:
SparseMatrix ;
SparseMatrix int n int m int cv;
SparseMatrix Transpose ; Matrix Transpose
SparseMatrix Multiply SparseMatrix& M;
SparseMatrix Add SparseMatrix& M;
ostream& operatorostream& s const SparseMatrix& sm;
displayMatrix ; Display the matrix in its original format
other methods that are necessary such as get and set
;
Your main program will have the following structure changes may be required
#include
using namespace std;
define all your classes here as given above
write the methods after the class definition
int main
int n m cv noNSV;
SparseMatrix temp;
cin n m cv noNSV;
SparseMatrix firstOne new SparseMatrixn m cv noNSV;
Write the Statements to read in the first matrix
cin n m cv noNSV;
SparseMatrix secondOne new SparseMatrixn m cv noNSV;
Write the Statements to read in the second matrix
cout First one in matrix format endl;
firstOnedisplayMatrix;
cout Fi
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
