Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 11 / lab1_1 / Line
.cpp#include "stdafx.h"
#include "Line.h"
#include "Point.h"
#include <iostream>
using namespace std;
Line::Line(): id(++total){
count++;
cout << "create Line#" << id << endl;
this->p1 = new Point();
this->p2 = new Point();
}
Line::Line(Point* p1, Point* p2): id(++total){
count++;
cout << "create Line#" << id << endl;
this->p1 = new Point(p1);
this->p2 = new Point(p2);
}
Line::Line(const Line* o): id(++total){
count++;
cout << "create Line#" << id << " via cc" << endl;
this->p1 = new Point(o->p1);
this->p2 = new Point(o->p2);
}
Line::Line(const Line& o): id(++total){
count++;
cout << "create Line#" << id << " via cc" << endl;
this->p1 = new Point(o.p1);
this->p2 = new Point(o.p2);
}
Line::~Line(){
count--;
cout << "destroy Line#" << id << endl;
delete p1;
delete p2;
}
Point* Line::getPoint(int n){
if (n == 1)
return p1;
else
return p2;
}
ostream& Line::print(ostream& os) const{
return os << "Line#" << id << ": " << endl
<< toString();
}
Line& Line::operator= (const Line& o){
if(this == &o)
return *this;
// call copy-assignment
*(this->p1) = o.p1;
*(this->p2) = o.p2;
return *this;
}
void Line::moveBy(const double x, const double y){
p1->moveBy(x,y);
p2->moveBy(x,y);
cout << "Line was moved by (" << x << ";" << y << ")" << endl;
}
string Line::toString() const {
return " Point1: " + p1->toString() + " Point2: " + p2->toString();
}
int Line::operator==(const Line& o) const {
return ((*p1 == *o.p1) && (*p2 == *o.p2));
};
// initialize static fields
unsigned long int Line::count = 0;
unsigned long int Line::total = 0;
Соседние файлы в папке lab1_1