C.I.S. 1.5 (Science Section)

Brooklyn College

Professor Langsam

 

Assignment #6

 

Once again, your instructors are very busy calculating and assigning your grades (that you so richly deserve). Write a program that will process student test grades. Each student has four test grades, and you are to compute the average for each student and some statistics for the tests. The input will consist of a datafile giving his/her first and last names and four test grades. Store this data in five arrays.

 

Keep a count of the number of students processed and have your program detect when all of the data has been processed.

 

After the data has been read, compute the average for each student. Call a function print, described below, to print out the data.

 

Using a function, sort, sort the data into descending order by average. (The student with the highest average comes first.) When you sort the data, don't forget to swap all of the data associated with the student. Now call print again to print the data in the new order.

 

Skip to a new page and print out the statistics for each test. For each test use functions, mean, median, mode, and sd described below to compute the mean, median, mode and standard deviation. Print these four pieces of information for each test, and label them accordingly. The mean should have 2 places to the right of the decimal point and the standard deviation should have 4 places to the right of the decimal point.

 

Once again call print to print the arrays a third time. (This should be identical with the second time it was printed.)

 

Finally, skip to a new page and print the students' scores, again using print, calculating the average after dropping the lowest score. Indicate which score has been dropped by printing an *** in its place.

 

Functions mean, median, mode, and sd are functions having two arguments, an array x, and an integer n (where n is the number of students determined earlier in your program). They return the mean, median, mode, and the standard deviation of the first n elements of the array x. The mean is the average and is defined by:

 

 

 

The standard deviation is:

 

 

The median is the value such that half of the scores lie above it and half of the scores lie below it. To find the median, the function median calls a function sort which sorts the first n elements of the array x. After sorting, the median is the middle number (if n is odd), while it is the average of the two middle numbers if n is even.

 

The function mode accepts an array and returns the element most often repeated in the array. If several elements are repeated equally frequently, return their average.

 

sort is a function whose arguments are an array x and an integer n. It sorts the first n elements of x.

 

Note: You are not allowed to rearrange the data for the students, so the argument for median must be a different array.

 

print is a function which prints the data for the students. First it skips to a new page and prints column headings as follows:

 

            Name               Test1                Test2                Test3                Test4                Average

 

Be sure to underline the headings. It then prints the data for all of the students. For average, print two places to the right of the decimal point.

 

Note: You are to print out the student scores a total of four times.

 

Data: Use the following datafile when you run the program.

 

            Name                                       Test1                Test2                Test3                Test4   

            Albert Einstein                          53                       75                    92                    68

            Charles Babbage                      96                       72                    85                    92

            Claude Shannon                       91                       86                    87                    41

            John vonNeumann                    40                       93                    92                    78

            Niklaus Wirth                           59                       83                    91                    67

            Ada Lovelace                          91                       84                    98                    63

            Thomas Bayes                          70                       81                    92                 100

            Sofia Kovalevskaya                  31                       46                    53                    61

            Blaise Pascal                            90                       72                    80                    75

            Grace Hopper                          81                       92                    73                    80

            Isaac Newton                           32                       85                    93                    67

 

All output is to be to a file. Be sure to use the structured programming techniques discussed in class as well as meaningful variables and appropriate comments. Submit your program and input and output files.