Matrix Calculator
Comp 150/170
You are to write a program
called matrix.cpp that will read in 4x4 matrices from the keyboard (as
shown below) and then allow the user to specify matrix algebra operations to be
performed on them. The operations are
add, subtract, scalar multiply, transpose, and matrix multiply. Each time an operation is performed; the
resulting matrix will be added to the list of matrices and can then be used in
one of the subsequent operations. There
will never be more than 25 matrices altogether.
The program should first ask
the user for the number of initial matrices and then allow them to be
entered. Then the program should loop,
asking each time for an operation to be performed. The choices which may be entered for the
operation are: 'Q' or 'q' which means
quit, '+' which means add, '-' which means subtract, '*' which means scalar
multiply, 'T' or 't' which means transpose, ‘D’ or ‘d’ which means display, and
'X' or 'x' which means matrix multiply.
Your program should follow
the example below as closely as possible (spacing, capitalization, etc.):
How many initial matrices? 2
Enter matrix 1:
Row 1? 2 4 0 1
Row 2? 3 0 1 2
Row 3? 1 0 1 -1
Row 4? 0 1 2 0
Enter matrix 2:
Row 1? 1 0 0 0
Row 2? 0 1 0 0
Row 3? 0 0 1 0
Row 4? 0 0 0
1
Operation? +
First matrix
for +? 1
Second matrix for +? 2
Result is matrix 3:
Row 1: 3 4 0
1
Row 2: 3 1 1 2
Row 3: 1 0 2
-1
Row 4: 0 1 2
1
Operation? *
Scalar value for *? 2
Matrix for *? 3
Result is matrix 4:
Row 1: 6 8 0
2
Row 2: 6 2 2 4
Row 3: 2 0 4
-2
Row 4: 0 2 4
2
Operation? t
Matrix for T? 4
Result is matrix 5:
Row 1: 6 6 2 0
Row 2: 8 2 0
2
Row 3: 0 2 4
4
Row 4: 2 4
-2 2
Operation? x
First matrix for X? 1
Second matrix for X? 3
Result is matrix 6:
Row
Row
Row 3: 4 3 0
-1
Row 4: 5 1 5
0
Operation? Q
You may assume that all
values used are integers. When you print
a row, place one space between each integer.
NOTE: Your instructor will work examples in class
to explain all of the required matrix operations. All of them are very simple except for matrix
multiplication, and we will help you with the code for that in class.
Make certain to use
functions to break up the program into smaller pieces where appropriate. Grading emphasis will be given to program
correctness and internal program documentation (use good variable names). Make sure you use constants for the number of
rows and columns of the matrices throughout the program.
Structure your program so the matrices are stored in
a 3D array and each matrix operation function works on 2D arrays. Provide data
validation for all input.