




BALL.H
Although class ball has inherited each sphere member variable, only public and protected variables are accessible.
#include "sphere.h"
class ball :public sphere
{
public:
ball(void);
~ball(void);
void fall(void);
void expand(float);
void setVelocity(float, float, float);
inline float getXVelocity(void) { return xVelocity; }
inline float getYVelocity(void) { return yVelocity; }
inline float getZVelocity(void) { return zVelocity; }
protected:
float xVelocity;
float yVelocity;
float zVelocity;
private:
void resetVelocity(void);
};
BALL.H
Private member variables must still be accessed using accessor functions just as they are by others.
include "ball.h"
ball::ball(void)
{
resetVelocity()
}
ball::~ball(void)
{
}
void ball::resetVelocity(void)
{
xVelocity = 0.0;
yVelocity = 0.0;
zVelocity = 0.0;
}
void ball::fall(void)
{
xPosition += xVelocity;
yPosition += yVelocity;
zPosition += zVelocity;
if (zVelocity > 0.0 && zPosition >= 100.0)
zVelocity = -zVelocity;
else if (zVelocity < 0.0 && zPosition <= 0.0)
resetVelocity();
}
void ball::expand(float value)
{
float radiusValue;
radiusValue = getRadius();
radiusValue += value;
setRadius(radiusValue);
}
void ball::setVelocity(float xValue, float yValue, float zValue)
{
xVelocity = xValue;
yVelocity = yValue;
zVelocity = zValue;
}