After class Circle was constructed, we could further use it to build other models. Here a Cylinder is built as following:

cylinder.png
(Image courtesy of Wikipedia)

class Cylinder
{
factor h, v, s;
circle bottom;

v = bottom.a * h;
s = bottom.a * 2 + bottom.c * h;
}

The bottom of the cylinder is a circle, as we declared an instance of it naming 'bottom'.
By given the height (h) as 3, and the bottom circumference (bottom.c) as 4, the rest are solved:

bottom.c = 4
h = 3
bottom.d = 1.2738853503184713375796178344
bottom.r = 0.6369426751592356687898089172
bottom.a = 1.27388535031847256
v = 3.82165605095541768
s = 14.54777070063694512

Last edited Jan 30, 2009 at 5:17 AM by samhuang, version 6

Comments

No comments yet.