第3题

来源:互联网 发布:linux listen 端口 编辑:程序博客网 时间:2024/06/05 05:22
#include<iostream>#include<cmath>using namespace std;class Location{public:void show1();   void show2();   void setlocation1(double X1,double Y1)   {this->x1=X1;y1=Y1;}       double Mathlong(Location&);   friend double Mathlong(Location& a,Location& b){return sqrt((a.x1-b.x1)*(a.x1-b.x1)+(a.y1-b.y1)*(a.y1-b.y1));}private:double x1;double y1;};void Location::show1(){cout<<"A"<<"("<<x1<<","<<y1<<")"<<"    ";}void Location::show2(){cout<<"B"<<"("<<x1<<","<<y1<<")"<<endl;} double Location::Mathlong(Location& a){return sqrt((a.x1-x1)*(a.x1-x1)+(a.y1-y1)*(a.y1-y1));}int main(){Location A,B;//A(x1,y1);Location B(x2,y2);    A.setlocation1(-1,-1);B.setlocation1(-1,1);    A.show1();B.show2();cout<<"Distance1="<<Mathlong(A,B)<<endl;cout<<"Distance2="<<B.Mathlong(A)<<endl;return 0;}

0 0
原创粉丝点击