Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <string>
- #include <cmath>
- #include <locale.h>
- using namespace std;
- struct point
- {
- float x;
- float y;
- };
- class square
- {
- float P;
- float S;
- float ab, bc, cd, da;
- point* mass;
- string type;
- void swap_point(point& a1, point& a2)
- {
- point a3;
- a3 = a1;
- a1 = a2;
- a2 = a3;
- }
- float dlina(point a1, point a2)
- {
- return sqrt((a1.x - a2.x) * (a1.x - a2.x) + (a1.y - a2.y) * (a1.y - a2.y));
- }
- float Acos(point a, point b, point c, point d)
- {
- float x1 = a.x - b.x, x2 = c.x - d.x;
- float y1 = a.y - b.y, y2 = c.y - d.y;
- float d1 = sqrt(x1 * x1 + y1 * y1);
- float d2 = sqrt(x2 * x2 + y2 * y2);
- return cos((x1 * x2 + y1 * y2) / (d1 * d2));
- }
- int fun1()
- {
- P = -1;
- S = -1;
- for (int i = 0; i < 3; i++)
- for (int j = i + 1; j < 4; j++)
- if (mass[i].x == mass[j].x && mass[i].y == mass[j].y)
- {
- type = "Что-то";
- return 0;
- }
- for (int i = 0; i < 4; i++)
- for (int j = i + 1; j < 4; j++)
- for (int k = j + 1; k < 4; k++)
- if (mass[i].x == mass[j].x && mass[j].x == mass[k].x || mass[i].y == mass[j].y && mass[j].y == mass[k].y)
- {
- type = "Что-то";
- return 0;
- }
- for (int i = 0; i < 4; i++)
- for (int j = 0; j < 4; j++)
- if (mass[i].x < mass[j].x && i != j)
- swap_point(mass[i], mass[j]);
- if (mass[0].y > mass[1].y)
- swap_point(mass[0], mass[1]);
- if (mass[3].y > mass[2].y)
- swap_point(mass[3], mass[2]);
- float a = dlina(mass[0], mass[1]);
- float b = dlina(mass[1], mass[2]);
- float c = dlina(mass[2], mass[3]);
- float d = dlina(mass[3], mass[0]);
- float d1 = dlina(mass[0], mass[2]);
- float d2 = dlina(mass[1], mass[3]);
- P = (a + b + c + d);
- S = sqrt((P / 2 - a) * (P / 2 - b) * (P / 2 - c) * (P / 2 - d));
- if ((Acos(mass[0], mass[1], mass[3], mass[2]) >= 0.540301 && Acos(mass[0], mass[1], mass[3], mass[2]) <= 0.540303) || (Acos(mass[0], mass[3], mass[1], mass[2]) >= 0.540301 && Acos(mass[0], mass[3], mass[1], mass[2]) <= 0.540303))
- if ((Acos(mass[0], mass[1], mass[3], mass[2]) >= 0.540301 && Acos(mass[0], mass[1], mass[3], mass[2]) <= 0.540303) && (Acos(mass[0], mass[3], mass[1], mass[2]) >= 0.540301 && Acos(mass[0], mass[3], mass[1], mass[2]) <= 0.540303))
- {
- type = "Параллелограмм";
- if (a == b && b == c && c == d)
- if (d1 == d2)
- type = "Квадрат";
- else
- type = "Ромб";
- }
- else
- type = "Трапеция";
- else
- type = "Четырехугольник";
- return 1;
- }
- public:
- void print_all_inf()
- {
- cout << "P: " << P << endl << "S: " << S << endl << "Type: " << type << endl;
- for (int i = 0; i < 4; i++)
- cout << "(" << mass[i].x << ";" << mass[i].y << ") ";
- cout << endl << endl;
- }
- square(int choice)
- {
- mass = new point[4];
- if (choice != 1 && choice != 2)
- {
- cout << "1) Rand\n2) Input\n\n";
- do
- {
- cin >> choice;
- } while (choice != 1 && choice != 2);
- }
- if (choice == 1)
- {
- for (int i = 0; i < 4; i++)
- {
- mass[i].x = (float)(rand() % 100);
- mass[i].y = (float)(rand() % 100);
- }
- }
- if (choice == 2)
- {
- for (int i = 0; i < 4; i++)
- {
- cout << "Enter x " << i + 1 << " point: ";
- cin >> mass[i].x;
- cout << "Enter y " << i + 1 << " point: ";
- cin >> mass[i].y;
- }
- }
- fun1();
- }
- };
- int main()
- {
- setlocale(LC_ALL, "rus");
- srand(time(NULL));
- square b(1);
- b.print_all_inf();
- square c(2);
- c.print_all_inf();
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment