Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int
Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_ROWS =10; const int MAX_COLS =10; class MatrixType \{ public: MatrixType(); void SetSize(int rowsSize, int colSize); void Storeltem(int item, int row, int col); void Add(MatrixType otherOperand, MatrixType\& result); void Sub(MatrixType otherOperand, MatrixType\& result); void Mult(MatrixType otherOperand, MatrixType\& result); void Print(); bool AddSubCompatible(MatrixType otherOperand); bool MultCompatible(MatrixType otherOperand); private: int values[MAX_ROWS][MAX_COLS]; int numRows; int numCols; \} Every instantiation of MatrixType will give you a new matrix. Initially, in the constructor, both the number of rows and the number of columns are set to 0 . This indicates that an empty matrix is created. Then, the user is asked to provide the number of rows, the number of columns, and the value for each combination of row and column. To represent the matrices, you need to consider an array (Matrix[10]) of MatrixType. Initially, the length of this array, NumberOfMatrices, is =0. The index of the array can be 0 to 9 , i.e., there can be at most 10 matrices at any given time. Note that the class provides two member functions, AddSubCompatible and MultCompatible, to allow the user to determine if the binary matrix operations (addition, subtraction, and multiplication) are possible. For example, adding a matrix of size 34 with another matrix 37 is infeasible. You need to check such necessary preconditions for each operation. If an operation is not possible, you should provide appropriate error message to user. An example of output Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 1 A matrix with 0XX is created. Enter the number of rows and the number of columns for this new matrix: 3 4 Enter the values: 4793 167519 10099317 Thank you. You now have total 1 matrices in system. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 5 Enter the matrix number for printing: 1 The input is invalid. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 5 Enter the matrix number for printing: 0 The matrix 0 is: 4793 167519 10099317 Suppose that you want to perform C=A+B. Enter A,B and C : 013 The operation is not compatible. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 1 A matrix with 0XO is created. Enter the number of rows and the number of columns for this new matrix: 4 Enter the values: 91715 231125 12719 171612 Thank you. You now have total 2 matrices in system. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 1 A matrix with OXO is created. Enter the number of rows and the number of columns: 3 4 Enter the values: 719136 5275117 10132015 Thank you. You now have total 3 matrices in system. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program A matrix with 0X0 is created. Enter the number of rows and the number of columns: 3 4 Enter the values: Enter the values: 1719136 5312710 181032205 Thank you. You now have total 4 matrices in system. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 2 Suppose that you want to perform C=A+B. Enter A,B and C : 023 Matrices 0 and 2 are added and the result is stored in matrix 3. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 5 Enter the matrix number for printing: 3 The matrix 3 is: 1126229 6845636 1101122332 Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 3 Suppose that you want to perform C=AB. Enter A,B and C : 032 Matrix 3 is subtracted from matrix 0 , and the result is stored in matrix 2. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 4 Suppose that you want to perform C=AB. Enter A,B and C : 031 The operation is not compatible. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 1 A matrix with 00 is created. Enter the number of rows and the number of columns: 3 3 Enter the values: 141712 176 0298 Thank you. You now have total 5 matrices in system. Enter the corresponding number for your desired operation: 1 - get a new matrix; 2 - add two matrices; 3 - subtract a matrix from another; 4 - multiply two matrices; 5 - print matrix; 6 - end the program 4 Suppose that you want to perform C=AB. Enter A,B and C:014
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started