#include<iostream>
#include<cmath>
using namespace std;

 

class MyPoint

{

private:

    double x, y;

public:

    // The no-arg constructor that contruccts a point with coordinates(0,0)

    MyPoint();

    MyPoint(double x, double y);

    double getX() const;

    double getY() const;

 

    //display the distance between two points in two-dimensional space.

    double distance(const MyPoint &point);

};

MyPoint::MyPoint() {
 x=0.0;
 y=0.0;
}
 
MyPoint::MyPoint(double x,double y){
 this->x = x;
 this->y = y;

double MyPoint::getX() const{
    return x; 
}
 
double MyPoint::getY() const{
    return y; 
}
 
double MyPoint::distance(const MyPoint &point){
 double a=this->x - point.x;
 double b=this->y - point.y;
 return sqrt( pow(a,2) + pow(b,2) );
}
 
 
 

class ThreeDPoint : public MyPoint

{

private:

    double z;

public:

    // The no-arg constructor that contruccts a point with coordinates(0,0,0)

    ThreeDPoint();

 

    ThreeDPoint(double x, double y, double z);

    double getZ() const;

 

    //display the distance between two points in Three-dimensional space.

    double distance(const ThreeDPoint &point);

};


ThreeDPoint::ThreeDPoint():MyPoint(){
 z=0.0;
}


ThreeDPoint::ThreeDPoint(double xx,double yy,double z):MyPoint(xx,yy){
 this->z = z;
}

double ThreeDPoint::getZ() const{
    return z;
}


double ThreeDPoint::distance(const ThreeDPoint &point){
 
 double a = this->getX()-point.getX();
 double b = this->getY()-point.getY();
 double c = this->z-point.z;
 return sqrt(pow(a,2) + pow(b,2) + pow(c,2));
}

 

 

 

 

 


int main(){
 
 
 
 
 return 0;
}

 

posted on 2016-10-22 13:23  任我主宰  阅读(244)  评论(0编辑  收藏  举报