4.22

来源:互联网 发布:卡梅隆安东尼数据 编辑:程序博客网 时间:2024/06/05 11:31
#include<iostream>#include<math.h>using namespace std;class dot{public:dot(int a,int b);void show();friend void dist(dot&,dot&);private:int x;int y;};dot::dot(int a,int b){x=a;y=b;}void dot::show(){cout<<"("<<x<<","<<y<<")"<<endl;}void dist(dot& s1,dot& s2){int t1,t2;t1=s1.x-s2.x;t2=s1.y-s2.y;cout<<"该两点间的距离是"<< sqrt(t1*t1+t2*t2)<<endl;}int main(){dot A(1,3),B(5,8);A.show();B.show();dist(A,B);return 0;}

0 0