proj8_04.cpp
来自「C++程序设计教程的全部源代码 包含与教程同步的PPT 方便学习」· C++ 代码 · 共 33 行
CPP
33 行
#include "iostream.h"
#include "math.h"
class Point
{
public:
Point(double i , double j)
{
x = i;
y = j;
}
void Getxy()
{
cout << "(" << x << "," << y << ")" << endl;
}
friend double Distance(Point a,Point b);
private:
double x , y;
};
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:" << d << endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?