123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #include "myRect.h"
- void Rect::WhereAmI()
- {
- std::cout << "Now I am in class Rect" << std::endl;
- }
- void Rect::WhereAmIVirtual()
- {
- std::cout << "Now I am in class Rect" << std::endl;
- }
- //êîíñòðóêòîð ñ ïàðàìåòðàìè äëÿ èíèöèàëèçàöèè ïåðåìåííûõ êëàññà
- Rect::Rect(int left, int right, int top, int bottom, colour col, bool contour, double transparency)
- :Shape(col,contour, transparency)
- {
- m_left = left;
- m_right = right;
- m_top = top;
- m_bottom = bottom;
- Standarting();
- }
- //ìåòîä "íîðìàëèçàöèè" ïðÿìîóãîëüíèêà
- void Rect::Standarting()
- {
- if (m_right < m_left)
- {
- int tmp = m_right;
- m_right = m_left;
- m_left = tmp;
- }
-
- if (m_bottom < m_top)
- {
- int tmp = m_bottom;
- m_bottom = m_top;
- m_top = tmp;
- }
- }
- void Rect::Inflate(int inflate)
- {
- this->InflateRect(inflate / 2, inflate / 2, inflate / 2, inflate / 2);
- }
- //ìåòîä êîòîðûé óâåëè÷èâàåò ðàçìåðû ïðÿìîóãîëüíèêà íà çàäàííûå ïðèðàùåíèÿ
- void Rect::InflateRect(int left, int right, int top, int bottom)
- {
- m_left -= left;
- m_right += right;
- m_top -= top;
- m_bottom += bottom;
- Standarting();
- }
- //ìåòîä êîòîðûé ïðèíèìàåò äâà àðãóìåíòà, ïî óìîë÷àíèþ ðàâíûõ 1
- void Rect::InflateRect(int left, int right)
- {
- m_left -= left;
- m_right += right;
- Standarting();
- }
- //êîíñòðóêòîð êîïèðîâàíèÿ
- Rect::Rect(const Rect& other):Shape(other)
- {
- m_left = other.m_left;
- m_right = other.m_right;
- m_top = other.m_top;
- m_bottom = other.m_bottom;
- }
- //ìåòîä êîòîðûé ïðèñâàèâàåò ïåðåìåííûì êëàññà ïåðåäàâàåìûå çíà÷åíèÿ
- void Rect::SetAll(int left, int right, int top, int bottom)
- {
- m_left = left;
- m_right = right;
- m_top = top;
- m_bottom = bottom;
- Standarting();
- }
- //ìåòîä êîòîðûé "äîñòàåò" çíà÷åíèÿ private-ïåðåìåííûõ êëàññà.
- void Rect::GetAll(int& left, int& right, int& top, int& bottom) const
- {
- left = m_left;
- right = m_right;
- top = m_top;
- bottom = m_bottom;
- }
- //ìåòîä êîòîðûé âîçâðàùàåò ïðÿìîóãîëüíèê, â êîòîðûé âïèñàíû çàäàííûå ïðÿìîóãîëüíèêè.
- Rect Rect::BoundingRect(const Rect& two)
- {
- Rect tmp;
- (m_left <= two.m_left) ? tmp.m_left = m_left : tmp.m_left = two.m_left;//ÒÅÐÍÀÐÍÛÉ ÎÏÅÐÀÒÎÐ
- (m_right >= two.m_right) ? tmp.m_right = m_right : tmp.m_right = two.m_right;
- (m_top <= two.m_top) ? tmp.m_top = m_top : tmp.m_top = two.m_top;
- (m_bottom >= two.m_bottom) ? tmp.m_bottom = m_bottom : tmp.m_bottom = two.m_bottom;
- return tmp;
- }
- Rect::~Rect()
- {
- std::cout << "Now I am in Rect's destructor!" << std::endl;
- }
|