Line類的實現

#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#

#文件在線驗證程序#

#標題驗證#

登錄后免費查看全文
立即登錄
App下載
技術鄰APP
工程師必備
  • 項目客服
  • 培訓客服
  • 平臺客服

TOP

1
1