Answered step by step
Verified Expert Solution
Question
1 Approved Answer
eProject 8 Description> You will write a program using functions that performs the following tasks. These tasks are explained in more detail later in this
eProject 8 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 eProject 8 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 eProiect 8 Directions> On Project 8, you may only use concepts presented in Chapters 1 -9 of your textbook Using your favorite text editor, type your solution and save it as a file named Project 08.cpp within your CPE211_SPR19/Project 08 directory. If there are syntax errors, correct them and compile again. Once your program successfully compiles, run it and verify that the output for your modified program matches the output from the solution executable - Project 08_solution Once you are satisfied with your solution, submit Project 08.cpp via Canvas NOTE: make sure that you do not change the order in which the information is entered. An automatic script is used to process all lab submissions, and if the order of the input information is modified, the script will not work properly with vour program eProiect 8 C++ Concepts Explained> 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 startinq 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. t 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. void function and it does not have any parameters coin. This is a void function without parameters when a four sided fair die is tossed 3) Calculate PI - this function calculates an approximation to Pl using the monte-carlo method. This is a 4) Flipping a Coin - This function determines the odds of heads or tails coming up when flipping a fair 5) Toss a Die This void function without parameters, determines the odds of a 1, 2, 3 or 4 coming up eProiect 8 C++ Math Explained> 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 PIradius radius which is PI since the radius is 1. Therefore the area of the circle divided by the area of the box is Pl/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) Two counters are used. One counter for counting the number of co-ordinate pairs that fall inside ( X2 + Y2 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started