Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C not C++ ) Prompt the user for a radius value r. If the user enters zero or a negative value, keep prompting and getting

C not C++

) 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.

Comments

To ensure non-negative results, you will need to use the fabs()function provided in library.

result = fabs ( number );

In order to make the fractional amounts display in a standardized format (exactly four digits after the decimal for radius, eight digits for error limit), be sure to use the correct %.nlf format code (where n is number of digits after the decimal.

Be sure to keep a copy of the original input error limit.

Your program must display informative prompts to the user, and display results that are fully informative (see example program.)

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_2

Step: 3

blur-text-image_3

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

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions