Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 32 / part31 / CCircle
.cpp#include "stdafx.h"
#include "CCircle.h"
CCircle :: CCircle():ShapePosition()
{
XRad = 0;
}
CCircle :: CCircle(int _X, int _Y, int _XRad):ShapePosition(_X,_Y)
{
XRad = _XRad;
}
CCircle ::~CCircle()
{}
void CCircle :: SetXRad(int _XRad)
{
XRad = _XRad;
}
int CCircle :: GetXRad() const
{
return XRad;
}
double CCircle :: GetArea() const
{
return M_PI * XRad * XRad;
}
int CCircle :: getNumType()
{
return 2; }
void CCircle ::display(ostream &os)
{
os << "Class CCircle Information :" << endl <<
"X :" << GetX() << endl <<
"Y :" << GetY() << endl <<
"Radius :" << GetXRad() << endl <<
"Area :" << GetArea() << endl;
}
void CCircle ::Draw(CDC* pDC, Shape* figure,bool doLine)
{
CPen aPen;
COLORREF aColor=RGB(0,0,0);
if(this == figure)
aColor = RGB(255,0,0);
if (doLine)
{
aColor = RGB(0,255,0);
}
if(!aPen.CreatePen(PS_SOLID, 1, aColor))
{
AfxMessageBox("Pen creation failed drawing a rectangle", MB_OK);
AfxAbort();
}
CPen* pOldPen = pDC->SelectObject(&aPen);
CPoint Start(GetX(),GetY());
CPoint End(GetX()+2*GetXRad(),GetY()+2*GetXRad());
CRect m_EnclosingRect(Start, End);
m_EnclosingRect.NormalizeRect();
pDC->Ellipse(m_EnclosingRect);
pDC->SelectObject(pOldPen);
}
CRect CCircle ::GetBoundRect()
{
CRect BoundingRect(GetX(),GetY(),GetX()+2*GetXRad(),GetY()+2*GetXRad());
return BoundingRect;
}
void CCircle ::writeAr(CArchive& ar)
{ar<<getNumType();
ar<<GetX();
ar<<GetY();
ar<<GetXRad();
}
void CCircle ::readAr(CArchive& ar)
{int _X,_Y;
ar>>_X;
ar>>_Y;
ar>>XRad;
SetX(_X);SetY(_Y);
}
CString CCircle::getName()
{return "Circle";}
Соседние файлы в папке part31