Get Instant Help From 5000+ Experts For

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
Guaranteed Higher Grade!
Exercise to process arrays and matrices with error checking
Answered

## Function to check if an array is sorted

Instructions: You must submit a with your code for each of the following exercises which can be compiled and run successfully. Your code must include comments which explain what your code is doing. You do not need to submit any other files explaining your code. You will lose marks if you do not follow these instructions, i.e., if you do not submit a .c file per exercise, if your code does not compile successfully, and if you do not include sufficiently enough comments.

The goal of this exercise is to write a program that processes arrays and matrices. The material of units 4 and 5 will be very useful.

Your program must include the following:

(a) A function with prototype

This function takes as input an array x of n integers and checks if it is sorted in the order defined by the mode string (increasing or decreasing). It returns 1 if this is indeed the case, and 0 otherwise. The mode string can only be equal to “increasing” or “decreasing”. If none of these two strings are given as input for mode, the function must print an error message “Incorrect sorting mode” and return -1. Use appropriate functions from string.h to check the value of the mode string.

(b) A function with prototype

The first three parameters z, x, y are integer pointers and correspond to arrays. The remaining two parameters n_x, n_y are integers and correspond to the sizes of x and y, respectively. The function first checks if x and y are sorted in increasing order by appropriately using the function is_sorted defined in (a); if any of them is not appropriately ordered, then the function and returns 0 (false). If both are sorted, then it merges their elements and stores them into z, so that the elements are all sorted in increasing order. Once this is done, it returns 1 to show that the operation was successful (true).

(c) A main function that does the following:

Asks the user to enter 15 non-negative integers in increasing order, which are stored in a 3 x 5 matrix named M. If at any point the user enters a negative number, this number must not be stored in M, and instead the user must be asked to re-enter this number; in other words, you need to check whether each given number is non-negative with a loop.

Once the numbers are given and are stored in M, by appropriately calling the function merge, the program merges the three rows of M into a single array named A with all 15 elements sorted. You can call the merge function with input the first two rows of M and store the outcome in an array named x of size 10; then you can again call the merge function again with input the third row of M and the array x, and store the outcome in array A (of size 15).

If the elements are not given in sorted order by the user, then the program must print an error message “Numbers not given in increasing order” and the program must terminate. You can check whether this has happened by appropriately checking the output of the merge each time that is called.

The goal of this exercise is to write a program that uses structuresto represent students and modules. The material of Units 5 and 6 will be very useful.

(a) A structure type named student. Variables of this type must have the following members:

• a string firstname,
• a string lastname,
• and a float avg_grade.

(b) A function with prototype

This function takes as input a pointer to a student structure and asks the user to enter the name of the student. In particular, the function asks the user to enter the first name of the student which is stored in the member firstname of x and the last name of the student player which is stored in the member lastname of x. These strings must not include any spaces.

(c) A function with prototype

The input is an array x with the information of n students, and a matrix grade with their grades in 10 modules (in particular, grade[i][j] is the grade of student i for module j). The function computes the average grade of each student over all modules and stores this information in the avg_grade member of the corresponding structure. The average grade of a student is computed by summing all the grades of a student and dividing by the number of modules (in this case, 5).

(d) A main function which declares an array of 10 students and a 10 x 5 matrix that will store their grades for 5 modules.

• By appropriately calling the function read_student defined in (b) it asks the user to enter the names of all students.
• Then, it asks the user to enter the grades of each student, which are stored in the grade matrix (this is done within the main function).
• By appropriately calling the function compute_avg defined in (c), the program calculates the average grades of all students.
• Finally, it prints a list with the names of the students and the classification of their degree right next to their name as follows: First (if the average grade is at least 70), Upper second (if the average grade is between 60 and 70), Lower second (if the average grade is between 50 and 60), Third (if the average grade is between 40 and 50), or Fail (otherwise).