CS140 -- Lab 6 -- hints


Wed Sep 19 14:42:56 EDT 2007

mydc

Whenever you are writing largish programs, you should try to write and test them incrementally. Mydc lends itself well to this. After each step below, make sure that you test the program to make sure it does what you think it does.

histogram

Histogram uses a Queue and an IS. You should first read standard input, putting each value of data into the Queue, and at the same time keeping track of the maximum and minimum values.

When you are done with this, you should be able to calculate the maximum and minimum bins and the total number of bins, tbins = (max-min+1). Allocate an array that has tbins integers. The 0-th element of this array will contain the number of data elements in the smallest bin. The tbin-1-th element will contain the number of data elements in the largest bin. Traverse the queue and for each element, add one to the element's bin.

Finally, traverse the array from top to bottom and print the output. Note, you will need to do a sprintf() to create the string containing the range of the bin, and then you will print that with printf().

Again, write this incrementally and test, test, test, test.