Question: How to make the implementation file (matrix.cpp) for this assignment? Not the main ASSIGNMENT #4: MATRIX MULTIPLICATION Objectives: Learn to use multi-dimensional arrays by multiplying
How to make the implementation file (matrix.cpp) for this assignment? Not the main
ASSIGNMENT #4: MATRIX MULTIPLICATION
Objectives: Learn to use multi-dimensional arrays by multiplying two matrices together and printing out the results as well as creating a namespace for the project. This assignment will involve creating class that stores and manipulates matrices as well as developing operator overloads and using new features of C++ 11. Those of you who are also in CDA3100 may find this assignment familiar but there are differences.
Matrix multiplication is an important operation in numeric methods. Given two matrices A and B whose sizes are mxn and nxl respectively, their product C=AXB is defined as the following The basic algorithm for matrix multiplication is shown below in a basic (although very inefficient) C program. You may use this function in your solution but you must document in the comments in your where you obtained it from.
// ***************************************************************** // * In the routine below, the parameters are described as such: * // * int * A - This is the first array to be multiplied * // * int * B - This is the second array to be multiplied. * // * int m - This is the size of the first matrix row. * // * int n - This is the size of the second matrix column * // * int l - This is the size of the second matrix row * // *****************************************************************
void MultArray(int ** A, int ** B, int ** C, int m, int n, int l) { int i,j,k; for (i=0; i
}
Implementation Specifications:
matrix.h file
//********************************************************** // matrix.h * // Header file for the matrix multiplication assignment. * // COP3330 ASSIGNMENT #4 * // Author: Dr. David A. Gaitros * // Date: January 6th, 2022 * // Copyright: For educational purposes Florida State * // University, Computer Science. Not for * // Distribution. * // *********************************************************
#ifndef MATRIX_H #define MATRIX_H
#include
namespace COP3330
{
class Matrix_Class { public: Matrix_Class(); // Default Constructor Matrix_Class(const int r, const int c=6); // Constructor ~Matrix_Class(); // Destructor void Clear(); // Delete Matrix void Zero(); // Set all values to zero void Print( string msg)const; // Print Matrix to Stdout void Input(); // Input Matrix from Stdin void Resize(const int r, const int c); // Clear and resize to row and col int Getrowsize() { return rowsize; } // Inline function to return rowsize int Getcolsize() { return colsize; } // Inline function to return colsize
// ************************************************************ // Operator overloads * // ************************************************************
Matrix_Class & operator = (const Matrix_Class & m); Matrix_Class & operator * (Matrix_Class & m1);
private: int * * matrix; // 2d array that holds the matrix int rowsize; int colsize; };
}
matrix.h function descriptions:
Matrix_Class(const int r-6, const int c=6) : Constructor with two parameters. The matrix must be between 2 and 6 rows and columns and if a bad value is passed in use the default of 6. Matrix_Class(): Default constructor. Just sets the row and columns to zero. ~Matrix_Class() : Destructor. Calls Clear(). void Clear(): Deletes the 2d Array and sets colsize and rowsize to zero. void Zero(): Sets all the values to zero void Print(string msg): Prints the matrix out to standard output along with a message that is passed in as a parameter. void Input(): Given the size of the row and column, it prompts the user to input the matrix void Resize(const int r, const int c) : Changes the size of the matrix to the row and column passed in. If either the row or column is invalid..do not make any changes. int Getrowsize(): Returns the size of the row. int Getcolsize(): Returns the size of the column
Matrix_Class & operator = ( const Matrix_Class & m) : Right Hand Side assignment operator. Designed to be used for values on the right side of the equal sign that can be changed such as another Matrix_Class object. Matrix_Class & operator * (Matrix_Class & m1). Multiply two matrices and return the results. If the matrices cannot be multiplied ( i.e. the column size of the first does not match the size of the rows and the second ) return *this as a results. Functional Specifications (Test the Following Functions in your Main Routine: ~
1. Your program will start and issue an appropriate and unique welcome message of your choosing. 2. Ask the user to input the first matrix which will be all integers (positive or negative numbers) - Ask the user to enter in the number of rows. - Ask the user to enter the number of columns - After the row and column sizes in you are to read in the matrix.. (See the example below) - Output the matrix, Format the output as per the example. 3. Resize a matrix, output the results to see if they are zero.
4. Multiply two matrices of the same size ( row and column)
5. Multiply two matrices of difference sizes but the rows of the first one match the columns of the second.
6. Try to multiply two matrices that are incompatible. If the matrices are incompatible , print out a message and stop the program when you first determine this.
7. Test all routines. 8. Output the results of A x B to standard output. Format the output as per the example.
9. Create a namespace called COP3330 for the class.
Implementation Specifications:
General Requirements:
1. No global variables, other than constants and type definitions!
2. Use the const qualifier on member functions wherever it is appropriate.
3. Your main routine should just mainly handle the calling of functions and basic program structure.
4. You will need to use the library for output. You may use the iomanip library for formatting your output if you wish.
5. When you write source code, it should be readable and well-documented.
6. You must have prototypes for all of your functions.
7. You may not use any standard template library that performs the matrix multiplications.
8. You can assume that the largest array ( A or B) will be 6 rows and 6 columns
9. Your program must use the namespace COP3330
Grading Criteria: The program compiles. If the program does not compile no further grading can be accomplished. Programs that do not compile will receive a zero. 1. The program compiles. If the program does not compile no further grading can be accomplished and incorporates the namespace COP3330. Programs that do not compile will receive a zero. 2. (25 Points) The program executes without exception and produces output. The grading of the output cannot be accomplished unless the program executes. 3. (25 Points) The program produces the correct output. 4. (25 Points) The program specifications are followed. 5. (10 Points)The program is documented (commented) properly. 6. (5 Points)Use constants when values are not to be changed 7. (5 Points)Use proper indentation 8. (5 Points)Use good naming standards
Submission:
Submit on canvas the matrix.cpp, main.cpp and makefile.
Sample Main routine ( You need to write your own)
#include
int main() { Matrix_Class MyMatrix1(4,4); // 4x4 matrix Matrix_Class MyMatrix2(4,4); // 4x4 matrix Matrix_Class MyMatrix3(2,3); // 2x3 matrix Matrix_Class MyMatrix4(3,3); // 3x3 matrix Matrix_Class DuplicateMatrix; MyMatrix1.Input(); MyMatrix2.Input(); // ******************************************** // * Test print of matrix. * // ******************************************** MyMatrix1.Print("Matrix1 after input"); MyMatrix2.Print("Matrix2 after input");
MyMatrix3.Input(); MyMatrix4.Input(); // ********************************************* // * Test multipication and assignment operator* // ********************************************* DuplicateMatrix = MyMatrix3 * MyMatrix4; DuplicateMatrix.Print("Duplicate Multiplication"); std::cout << "I am done Neo! !" << std::endl; return 0; }
Sample Output:
Enter 4 numbers for Row1:1 1 1 1 Enter 4 numbers for Row2:2 2 2 2 Enter 4 numbers for Row3:3 3 3 3 Enter 4 numbers for Row4:4 4 4 4 Enter 4 numbers for Row1:1 1 1 1 Enter 4 numbers for Row2:2 2 2 2 Enter 4 numbers for Row3:3 3 3 3 Enter 4 numbers for Row4:4 4 4 4 Matrix Output Matrix1 after input Row size = 4 Column Size = 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 Matrix Output Matrix2 after input Row size = 4 Column Size = 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 Enter 3 numbers for Row1:1 2 3 Enter 3 numbers for Row2:4 5 6 Enter 3 numbers for Row1:7 8 9 Enter 3 numbers for Row2:10 11 12 Enter 3 numbers for Row3:13 14 15 Multiplying matrix of size 2x3 Matrix Output Duplicate Multiplication Row size = 2 Column Size = 3 66 72 78 156 171 186 I am done Neo! !
This is all the content
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
