《程序设计基础二》类的设计部分练习题目:1432--1446,运算符重载部分练习题目:1447--1461

Problem 1411. -- Point类及自由函数求距离

1411: Point类及自由函数求距离

Time Limit: 1 Sec  Memory Limit: 65535 MB   64bit IO Format: %lld
Submitted: 1024  Accepted: 745
[Submit][Status][Web Board]

Description

设计点类Point,包含2个私有成员数据x,y,成员函数根据下面main函数来设计。
自由函数dist的作用用来求两个点之间的距离,其函数声明为:
       double dist(Point p1,Point p2);
main函数如下(提交时只需提交除main函数外的代码部分):
int main()
{
    Point p1,p2(518745.2345687,8.14584455);
    cout<<fixed<<setprecision(5);
    cout<<"p1:("<<p1.GetX()<<","<<p1.GetY()<<")"<<endl;
    cout<<"p2:("<<p2.GetX()<<","<<p2.GetY()<<")"<<endl;
    cout<<"distance(p1,p2)="<<dist(p1,p2)<<endl;
    return 0;
}

Sample Output

p1:(0.00000,0.00000)
p2:(518745.23457,8.14584)
distance(p1,p2)=518745.23463

[Submit][Status][Web Board]