This lab will help you practice with vectors and libraries.
Write a program to find the median of the user's data. The median is defined as the middle number in an ordered sequence. If the sequence has an even number of values, the median is the average of the two middle numbers.
Place your median function in a library for statistics support (stathelp?).
Your driver (to test your median function) should fill a vector, retrieve the median, report it, and ask if the user wants to go again. For the filling, just read values from the user until a non-numeric value is entered.
How many values can your program handle?
Does your program have the user enter ordered data or did you ensure it was ordered with a sort? (Hint: which way do you think is worth full credit?)
In a list of n data items, what is the value of the middle item for odd n? What if n is even?
This assignment is (Level 3).
Add (Level 1.5) to allow the user the option of entering the data by hand (as it is now) or filling the vector randomly. The user should be allowed to specify the bounds of the range for the random values with which you are filling the vector.
Add (Level 1) to develop functions which can generate random floating point values within a specified range and random characters within a specified range. Place these functions in a library. Create a small test program to make sure they are working. (This should be cat, compiled, and run during your script along-side the primary program for medians.) Hint:
inline long rand_range(long low, long high) { return low + rand() % (high - low + 1); } inline double rand_range(double low, double high) { // may call 'long' version } inline char rand_range(char low, char high) { // may use type-casting and call 'long' version }
Does your random library need an implementation file? Why/Why not? (Hint: for the double version, it might help if you had an intermediate function called rand_01().)
This option does not count if you already did it for the sorting lab...sorry.