Advertisement
dzieciol

obiektowe 1

Oct 7th, 2016
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. //a
  5. void wczytaj(float &x,float &y)
  6. {
  7.     cout<<"podaj x"<<endl;
  8.     cin>>x;
  9.     cout<<"podaj y"<<endl;
  10.     cin>>y;
  11. }
  12. //b
  13. void prosta (float x1,float y1, float y2, float x2, float &a, float &b, float &c)
  14. {
  15.     a = y2-y1;
  16.     b = x1-x2;
  17.     c = y1*x2-y2*x1;
  18. }
  19. int sprawdzenie(float a,float b,float c, float x, float y)
  20. {
  21.     float d;
  22.     d = ((fabs(a*x+b*y+c))/sqrt(a*a+b*b));
  23.     if(d<1e-10) return 1;
  24.     else return 0;
  25.  
  26. }
  27.  
  28. int main()
  29. {
  30.     cout << "Hello world!" << endl;
  31.     float x1,y1,x2,y2;
  32.     cout<<"podaj współrzędne pierwszego punktu"<<endl;
  33.     wczytaj(x1,y1);
  34.     cout<<"podaj współrzędne drugiego punktu"<<endl;
  35.     wczytaj(x2,y2);
  36.     float a,b,c;
  37.     prosta(x1,y1,x2,y2,a,b,c);
  38.     float x,y;
  39.     wczytaj(x,y);
  40.     //while(x!=0 && y!=0){
  41.     if(sprawdzenie(a,b,c,x,y)==1) cout<<"punkt lezy na prostej"<<endl;
  42.     else cout<<"punkt nie lezy na prostej"<<endl;
  43.     wczytaj(x,y);
  44.   //  }
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement