Using A Random Generator to Create a Histogram

In this lab we will learn to use the rand() and srand() functions from the stdlib library to produce a histogram.

Histograms are used to help visualize the relative frequency of a set of possible outcomes to some event. For example, one might create a histogram that shows the number of people who earn between 51k and 60k, 61k and 70k, 71k and 80k, etc.

In our case we would like to roll two dice 1000 times. Each time we roll two dice we record the sum of the dice.

In your program, create an array of size 13. Each time you generate a sum, increment the value in the array at index [sum].

You will probably need to create a class Die

Print out the probability that each sum occurs. A probablity is a number between 0 and 1. In addition, create a visual output using asterisks similar to the way they are used on page 241 of your text. You can test your output by making sure that the sum of the probabilities adds up to 1 (or something very close to 1).

The output should look something like:

  2    .10     *
  3    .20     **
  4    .50     *****
  
  etc.

NOTE: the probabilities shown in the above sample are incorrect.

courses/cs203-200903/assignments/internal_link.txt · Last modified: 2009/09/10 12:19 by jones
VCCS Top Events Extended Site Search Login Vassar Science Web Vassar Home Driven by DokuWiki Valid XHTML 1.0