Gradebook (Function) Assignment

CSC 7000-002 Algorithms & Programming
Fall 1999, Mendel 115
Dr. David Matuszek

A statistics professor likes to assign grades on the basis of Z-scores, according to the following table:

Z-score  Grade 
1 <= score A
0.5 <= score < 1 B
-0.5 <= score < 0.5 C
-1 <= score < -0.5 D
score < -1 F

She wants you to write a program to take the raw (unprocessed) scores for her students, which will be in the range zero to 100, and convert them to Z-scores. To test your program, since you don't have access to the actual grades, write a function to generate ("make up") some data. For the names of your students, just use numbers: if the class has 25 students, number them 1 to 25.

Here are the specifics of the functions you are to write:

int generate_raw_score (void)
Return a random integer value between 1 and 100, inclusive. Do this by getting five random numbers, each in the range 0 to 20 inclusive, and returning their sum. (This is a way of approximating a normal distribution.)
 
double mean (int raw_score[], int count)
Return the arithmetic mean of the array of integers (the second argument specifies the size of the array). Compute the mean by adding together all the numbers in the array, and dividing by how many there are.
 
double standard_deviation (int[] raw_score, int count, double mean)
Return the standard deviation of the array of numbers, given the mean. (For each number in the array, subtract it from the mean and square the result; add all these squares together, divide the total by the number of scores*, and take the square root).
 
double z_score (int raw_score, double mean, double stdev)
Given a single raw score, convert it to a Z-score by subtracting the mean from it, and dividing by the standard deviation.
 
char letter_grade (double z_score)
Given a single Z-score, convert it to a letter grade.
 
void print_grades (int raw_score[], int count)
Compute and print a table (with column headers) containing the numeric student id, raw score, Z-score, and letter grade for each student. 

Your program and all your functions should be documented with comments. Arrange your program so that it doesn't do redundant computations; for example, you should compute the mean only once. Try to avoid creating another array to hold Z-scores.

The purpose of this assignment is to familiarize you with writing and using functions.

Alternate assignment: Write a program that uses three or more functions that you define. At least one of your functions should return void, at least one should return an actual value, at least one should take no parameters, and at least one should take (and use) one or more parameters. Use comments to document your program, including all your functions. If appropriate, try to use at least one function from <math.h>.

* Thanks and 5 points to Rusong Wang for discovering this error.