Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Identifiers.h ///////////////////
- #pragma once
- #include <string>
- using namespace std;
- class Identifiers // Генератор идентификаторов фигур
- {
- private:
- static int Number; // Порядковый номер идентификатора
- public:
- static string GetId(); // Возвращает строковое представление идентификатора (статический метод)
- Identifiers();
- ~Identifiers();
- };
- // Identifiers.cpp ///////////////////
- #include "stdafx.h"
- #include "Identifiers.h"
- #include <string>
- using namespace std;
- int Identifiers::Number;
- string Identifiers::GetId()
- {
- Identifiers::Number++;
- return "S" + std::to_string(Identifiers::Number);
- }
- Identifiers::Identifiers()
- {
- }
- Identifiers::~Identifiers()
- {
- }
- // Shape.h ///////////////////
- #pragma once
- #include <list>
- #include <vector>
- #include "Coordinate.h"
- using namespace std;
- class Shape
- {
- private:
- static std::list<Shape> Items; // Список всех фигур
- string Id; // Идентификатор
- protected:
- int X = 0, Y = 0, Width, Height; // Коодринаты начала (центра) (в зависимости от фигуры), ширина и высота
- std::vector<Coordinate> Coordinates; // Список координат (не для всех фигур)
- public:
- string GetId(); // Возвращает идентификатор
- void MoveByX(int Offset); // Перемещает начало (центр) фигуры по оси X
- void MoveByY(int Offset); // Перемещает начало (центр) фигуры по оси Y
- virtual void Scale(int Multiplier); // Изменяет размер фигуры (виртуальный метод)
- virtual double GetArea(); // Возвращает площадь фигуры (виртуальный метод)
- virtual int Compare(Shape Left, Shape Right); // Сравнение двух фигур (виртуальный метод)
- virtual string to_string(); // Возвращает строковое представление класса (виртуальный метод)
- static long GetSumOfAreas(Shape Shapes[], int Length); // Возвращает сумму площадей всех фигур (статический метод)
- Shape();
- ~Shape();
- };
- // Shape.cpp ///////////////////
- #include "stdafx.h"
- #include "Shape.h"
- #include "Identifiers.h"
- #include <string>
- #include <list>
- #include <vector>
- #include <iostream>
- string Shape::GetId()
- {
- return this->Id;
- }
- void Shape::MoveByX(int Offset)
- {
- std::vector<Coordinate>::iterator Iterator;
- for (Iterator = this->Coordinates.begin(); Iterator != this->Coordinates.end(); ++Iterator)
- {
- Iterator->X += Offset;
- }
- this->X += Offset;
- }
- void Shape::MoveByY(int Offset)
- {
- std::vector<Coordinate>::iterator Iterator;
- for (Iterator = this->Coordinates.begin(); Iterator != this->Coordinates.end(); ++Iterator)
- {
- Iterator->Y += Offset;
- }
- this->Y += Offset;
- }
- void Shape::Scale(int Multiplier)
- {
- std::vector<Coordinate>::iterator Iterator;
- for (Iterator = this->Coordinates.begin(); Iterator != this->Coordinates.end(); ++Iterator)
- {
- Iterator->X *= Multiplier;
- Iterator->Y *= Multiplier;
- }
- }
- double Shape::GetArea()
- {
- cout << "This method must be overriden in a child class\n";
- return 0;
- }
- string Shape::to_string()
- {
- string Output = "OOP.Shape(X = " + std::to_string(this->X) + "; Y = " + std::to_string(this->Y) + "; Coordinates: ";
- int I = 1;
- std::vector<Coordinate>::iterator Iterator;
- for (Iterator = this->Coordinates.begin(); Iterator != this->Coordinates.end(); ++Iterator)
- {
- Output += std::to_string(I) + "(" + std::to_string(Iterator->X) + "; " + std::to_string(Iterator->Y) + ") ";
- }
- return Output;
- }
- long Shape::GetSumOfAreas(Shape Shapes[], int Length)
- {
- long Sum = 0;
- for (int I = 0; I < Length; ++I)
- {
- Sum += Shapes[I].GetArea();
- }
- return Sum;
- }
- int Shape::Compare(Shape Left, Shape Right)
- {
- return 0;
- }
- Shape::Shape()
- {
- this->Id = Identifiers::GetId();
- }
- Shape::~Shape()
- { }
- // Circle.h ///////////////////
- #pragma once
- #include "Shape.h"
- class Circle : public Shape
- {
- private:
- int Radius; // Диаметр
- int CenterX; // Координата X центра
- int CenterY; // Координата Y центра
- public:
- int GetRadius(); // Возвращает радиус
- int GetCenterX(); // Возвращает координату X центра
- int GetCenterY(); // Возвращает координату Y центра
- int GetDiameter(); // Возвращает диаметр
- double GetArea(); // Возвращает площадь
- double GetCircumference(); // Возвращает длину окружности
- double GetSectorArea(int Degree); // Возвращает площадь сектора заданного центрального угла (Degree)
- void SetRadius(int Radius); // Устанавливает радиус
- void SetCenterX(int X); // Устанавливает координату X центра
- void SetCenterY(int Y); // Устанавливает координату Y центра
- void Scale(double Multiplier); // Изменяет размер окружности на величину (Multiplier)
- string to_string(); // Возвращает строковое представление класса
- int Compare(Circle Left, Circle Right); // Возвращает -1, если Left имеет большую площадь, 0 - если площадь Left и Right равны, 1 - если Right имеет большую площадь
- bool operator < (Circle Circle);
- bool operator > (Circle Circle);
- Circle();
- ~Circle();
- };
- // Circle.cpp ///////////////////
- #include "stdafx.h"
- #include "Circle.h"
- #include <string>
- using namespace std;
- int Circle::GetRadius()
- {
- return this->Radius;
- }
- int Circle::GetCenterX()
- {
- return this->X;
- }
- int Circle::GetCenterY()
- {
- return this->Y;
- }
- int Circle::GetDiameter()
- {
- return this->Radius * 2;
- }
- double Circle::GetArea()
- {
- return 3.14 * pow((this->GetDiameter() / 2), 2);
- }
- double Circle::GetCircumference()
- {
- return 3.14 * this->GetDiameter();
- }
- double Circle::GetSectorArea(int Degree)
- {
- return (this->GetArea() / 360) * Degree;
- }
- void Circle::SetRadius(int Radius)
- {
- if (Radius > 0)
- {
- this->Radius = Radius;
- }
- }
- void Circle::SetCenterX(int X)
- {
- this->X = X;
- }
- void Circle::SetCenterY(int Y)
- {
- this->Y = Y;
- }
- void Circle::Scale(double Multiplier)
- {
- if (Multiplier > 0)
- {
- this->Radius *= Multiplier;
- }
- }
- string Circle::to_string()
- {
- return "OOP.Circle(X = " + std::to_string(this->X) + "; Y = " + std::to_string(this->Y) + "; Radius: " + std::to_string(this->Radius) + ")";
- }
- int Circle::Compare(Circle Left, Circle Right)
- {
- if (Left.GetArea() > Right.GetArea())
- {
- return -1;
- }
- if (Left.GetArea() < Right.GetArea())
- {
- return 1;
- }
- return 0;
- }
- bool Circle::operator < (Circle Circle)
- {
- return this->GetDiameter() < Circle.GetDiameter();
- };
- bool Circle::operator > (Circle Circle)
- {
- return this->GetDiameter() > Circle.GetDiameter();
- };
- Circle::Circle() : Shape()
- {
- }
- Circle::~Circle()
- {
- }
- // Pentagon.h ///////////////////
- #pragma once
- #include "Shape.h"
- #include "Circle.h"
- class Pentagon : public Shape
- {
- private:
- Circle OuterCircle; // Вписанная окружности
- public:
- int GetCircleRadius(); // Возвращает радиус вписанной окружности
- int GetCenterX(); // Возвращает координату X центра вписанной окружности
- int GetCenterY(); // Возвращает координату Y центра вписанной окружности
- int GetCircleDiameter(); // Возвращает диаметр вписанной окружности
- double GetSideLength(); // Возвращает длину стороны
- double GetPerimeter(); // Возвращает периметр
- double GetArea(); // Возвращает площадь
- double GetCircleCircumference(); // Возвращает длину вписанной окружности
- double GetSectorArea(int Degree); // Возвращает площадь сектора заданного центрального угла (Degree)
- double GetInnerCircleRadius(); // Возвращает радиус вписанной окружности
- void SetCircleRadius(int Radius); // Устанавливает радиус
- void SetCenterX(int X); // Устанавливает координату X центра вписанной окружности
- void SetCenterY(int Y); // Устанавливает координату Y центра вписанной окружности
- void Scale(double Multiplier); // Изменяет размер окружности на величину (Multiplier)
- string to_string(); // Возвращает строковое представление класса
- int Compare(Pentagon Left, Pentagon Right); // Возвращает -1, если Left имеет большую площадь, 0 - если площадь Left и Right равны, 1 - если Right имеет большую площадь
- bool operator < (Pentagon Pentagon);
- bool operator > (Pentagon Pentagon);
- Pentagon();
- ~Pentagon();
- };
- // Pentagon.cpp ///////////////////
- #include "stdafx.h"
- #include "Pentagon.h"
- #include "Circle.h"
- #include <string>
- #include <math.h>
- using namespace std;
- int Pentagon::GetCircleRadius()
- {
- return this->OuterCircle.GetRadius();
- }
- int Pentagon::GetCenterX()
- {
- return this->X;
- }
- int Pentagon::GetCenterY()
- {
- return this->Y;
- }
- int Pentagon::GetCircleDiameter()
- {
- return this->OuterCircle.GetRadius() * 2;
- }
- double Pentagon::GetSideLength()
- {
- return (2 * this->OuterCircle.GetRadius()) * sin(180 / 5);
- }
- double Pentagon::GetArea()
- {
- return 5 * pow(this->OuterCircle.GetRadius(), 2) * tan(180 / 5);
- }
- double Pentagon::GetPerimeter()
- {
- return this->GetSideLength() * 5;
- }
- double Pentagon::GetCircleCircumference()
- {
- return 3.14 * this->OuterCircle.GetDiameter();
- }
- double Pentagon::GetInnerCircleRadius()
- {
- return this->OuterCircle.GetRadius() * cos(180 / 5);
- }
- double Pentagon::GetSectorArea(int Degree)
- {
- return (this->GetArea() / 360) * Degree;
- }
- void Pentagon::SetCircleRadius(int Radius)
- {
- this->OuterCircle.SetRadius(Radius);
- }
- void Pentagon::SetCenterX(int X)
- {
- this->OuterCircle.SetCenterX(X);
- }
- void Pentagon::SetCenterY(int Y)
- {
- this->OuterCircle.SetCenterY(Y);
- }
- void Pentagon::Scale(double Multiplier)
- {
- this->OuterCircle.Scale(Multiplier);
- }
- string Pentagon::to_string()
- {
- return "OOP.Pentagon(X = " + std::to_string(this->OuterCircle.GetCenterX()) + "; Y = " + std::to_string(this->OuterCircle.GetCenterY()) + "; Outer circle's radius: " + std::to_string(this->OuterCircle.GetRadius()) + ")";
- }
- int Pentagon::Compare(Pentagon Left, Pentagon Right)
- {
- if (Left.GetArea() > Right.GetArea())
- {
- return -1;
- }
- if (Left.GetArea() < Right.GetArea())
- {
- return 1;
- }
- return 0;
- }
- bool Pentagon::operator < (Pentagon Pentagon)
- {
- return this->OuterCircle.GetDiameter() < Pentagon.GetCircleDiameter();
- };
- bool Pentagon::operator > (Pentagon Pentagon)
- {
- return this->OuterCircle.GetDiameter() > Pentagon.GetCircleDiameter();
- };
- Pentagon::Pentagon()
- {
- this->OuterCircle = Circle();
- }
- Pentagon::~Pentagon()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement