Advertisement
noler89

Untitled

Dec 18th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct point {
  6. double x;
  7. double y;
  8. };
  9.  
  10. struct triangle {
  11. point a;
  12. point b;
  13. point c;
  14. };
  15.  
  16. double length (point, point);
  17. double perimetr (triangle);
  18. double square (triangle);
  19. void type (triangle);
  20.  
  21. int main () {
  22. setlocale (LC_ALL, "Russian");
  23.  
  24. point dot1, dot2, dot3;
  25. triangle T;
  26.  
  27. cout << "Введи координаты точек.\n";
  28. cout << "Точка 1: ";
  29. cin >> dot1.x >> dot1.y;
  30. cout << "Точка 2: ";
  31. cin >> dot2.x >> dot2.y;
  32. cout << "Точка 3: ";
  33. cin >> dot3.x >> dot3.y;
  34.  
  35. T.a = dot1;
  36. T.b = dot2;
  37. T.c = dot3;
  38.  
  39. cout << "Расстояние между точкой 1 и 2: " << length (dot1, dot2) << endl;
  40. cout << "Расстояние между точкой 2 и 3: " << length (dot2, dot3) << endl;
  41. cout << "Расстояние между точкой 1 и 3: " << length (dot1, dot3) << endl;
  42. cout << "Периметр треугольника: " << perimetr (T) << endl;
  43. cout << "Площадь труегольника: " << square (T) << endl;
  44. type (T);
  45.  
  46. system ("pause");
  47. return 0;
  48. }
  49.  
  50. double length (point dot1, point dot2) {
  51. return sqrt (double ((dot1.x - dot2.x)*(dot1.x - dot2.x) + (dot1.y - dot2.y)*(dot1.y - dot2.y)));
  52. }
  53. double perimetr (triangle T) {
  54. double ab = length (T.a, T.b);
  55. double bc = length (T.b, T.c);
  56. double ac = length (T.a, T.c);
  57. return ab + bc + ac;
  58. }
  59. double square (triangle T) {
  60. double p = perimetr (T) / 2;
  61. return sqrt (p * (p - length (T.a, T.b)) * (p - length (T.b, T.c)) * (p - length (T.a, T.c)));
  62. }
  63. void type (triangle T) {
  64. double ab = length (T.a, T.b);
  65. double bc = length (T.b, T.c);
  66. double ac = length (T.a, T.c);
  67. double eps = 0.0000001;
  68. if ((ab*ab - bc*bc - ac*ac < eps) || (bc*bc - ab*ab - ac*ac < eps) || (ac*ac - ab*ab - bc*bc < eps))
  69. cout << "Прямоугольный" << endl;
  70. if ((ab - bc < eps) && (bc - ac < eps))
  71. cout << "Равносторонний" << endl;
  72. if ((ab - bc < eps) || (bc - ac < eps) || (ac - ab < eps))
  73. cout << "Равнобедренный" <<endl;
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement