//********************************************************** // matrix.h
Posted: Mon Jun 06, 2022 5:38 pm
//**********************************************************
// 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 <string>
using namespace std;
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.
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
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. 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
the matrix.cpp, main.cpp and
makefile.
Sample Main routine ( You need to write your own)
#include <iostream>
#include "matrix.h"
using namespace std;
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! !
// 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 <string>
using namespace std;
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.
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
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. 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
the matrix.cpp, main.cpp and
makefile.
Sample Main routine ( You need to write your own)
#include <iostream>
#include "matrix.h"
using namespace std;
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! !