⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example1-15.cpp

📁 关于书籍《Borland c++Builder工程实践》的源代码
💻 CPP
字号:
#include <iostream.h>
#include <math.h>
class Tpoint
{
private:
double x,y;
public:
 Tpoint(double i, double j)
{
x=i;
y=j;
}
void getpoint()
{
cout<<"("<<x<<","<<y<<")"<<endl;
}
friend double distance(Tpoint,Tpoint);//友元函数说明
};
double distance(Tpoint a,Tpoint b)
{
double dx=a.x-b.x;
double dy=a.y-b.y;
return sqrt(dx*dx+dy*dy);
}
void main()
{
double x1,x2,y1,y2;
cout<<"Enter first point: ";
cin>>x1>>y1;
cout<<endl;
cout<<"Enter second point: ";
cin>>x2>>y2;
cout<<endl;
Tpoint p1(x1,y1),p2(x2,y2);
p1.getpoint();
p2.getpoint();
double dd=distance(p1,p2);
cout<<"The distance is :"<<dd<<endl;
}

⌨️ 快捷键说明

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