Newbie needing help

From: J Swift (ejgjunk_at_hotmail.com)
Date: 01/21/05


Date: Fri, 21 Jan 2005 11:55:26 -0700

Below is a homework problem that I gave some time and thought to. I answered
it as best I could but I don't know if it's right. If it is wrong, would
someone care to guide me toward the correct answer? I don't think I'm
getting it.

THE PROBLEM:
The cylinder class provides measurement of a cylinder object, which we can
view as a 3-dimensional figure created by a circle sliding vertical upward
along a line denoting the height. A cylinder is defined by the radius of the
circular base and the height. Using OBJECT COMPOSITION, we represent the
base using a circle object.

class cylinder

{

    public:

        cylinder(double r, double h)

        : _______, height(h)

        {}

        MY ANSWER: base(r)

        double volume()

        // area of base * height

        { ________________}

        MY ANSWER:

            return base.area() * height

        double getRadius()

        // radius of the base

        { return ________ }

        MY ANSWER:

            return base.getRadius

    private:

    circle base;

    double height;

};

The following is the circle class implementation using inline code

const double PI = 3.141592653589793;

class circle

{

    public:

        circle(double r = 0.0): radius

        {}

        double getRadius() const

        { return radius; }

        void setRadius(double r)

        { radius = r; }

        double area() const

        { return PI * radius * radius; }

        double circumference() const

        { return 2.0 * PI * radius; }

    private:

        double radius;

};

(a) In the implementation of the cylinder constructor, complete the
initialization list.

(b) Give the return value for getRadius().

(c) Implement the member function volume().



Relevant Pages

  • Re: Newbie needing help
    ... >> Below is a homework problem that I gave some time and thought to. ... >> The cylinder class provides measurement of a cylinder object, ... >> circular base and the height. ... > Your compiler would have complained about that omission. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Understanding raytracing code
    ... each pixel of the screen, this code gets the direction towards each ... cylinder you're viewing, and that the cylinder is aligned along the z ... Now, to find out if you're inside a circle, all you need to do is ... Now, once this while loop is done, its either outside the cylinder ...
    (comp.graphics.algorithms)
  • Re: need help with homework
    ... Bryana says that the teacher was teaching about inverses of functions ... OK, but I presume the other items were taught earlier, such as what ... a "cylinder" of any type, not just a right-circular cylinder, etc. ... formulas (area of circle and volume of general cylinder). ...
    (sci.math)
  • Locus of z(z+c) for |z|=1 (z complex) and an optical phenomenon
    ... which is just a reparametrization of the unit circle and then ... The room where it is has a wall ... perpendicular to the cylinder axis, the wall being at about 85 cm. (or ... symmetric to it with respect to the normal line to the reflecting ...
    (sci.math)
  • Re: Determining the curve
    ... Where I work I use a roller to role a flat plate of metal into a curve. ... The diameter of each cylinder is 74 mm. ... the plate into a curve which in the end curves to form a circle. ...
    (sci.math)