Question: Your assignment is to write a program which will read in pairs of matrices from the user, calculate the sum and product if appropriate, and

Your assignment is to write a program which will read in pairs of matrices from the user, calculate the sum and product if appropriate, and output the results.

this is what i have so far but im terible with dynamic memory allocation not sure on if i even set this up right.

NOTE: YOU CANNOT USE GLOBAL VARIABLES IN THIS PROGRAM! YOU WILL GET A 0 IF YOU DO!

Your assignment is to write a program which will read in pairs

The user will specify the size of each matrix along with the data for the matrix.

After the program has read in a pair of matrices, it will need to validate the dimensions are appropriate to enable the calculation of the sum. If valid, the sum should be calculated in a separate function that creates a sum matrix and returns it as its result.

After the previous step, your program should then determine whether the dimensions of the matrices are appropriate to generate a product matrix. If so, the product of the matrices should be calculated in another separate function. This function creates a product matrix and returns it as its result.

Requirements

You must write a function that creates a matrix from user input. This function will need to get the size of the matrix from the user, dynamically allocate space for the matrix, and get user input (ints) to fill the matrix. Everything should be done with pointers and pointer arithmetic. The function will return the starting address of the matrix, and must also inform the caller of the number of rows and columns in the matrix. Hint: output parameters..

You must write a function that displays the contents of a matrix row by row. The function is given the address of the start of the matrix along with the dimensions of the matrix. Everything should be done with pointers and pointer arithmetic.

The sum function needs the starting addresses of two matrices along with the dimensions of one of the matrices. Note: both matrices must have the same dimensions to be able to add them together. The sum function must allocate space for the result matrix. The starting address of the result matrix is returned to the caller. Everything should be done with pointers and pointer arithmetic.

The multiply function needs the starting addresses of two matrices along with the dimensions of both of the matrices. Note: the number of columns in the first matrix must be the same as the number of rows in the second. The multiply function must allocate space for the result matrix which has the number of rows of the first matrix and the number of columns of the second. The starting address of the result matrix is returned to the caller. Everything should be done with pointers and pointer arithmetic.

The main program will call the function to create a matrix twice to get 2 matrices from the user. Main will need to allocate variables necessary to hold all the information returned by the create function. The main function will then output the two matrices entered by the user.

The main function will determine if the two matrices can be added and call the sum function if appropriate. The returned matrix should be displayed. The basic algorithm for summing matrices is:

For each row x less than r

For each column y less than c

Result[x][y] = InputOne[x][y] + InputTwo[x][y]

The main function will determine if the two matrices can be multiplied and call the multiply function if appropriate. The returned matrix should be displayed. The basic algorithm for multiplying matrices is:

For each row x less than r1

For each column y less than c2

Result[x][y] = 0

For each element z less than c1

Result[x][y] += InputOne[x][z] * InputTwo[z][y]

All functions must be commented explaining the purpose of the function, the parameters, and the return value.

exerrise7 Micrascit Visual Sturdio Uuck La.nchtn-UJ Debug 6 LocalWndows Deb gr Auto Elobs Scopel wrch Sulutiun Expon l Solution cse nt Inputone(int x. 1nt y) -Ertemal Depende nt InputTwo(int x, int y) Reisuice Fik Source tes int result int x, int y void ain) for (x r for (y c) result[xlyl nputUnelxllylInputlwo[xllyl; for (y

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!