Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 1 / lab_1 / Rectangle
.cpp// Copyright (C) 1991 - 1999 Rational Software Corporation
//////////////////////////////////////////////////////////////////////////
#include "Rectangle.h"
#include <ostream.h>
//////////////////////////////////////////////////////////////////////////
list<Rectangle*> Rectangle::_rectangles;
//////////////////////////////////////////////////////////////////////////
Rectangle::Rectangle( float l, float w, float x, float y )
: Shape(x, y)
{
_length = l;
_width = w;
cout<<"[rectangle] rectangle created"<<endl;
}
Rectangle* Rectangle::create(float length, float width, float x, float y)
{
// ищем, нет ли уже прямоугольника с такими параметрами
using namespace std;
list<Rectangle*>::iterator iter;
for (iter = _rectangles.begin(); iter != _rectangles.end(); iter++)
{
Rectangle* rectangle = *iter;
if (
rectangle->_length == length &&
rectangle->_width == width &&
rectangle->_x == x &&
rectangle->_y == y
)
{ // такой есть
return rectangle;
}
}
// не нашли - создаем новый
Rectangle* rectangle = new Rectangle(length, width, x, y);
_rectangles.push_back(rectangle);
return rectangle;
}
Rectangle::~Rectangle()
{
_rectangles.remove(this);
cout<<"[rectangle] rectangle destroyed"<<endl;
}
const float Rectangle::get__length() const
{
return _length;
}
void Rectangle::set__length(float value)
{
_length = value;
}
const float Rectangle::get__width() const
{
return _width;
}
void Rectangle::set__width(float value)
{
_width = value;
}
ostream& Rectangle::speak(ostream& os) const
{
return Shape::speak(os)
<<"[rectangle] rectangle size: ("
<<_length<<", "<<_width<<")"<<endl;
}
float Rectangle::Area() const
{
return _length * _width;
}
//////////////////////////////////////////////////////////////////////////
Соседние файлы в папке lab_1