Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Matrix Utilities (matrix utils.c) A dynamic integer matrix is a two dimensional array of integers. It can also be descried as a pointer to

2. Matrix Utilities (matrix utils.c) A dynamic integer matrix is a two dimensional array of integers. It can also be descried as a pointer to a pointer or an array of pointers. In this program you will write several small utility functions to test mastery of this concept. The function signatures and descriptions follow below. You may assume that the matrix will be a square matrix meaning that the number of rows equals the number of columns in the matrix.

Implement these functions:

int** makeMatrix(int n);

void printMatrix(int **A, int n);

bool sumEqual(int **A, int **B, int n);

bool isEqual(int **A, int **B, int n);

int diagonal(int **A, int n);

int** sumMatrix(int **A, int **B, int n);

int** product(int **A, int **B, int n);

int** subtractMatrix(int **A, int **B, int n);

For extra credit ONLY:

double** inverseMatrix(int **A, int n);

double** matrixDivision(int **A, int **B, int n);

SPECIAL NOTE: the last two functions (inverse and matrix division) are NOT required for full credit for this problem and are detailed below in the extra credit section at the bottom of this document. If you decide not to implement them, you should simply print NOT IMPLEMENTED and return to the main menu when their choice is selected in the main menu

Please read the description of these functions carefully.

The makeMatrix function dynamically allocates memory for an integer matrix of size n and allow the user to enter values for each position of the matrix from left to right row by row then returns the created matrix.

The printMatrix function displays the matrix from its argument row by row legibly enough so that a grader can see the numbers corresponding to each position of the matrix.

The sumEqual function computes the sum of all elements in each matrix and see if the sum of each matrix is equal to one another. The function returns true if the sums are equal or returns false if the sums are not equal to one another. You may want to use the enumerated type named bool that has only two values: true and false. It is defined in the stdbool.h header file. Function takes two matrices and an integer indicating the size of both matrices. Example (sumEqual): 1 2 3 4 and 5 5 0 0 is true.

The isEqual function checks each matrix element by element and see if each element of matrix A is equal to its corresponding element in matrix B. It returns true if the two matrices are element-wise qual or false if even one element is not equal to its corresponding element in the other matrix. You may want to use the enumerated type named bool that has only two values: true and false. It is defined in the stdbool.h header file. Function takes two matrices and an integer indicating the size of both matrices. 4 Example (isEqual): 1 2 3 4 and 1 2 3 4 is true.

The diagonal function calculates the product of the elements along the diagonal of the matrix and returns that number. Function takes a single matrix and an integer indicating the size of the matrix. It returns the product. Example (diagonal): 1 2 3 4 The product of the diagonal elements of the above matrix is 4.

The sumMatrix function computes the sum of the two matrices. Note that the matrix sum is done element by element in the two matrices. Function takes two matrices and and an integer indicating the size of both matrices. It returns a new dynamic matrix that contains the element by element sum for the corresponding positions. Example (sumMatrix): 1 2 3 4 and 5 5 0 0 is 6 7 3 4

The product function computes the matrix product by multiplying two matrices. It takes two matrices and an integer indicating the size of both matrices. It returns a new dynamic matrix that is the result of matrix multiplication. Matrix multiplication is done as follows: 5 C = A B The entries for C are: cij = Xn k=1 aikbkj where 1 i, j n and cij is the (i,j)-th entry of the matrix C. Example (product): Consider the following two matrices. A = 1 2 3 4 and B = 5 5 0 0 Then, A B = 5 5 15 15

The subtractMatrix function computes the difference of two matrices. The function take two matrices and an integer indicating the size of both matrices. It returns a new dynamic matrix containg the element-wise subtracion. Example (subtraction): Consider the following two matrices. A = 1 2 3 4 and B = 5 5 0 0 Then, A B = 4 3 3 4 Your main function should operate similar to the array problem in the last homework assignment. Meaning it will first prompt the user for a size value to be used for both matrices then allow data for them to be entered. The function then prints a menu as 6 defined below and allows user to enter a menu choice accounting for the fact that they may enter an invalid choice. It then displays the results of that choice assuming it was valid and prompting for choice again if menu choice was invalid.

Menu options: Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT

Sample output from the program (It doesnt show the output for the bonus parts): Please enter a value for the size of matrix: 2 Enter values for matrix A: 1 2 3 4 Matrix A: 1 2 3 4 Enter values for matrix B: 5 5 0 0 Matrix B: 5 5 0 0 7 Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 1 Sum of elements in each matrix is equal Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 2 Matrix A and B are NOT identical Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 3 The product of the diagonal elements of A is: 4 Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 4 The product of the diagonal elements of B is: 0 Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 5 The sum of matrix A and B is: 6 7 3 4 8 Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 6 The product of matrix A and B is: 5 5 15 15 Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 7 Matrix A - B is: -4 -3 3 4 Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 8 NOT IMPLEMENTED Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 9 NOT IMPLEMENTED Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 10 NOT IMPLEMENTED Enter a number between 1 and 11 to select your choice from the following menu. ...menu... Your entered number is: 11 Exiting

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

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions

Question

5. What is professionalism?

Answered: 1 week ago