Assignment briefing: Windows user please use CodeBlocks, whilst Mac user can use Xcode. This assignment will assess your ability to solve a problem using C as a tool. You will be using these C programming elements: repetition (e.g. for.. or while..), selection (if), structures, two dimensional arrays, pointers, I/O and functions. Your task is to write a C program to:
• **Allow the user to input the name and size of a matrix of integers. The contents of the matrix are read in from a file, which has a list of 100 integer numbers. (so for eg, if the matrix is 3×2, then the first 2 numbers form the first row, the second 2 numbers form the second row …and so on).
• The matrix of integers must have between 1 and 10 columns and between 1 and 10 rows. The matrix name, size (rows x columns) and contents will be stored in a struct matrix, which is specified below.
• Display the name and contents of the matrix to the screen.
• Ask the user to choose the row and column to form a 2×2 matrix, which is a subset of the
original matrix. The 2×2 matrix contents must be stored in a new struct matrix, along with its name and size. The determinant of this matrix is then calculated. (See sample run of program below).
• Display the name and contents of the 2×2 matrix and determinant to the screen.
• Find the inverse of the 2×2 matrix. The inverse matrix contents must be stored in a new struct
matrix, along with its name and size.
• Display the name and contents of inverse matrix to the screen.##
• Loop from ** to ##, but allow the user some way of exiting the loop and stopping the program
The program shall define a structure to hold information about the matrices as follows: struct matrix {
char name; // to hold the 1 character name of the matrix
float mValues[10][10]; // to hold the values in the matrix, up to 10 rows x 10 columns
int nrows; // to hold the number of rows used in mValues int ncols; // to hold the number of columns used in mValues };
Notes (refer to mark scheme for more details):
1. The array that holds the matrix values has maximum size 10×10, which means that the program must be able to work with any array up to that size. For this program, the minimum array size allowed is 1 x 1. 2. Whenever a new matrix is input or created in the program, the program must allow the user to assign the matrix a name of max 1 character, e.g. ‘A’, ‘B’, etc.
3. The program must display to the screen the name and the contents of each matrix in the program, after it has been input or created.
4. The program must allow both square and non-square matrices, e.g. 3 x 3 is square, 3 x 4 is not square. 5. You must program defensively. The program must check for out of range values (including non- numeric characters, eg r) at every possible instance, as well as checking if the input file is available. You also need to take into consideration things like: determinant of a 1×1 matrix, possibility of generating a 2×2 matrix (because the input matrix is smaller, eg, 2×1), and finding the inverse when the determinant is 0 or does not exist.
6. You cannot use global variables. You will get 0 for the whole code. #define can be used.
7. The program must include main( ) and 4 functions. Each of the four functions must be called from main( ) and not from any other function. The function prototypes must be as follows:
void matrixInput(struct matrix *mat); /* to input the size (number of rows and columns) of the matrix, the name of the matrix, and read in the values from the file into the 2D array that makes up the matrix */
void matrixDisplay(struct matrix mat); /* to display the name of the matrix and the values in the 2D array that makes up the matrix*/
int matrixDeterminant(struct matrix m1, struct matrix *m2); /* to find the determinant of m2, where m2 is a 2×2 subset matrix of m1; this function does not display either m1 or m2 */
void matrixInverse(struct matrix m2, int determinant, struct matrix *m3); /*to find the inverse of the 2×2 matrix; this function does not display either m2 or m3 */
8. You are free to add extra functions, for example, for out-of-range checks (for rows and columns).
Sample