Reference no: EM13711339
Program: Write a C++ program to evaluate the mathematical constant of PI:
Part (1) Imagine a circle, whose area is given by: Area=PI*R^2
Part (2) Now imagine that you divide the circle exactly into 4 quadrants.
Part (3) The area of one quadrant is hence: Area=0.25*PI*R (d) Now let us set the radius to be R=1;
Part (4) The equation hence becomes: Area=0.25*PI
Part (5) So we can simply say: PI = Area*4
y-axis
x=0 y=1
x=0 y=0
Note that this square is 1.0 x 1.0 in size.
x-axis
???????x=1 y=0
The question is how do you evaluate the area of the grey shaded quadrant of the circle above?
Use a random number generator and guess effectively the correct solution.
(Hint: use rand() from <cstdlib> and make sure that you divide through by RAND_MAX.)
The method you should use is to:
1. Guess a random number between 0.00 and 1.00 and assign this to x.
2. Guess a random number between 0.00 and 1.00 and assign this to y.
3. Find out if this (x,y) coordinate lies inside the grey shaded quadrant or outside. Hint: sqrt(x +y ).
4. Repeat these steps N times, where N is sufficiently big and then find the ratio of points inside the circle divided by the total number N, to determine the area of the grey shaded area.
5. Apply this to your equation to find the mathematical constant PI.