首页 > 其他 > 详细

线段的类

时间:2016-05-05 19:14:43      阅读:129      评论:0      收藏:0      [点我收藏+]

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;
}

线段的类

原文:http://www.cnblogs.com/huninglei/p/5462615.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!