CIS 223
Assignment Number 1-S97

DICE SIMULATION WITH ARRAYS OR CLASSES

Reading: Finish reading as directed in the Syllabus, Part A. (In doing this reading, skip material you are already familiar with; focus on anything that looks a bit new or unfamiliar). Unless questions are asked in class, I will assume that none of this material is new and that the reading will go fairly quickly.

Programming: An individual project -- not to be done in groups.

Simulate the rolling of a pair of dice until some number, n, of rolls has been completed OR until a 7 or 11 is rolled. The stopping condition should be the user's choice -- either some maximum number of rolls (such as 500 or 1000) or until some value (such as 7, 11, etc) is rolled. Also, if the loop repetition condition involves some maximum number of rolls, the user should be prompted for, and then enter, the maximum number of rolls involved. PLEASE -- no more than 1000 rolls.

Your program should keep track of the number of 2s, 3s, 4s, 5s, ... 12s rolled during the simulation. (You should use an array of counters, where "counter" is a user-defined data type, for storing these counts.) At the completion of execution of the program, print the counts (properly annotated so I can read your output).

You should also include in your program a highly user-friendly interface which welcomes the user by first asking for his or her name and then printing out a welcome message that includes the name. You then should ask the user to indicate whether a fixed number of rolls is involved and if so, request this number of rolls from the user. You should consider writing this interface as a separate class (perhaps named "interface").

In addition to the counter and interface classes, your program should include a "dice" class which manages the rolling of the dice and the returns of a value between 2 and 12. This class may contain only one function -- for rolling the dice. This function will use the C library's random number generator function to obtain a valid roll of the dice (between 2 and 12). You will need to look up the functions random and srand, and you will probably also find it useful to use the time function as well. The use of these functions will be explained in lab.

Turn In:

1) A data requirements table and structure chart for the main function. You need NOT provide any special documentation for your classes as they will be self-documenting and fairly simple.

Your structure chart should contain each major step to be performed and an indication as to which of these steps are to be handled using a member function in your three classes (indicate by placing the function name next to the step description). For each function you will need to indicate (using the small arrows) input and output arguments (if any).

2) A listing of a working program and two program tests.

NOTE 1: You will need to find out how to access the random number seed and random number generator function for your version of C. These should be named srand and random (or something similar) respectively.

DUE: Tuesday, February 4 (in class)

Structure Chart

Return to Previous Page