This lab will help you practice with dynamic memory (NOT mixed with classes).
One statistic of interest to many researchers is the median of a set of data. The median is the value in the middle. (This is NOT the average, mind you.) Being in the middle, of course implies that the data are in order (sorted). If there are an odd number of data items, the middle is simple to find. If there are an even number of data items, you are supposed to take the average of the two middle values.
You'll need to find the median of a set of data from a file. You don't know how many data are in the file, of course. You'll have to count the data, then read them in to sort, then find the median, and finally print it (the median) out.
(BTW, there are three sorts described in the online notes from 121 as well as the pseudocode for a decent bubble sort with several suggestions for efficiency tuning. You cannot use the sort function talked of in chapter 7! You also cannot use the qsort function you might find on the web...)
Do NOT use any more memory than is necessary!!
This assignment is (Level 1.5).
Add (Level 1) to allow the user to repeat the median calculations with another file as long as they would so desire. (This option is worth levels because the repetition of actions on a file brings in a new wrinkle above/beyond your typical yes/no loop. *smile*)
In fact, if you do this, you can make your program a little better by not reallocating the data array on every new file — only when you actually need more space. If you already have room for the number of items you see in the next file, why delete and reallocate? Just use the necessary portion of the array you already have. To do this will add another (Level 1) to this lab.