Newbie needing help
From: J Swift (ejgjunk_at_hotmail.com)
Date: 01/21/05
- Next message: B. v Ingen Schenau: "Re: Excellent C++ Tutorial?"
- Previous message: BobR: "Re: int to string - without using stringstream. [OT question]"
- Next in thread: B. v Ingen Schenau: "Re: Newbie needing help"
- Reply: B. v Ingen Schenau: "Re: Newbie needing help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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().
- Next message: B. v Ingen Schenau: "Re: Excellent C++ Tutorial?"
- Previous message: BobR: "Re: int to string - without using stringstream. [OT question]"
- Next in thread: B. v Ingen Schenau: "Re: Newbie needing help"
- Reply: B. v Ingen Schenau: "Re: Newbie needing help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|