Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. class Punkt
  7. {
  8. private:
  9.   int x,y;
  10. public:
  11.   Punkt():x(0), y(0){}
  12.   Punkt(int x, int y): x(x), y(y){}
  13.  
  14.   double odleglosc(const Punkt& a)const
  15.   {
  16.     return sqrt((x-a.x)*(x-a.x)+(y-a.y)*(x-a.y));
  17.   }
  18. };
  19.  
  20. class Wielobok
  21. {
  22. private:
  23.   unsigned roz;
  24.   Punkt *wsk;
  25. public:
  26.   Wielobok():roz(0),wsk(0){}
  27.   Wielobok(const Punkt * b,const Punkt *e):roz(e-b),
  28.   wsk(roz ? new Punkt[roz]:0)
  29.   {
  30.     for(unsigned i=0;i<roz;++i)
  31.  
  32.   wsk[i] = b[i];
  33.  
  34.   }
  35.   ~Wielobok(){delete[]wsk;}
  36.   Wielobok (const Wielobok&);
  37.   Wielobok& operator = (const Wielobok&);
  38. };
  39.  
  40.  
  41. int main()
  42. {
  43.   punkt p(2, 3);
  44.   cout << p.x() << ' ' << p.y() << '\n';
  45.   p.x() = 1;
  46.   p.y() = 1;
  47.   cout << p.x() << ' ' << p.y() << '\n';
  48.   cout << p.odleglosc(punkt()) << '\n';
  49.  
  50. }
  51. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement