Question: Hey please help me with writing the code below on C++ with the following restrictions. Restrictions: No arrays, no global variables, must use the 5

Hey please help me with writing the code below on C++ with the following restrictions.

Restrictions:

No arrays, no global variables, must use the 5 functions specified (more are allowed).

Description:

You will write a program using functions that performs the following tasks. These tasks are explained in more detail later in this document

(1) For a user specified number of iterations, determine an approximation for pi using the Monte Carlo Method. Set the output precision to 6 decimal places for this part of the program.

(2) Determine the outcome of a fair* coin being flipped. For a user specified number of coin flips, determine the percent of the time that heads comes up and the percent of the time tails comes up. Set the output precision to 4 decimal places for this part.

(3) Determine the outcome of a fair* 4-sided die being rolled. For a user specified number of rolls, determine the percent of the time that each side (sides 1,2,3 and 4) come up. Set the output precision to 4 decimal places for this part.

*fair means that each possible outcome is equally likely there is no bias for one outcome over the others.

For the coin it means that heads has a 50% chance of coming up and so does tails.

In order to perform the above tasks, a random number generator is to be used to determine values for testing. Information regarding the random number generator occurs later in this document.

To perform the above tasks, your program should have the following order (pseudo algorithm/functional decomposition setup) as illustrated in the sample solution: Prompt the user for a seed value for the random number generator

Write out a menu with the choices as shown in the sample solution and obtain the selection value

While the choice is not to exit, perform the following loop

For choice 1, generate random numbers and process to determine the approximation for pi

For choice 2, generate random numbers and process to determine the fair coin probabilities

For choice 3, generate random numbers and process to determine the fair die probabilities

Write out a menu for the next choice and obtain the selection value.

Assumptions:

The seed value entered for the random number generator is a valid positive integer value and the number of iterations entered is a valid positive integer. Largest integer value allowed is 2147483647

Concepts Explained:

This program uses the random number generator in C++. To use the random number generator, the header file cstdlib is required. In order to compare results from the run of one program to another program, the same random numbers need to be generated by both programs. This is accomplished by supplying a seed value to start the random number generator at the same point. The code below performs the task of initializing the random number generator with a seed value:

// Setup the random number generator starting point by obtaining a seed

cout << "enter in the seed(integer > 0) for the random number generator: ";

cin >> seed;

cout << seed << endl; // echo print out the value entered

srand(seed); // use the seed entered to initialize the generator

Use srand(seed) one time only at the beginning of the program. Random numbers are generated by calling the value returning function rand(). rand() returns an integer value between 0 and RAND_MAX (a constant with a value of 32767). In this program, all return values from rand() are converted to a floating-point number between 0 and 1 by dividing the returned value by RAND_MAX. An example of the type of line of code you will need to use is the following: x_coord = double(rand())/double(RAND_MAX); // value is 0 to 1 Note the type casting to double on all of the integer values.

Requirements:

For this project, at least five functions will be written. Function Prototypes must be used and function definitions must go below main. The five required functions are:

1) Print Menu This function is to print out a menu of options. It is to do no other task. It should be a void function

2) Obtain Integer This function obtains any integer value. It can be void or value returning. It handles all of the error correction and messages if any characters other than digits are entered. Use a switch statement or if-then-elseif statement in main to handle invalid integer values.

3) Calculate PI this function calculates an approximation to PI using the monte-carlo method. This is a void function and it does not have any parameters

4) Flipping a Coin This function determines the odds of heads or tails coming up when flipping a fair coin. This is a void function without parameters

5) Toss a Die This void function without parameters, determines the odds of a 1, 2, 3 or 4 coming up when a four sided fair die is tossed.

Message and Input Value Information:

You will write a program using functions that performs

the following tasks. These tasks are explained in more detail later in this document

(1) For a user specified number of iterations, determine an approximation for pi using the Monte Carlo Method. Set the output precision to 6 decimal places for this part of the program.

(2) Determine the outcome of a fair* coin being flipped. For a user specified number of coin flips, determine the percent of the time that heads comes up and the percent of the time tails comes up. Set the output precision to 4 decimal places for this part.

(3) Determine the outcome of a fair* 4-sided die being rolled. For a user specified number of rolls, determine the percent of the time that each side (sides 1,2,3 and 4) come up. Set the output precision to 4 decimal places for this part. *fair

means that each possible outcome is equally likely

there is no bias for one outcome over the others.

For the coin it means that heads has a 50% chance of coming up and so does tails.

In order to perform the above tasks, a random number generator is to be used to determine values for testing.

Information regarding the random number generator occurs later in this document.

To perform the above tasks, your program should have the following order (pseudo algorithm/functional decomposition setup) as illustrated in the sample solution:

Prompt the user for a seed value for the random number generator

Write out a menu with the choices as shown in the sample solution and obtain the selection value

While the choice is not to exit, perform the following loop

For choice 1, generate random numbers and process to determine the approximation for pi

For choice 2, generate random numbers and process to determine the fair coin probabilities

For choice 3, generate random numbers and process to determine the fair die probabilities

Write out a menu for the next choice and obtain the selection value

The menu has 25 characters across the top and bottom lines

Invalid integer and invalid character messages have 47 characters across the top and bottom

For the PI output, there are 46 characters across the top and bottom of the output section

For the coin output, there are 47 characters across the top and bottom of the output section

For the die output, there are 45 characters across the top and bottom of the output section

Hints:

The function srand() is to be called one time only at the beginning of the program. All random numbers are to be generated from this initial setting of the seed value.

Use double variables for the percent calculations for each of the methods.

Use a do-while loop in main to print the menu, obtain an integer, process the integer with a switch of if-then-else-if statement. Loop exits if the exit option is selected.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!