Advertisement
themlgyo

24.05.17

May 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using std::cin;
  4. using std::cout;
  5. using std::endl;
  6. struct Point
  7. {
  8.     double x;
  9.     double y;
  10.     double z;
  11. };
  12. double distance(Point A, Point B)
  13. {
  14.     return sqrt(pow((A.x - B.x), 2) + pow((A.y - B.y), 2) + pow((A.z - B.z), 2));
  15. }
  16. double Perimetre(Point A, Point B, Point C)
  17. {
  18.     return distance(A, B) + distance(B, C) + distance(A, C);
  19. }
  20. double Square(Point A, Point B, Point C)
  21. {
  22.     return sqrt((Perimetre(A, B, C) / 2)*((Perimetre(A, B, C) / 2) - distance(A, B))*((Perimetre(A, B, C) / 2) - distance(B, C))*((Perimetre(A, B, C) / 2) - distance(A, C)));
  23. }
  24. int main()
  25. {
  26.     setlocale(LC_ALL, "RUSSIAN");
  27.     Point A{ 1, 5, 9 },
  28.         B{ 2, 7, 4 },
  29.         C{ 3, 1, 0 };
  30.     cout << " " << endl;
  31.     cout << "Периметр треугольника ABC: " << Perimetre(A, B, C) << endl;
  32.     cout << "Площадь треугольника ABC: " << Square(A, B, C) << endl;
  33.     return 0;
  34. }
  35.  
  36.  
  37. ###########################################
  38.  
  39. Ф И Н А Л О Ч К А
  40.  
  41. #include <iostream>
  42. #include <cmath>
  43. using std::cin;
  44. using std::cout;
  45. using std::endl;
  46. struct Point
  47. {
  48.     double x;
  49.     double y;
  50.     double z;
  51. };
  52. double distance(Point A, Point B)
  53. {
  54.     return sqrt(pow((A.x - B.x), 2) + pow((A.y - B.y), 2) + pow((A.z - B.z), 2));
  55. }
  56. double Perimetre(Point A, Point B, Point C)
  57. {
  58.     return distance(A, B) + distance(B, C) + distance(A, C);
  59. }
  60. double Square(Point A, Point B, Point C)
  61. {
  62.     return sqrt((Perimetre(A, B, C) / 2)*((Perimetre(A, B, C) / 2) - distance(A, B))*((Perimetre(A, B, C) / 2) - distance(B, C))*((Perimetre(A, B, C) / 2) - distance(A, C)));
  63. }
  64. void Input(Point&P)
  65. {
  66.     cout << "x:";
  67.     cin >> P.x;
  68.     cout << "y:";
  69.     cin >> P.y;
  70.     cout << "z:";
  71.     cin >> P.z;
  72. }
  73. void Display(Point P)
  74. {
  75.     cout << "{" << P.x << ", " << P.y << ", " << P.z << "}";
  76. }
  77. int main()
  78. {
  79.     setlocale(LC_ALL, "RUSSIAN");
  80.     Point A, B, C;
  81.     cout << "Введите точки:" << endl;
  82.     Input(A);
  83.     cout << " " << endl;
  84.     Input(B);
  85.     cout << " " << endl;
  86.     Input(C);
  87.     cout << " " << endl;
  88.     cout << "Вы ввели точки:" << endl;
  89.     Display(A);
  90.     cout << " " << endl;
  91.     Display(B);
  92.     cout << " " << endl;
  93.     Display(C);
  94.     cout << " " << endl;
  95.     cout << "Периметр треугольника ABC: " << Perimetre(A, B, C) << endl;
  96.     cout << "Площадь треугольника ABC: " << Square(A, B, C) << endl;
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement