Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct point {
- double x;
- double y;
- };
- struct triangle {
- point a;
- point b;
- point c;
- };
- double length (point, point);
- double perimetr (triangle);
- double square (triangle);
- void type (triangle);
- int main () {
- setlocale (LC_ALL, "Russian");
- point dot1, dot2, dot3;
- triangle T;
- cout << "Введи координаты точек.\n";
- cout << "Точка 1: ";
- cin >> dot1.x >> dot1.y;
- cout << "Точка 2: ";
- cin >> dot2.x >> dot2.y;
- cout << "Точка 3: ";
- cin >> dot3.x >> dot3.y;
- T.a = dot1;
- T.b = dot2;
- T.c = dot3;
- cout << "Расстояние между точкой 1 и 2: " << length (dot1, dot2) << endl;
- cout << "Расстояние между точкой 2 и 3: " << length (dot2, dot3) << endl;
- cout << "Расстояние между точкой 1 и 3: " << length (dot1, dot3) << endl;
- cout << "Периметр треугольника: " << perimetr (T) << endl;
- cout << "Площадь труегольника: " << square (T) << endl;
- type (T);
- system ("pause");
- return 0;
- }
- double length (point dot1, point dot2) {
- return sqrt (double ((dot1.x - dot2.x)*(dot1.x - dot2.x) + (dot1.y - dot2.y)*(dot1.y - dot2.y)));
- }
- double perimetr (triangle T) {
- double ab = length (T.a, T.b);
- double bc = length (T.b, T.c);
- double ac = length (T.a, T.c);
- return ab + bc + ac;
- }
- double square (triangle T) {
- double p = perimetr (T) / 2;
- return sqrt (p * (p - length (T.a, T.b)) * (p - length (T.b, T.c)) * (p - length (T.a, T.c)));
- }
- void type (triangle T) {
- double ab = length (T.a, T.b);
- double bc = length (T.b, T.c);
- double ac = length (T.a, T.c);
- double eps = 0.0000001;
- if ((ab*ab - bc*bc - ac*ac < eps) || (bc*bc - ab*ab - ac*ac < eps) || (ac*ac - ab*ab - bc*bc < eps))
- cout << "Прямоугольный" << endl;
- if ((ab - bc < eps) && (bc - ac < eps))
- cout << "Равносторонний" << endl;
- if ((ab - bc < eps) || (bc - ac < eps) || (ac - ab < eps))
- cout << "Равнобедренный" <<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement