INTRODUCTION TO PROGRAMMING IN C++

Lab:
Reporting Fish Movement Using Histograms

Alyce Brady
Kalamazoo College


This lab is based on the two exercises on p. 8 of the AP Computer Science Marine Biology Case Study:+

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.

*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.