Programming Project 4
Age Statistics
NOTE: The extra credit parts are in red.
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;
}
15 and under 16 to 20 21 to 30 31 to 40 40 and aboveHere is the function call you would use:
GenerateAgeGroupTable(ageList, numberOfPeople);
This function call is given because the function needs to be called from within the ProcessAgeStats function. Therefore, there is no call in main() from which you can build the prototype on your own.
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:
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:
Here is an example of what the input data file could look like:
You will also find proj4.c in the directory with
ages.dat. You can copy it to your own directory
following the above directions.
Here is a sample submission command. Note that the project name starts with uppercase 'P'.
submit cs104_0501 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_0501 Proj4