(© Rolling Stones)

CMSC104 Fall 2012

Programming Project 3

Age Statistics


Out: Tuesday, November 27

Due: Monday, December 10, before 11:59 p.m.

NOTE: The extra credit parts are in red.


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 Background

You have just recently attended the "50 & Counting: The Rolling Stones Live" concert. (This concert is for real--and they mean the band is 50--the members are about 70!) You noticed that there was a quite diverse group of people attending the concert. Out of curiosity (and because you just happen to have a few hundred more dollars burning a hole in your pocket), 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.

The Task

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

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/p/a/park/pub/CS104/Proj3/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 proj3.c in the directory with ages.dat. You can copy it to your own directory following the above directions.

Sample Output

linux2[34]% gcc -ansi -Wall proj3.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

      Rolling Stones 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 20:      8
21 to 30:      1
31 to 40:      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'.

linux2[38]% submit cs104_park Proj3 proj3.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. <code>linux2[39]% submitls cs104_park Proj3</code>