Practical Assignment #1

Fun with Histograms
Due Sunday March 13th at noon

On this assignment you are not allowed to discuss the project with anyone. The GSIs and instructor will only answer questions related to clarifying the specification. We will not be providing any help with programming, debugging, or the like.

You are allowed to use code you've written previously in the class, code we've handed out to you, and anything from our textbook. In fact we strongly suggest you look at the displayMap() function from programming assignment A. You might also look over how the filename argument was taken from the command line.


You are two write a program which reads a file full of integers from 0 to 100 (inclusive). You are then to create a histogram of that data. The "width" or "bucket size" of the data is 5. That is, you are to group values into the catagories of 0-4, 5-9, 10-14, etc. You will then generate an ASCII graph of that data. Your graph must look exactly like ours. On the website we have provided you a number of input files and the resulting output graphs. Sample input and output files follow.
Input:
0
10
20
30
40
50
60
70
80
90
100
100
100
100
0
Output
  0: **
  5: 
 10: *
 15: 
 20: *
 25: 
 30: *
 35: 
 40: *
 45: 
 50: *
 55: 
 60: *
 65: 
 70: *
 75: 
 80: *
 85: 
 90: *
 95: 
100: ****
Your program is to take the file name of the input data as an argument and then print the histogram to the screen. You can assume the input file is correctly formatted (no extra characters, etc.) You may find the following helpful to figuring out if your code is working correctly: If the diff command returns nothing, your output file is the same as the output file we provided. Otherwise diff prints out the differences.

Style and handing in

Your program must be written in a reasonable way. There should not be huge blocks of if statements to check if a given value is in a given bucket. Further, you should make reasonable use of functions. The instructor's solution is 56 lines long (ignoring comments but including blank lines) and has two functions in addition to the main.

Futher your program should have some degree of commenting. Specifically, comments about the purpose of the program and a short explaination of what your functions are doing.

Finally, the program should called "hist.cc" and placed in a directory named "Prac1" in your handin directory.

Hints and thoughts

Bonus

For an extra 10% bonus, a different histogram format has been posted (see the website). If you elect to do this you elect to do this in addition to the normal format, you must get the files exactly right. This is significantly harder. Also, be sure you pay attention to where spaces are placed....