Question: write a program (C++) that gives the user the two options of quitting (Q) or performing matrix operations (P). If they select Q, the program
write a program (C++) that gives the user the two options of quitting (Q) or performing matrix operations (P). If they select Q, the program should quit. Until the user selects Q, the program will read in two matrices and a constant and print all of the following that is possible the sum, the difference, the product of the constant and the first matrix, the product of the two matrices, and the boolean product of the two matrices. Any that are not possible should have a statement printed saying why they were not printed. In order to do these operations, the program must ask for the dimensions of the first matrix, the first matrix, the dimensions of the second matrix, the second matrix, and the constant. You may assume that nothing can be larger than 10X10. You may NOT assume that the matrices are square.
Sample run data is as follows (printout from the program is shown here in bold face so you can delineate it from the user input which is shown in regular font):
Do you want to perform matrix operations(P) or quit(Q): P Please input the dimensions of the first matrix: 3 3 Please input the matrix: 1 0 1 1 1 1 0 0 1 Please input the dimensions of the second matrix: 3 3 Please input the second matrix: 1 1 1 0 0 0 0 1 0 Please input the constant: 2 The sum of the two matrices is: 2 1 2 1 1 1 0 1 1 The difference of the two matrices is: 0 -1 0 1 1 1 0 -1 1 The product of the constant and the first matrix is: 2 0 2 2 2 2 0 0 2 The product of the two matrices is: 1 2 1 1 2 1 0 1 0 The boolean product of the two matrices is: 1 1 1 1 1 1 0 1 0 Do you want to perform matrix operations(P) or quit(Q): P Please input the dimensions of the first matrix: 3 2 Please input the matrix: 3 2 0 1 2 2 Please input the dimensions of the second matrix: 2 2 Please input the second matrix: 1 0 1 1 Please input the constant: 4 The sum of the two matrices is: The matrices cannot be added because the dimensions are incompatible. The difference of the two matrices is: The matrices cannot be subtracted because the dimensions are incompatible. The product of the constant and the first matrix is: 12 8 0 4 8 8 The product of the two matrices is: 5 2 1 1 4 2 The boolean product of the two matrices is: The boolean product does not exist because the matrices are not boolean. Do you want to perform matrix operations(P) or quit(Q): P Please input the dimensions of the first matrix: 3 4 Please input the matrix: 0 1 0 1 1 1 1 1 0 1 1 0 Please input the dimensions of the second matrix: 3 4 Please input the second matrix: 1 1 1 1 1 1 1 1 1 0 0 1 Please input the constant: 6 The sum of the two matrices is: 1 2 1 2 2 2 2 2 1 1 1 1 The difference of the two matrices is: -1 0 -1 0 0 0 0 0 -1 1 1 -1 The product of the constant and the first matrix is: 0 6 0 6 6 6 6 6 0 6 6 0 The product of the two matrices is: The two matrices cannot be multiplied because the dimensions are incompatible. The boolean product of the two matrices is: The boolean product does not exist because the dimensions are incompatible. Do you want to perform matrix operations(P) or quit(Q): Q Enjoy!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
