码迷,mamicode.com
首页 > 其他好文 > 详细

1001. Extending MyPoint class

时间:2016-10-22 14:34:38      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:ons   bsp   space   name   const   gety   public   iostream   private   


#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;
}

 

1001. Extending MyPoint class

标签:ons   bsp   space   name   const   gety   public   iostream   private   

原文地址:http://www.cnblogs.com/sysu-eeman-yang/p/5987408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!