UMBC CMSC 104 | CSEE | 104 | current 104 |
CMSC104, Fall 2005Programming Project 4 Age Statistics
Out: Wednesday, Dec 2, 2005
The ObjectiveThis project is designed to give you practice working with arrays and functions. It will also give you practice passing arrays to functions.
The TaskYou 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
Input to the ProgramA 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 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
You will need to copy the file
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:
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
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 1435 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 ProgramHere 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
|