CS 368 Program 1: Process Student Grades

What to Write

This assignment involves writing code that processes information about the students in a class. You will need to use the following declarations:

You are to write two C++ functions called ReadStudents and HighestAverage, whose headers are given below, as well as a main function that tests the other two.

ReadStudents should read (from the given input stream input) information about students and their grades, and should store information about each student in the Info array (one array entry for each student). ReadStudents should also return the number of student records that were read.

You should assume that the array is large enough to hold information about all of the students. (However, note that the number of student records in the input file is not one of ReadStudents's parameters; if you use code like the following:

the while loop will terminate when input is at end-of-file.)

Assume that for each student, the input contains the student's ID (a 9-digit number), followed by the student's grades (NUMGRADES of them), with the ID and the grades separated by whitespace (spaces, tabs, or newlines). ReadStudents should store each student's ID, grades, and average grade in one element of the Info array.

HighestAverage should determine which student in the Info array has the highest average grade, and should set its id and maxAv parameters to the value of that student's ID and average.

Finally, your main function should be written to expect one command-line argument: the name of the file that contains student data. It should open that file for reading, then call ReadStudents to fill in an array of information about the students, then call HighestAverage to determine which student has the highest average, and finally should print (to the standard output), the message:

(Where x is the student's ID, and y is the student's average grade.)

Here is how to have your main function open the file named on the command line for input:

Note that in C++ (unlike Java), args[0] always contains the name of the program being executed. The other values in the args array are the command-line arguments.

Files and Compilation

Put the declarations of NUMGRADES and StudentInfo (as well as the two #includes), and the headers for functions ReadStudents and HighestAverage in a (plain text!) file named prog1.h. (Files with the .h extension are called header files, and will be discussed in the on-line notes for lesson 3.) Put the actual functions into a file named prog1.C, and put your main function in a file named main.C. Start both prog1.C and main.C with: To test your program, create an executable by typing: (this will create an executable named a.out).

What to Hand In

Hand in your code by uploading prog1.C, prog1.h and main.C (but not your executable), we will test your code with our own main function as well as running yours, so be sure to use exactly the definition of the StudentInfo structure given above, and exactly the right function names.

Grading Criteria

Your grade will depend on:

What to turn-in:prog1.C