6_52.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
- #include<iostream.h>
- #include<math.h>
- class Point
- {
- public:
- void SetPoint();
- double Distance();
- private:
- double X1,Y1,X2,Y2;
- };
- void Point::SetPoint()
- {
- double x1,y1,x2,y2;
- cout<<"Input the first point's coordinate!"<<endl;
- cout<<"x1=";
- cin>>x1;
- cout<<"y1=";
- cin>>y1;
- cout<<endl;
- cout<<"Input the second point's coordinate!"<<endl;
- cout<<"x2=";
- cin>>x2;
- cout<<"y2=";
- cin>>y2;
- X1=x1;Y1=y1;X2=x2;Y2=y2;
- }
- double Point::Distance()
- {
- double distance;
- distance=sqrt((X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2));
- return distance;
- }
- void main()
- {
- Point mypoint;
- mypoint.SetPoint();
- cout<<"The distance of the two points is:"<<mypoint.Distance();
- cout<<endl;
- }