友元 距离.txt

来自「最后声明」· 文本 代码 · 共 56 行

TXT
56
字号
#include<iostream> 
#include<math.h> 
using namespace std; 
class Point 
{ 
double x,y; 
public: 
Point(double a,double b) 
{ 
x=a;y=b; 
} 
friend double xdis(Point & a,Point & b); 
friend double ydis(Point & a,Point & b);
}; 
double xdis(Point & a,Point & b) 
{ 
return sqrt(a.x-b.x); 
} 
double ydis(Point & a,Point & b) 
{ 
return sqrt(a.y-b.y); 
} 
void main() 
{ 
Point A(1,1), B(2,2); 
cout<<"xdis is "<<xdis(A,B)<<endl; 
cout<<"ydis is "<<ydis(A,B)<<endl; 
} 



原版

#include<iostream> 
#include<math.h> 
using namespace std; 
class Point 
{ 
double x,y; 
public: 
Point(double a,double b) 
{ 
x=a;y=b; 
} 
friend double dis(Point & a,Point & b); 
}; 
double dis(Point & a,Point & b) 
{ 
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); 
} 
void main() 
{ 
Point A(1,1), B(1,3); 
cout<<dis(A,B)<<endl; 
} 

⌨️ 快捷键说明

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