CSC 2210, SPA 2: Histograms

This assignment will give you experience with writing procedural programs with arrays in C++. The basic process is to implement pseudocode we are giving you. But do read the writeup carefully; there are several common mistakes that can lead to endless hours of debugging. NOTE: this is an individual assignment; the CSC/SWE academic integrity document applies in full. Minimize your use of GenAI so that you will be able to write similar code during exams.

As shown to the right, a histogram sample histogram showing frequency vs.  value is a chart showing how frequently a particular value appears in a data set. For this assignment, you will create a similar chart, though in yours the frequency will be drawn across the x axis insteady of the y axis. The input to the program will be nonnegative integers, and the output will be an ASCII chart showing the frequencies of each item. The axes will be labeled as described below. For example, if the input values are

        0 1 1 4 3 1 1 0

then the chart you will draw will be

             4 |#
             3 |#
             2 |
             1 |####
             0 |##
               +----+----+
               0    5    10

Note that # is being used to mark each value read from the list of numbers, so the bottommost ## means there were two zeros in the input.

In addition to the actual values, the input will start with a specifier indicating the range of values to process. The first number is the lower limit, and the second is the upper limit. For example, if the lower limit is 5 and the upper is 10, then reading a 4 would result in printing

        Error: value 4 is out of range

The program will always display all of the possible values from the lower to the upper limit. Thus the above chart would be generated by the full input

        0 4 0 1 1 4 3 1 1 0

The 0 and the 4 represent the possible ranges, and the remaining numbers comprise the data. The input

        9 13
        12 9 9 12 9 11 14

would give the output

            Error: value 14 is out of range
             13 |
             12 |##
             11 |#
             10 |
              9 |###
                +----+----+
                0    5    10

A subtle thing to note is that numbers are right-justified in the first three columns. All ranges will be between 0 and 999, inclusive.

The above examples have fewer than ten values. If the input was twelve 5s,

        5 5 5 5 5 5 5 5 5 5 5 5

(so the legal input range is 5 to 5) the chart would be

             5 |##########
               +----+----+
               0    5    10

If some input has a frequency greater than 10, extend the bottom axis to be the next greater multiple of ten. For example, if the input has thirty-two 2s (so first two specify the range is 2 to 2), you would display

         2 |##############################
           +----+----+----+----+----+----+
           0    5    10   15   20   25   30

Thirty-three 2s would have a bottom axis that extends out 40 places. The minimum bottom axis is 10 places, so the input "0 0" would give the chart

         0 |
           +----+----+
           0    5    10

Do not prompt for any of the data; just read the numbers from standard input and draw the chart on standard output. You can assume the first two inputs are nonnegative integers. You can also assume that the lower limit is no larger than the upper limit.

Design Requirements

Pseudocode is being provided for this assignment (see below); the basic goal of the assignment is to convert the pseudocode into C++ code. However, you are not required to use the pseudocode.

All solutions must satisfy the following constraints. Some but not all of these are captured in the pseudocode.

Your solution is to be procedural, not object-oriented. This means you should not write classes.

Stage 1

You can receive 50% credit for this assignment by completing test 2, the example given above. For this input, you can write a function to read the data (as described above) and implement the longestRow and axisWidth functions to always return 10. That is, the body of both would be simply

        return 10;

Likewise, drawHorizontalAxis would simply write "----+----+" and labelHorizontalAxis would write just the 0, 5, and the 10. Getting this test to pass will go a long way to ensuring you have all of the basic structure in place.

Stage 2

Complete the rest of the lab. You might start by getting longestRow and axisWidth (or their equivalents) to return correct values, implement drawHorizontalAxis, implement labelHorizontalAxis, and then correct any remaining issues. If you run into segmentation fault errors or other run-time issues, see the bottom of this writeup.

Hints

This section gives further hints for portions of this assignment. You do not have to follow these hints, but they might save you time.

Submitting

Common Issues