博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1001. Extending MyPoint class
阅读量:4677 次
发布时间:2019-06-09

本文共 1495 字,大约阅读时间需要 4 分钟。

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

 

转载于:https://www.cnblogs.com/sysu-eeman-yang/p/5987408.html

你可能感兴趣的文章
Chrome浏览器 调试工具 vue-devtools 的安装和使用
查看>>
门面(Facade)模式
查看>>
html第一堂课
查看>>
IPv6 03-IPv6路由协议
查看>>
跨域请求
查看>>
Web 开发中很实用的10个效果
查看>>
HTML5上传文件显示进度
查看>>
友盟错误日志分析(转自:COCOACHINA shemy )
查看>>
HDU5336-XYZ and Drops-模拟
查看>>
powershell 查看程序的tcp网络连接
查看>>
C++技术问题总结-第12篇 设计模式原则
查看>>
Spring的事件处理
查看>>
利用Android属性动画实现Banner的原理与实践
查看>>
【MySQL案件】mysql登录-S失败
查看>>
白话经典算法系列之中的一个 冒泡排序的三种实现
查看>>
Eclipse断点调试
查看>>
ubuntu 步步为营之uclinux编译和移植(完整版)
查看>>
取消SVN版本号控制的bash脚本
查看>>
ASP.NET 后台接收前台POST过来的json数据方法
查看>>
Python(简单图形和文件处理)编程
查看>>