Question: CS 153 Program 06 - Pi Dart Random numbers can be used to calculate the value of TT-the value ordinarily expressed as 3.14159265.... Think of

 CS 153 Program 06 - Pi Dart Random numbers can be

CS 153 Program 06 - Pi Dart Random numbers can be used to calculate the value of TT-the value ordinarily expressed as 3.14159265.... Think of a square with sides of length 2r with a circle of radius r inscribed inside. Think of the center of the square as at the coordinate (0, 0) The area of the square is (2r)2-4r2 and the area of the circle is r2 . Now think of randomly throwing darts at the figure. Say that each dart will hit inside the square somewhere, but where it hits is completely random. This means that the number of darts that hits an area is proportional to that area. Say that 1000 darts were thrown. 1000 of them fall inside the square and a certain proportion, say C, also fall inside the circle If the darts have been thrown randomly, then C/1000 area of circle / area of square So if you throw 1000 darts, then m/4 ~ C/1000, or 4C/1000 Your program is to simulate the throw of 1000 darts (or more) and to keep track how many darts fall inside the circle and then use this number to calculate . Each dart hits the figure at a location (x, y) where x and y are random doubles in the range-1 to 1. A dart falls inside the circle if its distance from the center is less than or equal to 1.0 (Actually, it is best to determine this by checking that the square of the distance is less than or equal to 1.0. There is no need to calculate the square root.) Of course, Pythagoras has a formula for this Write a function throwDart (double *x, double y that returns (through pointers) random values in the open interval 1.0 to 1.0. Initialize the random number generator once at the beginning of the program using the current time (see C Puzzles) Ask the user for the number of times the dart is thrown (which will affect your result for ). You should get an estimate of TT that is accurate to 3 digits or so. With a better random number generator and more trials you would get a better estimate Start your program with some documentation that says who did it and what it does /* CS 153 PROGRAM 6 - P Dart AUTHOR: DATE: DESCRIPTION: Turn in (using the Blackboard mechanism) your source code CS 153 Program 06 - Pi Dart Random numbers can be used to calculate the value of TT-the value ordinarily expressed as 3.14159265.... Think of a square with sides of length 2r with a circle of radius r inscribed inside. Think of the center of the square as at the coordinate (0, 0) The area of the square is (2r)2-4r2 and the area of the circle is r2 . Now think of randomly throwing darts at the figure. Say that each dart will hit inside the square somewhere, but where it hits is completely random. This means that the number of darts that hits an area is proportional to that area. Say that 1000 darts were thrown. 1000 of them fall inside the square and a certain proportion, say C, also fall inside the circle If the darts have been thrown randomly, then C/1000 area of circle / area of square So if you throw 1000 darts, then m/4 ~ C/1000, or 4C/1000 Your program is to simulate the throw of 1000 darts (or more) and to keep track how many darts fall inside the circle and then use this number to calculate . Each dart hits the figure at a location (x, y) where x and y are random doubles in the range-1 to 1. A dart falls inside the circle if its distance from the center is less than or equal to 1.0 (Actually, it is best to determine this by checking that the square of the distance is less than or equal to 1.0. There is no need to calculate the square root.) Of course, Pythagoras has a formula for this Write a function throwDart (double *x, double y that returns (through pointers) random values in the open interval 1.0 to 1.0. Initialize the random number generator once at the beginning of the program using the current time (see C Puzzles) Ask the user for the number of times the dart is thrown (which will affect your result for ). You should get an estimate of TT that is accurate to 3 digits or so. With a better random number generator and more trials you would get a better estimate Start your program with some documentation that says who did it and what it does /* CS 153 PROGRAM 6 - P Dart AUTHOR: DATE: DESCRIPTION: Turn in (using the Blackboard mechanism) your source code

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!