CS31 Lab 4 Extra Challange

DO NOT try this until you have finished all regular parts of this lab (Parts 1-3). Extra Challenge parts are just a way to try something with an added challenge for fun. We will award a nominal amount of extra credit points to your lab score for successful completion of these (and it is all or nothing grading), but they will really have no impact on your lab score: it is much better to finish the required parts completely and to finish them well, than to try the extra challenge and not submit complete required parts.

You only will receive a few extra lab points if you get all parts of the Extra Challange correct: all or nothing. However, if you have time, we encourage to try some of it just for the extra fun and challenge, and maybe you will get it all.

As an extra challenge, add these two features to your Part 1 solution:

  1. Add support for variable-width histogram buckets.
  2. Add support for a scaled histogram display.
If you do the extra challenge part, copy your grades.c to a new file into which you will add the extra parts:
cp grades.c extra.c
Add it to your git repo to share with your partner and to submit it:
git add extra.c
git commit
git push
You can compile extra.c to an executable named extra by doing:
gcc -g -Wall -o extra extra.c readfile.c -lm
You could try to modify the Makefile to add this command, but you do not have to. Here is some information about writing Makefiles if you want to try.

You should implement your extra challenge solutions in a good modular and generic way that will work correctly for any sized data set and any size histogram buckets.

Variable-Width Buckets

Modify your program so that after reading in the file of grade values, it prompts the user for a bucket width and then reads it as an int (you can use scanf). Use this bucket width value to change how your histogram and histogram printing functions work. You should dynamically allocate a histogram array of enough buckets based on the bucket width and the min and max values in the data set. When you print the histogram, print out only from the first bucket with non-zero values, and stop printing buckets beyond the largest exam value. For example, if the bucket width is 20, and the set of grade values is (47.5, 51.0, 53.5, 56.0, 59.5, 67.25, 78.0), then your histogram when print out would look something like this:
 40-59: *****
 60-79: ** 
If you run on the same data set with a bucket width of 5, your histogram will look something like:
45-49: *
50-54: **
55-59: ** 
60-65: 
65-69: *
70-74:
75-79: *
If one bucket's range needs to be smaller than the others, it should contain the largest grade values, e.g. [..., 80-87, 88-95, 96-99].

Scaled Histogram

Modify your histogram printing function so that if the data set is large, each histogram bucket can still be represented in one line. You should define a constant, e.g.
#define HISTWIDTH 50
for the maximum number of * characters allowed. Then, scale the number of stars for each bucket by the smallest power of 10 that keeps each line's length below that constant (rounding the number of stars up to ensure that all grades are represented). You should also print the scale so that readers can interpret your histogram correctly. If the file contains 1000 grade values in the 40-59 range, 1101 in the 60-79 range, and 25 in the 80-99 range, your histogram might look like:
 40-59: **********
 60-79: ************
 80-99: *
scale: * = 100 grades

Generating Large Input Files

You can copy over a python program for generating a large number of grade values from here:
cp ~newhall/public/cs31/makevalues.py .
This program takes one command line argument specifying the number of values to generate. Here are two runs, one to generate 10 values, the other to generate 1,000 values:
python makevalues.py 10
python makevalues.py 1000
You can redirect the ouput of a run of makevalues to a file:
python makevalues.py 10 > file_10
python makevalues.py 100 > file_100
python makevalues.py 1000 > file_1000
This way you can easily generate files of gradevalues of different sizes that you use as input to your extra program. In testing the scaled histogram, you should generate some different sized files to ensure that the scaled histogram is working. However, don't go nuts with generating lots of huge files here. A few of different size, maybe the max of a couple thousand should be more than sufficient to test scaling. And feel free to change the makevalues program in any way you'd like (changing sigma and mu will give you different distributions of grade data) or write your own grade generator. Just be careful that it only produces values between 0.0 and 100.0 inclusive.

Submit

This is due at the same time as regular lab 4

If you are submitting extra.c as a complete solution to the challenge part, add a CHALLENGE_MET file to your git repo (so we can distinguish between attempted and submitted extra.c's).
echo "yippie" >  CHALLANGE_MET    # or just open in vim and enter a short message
git add CHALLANGE_MET
git commit
Then make sure to add extra.c to your git repo, commit and push:
git add extra.c
git commit
git push