Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

OKAY, THIS IS THE ASSIGNMENT OVERVIEW, THE START TO THE PROGRAM IS LISTED BELOW

ID: 3534949 • Letter: O

Question

OKAY, THIS IS THE ASSIGNMENT OVERVIEW, THE START TO THE PROGRAM IS LISTED BELOW IT. WE ARE JUST SUPPOSED TO FILL IT IN WHERE IT SAYS. ANYONE THAT CAN HELP ME IT WOULD BE VERY APPRECIATED. I NEED THIS.

For this assignment, implement a class called Matrix that will be used to represent a matrix of values. This class will have the ability to add, subtract, and multiply two matrices.

The Matrix class definition should be placed at the top of a source code file while the method implementation should be done after the closing curly brace for main().

The Matrix class should contain five private data members. They are:

Note: For ease, the two-dimensional array of integers will always have a maximum of 5 rows, each of which has 5 columns. However, it's possible that the entire two-dimensional array will not be used. This is why the number of rows and columns is being kept as separate data members. So a 2x3 matrix, will have its data stored in the first 2 rows of the matrix and within the first 3 columns of those 2 rows.

The first constructor for the Matrix class (the default constructor) takes no arguments. Like all C++ constructors, it does not have a return data type.

It should set the number of rows and number of columns data members so that they hold the maximum values (ie. use the symbolic constants). The two-dimensional array should be set to all 0s.

The second constructor for the Matrix class should take two arguments: an integer that represents the desired number of rows for the matrix, and an integer that represents the desired number of columns for the matrix. DO NOT GIVE THESE ARGUMENTS THE SAME NAMES AS YOUR DATA MEMBERS. Like all C++ constructors, this constructor does not have a return data type.

If the desired number of rows is less than or equal to the maximum number of rows, use the desired number rows to initialize the number of rows data member. Otherwise, initialize the number of rows data member to the maximum number of rows.

If the desired number of columns is less than or equal to the maximum number of columns, use the desired number columns to initialize the number of columns data member. Otherwise, initialize the number of columns data member to the maximum number of columns.

The third constructor for the Matrix class should take three arguments: a two-dimensional array of integers (5x5), an integer that represents the number of rows in the passed in two-dimensional array of integers, and an integer that represents the number of columns in the passed in two-dimensional array of integers. DO NOT GIVE THESE ARGUMENTS THE SAME NAMES AS YOUR DATA MEMBERS. Like all C++ constructors, this constructor does not have a return data type.

If the number of rows in the passed in two-dimensional array of integers is less than or equal to the maximum number of rows, use it to initialize the number of rows data member. Otherwise, initialize the number of rows data member to the maximum number of rows.

If the number of columns in the passed in two-dimensional array of integers is less than or equal to the maximum number of columns, use it to initialize the number of columns data member. Otherwise, initialize the number of columns data member to the maximum number of columns.

The passed in two-dimensional array of integers should be used to initialize the two-dimensional array of integers data member.

This method is used to print/display a matrix. It takes no arguments and returns nothing.

Use a set of nested loops (probably for loops) to display the matrix in the form of a table.

This method adds two Matrix objects. It takes a Matrix object as its argument and returns a Matrix object.

Two matrices can only be added if their number of rows and number of columns are equal. If the matrices cannot be added together, display a meaningful error message and then execute return *this;.

These two matrices cannot be added together because they are different sizes.

If the matrices can be added together, it is done by adding together the integers that are located at corresponding spots of the matrices. So the values at [0][0] and at [0][0] of the passed in Matrix object (anotherMatrix) should be added together, the values at [0][1] and at [0][1] of anotherMatrix should be added together, etc... To do this:

Create a local Matrix object that has the same number of rows and columns as the two Matrix objects that are being added together.

Use a set of nested loops, to go through and add up the values that are in correspoding locations of the current instance and the passed in Matrix (anotherMatrix). The resulting sum should be placed in the corresponding location in the local Matrix object.

return the local Matrix object

This method subtracts a Matrix object from another Matrix object. It takes a Matrix object as its argument and returns a Matrix object.

Two matrices can only be subtracted if their number of rows and number of columns are equal. If the matrices cannot be subtracted, display a meaningful error message and then execute return *this;.

These two matrices cannot be subtracted because they are different sizes.

If the matrices can be subtracted, it is done in a manner similar to the addition from above where the integers that are located at corresponding spots of the matrices are used. So the value at [0][0] of the current instance has the value at [0][0] of the passed in Matrix object (anotherMatrix) subtracted from it, the value at [0][1] of the current instance has the value at [0][1] of anotherMatrix subtracted from it, etc... To do this:

Create a local Matrix object that has the same number of rows and columns as the two Matrix objects that are being subtracted.

Use a set of nested loops, to go through and subtract the values that are in correspoding locations of the current instance and the passed in Matrix (anotherMatrix). The resulting difference should be placed in the corresponding location in the local Matrix object.

return the local Matrix object

This method multiplies the current Matrix object by a scalar value. It takes an integer as its argument and returns a Matrix object.

Scalar multiplication is simple. Multiply each value in the current Matrix object by the passed in integer argument. To do this:

Create a local Matrix object that has the same number of rows and columns as the current Matrix object.

Use a set of nested loops, to go through the two dimensional array data member of the current instance. For each value in the array, multiply it by the passed in integer argument. The resulting product should be placed in the corresponding location in the local Matrix object.

return the local Matrix object

This method multiplies a Matrix object by another Matrix object. It takes a Matrix object as its argument and returns a Matrix object.

Two matrices can only be multiplied if the number of columns in the current Matrix object is equal to the number of rows in the passed in Matrix object. If the matrices cannot be multiplied, display a meaningful error message and then execute return *this;.

These two matrices cannot be multiplied because the number of columns in the current Matrix object (2) does not equal the number of rows in the passed in Matrix object (3).

If the matrices can be multiplied, it is done by calculating the dot product of the rows from the current instance and the columns of the passed in Matrix object. The dot product is calculated by taking each of the values in a row from the current instance and multiplying them by the corresponding values in the column of the passed in Matrix object. The resulting products are added together and the resulting sum is placed into a Matrix object. For example:

Repeat the process with the first row from the current instance and the second column from the the passed in Matrix object.

Finally, do the same thing using the second row of the current instance and the columns from the passed in Matrix object.

Notice that the resulting Matrix has a size equal to the number of rows in the current instance by the number of columns in the passed in Matrix object. Implenting this logic in C++ is a little difficult, so it's advisable to follow these steps:

Create a local Matrix object that has the same number of rows as the current instance and the same number of columns as the passed in Matrix object.

Create 6 integer subscripts. These will be used to access the 3 Matrix objects that are used in the calculation. For the logic that follows: currRowSub and currColSub will be used for the current instance; anotherRowSub and anotherColSub will be used for the passed in Matrix object; and localRowSub and localColSub will be used for the local Matrix object.

Create an integer variable to hold the dot product result

Implement the following:

The main() function has already been written. It can be downloaded from: http://faculty.cs.niu.edu/~byrnes/csci240/pgms/pgm10.cpp.

Add the class definition at the top of the program and the methods at the bottom. Also don't forget to fill in the documentation box at the top and to document the methods for the class.

Each method must have a documentation box like a function.

Hand in a copy of your source code using Blackboard.

The output for the program should resemble:

9 8 7



THE START TO THE PROGRAM!!!

#include<iostream>

#include<iomanip>

#include<cmath>

#include<cstdlib>


using namespace std;


// The Matrix class definition goes here





int main()

{

int ar1[5][5] = {{0,1,2},

{9,8,7}};


int ar2[5][5] = {{6,5,4},

{3,4,5}};


int ar3[5][5] = {{-1,2,0,15,9},

{0,3,6,7,-11},

{-4,50,12,0,6},

{1,1,1,1,1},

{-8,16,4,6,22}};


int ar4[5][5] = {{0,-4,3},

{9,-4,-3}};


int ar5[5][5] = {{1,2,3,4,5},

{2,3,4,5,6},

{3,4,5,6,7},

{4,5,6,7,8},

{5,6,7,8,9}};


int ar6[5][5] = {{7,8},

{9,10},

{11,12}};



cout << "Test 1: Constructors and print method" << endl << endl;


Matrix m1;

Matrix m2(2, 3);

Matrix m3( ar1, 2, 3);


cout << "Result of the default constructor" << endl;

m1.print();


cout << endl << endl << "Result of constructor 2" << endl;

m2.print();


cout << endl << endl << "Result of constructor 3" << endl;

m3.print();



cout << endl << endl << endl

<< "Test 2: add method" << endl << endl;


Matrix m4( ar4, 2, 3);

Matrix m5;

Matrix m6;


cout << "Matrix m3 contains" << endl;

m3.print();


cout << endl << endl << "Matrix m4 contains" << endl;

m4. print();


cout << endl << endl << "The result of adding matrices m3 and m4" << endl;


m5 = m3.add( m4 );

m5.print();


cout << endl << endl << endl << "Matrix m5 contains" << endl;

m5.print();


cout << endl << endl << "Matrix m1 contains" << endl;

m1. print();


cout << endl << endl << "The result of adding matrices m5 and m1" << endl;


m6 = m5.add( m1 );

m6.print();



cout << endl << endl << endl

<< "Test 3: subtract method" << endl << endl;


Matrix m7( ar2, 2, 3);

Matrix m8( ar6, 3, 2);

Matrix m9;

Matrix m10;


cout << "Matrix m7 contains" << endl;

m7.print();


cout << endl << endl << "Matrix m8 contains" << endl;

m8. print();


cout << endl << endl << "The result of subtracting matrices m7 and m8" << endl;


m9 = m7.subtract( m8 );

m9.print();


cout << endl << endl << endl << "Matrix m9 contains" << endl;

m9.print();


cout << endl << endl << "Matrix m5 contains" << endl;

m5. print();


cout << endl << endl << "The result of subtracting matrices m9 and m5" << endl;


m10 = m9.subtract( m5 );

m10.print();



cout << endl << endl << endl

<< "Test 4: multiply method (scalar multiplication)" << endl << endl;


Matrix m11( ar3, 5, 5);

Matrix m12;


cout << "Matrix m11 contains" << endl;

m11.print();


cout << endl << endl << "The result of multiplying matrix m11 by 6" << endl;


m12 = m11.multiply( 6 );

m12.print();



cout << endl << endl << endl

<< "Test 5: multiply method (matrix * matrix)" << endl << endl;


Matrix m13;

Matrix m14( ar5, 5, 5 );

Matrix m15;

Matrix m16;


cout << "Matrix m3 contains" << endl;

m3.print();


cout << endl << endl << "Matrix m8 contains" << endl;

m8. print();


cout << endl << endl << "The result of multiplying matrices m3 and m8" << endl;


m13 = m3.multiply( m8 );

m13.print();


cout << endl << endl << endl << "Matrix m11 contains" << endl;

m11.print();


cout << endl << endl << "Matrix m14 contains" << endl;

m14. print();


cout << endl << endl << "The result of multiplying matrices m11 and m14" << endl;


m15 = m11.multiply( m14 );

m15.print();



cout << endl << endl << endl << "Matrix m3 contains" << endl;

m3.print();


cout << endl << endl << "Matrix m15 contains" << endl;

m15. print();


cout << endl << endl << "The result of multiplying matrices m3 and m15" << endl;


m16 = m3.multiply( m15 );

m16.print();


return 0;

}


// Code the Matrix class methods below this line

Explanation / Answer

http://www.chegg.com/homework-help/questions-and-answers/overview-assignment-implement-class-called-matrix-used-represent-matrix-values-class-abili-q3984601