Line类的实现
更新于2022年7月30日 浏览:1328
#include<iostream>#include "line.h"#include<math.h>using namespace std;//默认构造Line::Line() { this->p_1 = p_1; this->p_2 = p_2; this->l_L = lineLength();}//构造函数Line::Line(Point p_1, Point p_2) { this->p_1 = p_1; this->p_2 = p_2; this->l_L = lineLength();}//拷贝构造Line::Line(const Line& l) { this->p_1 = l.p_1; this->p_2 = l.p_2; this->l_L = l.l_L;}//获取端点坐标Point Line::get1() { return p_1;}Point Line::get2() { return p_2;}//设置线端点void Line::setLine(Point p1, Point p2) { this->p_1 = p1; this->p_2 = p2; l_L = lineLength();}//重载赋值运算void Line::operator=(const Line& l) { this->p_1 = l.p_1; this->p_2 = l.p_2; this->l_L = l.l_L;}//打印线端点坐标void Line::show() { cout << "线起点:"; this->p_1.show(); cout << "线终点:"; this->p_2.show(); cout << "长度:"<<l_L<<endl<<endl;}//计算线段长度 double Line::lineLength() { double dx = pow(p_1.getX() - p_2.getX(), 2); double dy = pow(p_1.getY() - p_2.getY(), 2); return pow(dx+dy,0.5);}
#CAD Vor适用2.2 b#
#文件在线验证程序#
#标题验证#
点赞 评论 收藏