Homework 8 - UMBC-CMSC104/General GitHub Wiki
The assignment
Name this homework analytic_engine.c. Also, please read the entire assignment before implementing. There is an important detail that will make this less annoying.
For this homework, we'll be performing some analytics on data: average and median. Your program will need to support calculating this on 20 different numbers. You'll need to handle reading in 20 values for either one. Assume that this list is sorted.
IMPORTANT: Your program should first read an integer. If this number is 1, than this is an average calculation. If this number is 2, than this is a median calculation. After this, you should read in your 20 numbers. These numbers should be stored in an array.
After this, it should print out the analytic information (average for average, median for median):
Average: 48.250000
or
Median: 44
Data files
Now, rather than manually typing in all of these numbers when we test the program, we're going to do something different. We're going to use files as input. To support this, I've made two data files for you, as well as a program that will automatically generate a random list of numbers.
To obtain the data files and program, type:
cp /afs/umbc.edu/users/m/w/mwilson3/pub/cmsc104/hw08/average.txt .
cp /afs/umbc.edu/users/m/w/mwilson3/pub/cmsc104/hw08/median.txt .
cp /afs/umbc.edu/users/m/w/mwilson3/pub/cmsc104/hw08/data_generator.py .
Once you've written your program, you can feed a data file into your program by typing:
./analytic_engine < average.txt
or
./analytic_engine < median.txt
You can generate new data files by typing:
./data_generator.py avg > new_data_file.txt
for a file that is meant for average calculation, or:
./data_generator.py med > new_data_file.txt
To submit:
submit cs104_wilson hw08 analytic_engine.c
IMPORTANT
For the data files to work properly, your program must adhere exactly to the menu/data reading specification described above. That is, a menu that reads in 1 or 2, followed by 20 number scans, and then a print. You can assume that this data will be entered only by data file.
Extra Credit
Three things you can do for extra credit:
- Add a third analytic for standard deviation and calculate that. This will be the same number list as before, but it will begin with a 3 instead of a 1 or 2.
- Handle arbitrary amounts of numbers (not just 20) up to 256. If you do this, you can utilize the -1 at the end of the data file.
- Handle unsorted data. This will be easiest utilizing qsort.
If you want to generate a data file for files larger than 20, you can use the data_generator.py with the --num-of-integers option:
./data_generator.py avg --num-of-integers 40 > large_data_file.txt