Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ using classes: we need to make this main work : Explanation about class Matrix: 1. The initialization take O(1) time (no matter what the

C++ using classes:

we need to make this main work :

Explanation about class Matrix: 1. The initialization take O(1) time (no matter what the matrix size). 2. The default value is specified in the construction (if not specified the default is 0). 3. matrix[i][j] should return a real value (if was set) or default (if was not set before). 4. Access operations to a matrix element should take constant time. Thus initialization can't be done during the first access or anything like this. (You have to work with this matrix in the same way we worked with an uninitialized array.)

All related functions should be implemented. If you implement operator == don't forget to add operator !=

send me all the files (and instructions if needed) + the output of the main()

---------------------------------------------------------------------------------------------------------------

// ADD REQUIRED INCLUDES. int main () { const Matrix m1; // Creates 3*2 matrix, with all the default elements set to 0; Matrix m2(4); // Creates 3*3 matrix, with the default elements equals to 4; const Matrix m3 = m2; // C-py constructor may take O(MN) and not O(1). // min() returns the minimal value in the matrix. if (min(m1) < min(m3)) cout << "Min value of m3 is bigger"; if (m1.avg() < m3.avg()) // Compares the average of the elements cout << "Max value of m3 is bigger"; m2(0, 0) = 13; cout << m2[0][0] << " " << m2[1][0]; // Should print "13 4" try { cout << m2 + m3 << m3 * m1; // You can choose the format of matrix printing; cout << m1 * m2; // This should throw an exception } catch (const Matrix::IllegalOperation& e) { cout << e.what(); } Matrix m4; m4 = m3; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) m4(i, j) = i+j; cout << "m3[1][1] = " << m3[1][1]; cout << "m4[1][1] = " << m4(1,1); // m4(1,1) same result as m4[1][1] Matrix m5(3); m5 = 2 * m4; Matrix m6(m4); m5 += m4; if (m6 != m5) cout << "m6 != m5"; Matrix, 4, 4> composite(m1); // Creates matrix, where each element is m1; cout << composite; auto_ptr> symetric_matrix(new SymetricMatrix(5)); // SymetricMatrix matrix 3*3 with default element equals to 5; (*symetric_matrix)(1, 2) = 8; cout << (*symetric_matrix)[1][2] << " " << (*symetric_matrix)[2][1]; // Should print "8 8" return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions

Question

=+Are there shop stewards?

Answered: 1 week ago