8_73.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
- #include<iostream.h>
- class line
- {
- double k,b;
- friend class process;
- public:
- line(double kk,double bb)
- {
- k=kk;
- b=bb;
- }
- void print()
- {
- cout<<"y=("<<k<<")*x+("<<b<<")"<<endl;
- }
- };
- struct point
- {
- double x;
- double y;
- };
- class process
- {
- point point1;
- public:
- point setpoint(line& p,line& q)
- {
- point1.x=(q.b-p.b)/(p.k-q.k);
- point1.y=(p.k*q.b-q.k*p.b)/(p.k-q.k);
- return point1;
- }
- void disp(point &s)
- {
- cout<<"两直线交点为:("<<s.x<<","<<s.y<<")."<<endl;
- }
- point getpoint(){return point1;}
- };
- void main()
- {
- double slope1,slope2,section1,section2;
- cout<<"请输入第一条直线的斜率:";
- cin>>slope1;
- cout<<"请输入第一条直线的截距:";
- cin>>section1;
- cout<<"请输入第二条直线的斜率:";
- cin>>slope2;
- cout<<"请输入第二条直线的截距:";
- cin>>section2;
- line line1(slope1,section1),line2(slope2,section2);
- cout<<"直线方程为:"<<endl;
- line1.print();
- line2.print();
- process p1,p2;
- p1.setpoint(line1,line2);
- p2.disp(p1.getpoint());
- }