CPTR 124 Fundamentals of Programming


In this lab you will write a program that displays a set of numeric data in a graphical manner.


  1. What to do

    Write a C++ program that reads in an arbitrary number of nonnegative integer values from standard input (std::cin). The input is terminated by an integer value less than zero. After all the values have been entered the program should print a histogram of the number of values in the following ranges: 0-99, 100-199, 200-299, 300-399, 400-499, and 500+.

    Given the following input values:

    115 556 130 605 714 808 415 494 769 278 451 114 816 398 669 481 166 81 335 459 388 504 548 402 646 299 458 733 187 615 932 983 342 302 483 543 358 373 469 881 458 114 214 253 265 869 55 198 337 889 533 694 343 307 620 712 710 650 827 62 115 951 257 116 801 31 192 820 8 686 208 444 300 671 200 325 562 761 185 197 126 380 771 384 131 397 773 570 523 262 510 304 360 793 481 391 313 534 145 645 -1

    the program should print the following histogram:

    0- 99 5|****** 100-199 15|******************* 200-299 9|*********** 300-399 19|************************ 400-499 12|*************** 500+ 40|**************************************************

    Each line lists the data range, the actual number of values in that range, a vertical bar, and then the bar of asterisks representing that quantity.

    The longest bar always should contain 50 asterisks, and the other bars should be scaled proportionally. The sample input

    450 401 3 78 444 200 -1

    would display

    0- 99 2|********************************* 100-199 0| 200-299 1|***************** 300-399 0| 400-499 3|************************************************** 500+ 0|

    and input consisting merely of

    -1

    that is, no nonnegative values, would produce

    0- 99 0| 100-199 0| 200-299 0| 300-399 0| 400-499 0| 500+ 0|

    Ensure your program handles ties properly:

    1 1 100 100 -1

    would produce

    0- 99 2|************************************************** 100-199 2|************************************************** 200-299 0| 300-399 0| 400-499 0| 500+ 0|

    Format your output identically to example outputs above. Note especially the placement of the numbers and spacing. Be sure to round properly the number of asterisks to print; for example, if the computation indicates that there should be 15.7 asterisks in a bar, you should print 16 asterisks, not 15 (you cannot print a fraction of an asterisk character, of course).

    You are welcome to write your own functions to avoid repetitive code if you wish, but you are not required to do so for this assignment.

  2. Check out

    Your finished programs will be evaluated for correctness and compliance. During check out be prepared to slightly modify your program to assist the evaluation process. When approved, you should submit your C++ source file (the .cpp file only) to eclass.e.southern.edu.