L.A.12.1 o Dice

LAB EXERCISE

 

DICE

 

 

Background:

 

1.    A 6-sided die is an object which produces a random value from 1-6.  A pair of dice consists of two separate independent objects, each of which returns a random value from 1-6.  When two dice are rolled, the values 2-12 have the following probabilities of occurrence.

 

 

                                          Number          Probability             % Occurrence         

 

                                               2                   1/36                      2.78 %

                                               3                   2/36                      5.56 %

                                               4                   3/36                      8.33 %

                                               5                   4/36                    11.11 %

                                               6                   5/36                    13.89 %

                                               7                   6/36                    16.67 %

                                               8                   5/36                    13.89 %

                                               9                   4/36                    11.11 %

                                             10                   3/36                      8.33 %

                                             11                   2/36                      5.56 %

                                             12                   1/36                      2.78 %

 

 

Assignment:

 

1.    Write a program which simulates the rolling of a pair of 6-sided dice and computes the % occurrence of a specific dice roll value ranging from 2-12.

 

2.    Your program should use the dice class as provided in Handout 12.2 - A Dice Class.  Copy the dice class as a separate file and save it as dice.h.

 

3.    You must also modify the dice class to keep track of the number of times a die has been rolled.  Add a new private state variable called myRollCount and add a new member function called numRolls() which returns the number of times the die has been rolled since it was instantiated.  After computing the % occurrence of a dice roll, print out the number of times each die was rolled.

 

4.    Here's a suggestion regarding how to compute the probability of each dice throw.  Rather than roll the dice and keep track of how many 2's, 3's, etc., focus on one number at a time.  For example, roll the dice 1000 times and keep track of the number of 2's, and print the results.  Then roll the dice 1000 more times and keep track of the number of 3's.  This will the eliminate the need for a complex if-else structure, or a huge switch statement, and eleven different counting variables.

 


5.    The results should be tabulated as follows (these % will not necessarily add up to 100%):

 

 2    35 / 1000     3.5 %

 3    51 / 1000     5.1 %

 4    71 / 1000     7.1 %

 5   106 / 1000    10.6 %

 6   130 / 1000    13.0 %

 7   158 / 1000    15.8 %

 8   146 / 1000    14.6 %

 9   123 / 1000    12.3 %

10    84 / 1000     8.4 %

11    54 / 1000     5.4 %

12    35 / 1000     3.5 %

 

Number of rolls of die1 = 11000

Number of rolls of die2 = 11000

 

 

6.  Turn in the source code of testdice.cpp, your revised dice.h, and a run output.