CIS 067 Section 1
Assignment 7a-F2001
First Phase of the Dice Simulation Problem
Assignment: Do a complete design of the dice class, implement the designed class, and write a program to test it. DUE: Wednesday Noon, Nov 14.
Helpful (?) Hints:
Your class design should begin with the kind of picture we drew on the board in the last few days (illustrating the local member data stores for the class and the member fiunctions of the class. This should be followed by a Data Requirements Table that might appear as shown next.
Class Name: dice_type
Purpose: Implements a new data type modeling a pair of dice and actions / inquiries about these "objects."
(Public) Member Functions of the class
roll_dice
-- Function responsible for rolling each die separately and returning the sum of the values on each die. [You need to describe the return value and the arguments (if any) for this function.] Uses the rand function from the stdlib library in the C Standard Library.set_seed
-- Function responsible for setting a different seed value to start the sequence of pseudo-random numbers r0, r1, r2, generated by the random number generator function. [Again -- you decide on any return values and/or arguments required.] Uses the srand function from the stdlib library in the C Standard Library. NOTE: We will soon see how we can hide this function as a private function called by the constructor for this class (which is itself called when any object of type dice_type is declared)].Class Attributes (member data stores -- you work out the descriptions and types etc of these values)
die1_value --
die2_value --
dice_value --
To test this class, you will need a test driver program in which you declare an object of type
dice_type:dice_type my_dice_pair;
and then call
set_seed to set the initial seed value as a function of time. You will need a loop that executes perhaps 50 times. Inside the loop call roll_dice -- and see if you get a distribution that roughly meets the probabilistic expectations we discussed in class today. Remember that to call a member function of a class you can writemy_dice_pair.roll_dice ( ??? ); // object of a given type . function
E-mail your program to the grader by no later than noon Wednesday, Nov. 14. Also, submit the following to the grader:
How come we can't see the seed? Is it good that we can't see the seed?
Where is the value of the seed stored?
How is it that the seed is visible to both rand and srand? It is not passed to or from either.