fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Punkt {
  5. double x;
  6. double y;
  7. };
  8.  
  9. double det(Punkt A, Punkt B, Punkt P) {
  10. return (B.x - A.x) * (P.y - A.y) - (B.y - A.y) * (P.x - A.x);
  11. }
  12.  
  13. void czytaj_punkt(Punkt &p, char nazwa) {
  14. cout << "Podaj wspolrzedne punktu " << nazwa << " (x y): ";
  15. cin >> p.x >> p.y;
  16. }
  17.  
  18. void punkt_po_stronie(Punkt A, Punkt B, Punkt P) {
  19. double d = det(A, B, P);
  20.  
  21. if (d > 0)
  22. cout << "Punkt P lezy po lewej stronie" << endl;
  23. else if (d < 0)
  24. cout << "Punkt P lezy po prawej stronie" << endl;
  25. else
  26. cout << "Punkt P lezy na prostej AB" << endl;
  27. }
  28.  
  29. int main() {
  30. Punkt A, B, P;
  31.  
  32. czytaj_punkt(A, 'A');
  33. czytaj_punkt(B, 'B');
  34. czytaj_punkt(P, 'P');
  35.  
  36. punkt_po_stronie(A, B, P);
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Podaj wspolrzedne punktu A (x y): Podaj wspolrzedne punktu B (x y): Podaj wspolrzedne punktu P (x y): Punkt P lezy na prostej AB