Question: C++: Write a function double picalc( int round) which is described below and call it inside a for loop for six times in your main

C++:

Write a function double picalc( int round) which is described below and call it inside a for loop for six times in your main program. Each time, change the value of round with multiples of 10 and print its output.

Pi Calculation with Monte-Carlo Simulation: We know that a unit circle has the area, A = since r = 1 in the formula, r 2 . Hence, a quarter circle would have the area of 4 . If you assume that you have a square which can include this quarter circle, you would have the following ratio between the area of the quarter circle and the square (As):

A/As = (/4)/ 1 = /4

Suppose you throw N darts (generate N random (x, y) pairs) to the square illustrated in Figure 1. Then, count how many times (Nin) you are able to hit the inner part of the arc by checking if x^2 + y^2 <= 1

Finally, you will see that

A/As = (/4) /1 = /4 = Nin/N

Then, you can approximate

= 4 (Nin/N)

Your function will get the number of throws, N (rounds), and generate (x, y) pairs by using rand() from stdlib. To be able to generate values less than 1, you should divide your random number by RAND MAX. You may need to do casting as your random number and RAND MAX will be integers

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!