UMBC CMSC 104 CSEE | 104 | current 104

CMSC104, Fall 2005

Programming Project 4

Age Statistics

Out: Wednesday, Dec 2, 2005
Due: Friday, December 9, 2005 before 11:59 PM


The Objective

This project is designed to give you practice working with arrays and functions. It will also give you practice passing arrays to functions.

The Task

You have just recently attended an Eminem concert. You noticed that there was a quite diverse group of people attending the concert. Out of curiosity you have decided to attend another concert and pass out a survey asking the attendees to list their ages. Based on their ages, you are going to determine some statistics about the people attending the concert. You are to store the ages of the people attending the concert in an array. Here is the main function that you MUST use in your program:

int main()
{

   int   ageList [MAX];      /* Array to store ages of people attending  */
   int   youngestAge = 0;    /* Age of youngest person                   */
   int   oldestAge   = 0;    /* Age of oldest person                     */
   int   numberOfPeople = 0; /* Total number of people                   */
   float averageAge  = 0.0;  /* Average age of people attending          */

   /* Fill array with ages of people attending */
   numberOfPeople = FillAgeList (ageList);

   /* Calculate the average age */
   averageAge = ComputeAverageAge (ageList, numberOfPeople);

   /* Calculate the youngest age */
   youngestAge = FindYoungestAge (ageList, numberOfPeople);

   /* Calculate the oldest age */
   oldestAge = FindOldestAge (ageList, numberOfPeople);

   /* Determine and print age statistics */
   ProcessAgeStats (ageList, numberOfPeople, averageAge, youngestAge,
                  oldestAge);
   return 0;

}

More Details

  • You MUST use the main() function exactly as it is given. However, you need to add the following code before main:
    • A file header comment
    • Any necessary preprocessor directives
    • A #define directive to set MAX to 100
    • Function prototypes

  • You must also add the definitions of the functions after main(). You may add additional functions if you wish.

  • Your output does not have to look exactly like the sample output shown below.

Input to the Program

A data file containing the items for you to use as input to your program will be provided. The items are all greater than 0. The last value in the file will be 0. This is the sentinel value that signals the program to stop reading items.

To use the data file as input to your program, you will use Unix redirection. By using redirection, you will be able 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 < ages.dat

This is how Unix redirection is done. It is saying to run your executable file using the file ages.dat as input.

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

cp /afs/umbc.edu/users/d/b/dblock/pub/CS104/Proj4/ages.dat .

Notice that the space and period at the end of the command are part of the command.

Here is an example of what the input data file could look like:
7
12
14
35
20
17
18
33
52
21
19
20
17
18
35
19
8
0
You will also find proj4.c in the directory with ages.dat. You can copy it to your own directory following the above directions.

Note you should read the values till you encounter a zero which is the last number in the file. clearly zero should not be part of the computations. 

Sample Output

linux2[34]% gcc -ansi -Wall proj4.c

linux2[35]% cat ages.dat

7
12
14
35
20
17
18
33
52
21
19
20
17
18
35
19
8
0

linux2[36]% a.out < ages.dat

Eminem Concert Age Statistics Report There were 17 people that completed the survey.

Their ages were:

7 12 14

35 20 17

18 33 52

21 19 20

17 18 35

19 8

Breakdown by Age Group:

15 and under: 4

16 to 19: 6

20 to 29: 3

30 to 39: 3

40 and above: 1

The average age was: 21.5

The youngest person that attended was: 7

The oldest person that attended was: 52

linux2[37]%

Submitting the Program

Here is a sample submission command. Note that the project name starts with uppercase 'P'.

submit cs104_0301 Proj4 proj4.c

To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show the file that you submitted in a format similar to the Unix 'ls' command.

submitls cs104_0301 Proj4