Question: A matrix is a 2D array of numerical values. In this problem, you only need to consider square matrices. You can add, subtract or multiply
A matrix is a 2D array of numerical values. In this problem, you only need to consider square matrices. You can add, subtract or multiply two matrices to form a third matrix provided that the two matrices have the same size. You can also multiply a matrix by a scalar. Design and implement an ADT SquareMatrix using separate compilation to support these operations. Specifically, you are required to include the following member functions in your ADT:
1. A default constructor that initializes a matrix to 10 by10 with all elements set to 0.0.
2. A constructor that initializes a matrix by using values stored in a vector of vectors. In other words, this constructor will look like SquareMatrix(vector< vector
3. A read-only accessor getValue(int i, int j) that returns the value at position (i, j) in the matrix.
4. A mutator setValue(int i, int j, double value) that sets the element at position (i, j) to value.
5. An overloaded, read-only multiplication operator (*) as a member function to multiply two matrices if their dimensionality matches. Let m1, m2 and m3 be three matrices of the same size. The following statement m3= m1 * m2; will not change m1 and m2 and will save the multiplication result in m3.
6. An overloaded, read-only subtraction operator (-) as a member function to subtract one matrix from another if their dimensionality matches. Let m1, m2 and m3 be three matrices of the same size. The following statement m3= m1 - m2; will not change m1 and m2 and will save the subtraction result in m3.
7. Also include an overloaded put operator (<<) as a friend function of the SquareMatrix ADT to print out a matrix on an output stream in a readable format. For example, let m1 be a 2 by 2 matrix. Its first row contains numbers 11.11 and a1212. Its second row contains numbers 21.21 and 22.22 The statement cout< ( 11.11, 12.12 21.21, 22.22) Lastly, in your main() function, please provide a user-friendly interface that allows the grader to test each and every function implemented above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
