1001. Extending MyPoint class
Posted 任我主宰
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1001. Extending MyPoint class相关的知识,希望对你有一定的参考价值。
#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的主要内容,如果未能解决你的问题,请参考以下文章
auto-extending data file ./ibdata1 is of a different size auto-extending data file ./ibdata1 is of