//LA_CHO3_39
/*
直线方程可以表示为:ax+by+c=0.首先设计一个直线类Line,
然后编写一个求两直线交点的友元函数,最后在main()函数中给出对象进行测试。
*/
#include<iostream>
#include<iomanip>
using namespace std;
class Line {
friend void point(Line&, Line&);
private:
float a=0;
float b=0;
float c=0;
public:
Line(float a, float b, float c);
};
Line::Line(float a, float b, float c) {
this->a = a;
this->b = b;
this->c = c;
}
void point(Line& LA, Line& LB) {
float x=0;
float y=0;
if ((LA.a / LA.b) != (LB.a / LB.b)) {
x = (-LA.c * LB.b + LB.c * LA.b) / (LA.a * LB.b - LB.a * LA.b);
y = (-LB.c * LA.a + LB.a * LA.c) / (LA.a * LB.b - LB.a * LA.b);
cout << "Point of intersection is:" << "(" << x << "," << y << ")" << endl;
}
else
cout << "They do not have point of intersection" << endl;
}
int main() {
Line LA(6, 2, 1);
Line LB(3, 1, 5);
point(LA, LB);
return 0;
}