Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Multi-Dimensional Arrays Declaring, initializing, and displaying the contents of two-dimensional arrays: HOMEWORK: MATRIX ADDITION A matrix is a two-dimensional structure often found in mathematics.

C++ Multi-Dimensional Arrays

Declaring, initializing, and displaying the contents of two-dimensional arrays:

HOMEWORK: MATRIX ADDITION

A matrix is a two-dimensional structure often found in mathematics. For example, a 4 x 3 matrix (which has four rows and three columns) might look like this:

1.2 77 0

8.8 2 44

1 -5 11

420 15 -5

The file that stores this array would be

4 3

1.2 77 0

8.8 2 44

1 -5 11

42 15 -5

where we provide the dimensions at the beginning of the file. The program can then open the file, read the first two values, create an appropriate two-dimensional array, and then read the contents of the file into that array.

Two matrices can be added if their dimensionality is the same. For example, the above matrix could only be added to another 4 x 3 matrix. To perform matrix addition, sum the values in each location to produce the resulting matrix.

Write a program that prompts the user for the two file names, each containing one matrix. Read the two matrices into two-dimensional arrays and display them. If the dimensionality is the same, compute and display the sum of the two matrices; if not, display an error message.

BONUS HOMEWORK: MATRIX MULTIPLICATION

Matrix multiplication is possible if the number of columns of the left-hand matrix is equal to the number of rows of the right-hand matrix. For example, if you wanted to multiply the 4 x 3 matrix above by a second matrix, that second matrix must have three rows.

The resulting matrix has the row count of the first matrix, and the column count of the second matrix.

For example, multiplying a 4 x 3 matrix by a 3 x 8 matrix produces a 4 x 8 result.

The algorithm for matrix multiplication is readily available online. Write a program that prompts the user for the two files that contain the matrices, displays the two matrices, and then (if possible) multiplies them and displays the result. If multiplication is not possible, display an error message and exit. Note that matrix multiplication (unlike numeric multiplication) is not commutative, so make sure you provide the file names in the correct order.

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

7 Explain the equity theory of motivation.

Answered: 1 week ago