Скачиваний:
14
Добавлен:
01.05.2014
Размер:
1.9 Кб
Скачать
// Copyright (C) 1991 - 1999 Rational Software Corporation
//////////////////////////////////////////////////////////////////////////
#include "Oval.h"

#include <ostream.h>
//////////////////////////////////////////////////////////////////////////
#define M_PI 3.1415926
//////////////////////////////////////////////////////////////////////////

list<Oval*> Oval::_ovals;
//////////////////////////////////////////////////////////////////////////

Oval::Oval(float rad1, float rad2, float x, float y)
: Shape(x, y)
{
    _rad1 = rad1;
    _rad2 = rad2;
    cout<<"[oval] oval created"<<endl;
}


Oval* Oval::create(float rad1, float rad2, float x, float y)
{
    using namespace std;
    // ищем, нет ли уже овала с такими параметрами
    list<Oval*>::iterator iter;
    for (iter = _ovals.begin(); iter != _ovals.end(); iter++)
    {
        Oval* oval = *iter;
        if (
            oval->_rad1 == rad1 &&
            oval->_rad2 == rad2 &&
            oval->_x == x &&
            oval->_y == y
            )
        {   // такой есть
            return oval;
        }
    }
    // не нашли - создаем новый
    Oval* oval = new Oval(rad1, rad2, x, y);
    _ovals.push_back(oval);
    return oval;
}


Oval::~Oval()
{
    _ovals.remove(this);
	cout<<"[oval] oval destroyed"<<endl;
}


const float Oval::getRad1() const
{
	return _rad1;
}


void Oval::setRad1(float value)
{
	_rad1 = value;
}


const float Oval::getRad2() const
{
	return _rad2;
}


void Oval::setRad2(float value)
{
	_rad2 = value;
}


ostream& Oval::speak(ostream& os) const
{
    return Shape::speak(os)
        <<"[oval] oval chords: ("
        <<_rad1<<", "<<_rad2<<")"<<endl;
}


float Oval::Area() const
{
    return M_PI * _rad1 * _rad2;
}

//////////////////////////////////////////////////////////////////////////





Соседние файлы в папке lab_1