急急急!c++题目的 题目关于定义类line描述直线!高分!

来源:百度知道 编辑:UC知道 时间:2024/06/17 17:11:08
题目:定义类line描述直线,封装恰当的属性和方法,并且给出两条直线是否相交相交的函数实现!!!

class line{
public:
line(double a,double b,double c,double d);
bool isJiao(line line2);
double x1;
double y1;
double x2;
double y2;
};
line::line(double a,double b,double c,double d){
x1=a;
y1=b;
x2=c;
y2=d;
}
bool line::isJiao(line line2){
if((x1==x2) && (line2.x1==line2.x2)){
return false;
}
else if(((x1==x2) && (line2.x1!=line2.x2)) || ((x1!=x2) && (line2.x1==line2.x2)))
{
return true;
}
else {
double k1;
double k2;
k1=(y2-y1) / (x2-x1);
k2=(line2.y2-line2.y1) / (line2.x2-line2.x1);
double cha=k1-k2;
if(cha<0.0000001){
return false;
}
else
return true;
}
}

.....
30