Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ must use header files and implementation files as separate files. Ill need a header file, implementation file and the main program file at a

C++ must use header files and implementation files as separate files. Ill need a header file, implementation file and the main program file at a minimum. Compress these files into one compressed file.

Make sure you have adequate documentation.

We like to manipulate some matrix operations. Design and implement a class named matrixMagic that can store a matrix of any size.

1. Overload the addition, subtraction, and multiplication operations.

2. Overload the extraction (>>) and insertion (<<) operators to read in the matrix and to display its output.

3. Your class must have private attributes such as: int **matrix; and variables for the number of rows and number of columns of the matrix.

4. Addition and subtraction: You can only add 2 matrices of the same size. For example, the first matrix can have 3 rows and 3 columns and the second matric could have 3 rows and 2 columns. We cannot add or subtract matrixes of different size. Check this constraint before performing addition and subtraction of matrices.

5. Multiplication: If the size of the first matrix is m X n (m is the number of rows and n is the number of columns) and the size of the second matrix is n X t (n is the number of rows and t is the number of columns), matrix multiplication only works if the number of columns in the first matrix (n) is the same as the number of rows in the second matrix (n). For example, we can multiply a 2 x 3 and a 3 x 4 matrix, but not a 2 x 3 and 4 x 2 matrix. Check this constraint before performing multiplication of matrices.

6. Use a continuous menu to allow the user for selecting the desired operation. Ask the user for the entries in the matrix and display the output.

NOTE: The purpose of this exercise is to practice with overloading of operators. The actual computation of matrices should be trivial. Start with one operation at a time. Do not try to build the entire program before running and testing individual pieces. For example, overload the input operator to read a matrix and test it. Then, overload the output operator and test it. And, then move on to matrix operations starting with the simple addition and subtraction, before moving to the matrix multiplication operation. If matrix 1 contains: 1 3 2 5 And matrix 2 contains: 4 3 6 -1 Then, the result will be: M1 + M2 = 5 6 8 4 M1 - M2 = -3 0 -4 6 M1 * M2 = 22 0 38 1 You can use the above matrices to test your code. Here is a possible sample run: Enter data for this matrix: 1 3 2 5 Enter data for this matrix: 4 3 6 -1

Here is what you entered: Matrix 1: 1 3 2 5 Matrix 2: 4 3 6 -1 Adding matrices 5 6 8 4 Subtracting matrices -3 0 -4 6 multiplying matrices 22 0 38 1 Matrix multiplication: Here is how we get the 22 in row 0, columns 0 1*4 + 3*6 = 22 1*3+3*(-1) = 0 2*4+5*6 = 38 2*3+5*(-1) = 1 The first row of the first matrix is multiplied by the first column of the second matrix and added together, to give you the first element of the new matrix, etc. As you see, you need to create a running total for the inner loop. To get the 22, youll have the total of m1[0][0]*m2[0][0]+m1[0][1]*m2[1][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_2

Step: 3

blur-text-image_3

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions