Question: WIGULUSLUUPLIUI You will write a program using functions that performs the following tasks. These tasks are explained in more detail later in this document (1)

 WIGULUSLUUPLIUI 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

WIGULUSLUUPLIUI 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 and use it to initialize the 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 pl 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 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 This program uses the random number generator in C++. 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 0) for the random number generator: "; cin >> seed; cout For this project, at least five functions will be written. The five required functions are: 1) Print Menu - This function is to print out a menu of options only. It is to do no other task. It should be a void function. It will not read in the selection 2) Obtain Integer - This function obtains any integer value. It handles all of the error correction and messages if any characters other than digits are entered. It can be void or value returning. 3) Calculate PI- this function calculates an approximation to Pl 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. Monte Carlo Method: The Monte Carlo method is a way to use random numbers to approximate a value. In this program it is used to determine a value for pi. The background on the method is now discussed. Consider the figure below showing a circle of radius 1 inscribed inside a box of side length 2. The area of the square is 2'2 or 4 units. The area of the circle is Pl'radius radius which is PI since the radius is 1. Therefore the area of the circle divided by the area of the box is PI/4. In the Monte Carlo method, two random numbers are used to represent an X-coordinate value (from 0 to 1) and a Y-coordinate value (from 0 to 1). The position of the X-Y coordinate pair relative to the circle is determined (is the pair inside the circle or outside the circle). Page 2 of 3 Spring 2020 CPE211 Project Assignment Project 7 Two counters are used. One counter for counting the number of co-ordinate pairs that fall inside VX?+Y? The menu has 26 characters across the top and bottom lines Invalid integer and invalid character messages have 47 characters across the top and bottom For the Pl 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 The only input value that needs to be tested and verified is the menu choice. Valid Integer values will be supplied for the seed number and the number of iterations Menu choice must be read into an integer variable All user defined functions can be called from main only. Usor defined functions cannot call other user defined functions. The only exception is that the function to obtain an integer can call the print menu function (note the PrintMenu function cannot call any user defined functions) Global variables are not allowed Must have at least the five functions stated on page 2 Use integer variables for all counters and the iteration number read Use double variables for all percentage and result calculations - do not forget to type cast Use double variables for the x and y coordinates used in the Monte Carlo method All user defined functions must have their definitions below main and function prototypes must be used. The function prototypes are to be placed above main and below the using namespace std; line Page 3 of 3

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!