Advertisement
Czapek

laby3 obiektowka zadanie1

Oct 18th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5. class punkty
  6. {
  7.     float x,y;
  8.  
  9. public:
  10.     punkty(float x1, float y1)
  11.     {
  12.         x=x1;
  13.         y=y1;
  14.     }
  15.     void wektor()
  16.     {
  17.         cout << "Wspolrzedne wektora to (" << x << "; " << y << ")" <<endl;
  18.     }
  19.     float odleglosc()
  20.     {
  21.         float odl;
  22.         odl = sqrt(x*x + y*y);
  23.         return odl;
  24.     }
  25.     void czyOX()
  26.     {
  27.         if(y == 0) cout << "Punkt należy do osi OX" << endl;
  28.         else cout << "Punkt nie należy do osi OX" << endl;
  29.     }
  30.     void czyOY()
  31.     {
  32.         if(x == 0) cout << "Punkt należy do osi OY" << endl;
  33.         else cout << "Punkt nie należy do osi OY" << endl;
  34.     }
  35.     int cwiartka()
  36.     {
  37.         if(x>0 and y>0) return 1;
  38.         if(x<0 and y>0) return 2;
  39.         if(x<0 and y<0) return 3;
  40.         if(x>0 and y<0) return 4;
  41.         if(x==0 and y==0) return 0;
  42.     }
  43. };
  44. int main()
  45. {
  46.     punkty A(10,20);
  47.     A.wektor();
  48.     cout << "odleglosc miedzy punktami jest rowna " << A.odleglosc() << endl;
  49.     A.czyOX();
  50.     A.czyOY();
  51.     cout << "punky lezy w cwiartce nr: " << A.cwiartka() << endl;
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement