Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <string>
- using namespace std;
- const double pi = acos(-1);
- class point
- {
- private:
- int x, y;
- public:
- point() {}
- point(int x, int y)
- {
- this->x = x;
- this->y = y;
- }
- int get_x()
- {
- return x;
- }
- int get_y()
- {
- return y;
- }
- double get_dist_to_O()
- {
- return sqrt(x * x + y * y);
- }
- double get_dist_to_point(point A)
- {
- return sqrt((x - A.x) * (x - A.x) + (y - A.y) * (y - A.y));
- }
- int get_dist_to_point2(point A)
- {
- return (x - A.x) * (x - A.x) + (y - A.y) * (y - A.y);
- }
- void change_x(int a)
- {
- x += a;
- }
- void change_y(int b)
- {
- y += b;
- }
- void change_x_and_y(int a, int b)
- {
- x += a;
- y += b;
- }
- void multiply(int a)
- {
- x *= a;
- y *= a;
- }
- void operator+(int a)
- {
- x += a;
- y += a;
- }
- void operator*(int a)
- {
- x *= a;
- y *= a;
- }
- void print()
- {
- cout << x << " " << y << "\n";
- }
- };
- class vectr
- {
- private:
- int x, y;
- public:
- vectr() {}
- vectr(int x, int y)
- {
- this->x = x;
- this->y = y;
- }
- vectr(point A, point B)
- {
- this->x = B.get_x() - A.get_x();
- this->y = B.get_y() - A.get_y();
- }
- int get_x()
- {
- return x;
- }
- int get_y()
- {
- return y;
- }
- int operator*(vectr a)
- {
- return x * a.get_x() + y * a.get_y();
- }
- int operator%(vectr a)
- {
- return x * a.get_y() - y * a.get_x();
- }
- };
- class figure
- {
- private:
- int num_vertexes;
- vector<point> vertex;
- public:
- figure() {}
- figure(vector<point> vertex)
- {
- this->vertex = vertex;
- num_vertexes = vertex.size();
- }
- double get_perimetr()
- {
- double p = 0;
- for (int i = 0; i < num_vertexes; i++)
- p += vertex[i].get_dist_to_point(vertex[i + 1]);
- p += vertex[0].get_dist_to_point(vertex[num_vertexes - 1]);
- return p;
- }
- double get_area()
- {
- double s = 0;
- point O(0, 0);
- for (int i = 0; i < num_vertexes; i++)
- s += vectr(O, vertex[i]) % vectr(O, vertex[i + 1]);
- s += vectr(O, vertex[num_vertexes - 1]) % vectr(O, vertex[0]);
- s = fabs(s / 2.0);
- return s;
- }
- vector<point> get_vertex()
- {
- return vertex;
- }
- void get_information()
- {
- cout << "num_vertexes = " << num_vertexes << "\n"
- << "vertexes :"
- << "\n";
- for (point now : vertex)
- now.print();
- }
- double operator+(figure a)
- {
- return this->get_area() + a.get_area();
- }
- };
- class triangle : figure
- {
- private:
- string type;
- public:
- triangle(vector<point> vertex) : figure(vertex)
- {
- type = "not determined";
- }
- vector<point> roll = this->get_vertex();
- string get_type()
- {
- if (type != "not determined")
- return type;
- int temp1 = vectr(roll[0], roll[1]) * vectr(roll[0], roll[2]);
- int temp2 = vectr(roll[1], roll[2]) * vectr(roll[1], roll[0]);
- int temp3 = vectr(roll[2], roll[0]) * vectr(roll[2], roll[1]);
- if (temp1 == 0 || temp2 == 0 || temp3 == 0)
- type = "rectangular";
- else if ((temp1 > 0 && temp2 > 0 && temp3 > 0) || (temp1 < 0 && temp2 < 0 && temp3 < 0))
- type = "acute-angled";
- else
- type = "obtuse";
- return type;
- }
- bool check()
- {
- int a = roll[0].get_dist_to_point2(roll[1]);
- int b = roll[0].get_dist_to_point2(roll[2]);
- int c = roll[1].get_dist_to_point2(roll[2]);
- if (a == b && b == c)
- return true;
- return false;
- }
- void get_information()
- {
- cout << this->get_type() << " triangle\nvertexes :\n";
- for (point now : this->roll)
- now.print();
- }
- };
- class quadrangle : figure
- {
- private:
- string type;
- public:
- quadrangle(vector<point> vertex) : figure(vertex)
- {
- type = "not determined";
- }
- vector<point> roll = this->get_vertex();
- string get_type()
- {
- if (type != "not determined")
- return type;
- vectr AB(roll[0], roll[1]), BC(roll[1], roll[2]), DC(roll[3], roll[2]), AD(roll[0], roll[3]);
- int temp1 = AB % DC, temp2 = BC % AD;
- if (temp1 == 0 && temp2 == 0)
- {
- bool rectangle = false, rhombus = false;
- if (AB * BC == 0)
- rectangle = true;
- if (roll[0].get_dist_to_point2(roll[1]) == roll[1].get_dist_to_point2(roll[2]))
- rhombus = true;
- if (rectangle && rhombus)
- type = "square";
- else if (rectangle)
- type = "rectangle";
- else if (rhombus)
- type = "rhombus";
- else
- type = "parallelogram";
- }
- else if (temp1 == 0 || temp2 == 0)
- type = "trapeze";
- else
- type = "no-type quadrangle";
- return type;
- }
- void get_information()
- {
- cout << type << "\nvertexes :\n";
- for (point now : roll)
- now.print();
- }
- };
- class right_polygon : figure
- {
- private:
- string type;
- public:
- right_polygon(string type, vector<point> vertex) : figure(vertex)
- {
- this->type = type;
- }
- vector<point> roll = this->get_vertex();
- void get_information()
- {
- cout << type << "\nvertexes :\n";
- for (point now : roll)
- now.print();
- }
- };
- class circle : figure
- {
- private:
- point centre;
- int radius;
- public:
- circle(point centre, int radius) : figure()
- {
- this->centre = centre;
- this->radius = radius;
- }
- double get_petimetr()
- {
- return 2.0 * pi * radius;
- }
- double get_area()
- {
- return pi * radius * radius;
- }
- void get_information()
- {
- cout << "centre = (" << centre.get_x() << " " << centre.get_y() << ")\n";
- cout << "radius = " << radius << "\n";
- }
- };
- int main()
- {
- point A(0, 0), B(2, 0), C(0, 3);
- vector<point> roll;
- roll.push_back(A);
- roll.push_back(B);
- roll.push_back(C);
- triangle a(roll);
- a.get_information();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement