线段的类
class Line
{
double x1, y1;
double x2, y2;
public:
Line(double x1, double y1, double x2, double y2)
{
this->x1 = x1;
this->x2 = x2;
this->y1 = y1;
this->y2 = y2;
}
double getx1(){ return x1; }
double getx2(){ return x2; }
double gety1(){ return y1; }
double gety2(){ return y2; }
void show()
{
cout << "length=" << length(*this);
//length(Line l)this是指向Line类的指针 length(Line)需要传递this对象的成员变量
this->getx2();
}
};
double length(Line l)
{
return sqrt((l.getx1() - l.getx2())*(l.getx1() - l.getx2()) +
(l.gety1() - l.gety2())*(l.gety1() - l.gety2()));
}
int _tmain()
{
Line r1(1.0, 8.0, 5.0, 2.0);
r1.show();
return 0;
}