C++ CS106B Standford University

Hi All,
I am doing CS106B Standford university course and practising C++ exercises from the book/reader.I am stuck on the exercise bcoz i don't understand what i have to do here.Could anybody give hints please.I believe i can do this if i get some hints.The quesion is as follows
You can also approximate π by approximating the area bounded by a circular arc. Consider the following quarter circle:
which has a radius r equal to two inches. From the formula for the area of a circle, you can easily determine that the area of the quarter circle should be π square inches. You can also approximate the area computationally by adding up the areas of a series of rectangles, where each rectangle has a fixed width and the height is chosen so that the circle passes through the midpoint of the top of the rectangle. For example, if you divide the area into 10 rectangles from left to right, you get the following diagram:
The sum of the areas of the rectangles approximates the area of the quarter circle. The more rectangles there are, the closer the approximation.
For each rectangle, the width w is a constant derived by dividing the radius by the number of rectangles. The height h, on the other hand, varies depending on the position of the rectangle. If the midpoint of the rectangle in the horizontal direction is given by x, the height of the rectangle can be computed using the distance formula

h = √r–x

The area of each rectangle is then simply h x w.
Write a program to compute the area of the quarter circle by dividing it into 100 rectangles.
**the diagram and formula cannot be seen.

if the radius is 40, and we have four rectangles. The width will be 10 each. height can be calculated by the formula given above. So the height will increase for each rectangle if we go from left to right.
just add the area you get four time or the number of rectangle times. Thats it.

I don't if this is the question or I understood something else.
if you think about this image: http://img20.imageshack.us/i/97770678.png/

the number of rectangles is 100,
radius; 2 inch
according to the definition above;
w = 2 inch / 100 for each rectangular. (on the picture they're not equal though)

height for each rectangular;
for example, for the 49th rect;

it's corner coordinates;
a = 0
b = 49 * ( 2 / 100).

the height is the distance of the corner of the 49th rect to the intersection at the arc;
intersection point is from the circle equation:
(x * x ) - ( y * y ) = 2 * 2

x = b;
sqrt((b * b) - (2 * 2)) = y

the height of this 49th rectangle is y (it is equal to h)

which means,
1. first find w, it's a fixed number.
2. go into a loop, find all rectangles' height
3. within the loop, calculate w * h for each rect, and add it to a totalArea variable.

which is the answer. I think.
Last edited on
Aren't you just trying to compute the Riemann sum with 100 divisions and middle sum? If you research this, you will probably understand the problem a little better - at least how I think you are proposing it.
Topic archived. No new replies allowed.