We're going to explore the law of large numbers here with a dice rolling program.  Seed the random number generator with the current time and then roll three 6-sided dice (often described as 3d6) a total of 1,000,000 times and keep track of the number of times each sum 3 - 18 occurs.   Be sure to separate all functions and methods (if you chose to use a class or structure) into both the prototype and an implementation below the main. 1.  Build a regular c-type function that returns a random number between 3 - 18.  This will simulate a single roll of three dice.  Use the prototype: int rollDice(void); 2. In the main, roll the dice 1,000,000 times and tally up the results in an array. I DO NOT want each individual roll printed to screen. Let the index represent the number rolled and the value will represent the number of times that number has been rolled.  For example, a[3] = 5357

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

We're going to explore the law of large numbers here with a dice rolling program.  Seed the random number generator with the current time and then roll three 6-sided dice (often described as 3d6) a total of 1,000,000 times and keep track of the number of times each sum 3 - 18 occurs.  

Be sure to separate all functions and methods (if you chose to use a class or structure) into both the prototype and an implementation below the main.

1.  Build a regular c-type function that returns a random number between 3 - 18.  This will simulate a single roll of three dice.  Use the prototype:

int rollDice(void);

2. In the main, roll the dice 1,000,000 times and tally up the results in an array. I DO NOT want each individual roll printed to screen. Let the index represent the number rolled and the value will represent the number of times that number has been rolled.  For example,

a[3] = 5357
a[4] = 14750
...
a[18] = 4981

This array set-up will mean that the result 3 occurred 5,357 times and the outcome 4 was rolled 14,750 times.  These are just sample numbers, your results will vary.

3. Make a print function that takes in the array and prints out the results, again using separation with a prototype and implementation.  Use a for loop to print out each array cells' value (similar to what's listed above), and then a separate for loop to print out each the probability of each outcome 2 - 18 as a percentage.  That is,  use the formula  (number of times rolled) / (total number of rolls) * (100.0).  For example, with the example numbers in the array above, you should get percentages similar to what is below,  The print function should print integers (no decimal places) for the number of times rolled, but then set the precision in the output to 2 decimal places for the probability portion of it (i.e., set the precision after the first print loop is done).

... and so on.  Here are the true probabilities, so your program is working well if it's close to these probabilities:  (Turn in one file, no user interaction, with separation.)

Probability of a sum of 3: 1/216 = 0.5%
Probability of a sum of 4: 3/216 = 1.4%
Probability of a sum of 5: 6/216 = 2.8%
Probability of a sum of 6: 10/216 = 4.6%
Probability of a sum of 7: 15/216 = 7.0%
Probability of a sum of 8: 21/216 = 9.7%
Probability of a sum of 9: 25/216 = 11.6%
Probability of a sum of 10: 27/216 = 12.5%
Probability of a sum of 11: 27/216 = 12.5%
Probability of a sum of 12: 25/216 = 11.6%
Probability of a sum of 13: 21/216 = 9.7%
Probability of a sum of 14: 15/216 = 7.0%
Probability of a sum of 15: 10/216 = 4.6%
Probability of a sum of 16: 6/216 = 2.8%
Probability of a sum of 17: 3/216 = 1.4%
Probability of a sum of 18: 1/216 = 0.5%

C++ PLZ <IOSTREAM>

<IOMANIP>

We're going to explore the law of large numbers here with a dice rolling program. Seed the random number generator with the current time and then roll three 6-sided dice (often
described as 3d6) a total of 1,000,000 times and keep track of the number of times each sum 3 - 18 occurs.
Be sure to separate all functions and methods (if you chose to use a class or structure) into both the prototype and an implementation below the main.
ts
1. Build a regular c-type function that returns a random number between 3 - 18. This will simulate a single roll of three dice. Use the prototype:
int rollDice(void);
2. In the main, roll the dice 1,000,000 times and tally up the results in an array. I DO NOT want each individual roll printed to screen. Let the index represent the number rolled and the
value will represent the number of times that number has been rolled. For example,
pom
a[3] = 5357
a[4] = 14750
n
...
a[18] = 4981
This array set-up will mean that the result 3 occurred 5,357 times and the outcome 4 was rolled 14,750 times. These are just sample numbers, your results will vary.
3. Make a print function that takes in the array and prints out the results, again using separation with a prototype and implementation. Use a for loop to print out each array cells' value
(similar to what's listed above), and then a separate for loop to print out each the probability of each outcome 2 - 18 as a percentage. That is, use the formula (number of times rolled) /
(total number of rolls) * (100.0). For example, with the example numbers in the array above, you should get percentages similar to what is below, The print function should print integers
arships
(no decimal places) for the number of times rolled, but then set the precision in the output to 2 decimal places for the probability portion of it (i.e., set the precision after the first print
loop is done).
. and so on. Here are the true probabilities, so your program is working well if it's close to these probabilities: (Turn in one file, no user interaction, with separation.)
Probability of a sum of 3: 1/216 = 0.5%
Probability of a sum of 4: 3/216 = 1.4%
Probability of a sum of 5: 6/216 = 2.8%
Probability of a sum of 6: 10/216 = 4.6%
Probability of a sum of 7: 15/216 = 7.0%
Probability of a sum of 8: 21/216 = 9.7%
Probability of a sum of 9: 25/216 = 11.6%
Probability of a sum of 10: 27/216 = 12.5%
Probability of a sum of 11: 27/216 = 12.5%
Probability of a sum of 12: 25/216 = 11.6%
Probability of a sum of 13: 21/216 = 9.7%
Probability of a sum of 14: 15/216 = 7.0%
Probability of a sum of 15: 10/216 = 4.6%
Probability of a sum of 16: 6/216 = 2.8%
Probability of a sum of 17: 3/216 = 1.4%
Probability of a sum of 18: 1/216 = 0.5%
Transcribed Image Text:We're going to explore the law of large numbers here with a dice rolling program. Seed the random number generator with the current time and then roll three 6-sided dice (often described as 3d6) a total of 1,000,000 times and keep track of the number of times each sum 3 - 18 occurs. Be sure to separate all functions and methods (if you chose to use a class or structure) into both the prototype and an implementation below the main. ts 1. Build a regular c-type function that returns a random number between 3 - 18. This will simulate a single roll of three dice. Use the prototype: int rollDice(void); 2. In the main, roll the dice 1,000,000 times and tally up the results in an array. I DO NOT want each individual roll printed to screen. Let the index represent the number rolled and the value will represent the number of times that number has been rolled. For example, pom a[3] = 5357 a[4] = 14750 n ... a[18] = 4981 This array set-up will mean that the result 3 occurred 5,357 times and the outcome 4 was rolled 14,750 times. These are just sample numbers, your results will vary. 3. Make a print function that takes in the array and prints out the results, again using separation with a prototype and implementation. Use a for loop to print out each array cells' value (similar to what's listed above), and then a separate for loop to print out each the probability of each outcome 2 - 18 as a percentage. That is, use the formula (number of times rolled) / (total number of rolls) * (100.0). For example, with the example numbers in the array above, you should get percentages similar to what is below, The print function should print integers arships (no decimal places) for the number of times rolled, but then set the precision in the output to 2 decimal places for the probability portion of it (i.e., set the precision after the first print loop is done). . and so on. Here are the true probabilities, so your program is working well if it's close to these probabilities: (Turn in one file, no user interaction, with separation.) Probability of a sum of 3: 1/216 = 0.5% Probability of a sum of 4: 3/216 = 1.4% Probability of a sum of 5: 6/216 = 2.8% Probability of a sum of 6: 10/216 = 4.6% Probability of a sum of 7: 15/216 = 7.0% Probability of a sum of 8: 21/216 = 9.7% Probability of a sum of 9: 25/216 = 11.6% Probability of a sum of 10: 27/216 = 12.5% Probability of a sum of 11: 27/216 = 12.5% Probability of a sum of 12: 25/216 = 11.6% Probability of a sum of 13: 21/216 = 9.7% Probability of a sum of 14: 15/216 = 7.0% Probability of a sum of 15: 10/216 = 4.6% Probability of a sum of 16: 6/216 = 2.8% Probability of a sum of 17: 3/216 = 1.4% Probability of a sum of 18: 1/216 = 0.5%
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY