Reference no: EM131323862
Assignment
After informing the user what the program does, prompt the user for the number of darts to throw. Also, prompt for a number of simulations (why not have the program simulate this dart throwing more than once). Then, for each "dart" to be thrown, generate a random x and y coordinate within this region. Calling the function rand() will give you a random number 0...INT_MAX. If you divide the number by INT_MAX, you'll be able to generate a random number in the interval [0,1). Remember to seed the random generator. After these random coordinates are generate, (i.e., a dart is thrown), see if the dart falls within the unit quarter-circle. Since the radius of the unit circle is 1, to determine if the dart is inside simply calculate the distance from the origin to the coordinate. If the distance is less than one, the dart must be inside the quarter circle. Otherwise, it falls outside this region. If the dart is inside the quarter circle, keep track of this by incrementing a count variable, say dartsInside. Once all the darts are thrown, divide the dartsInside by the total number of darts thrown to approximate the area of the quarter circle.
This has now successfully made an approximation of pi/4, but was only a throw of n darts. Your program is going to simulate throwing n darts m times. Just reset the count variable and run the approximation again. Each simulation will generate a new approximation of pi/4. We'll take the average of all these approximations to give our final approximation of pi. Normally, the average of m numbers is the sum of the data divided by m. However, in order to avoid overflow, convince yourself of the equality
a1+a2+...+am / m = a1 / m + a2 / m + ... am/m
Thus, instead of accumulating the approximations of pi, your program will accumulate the approximation divided by m. Once all the simulations are finished, multiply your value by four and print the programs approximation of pi.
Finally, to see different approximations, allow the user to repeat this process of throwing n darts m simulated times an indefinite number of times-until the user enters in a value indicated to quit. For example, the sentinel value could be 0. This program will also guard against bad data. When the user enters in a number, the number could be invalid - i.e., less than 0, or it could be a character. In either event, your program should handle this without crashing, recover from this bad data and continue execution.
Find the maximum normal and shear stresses in beam
: A linearly increasing load sits on a brass rail of length L. Find the centroid (4) of the cross section below. Using successive integration, find the maximum bending moment (5) and deflection (8) in the rail and their respective locations along th..
|
Design a program that asks the user to enter a string
: Sum of Digits in a String Design a program that asks the user to enter a string containing a series of single digit numbers with nothing seperating them.
|
Why did you decide on this profession-health counselor
: Part of developing your clinical mental health counselor identity is exploring your motivations for entering this profession. Why did you decide on this profession? What experiences have you had in the past that make you think this profession woul..
|
Calculate that the correct answer
: For example, if you calculate that the correct answer is 514 mm Hg, simply type "510" in the box without the quotation marks (") or units as part of your answer.
|
Prompt the user for the number of darts to throw
: After informing the user what the program does, prompt the user for the number of darts to throw. Also, prompt for a number of simulations (why not have the program simulate this dart throwing more than once).
|
Write the paper on domestic violence
: Write the given paper assignment.- The topic is: "Domestic Violence: The After-Effects."- Also provide the Thesis statement.
|
Calculate the molarity of solution
: Dr. Pepper has 40.0g of sugar per 12 oz. of liquid. Calculate the molarity of this solution. Put that molarity into your regression line and calculate the density (all other things being equal) of this sugar solution. Show your work
|
Probelm regarding the buffer solution
: What mass of NaH2PO4 must be added to 1.20 L of 0.20 M Na2HPO4to make a buffer solution whose pH=6.90? pKa2(H3PO4)=7.21.
|
Why does the temperature of a solution increase
: Why does the temperature of a solution increase if the reaction is exothermic? For example, in the precipitation of silver iodide, delta H is -110.7 kj. Why is this reaction exothermic and why does it cause the solution temperature to increase?
|