Question: 1. [10 pts] Use basic input/output in C++ (cin, cout). 2. [10 pts] Use arrays in C/C++. 3. [20 pts] Use at least 2 classes

1. [10 pts] Use basic input/output in C++ (cin, cout).

2. [10 pts] Use arrays in C/C++.

3. [20 pts] Use at least 2 classes with constructors(default and non-default), destructors, overloaded ostream operator and necessary functions.

4. [40 pts] Design and implement the program according to the project description. 50 pts are distributed as following. a. [10 pts] Getting the redirected input and storing it in the appropriate class.

b. [10 pts] Operator overloading (int i, int j) in the sparse matrix class, returns the element in the ith row and jth column stored in the sparse matrix.

c. [20 pts] Multiplication of the two matrices.

5. [20 pts] Document your project thoroughly as the examples in the textbook. This includes but not limited to header comments for all classes/methods, explanatory comments for each section of code, meaningful variable and method names, and consistent indentation.

Discussion

Consider the following matrix below. This matrix has 5 rows and 5 columns. The number of 0 elements is significantly greater than the number of non-zero elements. Such a matrix is called a Sparse matrix. This matrix can be represented using the sparse matrix representation as shown next to the matrix.

Indicies 0 1 2 3 4
0 0 0 -1 0 0
1 3 0 0 0 0
2 5 0 0 0 0
3 0 3 0 0 1
4 0 0 6 0 0
Number of Rows rowNumber colNumber _value
0 0 2 -1
1 1 0 3
2 2 0 5
3 3 1 3
4 3 4 1
5(nSparseRows) 4 2 6

In this problem, you will be creating two classes (additional classes as you deem fit). First one is the SparseRow class through which you create an object for each row in the SparseRow class. Here is the incomplete class structure.

template

class SparseRow

{

int rowNumber;

int colNumber;

DT* _value;

public:

//all the other setter, getter, constructor, destructor, display and any other function will go here.

};

The second class you should create is the SparseMatrix class. This class should store the number of rows, number of columns, number of sparse rows and the SparseRow object as its fields. The other necessary functions should be written under it. Have array of SparseRow objects to store all the values of the matrix.

For example, if we have a matrix of integers, then the sparse matrix representation can be told to store those integers that are not equal to 0. The user can specify this value as a parameter to the sparse matrix constructor. We will refer to this value as the default value. Thus a sparse matrix stores all elements whose value is not equal to the default value. In a sparse matrix, the elements are ordered first by row number and then by column number. The following is an example of a sparse matrix.

template

class SparseMatrix

{

protected:

SparseRow

* mySparseRow;

int nSparseRows;

int noRows;

int noCols;

public:

//constructors, destructor, setters, getters, getSparseRows, getNumRows, getNumCols, operator overloading functions and all other necessary functions here.

};

Input File

The provided input file can be taken as an example input. This has to be read as a redirected input file. The first value is the number of rows and the second value is the number of columns and they are followed b the 2 matrices of that size. You need to convert them to integer after reading it in.

Redirected input provides you a way to send a file to the standard input of a program without typing it using the keyboard. To use redirected input in Visual Studio environment, follow these steps: After you have opened or created a new project, on the menu go to project, project properties, expand configuration properties until you see Debugging, on the right you will see a set of options, and in the command arguments type

#include

using namespace std;

//The character for end-of-line is ' ' and you can compare c below with this character to check if end-of-line is reached.

int main () {

char c;

cin.get(c);

while (!cin.eof()) {

cout << c;

cin.get(c);

}

return 0;

}

Description

1. Create a main function and create all the necessary objects(of SparseMatrix class) for the two matrices. The constructors should specify all the default values for these matrices.

2. Use redirected input to get the matrix values and then use the setter functions to set the values for these specific values. You are forbidden to use any other header libraries other than iostream.

3. Multiply the two matrices using traditional multiplication method. But the (i. j) operator should be overloaded to access the specific values in the matrix. Store the result in the resultant matrix C.

4. All the matrices after the execution should be displayed on the console.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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

Students Have Also Explored These Related Databases Questions!