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

文章/文档

开发平台:

C/C++

  1. #include<iostream.h>
  2. class line
  3. {
  4. double k,b;
  5. friend class process;
  6. public:
  7. line(double kk,double bb)
  8. {
  9. k=kk;
  10. b=bb;
  11. }
  12. void print()
  13. {
  14. cout<<"y=("<<k<<")*x+("<<b<<")"<<endl;
  15. }
  16. };
  17. struct point
  18. {
  19. double x;
  20. double y;
  21. };
  22. class process
  23. {
  24.     point point1;
  25. public:
  26. point setpoint(line& p,line& q)
  27. {
  28. point1.x=(q.b-p.b)/(p.k-q.k);
  29. point1.y=(p.k*q.b-q.k*p.b)/(p.k-q.k);
  30. return point1;
  31. }
  32. void disp(point &s)
  33. {
  34. cout<<"两直线交点为:("<<s.x<<","<<s.y<<")."<<endl;
  35. }
  36. point getpoint(){return point1;}
  37. };
  38. void main()
  39. {
  40. double slope1,slope2,section1,section2;
  41. cout<<"请输入第一条直线的斜率:";
  42. cin>>slope1;
  43.     cout<<"请输入第一条直线的截距:";
  44.     cin>>section1;
  45. cout<<"请输入第二条直线的斜率:";
  46. cin>>slope2;
  47.     cout<<"请输入第二条直线的截距:";
  48. cin>>section2;
  49.     line line1(slope1,section1),line2(slope2,section2);
  50. cout<<"直线方程为:"<<endl;
  51. line1.print();
  52. line2.print();
  53. process p1,p2;
  54. p1.setpoint(line1,line2);
  55. p2.disp(p1.getpoint());
  56. }