chapter1-20.cpp

来自「STL程序员开发指南源码」· C++ 代码 · 共 31 行

CPP
31
字号
//文件名:CHAPTER1-20.cpp
#include <iostream.h>
#include <math.h>
class Point
{
public:
     Point(double xx, double yy) { x=xx; y=yy; }
     void Getxy();
     friend double Distance(Point &a, Point &b);
private:
     double x, y;
};
void Point::Getxy()
{
  cout<<"("<<x<<","<<y<<")"<<endl;
}
double Distance(Point &a, Point &b)
{
    double dx = a.x - b.x;
    double dy = a.y - b.y;
    return sqrt(dx*dx+dy*dy);
}
void main()
{
    Point p1(3.0, 4.0), p2(6.0, 8.0);
    p1.Getxy();
    p2.Getxy();
    double d = Distance(p1, p2);
    cout<<"Distance is "<<d<<endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?