UMBC CS 104
UMBC CMSC 104 CSEE | 104 | current 104

CMSC 104, Spring 2002

Project 8 - Using Arrays with Functions

("Exam Statistics" Revisited)

Due Date: Midnight, Tuesday May 14

Note: No late projects will be accepted.

Point Value:

This assignment is worth 50 points.

Objectives:

This assignment is very similar to Project 6, "Exam Statistics." But this time, you will be reading the exam scores into an array and then producing statistics, rather than processing the exam scores one at a time. You will also be dividing your program into functions. The code for the main function will be supplied (see below). You will need to write the code for the remaining six functions and their prototypes.

Note that for this project you only need to compute the number of A's, not the number of B's, C's, D's, and F's.

Assignment:

Background

Congratulations! You are the new Teaching Assistant for CMSC 104, Section 0601! As part of your job, you are to write a program to analyze class exam scores. Your program should compute

Save your program in a file called proj8.c.

A data file containing the scores for you to use as input to your program will be provided. (NOTE: These are NOT the real scores from your exams!) The scores are between 0 and 100, inclusive, and are in random order. The last value in the file is
-1. This is the sentinel value that signals the program to stop reading scores.

To use the data file as input to your program, you will use Linux redirection. By using redirection, you can tell Linux to read data from a file rather than from the keyboard. The scanf statement that you use in your program will look exactly the same as it would if you were getting your input from the keyboard. But since you will be getting the values from a file instead of from a user typing at the keyboard, you will not need to prompt the user. When you run your program, use the following command:

a.out < proj8.dat This is how Linux redirection is done. It is saying to run your executable file using the file proj8.dat as input.

You will need to copy the file proj8.dat into your directory. To do this, go to the directory where you would like to store proj8.dat. Then, use the following command to copy proj8.dat into the directory:

cp /afs/umbc.edu/users/s/m/smitchel/pub/CS104/proj8.dat . Notice that the space and period at the end of the command are part of the command. Also note that this file does not contain the same data as proj6.dat did.

Sample Program Run

Here is an example of what an input data file might look like:

52 89 98 79 42 85 82 75 94 98 78 85 -1 Here is the output that would result from using this sample data file: CMSC 104, Section 0601, Midterm Exam Analysis 12 exams were taken. The highest score was 98 percent. The lowest score was 42 percent. The average score was 79.8 percent. The number of A's was 3.

Your program's output should follow this EXACT format.

Main Function

Here is the main function EXACTLY as it should appear in your program. Do NOT alter it IN ANY WAY. Note that you will have to add the following code before the main function:

You can copy the main function from my pub directory into your directory in the same manner that you copy the proj8.dat file. The file is called main8.c.

int main() { int scoresArray[MAX]; /* Array to hold exam scores */ int numExams; /* Total number of exams taken */ int highest; /* Highest numeric score */ int lowest; /* Lowest numeric score */ float averageScore; /* Average of all scores */ int numAs; /* Number of A's */ /* Read the scores into the array and compute the number of exams */ numExams = readData(scoresArray); /* Find the highest exam score */ highest = findHighest(scoresArray, numExams); /* Find the lowest exam score */ lowest = findLowest(scoresArray, numExams); /* Compute the average exam score */ averageScore = average(scoresArray, numExams); /* Compute the number of A's */ numAs = countAs(scoresArray, numExams); /* Print the final statistics */ printStats(numExams, highest, lowest, averageScore, numAs); return 0; }

Coding Standards:

Note that you MUST adhere to the coding standards and indentation style given on the Projects home page. So read them carefully and immediately!

Project Submission:

Submit your project by e-mailing your source code (proj8.c) to Zhipeng (zhipeng1@cs.umbc.edu) as an attachment. Make the Subject of the e-mail Project 8 so that Zhipeng knows what it is. Do NOT send your executable file (a.out) or the input data file (proj8.dat).



Thursday, 02-May-2002 10:21:40 EDT