Project 4
This project is due at Midnight, Sunday 12/13/98 for both sections
The program you write will simulate the rolling of a pair of dice 300 times. You will keep track of the number of times a particular dice face occurs (one through six) as well as the number of times each possible total (2 to 12) occurs. You will accumulate the counts in two separate arrays.
The probability of 1,2,3,4,5 or 6 showing on a die face are all equally likely, so we expect the total counts for each of these to be approximately the same. The possible totals of the two dice (2 to 12), however are not equally likely. The value 2, aka snake eyes, can only be produced when each of the two dice have come up 1's. Likewise, the value 12, aka boxcars, can only be produced when each of the two dice have come up with the value 6.
The other totals (3 to 11) will tend to occur more often
than either the snake eyes or the boxcars, because there is more than one roll
possible to create those values. The 3 could be gotten by die #1 rolling a 1,
and die #2 rolling a 2 OR by die #1 rolling a 2 and die #2 rolling a 1. So
theoretically, it is twice as likely that a 3 will be rolled, rather than a
2 or a 12. The total 7 is most likely to occur. Other totals rolled
will exhibit other probabilities.
The basic project is to simulate the rolling of two dice using rand() and count how many times the dice show 1 - 6 AND how many times each of the possible totals (2 - 12) was rolled. The counts are to be stored in arrays. After all of the rolling is complete, print out results in the format shown below. DO NOT ATTEMPT TO STORE THE INDIVIDUAL VALUES ROLLED IN AN ARRAY. Your book can really help you out with this project, since it gives an example of a similar program. You are rolling two dice, rather than one.
Your program must include at least one function that takes the array as an argument. I would suggest the functions that do the printing as logical choices of such a functions.
You should do most of your work in functions. I would suggest that you write a function called RollDie, which would return the result of rolling 1 die. You should also have a function that will print out the number of times that each possible total occurred and a function that prints out the statistics on the number of times each die face (1 to 6) occurred. You may have other functions if you like. You output should be formatted so that the values and number of occurrences line up in columns as shown below.
NOTE -- your final version of this program should use a different seed for the random number generator each time it is run. This was discussed in class.
The sum of the dice were: 2 occurred 61 times: ****** 3 occurred 139 times: ************* 4 occurred 264 times: ************************** 5 occurred 413 times: ***************************************** 6 occurred 480 times: ************************************************ 7 occurred 431 times: ******************************************* 8 occurred 423 times: ****************************************** 9 occurred 377 times: ************************************* 10 occurred 227 times: ********************** 11 occurred 129 times: ************ 12 occurred 101 times: ********** Scale: Each * equals approximately 10 rollsYou must absolutely do this extra credit with a function. You are likely to need more than one function.
If you do this extra credit portion, you must use the following number of rolls as the input from the user for your five test runs in the typescript file : 10, 100, 1000, 10000, 30000.
% script % cc project4.c -lm % a.out % exit % mv typescript project4.outThen submit your files (project4.c and project4.out) in the usual way.
For section 103, use the command -- submit cs104-103 proj4 project4.c project4.out
For section 301, use the command -- submit cs104-301 proj4 project4.c project4.out