Create a new file in C++ and save it as lab12_XYZ.cpp  Consider rolling two six-sided dice. While the result of each throw is independent of all rolls that have come before, we can still calculate the odds of rolling any given number between 2 and 12. This program will calculate those odds by generating a large number (100,000) of random values (i.e. "rolling the dice") and storing the results in an array. When all values have been rolled, we will display the results (counts and odds to 2 decimal places) to the user.   x   x   2   3   4   5   6   7   8   9   10  11  12     //value for sum of 2 dice rolls +---+---+---+---+---+---+---+---+---+---+--- |   |   |   |   |   |   |   |   |   |   |   |   |   |    //counters for number of times value is rolled +---+---+---+---+---+---+---+---+---+---+---+---+---+   0   1   2   3   4   5   6   7   8   9  10  11  12     //array index In Lab 5, sample code was provided for generating a random number. In this lab, I've provided a header file for you to include, getRandomLib.h, which lets you get all kinds of random things. We need some functions: void displayMessage();  //hello, goodbye, etc. int rollDice();  //returns a number between 2 and 12 (by rolling two dice and summing the result) void displayResults(int[]);  //displays results in the array HINT: Make sure to initialize counters before starting loop HINT: To calculate odds: odds = count * 100 / NUM_ROLLS; Header comments must be present Prototypes must be present if functions are used Hello and goodbye messages must be shown Array(s) must be used for implementation Results should be formatted neatly (2 decimal places for odds, decimals lined up, etc.) Use comments and good style practices Make sure to #include "getRandomLib.h". Download the attached header file and place in same location as your program. SAMPLE OUTPUT: Welcome! This program will calculate the odds of rolling 2 - 12 with two 6-sided dice. Number of  2s rolled:          270  ( 2.70%) Number of  3s rolled:          556  ( 5.56%) Number of  4s rolled:          814  ( 8.14%) Number of  5s rolled:         1136  (11.36%) Number of  6s rolled:         1379  (13.79%) Number of  7s rolled:         1705  (17.05%) Number of  8s rolled:         1397  (13.97%) Number of  9s rolled:         1140  (11.40%) Number of 10s rolled:          818  ( 8.18%) Number of 11s rolled:          532  ( 5.32%) Number of 12s rolled:          253  ( 2.53%) Exiting program. Goodbye! Attached Files:  getRandomLib.h (3.468 KB): #ifndef GET_RANDOM_LIB_H#define GET_RANDOM_LIB_H #include <cstdlib>#include <random>#include <ctime>using namespace std; const int MIN_UPPER = 65;const int MAX_UPPER = 90;const int MIN_LOWER = 97;const int MAX_LOWER = 122;const int MIN_DIGIT = 48;const int MAX_DIGIT = 57;const int MIN_CHAR = 33;const int MAX_CHAR = 126; //unsigned seed = time(0); int getRandomInt(int min, int max) {//seed random enginestatic default_random_engine gen((unsigned int)time(0));// if max < min, then swapif (min > max) {int temp = min;min = max;max = temp;}//set up random generatoruniform_int_distribution<int> dis(min, max); //range//need to throw away the first call, as it is always max...static int firstCall = dis(gen);return dis(gen);} //end getRandomInt() float getRandomFraction() {//seed random enginestatic unsigned seed = time(0);return rand() / static_cast<float>(RAND_MAX);} //end getRandomFraction() float getRandomFloat(float min, float max) {if (min > max) {float temp = min;min = max;max = temp;}return (getRandomFraction() * (max - min)) + min;} //end getRandomFloat() double getRandomDouble(double min, double max) {if (min > max) {double temp = min;min = max;max = temp;}return (static_cast<double>(getRandomFraction()) * (max - min)) + min;} //end getRandomDouble() bool getRandomBool() {if (getRandomInt(0,1) == 0)return false;elsereturn true;} //end getRandomBool char getRandomUpper() {return static_cast<char>(getRandomInt(MIN_UPPER, MAX_UPPER));} //end getRandomUpper() char getRandomUpper(char min, char max) { return static_cast<char>(getRandomInt(static_cast<int>(min), static_cast<int>(max)));} //end getRandomUpper() char getRandomLower() {return static_cast<char>(getRandomInt(MIN_LOWER, MAX_LOWER));} //end getRandomLower() char getRandomLower(char min, char max) {return static_cast<char>(getRandomInt(static_cast<int>(min), static_cast<int>(max)));} //end getRandomLower() char getRandomAlpha() {if (getRandomBool())return getRandomUpper();elsereturn getRandomLower();} //end getRandomAlpha() char getRandomDigit() {return static_cast<char>(getRandomInt(MIN_DIGIT, MAX_DIGIT));} //end getRandomDigit() char getRandomDigit(char min, char max) {return static_cast<char>(getRandomInt(static_cast<int>(min), static_cast<int>(max)));} //end getRandomDigit() char getRandomChar() {return static_cast<char>(getRandomInt(MIN_CHAR, MAX_CHAR));} //end getRandomChar() #endif

Question

Create a new file in C++ and save it as lab12_XYZ.cpp 

  1. Consider rolling two six-sided dice. While the result of each throw is independent of all rolls that have come before, we can still calculate the odds of rolling any given number between 2 and 12. This program will calculate those odds by generating a large number (100,000) of random values (i.e. "rolling the dice") and storing the results in an array. When all values have been rolled, we will display the results (counts and odds to 2 decimal places) to the user.
  x   x   2   3   4   5   6   7   8   9   10  11  12     //value for sum of 2 dice rolls +---+---+---+---+---+---+---+---+---+---+--- |   |   |   |   |   |   |   |   |   |   |   |   |   |    //counters for number of times value is rolled +---+---+---+---+---+---+---+---+---+---+---+---+---+   0   1   2   3   4   5   6   7   8   9  10  11  12     //array index

In Lab 5, sample code was provided for generating a random number. In this lab, I've provided a header file for you to include, getRandomLib.h, which lets you get all kinds of random things.

We need some functions:
  • void displayMessage();  //hello, goodbye, etc.
  • int rollDice();  //returns a number between 2 and 12 (by rolling two dice and summing the result)
  • void displayResults(int[]);  //displays results in the array

HINT: Make sure to initialize counters before starting loop

HINT: To calculate odds: odds = count * 100 / NUM_ROLLS;

  • Header comments must be present
  • Prototypes must be present if functions are used
  • Hello and goodbye messages must be shown
  • Array(s) must be used for implementation
  • Results should be formatted neatly (2 decimal places for odds, decimals lined up, etc.)
  • Use comments and good style practices

Make sure to #include "getRandomLib.h". Download the attached header file and place in same location as your program.

SAMPLE OUTPUT: Welcome! This program will calculate the odds of rolling 2 - 12 with two 6-sided dice.
Number of  2s rolled:          270  ( 2.70%) Number of  3s rolled:          556  ( 5.56%) Number of  4s rolled:          814  ( 8.14%) Number of  5s rolled:         1136  (11.36%) Number of  6s rolled:         1379  (13.79%) Number of  7s rolled:         1705  (17.05%) Number of  8s rolled:         1397  (13.97%) Number of  9s rolled:         1140  (11.40%) Number of 10s rolled:          818  ( 8.18%) Number of 11s rolled:          532  ( 5.32%) Number of 12s rolled:          253  ( 2.53%)
Exiting program. Goodbye!
Attached Files:
  •  getRandomLib.h (3.468 KB):

#ifndef GET_RANDOM_LIB_H
#define GET_RANDOM_LIB_H

#include <cstdlib>
#include <random>
#include <ctime>
using namespace std;

const int MIN_UPPER = 65;
const int MAX_UPPER = 90;
const int MIN_LOWER = 97;
const int MAX_LOWER = 122;
const int MIN_DIGIT = 48;
const int MAX_DIGIT = 57;
const int MIN_CHAR = 33;
const int MAX_CHAR = 126;

//unsigned seed = time(0);

int getRandomInt(int min, int max) {
//seed random engine
static default_random_engine gen((unsigned int)time(0));

// if max < min, then swap
if (min > max) {
int temp = min;
min = max;
max = temp;
}

//set up random generator
uniform_int_distribution<int> dis(min, max); //range

//need to throw away the first call, as it is always max...
static int firstCall = dis(gen);

return dis(gen);
} //end getRandomInt()

float getRandomFraction() {
//seed random engine
static unsigned seed = time(0);

return rand() / static_cast<float>(RAND_MAX);
} //end getRandomFraction()

float getRandomFloat(float min, float max) {

if (min > max) {
float temp = min;
min = max;
max = temp;
}

return (getRandomFraction() * (max - min)) + min;
} //end getRandomFloat()

double getRandomDouble(double min, double max) {

if (min > max) {
double temp = min;
min = max;
max = temp;
}

return (static_cast<double>(getRandomFraction()) * (max - min)) + min;
} //end getRandomDouble()

bool getRandomBool() {
if (getRandomInt(0,1) == 0)
return false;
else
return true;
} //end getRandomBool

char getRandomUpper() {
return static_cast<char>(getRandomInt(MIN_UPPER, MAX_UPPER));
} //end getRandomUpper()

char getRandomUpper(char min, char max) {
return static_cast<char>(getRandomInt(static_cast<int>(min), static_cast<int>(max)));
} //end getRandomUpper()

char getRandomLower() {
return static_cast<char>(getRandomInt(MIN_LOWER, MAX_LOWER));
} //end getRandomLower()

char getRandomLower(char min, char max) {
return static_cast<char>(getRandomInt(static_cast<int>(min), static_cast<int>(max)));
} //end getRandomLower()

char getRandomAlpha() {
if (getRandomBool())
return getRandomUpper();
else
return getRandomLower();
} //end getRandomAlpha()

char getRandomDigit() {
return static_cast<char>(getRandomInt(MIN_DIGIT, MAX_DIGIT));
} //end getRandomDigit()

char getRandomDigit(char min, char max) {
return static_cast<char>(getRandomInt(static_cast<int>(min), static_cast<int>(max)));
} //end getRandomDigit()

char getRandomChar() {
return static_cast<char>(getRandomInt(MIN_CHAR, MAX_CHAR));
} //end getRandomChar()

#endif

 

 

 

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: Prove that the following languages are not regular: (b) L = {anblak : k ≠ n + l}. (c) L = {anblak : ...

A: In the given question, multiple parts are there and we will solve only first three parts as no parti...

Q: Design a program that prompts user enters user name and password. Until user entered user name as "F...

A: Note:The programming language is not mentioned in the question. So, it is programmed in Java.Step by...

Q: write a program to enter two sides a and b of a right triangle from keyboard calculate its area and ...

A: Given below is the C++ program to enter the two sides of a right triangle and then calculate its are...

Q: How can I create a decoder and a multiplexer in a circuit? The decoder has a 3 bit select input and ...

A: A decoder is a circuit which has n inputs and 2n outputs. So if there are 3 inputs to a decoder it w...

Q: Construct the XOR operator using only AND, OR, and NOT gates.

A: XOR gate:An XOR gate is referred to an Exclusive OR gate. The output of an XOR gate is “1” only when...

Q: Programming in C language.

A: In order to implement the question mentions a method called getChoice() information about which has ...

Q: Give an implementation of the macroinstruction searchleft (a, qi, qj), which indicates that the mach...

A: Turing machine uses “searchleft” for an implementation of the macroinstructions. If the machine read...

Q: Is the following distributive law valid or invalid? Prove your answer. x XOR (y + z) = (x XOR y) + ...

A: Answer:Here, the truth table is used to get the answer for each side of the question.First take LHS,

Q: Eliminate useless productions from S → a |aA| B|C, A → aB|λ, B → Aa, C → cCD, D → ddd|Cd.

A: Identifying non-generating variables:

Q: write a program in c++. You work for a box company, and have been asked to write a program to compar...

A: Solution:The C++ program has the following algorithm:Declare and initialize the required variables.D...

Q: Show that the following grammar is ambiguous: S→AB|aaaB,A→a|Aa,B→b.

A: A grammar is known as ambiguous when there is more than one derivation tree (right most derivation t...

Q: (The Fan class) Design a class named Fan to represent a fan. The class contains:■ Three constants na...

A: Java program to create Fan class is as follows:

Q: This is a Python question. How do I get the following code to create a numerical list of guest names...

A: We need to convert the guest_name variable as a Python list of 50 elements and initialize each eleme...

Q: A pet shop wants to give a discount to its clients if they buy one or more pets and at least four ot...

A: The program has two main parts – the part which receives the input and the part which validates the ...

Q: steps to build up a new prodect brand?

A: Steps to build up a new product brand are as follows:

Q: Give regular expressions for the following languages. (a) L1 = {anbm, n ≥ 3, m ≤ 4} (b) L2 = {anbm :...

A: Answer:Regular expression:a. L = {an bm, n &gt;=3, m &lt;= 4}

Q: For this program you need to use Eclipse

A: Program plan:Declare the integer variables “coin” and “guess” and string variable “num”.Generate the...

Q: I need help with creating a main.css, I already have the HTML.the details are in the pic and I will ...

A: You can use following code in your main.css file to format your HTML document.Note: Make use of &lt;...

Q: Construct npda that accept the following regular language: L1 = L (aaa∗bab).

A: Non-deterministic pushdown automaton (NPDA):Given: aaa*bab To construct NPDA, when “a” comes then pu...

Q: For this program you need to use Eclipse. Carefully read the instructions and write a program that r...

A: The program has the following algorithm: Step 1: Create object for “Scanner” class to read the user ...

Q: Consider a 32-bit hexadecimal number stored in memory as follows: Address Value 100 2A 101 ...

A: Big-endian:Big-endian is defined as the order in which the most significant value in the sequence is...

Q: Hello, I have a question with the program javascript and in the program I need to create a timer in ...

A: To display the greeting message, we can declare a new variable, suppose wish, to store the greeting ...

Q: Used Java 4.23 (Financial application: payroll) Write a program that reads the following information...

A: The program would have the following 4 sections:The declaration and initialization of the variables ...

Q: how to write a function in python 3 that take a tuple t = (7,8,4,20,11) and returns a list which inc...

A: Note: The below program has been complied and executed in “repl.it” online complier

Q: Write a program called StudentTable that prints the below table. Use only print() orprintf(). DO NOT...

A: The program in Java would be using print and printf statements with formatting for left alignment of...

Q: Write a python code of a function that takes in four points in a counterclockwise order, a, b, c, d ...

A: Program Instructions:Create a function isConvex() and pass the four points as arguments.Save the par...

Q: how to write a function in python 3 that reads a txt file which includes three number (each line has...

A: AlgorithimStartOpen a file in read modeRead a line from file and store the number in variable aRead ...

Q: Develop the ‘Shape’ application such that: Implement an array of objects of various types (all SIX ...

A:  Program to develop a ‘Shape’ application, by implementing an array of objects of the given six clas...

Q: Consider the following procedure: procedure mystery (x, y, z); integer x, y, z;beginz =2; y = z + x;...

A: Call by reference The arguments passed to a function will copy the address of an argument into the f...

Q: This code is for python Searching for Data In this lab we'll compare the time it takes to search for...

A: Instructions for solving the given problem:In part 1, use random.randint() function to generate rand...

Q: 1) The UsingMethod class consists of a main method and a method called xMethod. What will the code p...

A: Hey, since there are multiple questions posted, we will answer first question. If you want any speci...

Q: How do I get this flat list table into 1NF, 2NF and 3NF?

A: Normalization:Normalization is a process of dividing the tables by more than one idea into set of ta...

Q: Write a class named StockPrice. The class constructor should accept an array of stock prices as its ...

A: First of all ,you  need to create a class .The class name is StockPrice  in which you need to create...

Q: Programming in C

A: We use the bsearch function from the stdlib.h and define a compare function to return the result of ...

Q: 4.23 (Financial application: payroll) Write a program that reads the following information and print...

A: C code#include&lt;stdio.h&gt;#include&lt;string.h&gt; int main(){char employeeName[20]="";double hou...

Q: Find context-free grammars for the following language: L = anbn, n is even.

A: Context-free grammar (CFG): This grammar containing predictable set of grammar rules which contains ...

Q: Create a new file (in Dev C++) . In Lab 2, you created a menu for a simple calculator program. In La...

A: Program Instructions:Declare variables and call the printHelloMsg() function to display a welcome me...

Q: Hello! I am trying to write a program in Pynthon. Need help. Requirements: Write a .py file like Kev...

A: Program Plan:Import required packagesPrompt the path and the number of characters to delete from the...

Q: Convert the grammar S → aSb|bSa|a|b|ab into Greibach normal form.

A: A context free grammar  is in Greibach Normal Form (GNF) if all production rules satisfy one of the ...

Q: This program uses hours, pay rate, state tax and fed tax to determine grossand net pay. The code is ...

A: Program Descriptions:The given program does not have any errors.It takes input from a file named pay...

Q: Load “Lock5Data” into your R console. Load “OlympicMarathon” data set in“Lock5Data”. This data set c...

A: First we install the Lock5Data package and then load the package. Then we load the library dplyr to ...

Q: How do I define a recursive function with C++? I am supposed to compute the Fibonacci numbers with a...

A: The algorithm for the recursive Fibonacci series is as below:Start with the first element which is 0...

Q: #include#include#includeusing namespace std;// outputHtmlTitle// parameters// This function...void o...

A: Instructions to remove the error from the program:Use all these header files:#include &lt;iostream&g...

Q: Write a function for the Superman ride at Six Flags that determines whether the user is taller than ...

A: Program code to write a function for the Superman ride  to determines whether the user is taller tha...

Q: function myCompose(f,g){// TODO: return (f o g);// that is, a function that returns f(g(x)) wh...

A: Click to see the answer

Q: Write a class AnalyzeNumbers which asks the user to enter the number of inputs andstores them in an ...

A: Program plan:Define the class “AnalyzeNumbers”.Define the “main()” method.Create object for “Scanner...

Q: 5-9) (Find the two highest scores) Write a program that prompts the user to enter the number of stud...

A: Program that prompts the user to enter the number of students and each student’s name and score, and...

Q: I could use help with the following SQL questions (the fields ProductModelName, ProductCategory, Pro...

A: As the table name is not shown in the picture, we are assuming the table name as Product. There are ...

Q: Help.

A: Below is the algorithm:-start    function quadratic(a,b,c)        if a=0 then            display "no...

Q: Write a function is_mirror(s) that takes as input a string s and returns True if s is a mirrored str...

A: The algorithm for the program would be as follows:Find the length of the program if it is even lengt...