Back to Challenge Set 17

Code Challenge: Histogram

Extra CreditOptional. Not required for any homework drop.

Difficulty  

divider

The Brief

What they asked for
I have a set of numbers and I want a text histogram. One
bar per value, scaled so the biggest one fits the width I
give it. Labels on the left.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Scaling means the longest bar hits your width exactly and everything else is proportional.
  • Finding the largest value is a running maximum, from Activity 1.20.
  • That means two passes over the data: one to find the maximum, one to draw.
  • Labels must line up in a column. You have no padding tools, so work it out — and say what you would do if one label were longer than the rest.

Sample Output

Sample Output
Mon |########## | 24
Tue |####################| 48
Wed |##### | 12

48 is the largest value, so its bar fills all twenty characters; 24 fills half and 12 a quarter.


Submit

Your requirements list and your program file, named cc-histogram.

Commence Challenge