Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Array Program need help with 1) Prompt the user for a radius value r. If the user enters zero or a negative value, keep

C Array Program need help with

1) Prompt the user for a radius value r. If the user enters zero or a negative value, keep prompting and getting a value till valid. Then, prompt the user for a starting acceptable error. This must be between 0.001 and 1/4*radius. If the user enters a value that is out of the range of [0, .25r], keep prompting and getting a value till valid. (2) Starting with the input error, repeat 5 times: Compute the approximation of the area using each of the three methods (see below). Keep count of the number of iterations required to meet the desired error limit. Store the number of iterations each calculation took to an array (one array for each method.) Set the error limit to 1/10 that used in the previous calculation. (Example, input error = 0.02. Second round of calculations use 0.002, then 0.0002, etc.) (3) Display a table showing the radius, error limit and number of iterations required for each method, for all the error limits. (see sample run below) (4) Determine and display which method was the best and the worst at each error limit. Calculation Methods Inscribed method: Initialize a variable called n to 3 Compute angle as a=360 / nsides Compute the area of the polygon by adding up the areas of all triangles, as area=n12r2sina *note: you must convert angle to radian in order to use trig functions. Assume the area can be precisely computed using (use constant M_PI in library), and compute the difference or error of the approximated area value. The equation to compute the error is given below. error=area-r2 If the absolute value of error is less than or equal to the acceptable error entered by user then consider the current area value as close enough to be the real area of the circle. Otherwise, increase n by 1 and then loop to step 2. Circumscribed method, The only difference in this method compared to inscribed is to use the following formula in step 3. area=n12rcos(a2)2sina Middle Rectangles method Implement as follows: Initialize a variable called n to 1 Compute width of the rectangles as w=r / n Compute the area by adding up the areas of all rectangles, as area=i=1nwr2-wi-122 Assume the area can be precisely computed using (use constant M_PI in math.h library), and compute the difference or error of the approximated area value. The equation to compute the error is given below. error=area-r2 If the absolute value of error is less than or equal to the acceptable error entered by user then consider the current area value as close enough to be the real area of the circle. Otherwise, increase n by 1 and then loop to step 2.

Sample run of the program (user input in bold italics) Radius: -4 The radius must be a positive value. Enter radius: 2.6 Error limit: 2 Error must be between 0.001 and 0.65. Enter error limit: 0.00001 Error must be between 0.001 and 0.65. Enter error limit: .5 A: Iterations using inscribed polygons B: Iterations using circumscribed polygons C: Iterations using rectangles Radius Error Limit A B C 2.600 0.50000000 14 9 3 2.600 0.05000000 50 35 13 2.600 0.00500000 165 116 61 2.600 0.00050000 526 371 279 2.600 0.00005000 1669 1180 1295 At error 0.50000000 method C is best At error 0.50000000 method A is worst At error 0.05000000 method C is best At error 0.05000000 method A is worst At error 0.00500000 method C is best At error 0.00500000 method A is worst At error 0.00050000 method C is best At error 0.00050000 method A is worst At error 0.00005000 method B is best At error 0.00005000 method A is worst

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

More Books

Students also viewed these Databases questions

Question

Knowledge of process documentation (process flow charting)

Answered: 1 week ago