Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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-4f2 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 /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 dist -x2 + y2 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 TT). 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 doe:s /* CS 153 PROGRAM 6 - Pi Dart AUTHOR: DATE: DESCRIPTION: Turn in (using the Blackboard mechanism) your source code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

More Books

Students also viewed these Databases questions

Question

fscanf retums a special value EOF that stands for...

Answered: 1 week ago