#
~~Homework 11:~~
Extra Credit 3:
Median

##
Due:
~~Tuesday 4/24 by 11:59pm~~
Friday May 11, 2012

## Objectives

More practice with arrays.

## Assignment

This assignment is a continuation of
Classwork 14.
(Note: you must still submit Classwork 14 and Homework 11 separately.)
For this assignment you will extend your program in
Classwork 14
to calculate the *median* score. Recall that the median
score is the value *x* such that half of the scores are
less than or equal to *x* and half of the scores are
greater than or equal to *x*.
(Note: if there are an even number of values, then two
values might be considered the median. Just report one
of these two values, do not take the average.)

For example, the median of {1, 7, 2, 2, 4, 2, 9, 3, 7} is 3 because 4 values (1, 2, 2 and 2) are less than 3 and 4 values (7, 4, 9 and 7) are greater than 3.

## Notes

- Make a
**copy**of your program from Classwork 14 using the Unix`cp`command:cp mode.c median.c

- Two test files have been prepared for you:
`hw11test1.txt`and`hw11test2.txt`. The first one has 21 scores and is good for debugging. The second file has 999 scores. -
It is useful to print out
`n`just for debugging/development purposes. - Think about how to calculate the median.
You already have the
`count[]`array computed. If you iterate through the`count[]`array, you should be able to determine when half of the scores have been encountered. Then you have the median. Do this by hand on a small example first. - Remember to use input redirection.
PT[351]% ./a.out <hw11test1.txt The number of scores is 21. The average score is: 13.047619 count[0] is 0. count[1] is 1. count[2] is 2. count[3] is 0. count[4] is 0. count[5] is 0. count[6] is 0. count[7] is 1. count[8] is 1. count[9] is 1. count[10] is 0. count[11] is 1. count[12] is 2. count[13] is 1. count[14] is 0. count[15] is 1. count[16] is 2. count[17] is 2. count[18] is 1. count[19] is 2. count[20] is 3. The mode of the scores is 20. It occurred 3 times. The median score is 15.

- Test your program on your own test data as well.
Your
`myrandom()`function from Homework 9 can be used to generate test data. Your program will also be tested on data other than`hw11test1.txt`and`hw11test2.txt`.

## What to submit

Use the `script` command to record yourself compiling your
program and running your program on
`hw11test1.txt`,
`hw11test2.txt` and
any other test file that you have created.
Then submit your program and typescript file as usual:

submit cs104_chang hw11 median.c typescript