Question: C++ Write a program that multiplies two matrices and prints the resulting matrix. Your inputs will be the two matrices. Data will be provided in
Write a program that multiplies two matrices and prints the resulting matrix. Your inputs will be the two matrices. Data will be provided in a file called CS1Asg2Data.txt, and will have the form of two numbers, the number of rows and the number of columns, followed by a matrix of m rows and n columns. All numbers will be separated by spaces, so you can use a file and stream extraction for input. Once you have read all of the rows, there will be another pair of numbers m and m for the second matrix. Once you have done the multiplication and printed the result, read the file again to look for additional matrices. If you hit the end of the file, there are no more. The data will be clean in the sense that you will have actual numbers. However, you must check the dimensions of the arrays to insure that they can be multiplied and print an error message if they cannot. Your output must show the two input matrices and the result of the multiplication, and each must be labeled. Your output should have each matrix in columns 6 characters wide, with the numbers right-justified in the field. Since you cannot know the sizes of the arrays until you read them from the file, you must dynamically allocate them. Remember the formula for computing the offset into linear memory space from a row and column. Once you have computed and printed the result, deallocate all three matrices using the delete operator
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
