6_52.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
源码类别:

文章/文档

开发平台:

C/C++

  1. #include<iostream.h>
  2. #include<math.h>
  3. class Point
  4. {
  5. public:
  6. void SetPoint();
  7. double Distance();
  8. private:
  9. double X1,Y1,X2,Y2;
  10. };
  11. void Point::SetPoint()
  12. {
  13. double x1,y1,x2,y2;
  14. cout<<"Input the first point's coordinate!"<<endl;
  15. cout<<"x1=";
  16. cin>>x1;
  17. cout<<"y1=";
  18. cin>>y1;
  19. cout<<endl;
  20. cout<<"Input the second point's coordinate!"<<endl;
  21. cout<<"x2=";
  22. cin>>x2;
  23. cout<<"y2=";
  24. cin>>y2;
  25. X1=x1;Y1=y1;X2=x2;Y2=y2;
  26. }
  27. double Point::Distance()
  28. {
  29. double distance;
  30. distance=sqrt((X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2));
  31. return distance;
  32. }
  33. void main()
  34. {
  35. Point mypoint;
  36. mypoint.SetPoint();
  37. cout<<"The distance of the two points is:"<<mypoint.Distance();
  38. cout<<endl;
  39. }