#include <iostream.h>
#include <math.h> //for sqrt()
class C2D
{
protected:
double x, y; //x and y coordinates
public:
C2D() { x = y = 0.0; } //default constructor
C2D(double i, double j):x(i), y(j) { }
void setX(double newX) { x = newX; }
void setY(double newY) { y = newY; }
double getX() const { return x; }
double getY() const { return y; }
double getDistance(C2D point) const; // get distance of 2D points
};
// calculate the distance of two 2D points
double C2D::getDistance(C2D point) const
{
double dx, dy;
double distance;
dx = x – point.getX();
dy = y – point.getY();
distance = sqrt(dx * dx + dy * dy);
return distance;
}
class C3D:public C2D
{
private:
double z;
public:
C3D():C2D();
C3D(double i, double j, double k);
void setZ(double newZ);
double getZ();
double getDistance(C3D point) const; //get distance for two 3D points
該怎麽延伸到三維的啊!!!!