Calculate the determinant

Assignment Help C/C++ Programming
Reference no: EM133112553

C Programming Task

You must make sure that your code runs on Codeblocks .It is your responsibility to submit a .c code that compiles and runs.

Briefing:
This task will assess your ability to solve a problem 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 size of a matrix. The contents of the matrix are read in from a file, which has a list of 100 float numbers (numbers in the file are <100.00). If the matrix is 3x2, then the first 2 numbers in the list form the first row, the second 2 numbers in the list form the second row ...and so on).
• The matrix must have between 1 and 10 columns and between 1 and 10 rows. The matrix size (rows x columns) is determined by the user, and this information is stored in a struct matrix (specified below) in members int nrows and int ncols.
• The contents of the matrix will also be stored in the struct matrix in member float mValues[10][10].
• Calculate the determinant: Ask the user to choose the row and column to form a 2x2 matrix, which is a subset of the original matrix. The 2x2 matrix contents must be stored in a new struct matrix variable, along with its size. The determinant of this matrix is then calculated. (See sample run of program below).
• Find the inverse of the 2x2 matrix: The inverse matrix contents must be stored in a new struct matrix variable, along with its size. ##
• 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 (only define one structure, but declare 3 structure variables: one for the original matrix, one for the 2x2 sub matrix and one for the inverse):

struct 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 10x10, 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. A sample .txt file with 100 numbers is available on ACS130 Blackboard. Please note that you will need to test your code thoroughly to cover every possible scenario (eg to get a det=0). I will be using a different test data to test your program.

3. The program must display to the screen 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 ofrange values for rows and columns at every possible instance. The program must ask the user to enter again if incorrect. You also need to check if the input file is available. You also need to take into consideration things like: possibility of generating a 2x2 matrix (because the input matrix is smaller, eg, 2x1), having a 1x1 matrix, 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. You cannot use while(1) loops. You will get 0 for the whole code. You can use a while(OK) loop where OK is a variable that is, for eg, 0 or 1

8. You cannot use break (unless it is part of a switch case).

9. You cannot use goto, continue, jump.

10. The program must include main( ) and the following 4 functions. The function prototypes must be as follows:

void matrixInput(struct matrix *mat, FILE *in); /* to input the size (number of rows and columns) of the matrix, and read in the values from the file (using fscanf) into the 2D array that makes up the matrix */ NOTE, the file opening and checking occurs in main(), eg FILE
*fin; fin=fopen(" xyz.txt",'r'); then use fin in the function call.

void matrixDisplay(struct matrix mat); /* to display the values in the 2D array that makes up the matrix*/

float matrixDeterminant(struct matrix m1, struct matrix *m2, int
*check); /* to find the determinant of M2, where M2 is a 2x2 subset matrix of m1; returns determinant to main. If determinant is not equal to 0, check =1; if determinant=0, cheCK=2, otherwise check is 0 (when size of matrix <2x2). check variable is needed for the inverse. This function does not display either M1 or M2. */

void matrixInverse(struct matrix m2, float determinant, struct matrix
*m3); /* to find the inverse (if possible) of the 2X2 matrix; this function does not display either M2 or m3. */

11. You are free to add extra functions, for example, for out-of-range checks (for rows and columns), or any other defensive programming required, but you must have the 4 functions listed above.

Attachment:- C Programming - Structures and 2D arrays.rar

Reference no: EM133112553

Questions Cloud

What is the net present value of the project : Your company has five delivery trucks that are getting old and only have two years of useful life left in them. As they are not fuel efficient and need a lot of
Calculate the present value of the bond : On January 1st, 20Y1 Buckle Corporation issued $160,000,000 of 10-year, 12% bonds at a market interest rate of 15%. Calculate the present value of the bond
What is the project payback period : What is the project's payback period? Round your answer to two decimal places.
Outline and detail the ethical decision-making model : Mary Rogers graduated from Deakin and joined a financial advice firm. She succeeded in passing the three month probation period, and she now works full-time wit
Calculate the determinant : Calculate the determinant: Ask the user to choose the row and column to form a 2x2 matrix, which is a subset of the original matrix
Prepare the adjusting journal entries as of august : A telephone bill in the amount of $122 covering August charges is unpaid at August 31. Prepare the adjusting journal entries as of August
Regression equation of e : Given the fitted the regression equation of E(Price ¦ Weight) =-260 + 3721 Weight and an RMSE from the regression of 32, then which of the following is the appr
Discuss the credit risk management measures : Discuss the credit risk management measures available to a financial institution
Capital structure and the percentage change in wacc : MGMT2023 paid dividends of $10 last year. The dividends are expected to grow into perpetuity at a rate of 7%. The price of each stock is set at $60 per share.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Program simulates the game of paper, rock, scissors

This program simulates the game of paper, rock, scissors. At each turn each player enters R, P, or S (either upper or lower case) to indicate their choice. The program announces the winner along with a message indicating the reason (such as Paper cov..

  Display the resut on the screen

C program that will receive sixteen integer numbers from the keyboard, store them n a two dmensional array then display the resut on the screen

  Write a c++ program that creates and populate a tree

Write a C++ program that creates and populate a tree for an arithmetic expression. Then it should perform an in-order and a post-order traversal on the tree.

  Describe the logical formulas realize boolean functions

Many familiar gates correspond to familiar sentential connectives, such as '~', '/\', and '\/'.

  Write a program about a book order

Write a C++ program that asks for the following information about a book order from the console: Title and Author

  Define the method called fraction done

Write a method called fraction Done that could be added to the class Date Third Try in Display 4.4. The method fraction Done has a parameter target Day of type.

  Enrolling courses for students and for enrolledclass

A summary of business activities for enrolling courses for students and for enrolledclass lists for faculty members at an online university is as follows:

  Determine the best threshold size for the combined

Design an experiment to determine the best threshold size for the combined "quicksort-plusinsertion-sort" implementation. You'll need to consider a range of data sizes, including both random and "worst-case" data sets.

  Compute the time required to cut the grass

Write a program that takes the length and width of a rectangular yard and the length and width of a rectangular house situated in the yard.

  Write a function num_digits(n)

C programing, not C++ write a function num_digits(n) that returns the number of digits in a nonnegative integer n.

  Create a graphical calculator with buttons

Create a graphical calculator with buttons that can add, subtract, multiply, divide, +/-, Sin, Cos, Tan, clear and Modulus and write a method for each of these calculations that will accept the needed incoming numbers and return the calculated value.

  Design for storing the maze layout

Design and implement a C++ program for maze layout

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd