INTRODUCTION TO PROGRAMMING IN C++

# Assignment: Adding Vectors to the Histogram Project

Enhance the Histogram program from the Histogram Lab.

• Replace the seven variables representing the final location counters with a single vector of seven values. You will need to initialize the counters to 0, just as you did with the seven variables.

• Replace your series of if/else-if/else statements that increment the seven variables with a single statement that increments the appropriate element in the vector. To do this, you will need to develop an arithmetic expression that, given the final location of the fish, will give you the correct index into the vector. For example,
Final LocationIndex
-6
0
-4
1
...
...
0
3
...
...

• Replace the seven calls to DrawRectangle with a single call in a loop. You will need to use a variable rather than constants for the top of each bar in the rectangle, and increment that variable by the appropriate amount just before looping around to produce the next bar in the histogram.

• Research the demo program in the CMU graphics package to see how to write text to a graphics window. Label the bars of your histogram with the final locations they represent. Provide a title and explanation for the histogram, such as "Distribution of final locations of fish after six random moves starting at location 0."

• Challenge exercise: This exercise is optional, and is not worth any points - it is just for fun! (After you have completed all required work, of course.) Since the bars represent final locations of fish after six right/left moves, you might want to turn the histogram 90 degrees.
 0 -2 +2 -4 +4 -6 +6