wiktortokumpel

Untitled

Dec 14th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cassert>
  4.  
  5. struct Point
  6. {
  7. double x;
  8. double y;
  9. };
  10. double distance( Point p1, Point p2)
  11. {
  12. double d;
  13. d = pow( pow( p1.x-p2.x, 2) + pow( p1.y - p2.y, 1/2), 2);
  14. return d;
  15. }
  16. struct Linia
  17. {
  18. Point p1;
  19. Point p2;
  20. };
  21. void test_distance()
  22. {
  23. {
  24. Point a {2, 4};
  25. Point b { 2, 3};
  26. assert ( distance( a, b)== 1);
  27. }
  28. {
  29. Point a { -1, 5};
  30. Point b { 2, 9};
  31. assert ( distance( a, b)==5);
  32. }
  33. }
  34. bool prostopadla( Linia l1, Linia l2)
  35. {
  36. int a1, a2;
  37. a1 = (l1.p2.y-l1.p1.y)/(l1.p2.x-l1.p1.x);
  38. a2 = (l2.p2.y-l2.p1.y)/(l2.p2.x-l2.p1.x);
  39. if ( a1 == 0 || a2 == 0)
  40. {
  41. if( a1 == 0 && a2 != 0 && l2.p2.x == l2.p1.x)
  42. {
  43. return true;
  44. }
  45. if( a2 == 0 && a1 != 0 && l1.p2.x == l1.p1.x)
  46. {
  47. return true;
  48. }
  49. return false;
  50. }
  51. else
  52. {
  53. if (a1 * a2 == -1) {
  54. return true;
  55. }
  56. return false;
  57. }
  58. }
  59. void test_prostopadla()
  60. {
  61. {
  62. Linia l1 { { 0, 1}, 0, 4}};
  63. Linia l2 { { 3, 5}, { 3, -2};
  64. assert ( prostopadla ( l1, l2)==true);
  65. }
  66. int main()
  67. {
  68.  
  69. return 0;
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment