和之前的4.22差不多
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
class Location{
public:
Location(double a,double b);
double Getx();
double Gety();
static double distance1(Location &i,Location &j);
friend double distance2(Location &k,Location &l);
private:
double x,y;
};
Location::Location(double a,double b)
{
x=a;
y=b;
}
double Location::Getx()
{
return x;
}
double Location::Gety()
{
return y;
}
double Location::distance1(Location &i,Location &j)
{
return sqrt((j.y-i.y)*(j.y-i.y)+(j.x-i.x)*(j.x-i.x));
}
double distance2(Location &k,Location &l)
{
return sqrt((l.y-k.y)*(l.y-k.y)+(l.x-k.x)*(l.x-k.x));
}
int main()
{
Location L1(0,0);
Location L2(3,4);
cout<<"L1点的坐标为:"<<"("<<L1.Getx()<<","<<L1.Gety()<<")"<<", ";
cout<<"L2点的坐标为:"<<"("<<L2.Getx()<<","<<L2.Gety()<<")"<<endl;
cout<<"Distance1="<<Location::distance1(L1,L2)<<endl;
cout<<"Distance2="<<distance2(L1,L2)<<endl;
system("pause");
return 0;
}