INTRODUCTION TO PROGRAMMING IN C++
Kalamazoo College

LAB: REPORTING FISH MOVEMENT USING HISTOGRAMS


Last week, two of the discussion questions were:+

In this lab you will write a program that will simulate a fish moving randomly back and forth six times, starting at location 0. Your program will print the final fish location (an integer between -6 and 6). You will then modify your program to run the simulation 1000 times, keeping track of how many times the fish ends up in each of the possible final fish locations. Finally, you will enhance your program to draw a histogram (bar graph) of the various fish locations. For example, a text-based histogram might look like the following:
     -6   xxxxx
     -4   xxxxxxxxx
     -2   xxxxxxxxxxxxxx
      0   xxxxxxxxxxxxxxxxx
      2   xxxxxxxxxxxxxx
      4   xxxxxxxxx
      6   xxxxx

Simulate a fish moving six times.

Add multiple runs.

Draw a histogram.

Print and save your modifications.


+These questions came from the Advanced Placement Computer Science Marine Biology Simulation Case Study, available from the College Board for face-to-face teaching purposes.

*The CMU Graphics Library was created by the Carnegie Mellon University School of Computer Science and is used in their introductory programming courses. It is available from Mark Stehlik's Advanced Placement page.