Question: PROBLEM: Write a function that has four arguments: a one dimensional array (input) the length of the array (input) average of the array (output) distribution

PROBLEM: Write a function that has four arguments:

a one dimensional array (input)

the length of the array (input)

average of the array (output)

distribution of grades array (output). This function will be in its own file separate from the other code. The function prototype is:

/* function to return average & distributed grade count */

void class_stats(int grades[], /* input, array that holds data */ int number_of_grades, /* input, actual size of the file */

double *average, /* output, average of the array */

int distribution[]); /* output, distribution count */ You will need the file lab5.c as your main/driver program for the function. This main program will set things up, read the values from the file, and print the output sentences. You will also need the file lab5.h.

ALGORITHM DEVELOPMENT - Pseudocode: int main(void) /* given to you */ Print your name & assignment number.

Loop through each file

Call get_data function and get the number_of_grades.

Call class_stats.

Call print_all and print out the average and the distribution. /*--------------------------------------------------------------------*/

int get_data (const char * filename, int grades[])

/* sub-function given to you */

Open the data file and check for error on open. Read and count the values, putting them into an array, returning the number_of_grades. /*--------------------------------------------------------------------*/

void print_all (const char * filename, double *average, int distribution[])

/* sub-function given to you */

Print to the screen, rather than to a file.

Print the headers, Average, and then the Grade Distribution /*--------------------------------------------------------------------*/

#include lab5.h void class_stats( int grades[], int number_of_grades, double *average, int distribution[])

/* A sub-function for you to write. Place it in a separate file. */ set *average to zero

for loop from zero to < DIST_SIZE, incrementing by one

zero out each element of the distribution array for loop from zero to < number_of_grades, incrementing by one

add the current value from the grades array into *average or sum

compute the correct position in distribution array for current grade

(Hence divide the current grade by ten, using integer division.) Add one to the count in the distribution array, based on the position

just figured above. [Example: if grade is 66, the position would be 6 (because it is a grade between 60 and 69) and distribution[6] would have a one added to it.] figure the average

return /*--------------------------------------------------------------*/

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!