Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ using calsses: you can find the main() function of some program. we need to write the real main file and the needed classes (including

C++ using calsses:

you can find the main() function of some program. we need to write the real main file and the needed classes (including implementation) so that the code would work. 1. The code should be working correctly. 2. All related functions should be implemented. If you implement operator == don't forget to add operator != 3. Define const functions when possible. 4. Don't add functions that you was not asked to implement. 5. You can add #includes that are needed. 2. Design & Style 1. Don't do something twice! No code duplication. 2. The code should be easy to read. 3. Use all needed #define etc. 4. Use inline, explicit etc when possible.

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

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.)

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

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago