Advertisement
zielo

Untitled

Apr 11th, 2018
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. ///// zadanie 6
  7. class extended_complex
  8. {
  9.     float re, im;
  10. public:
  11.     extended_complex(float re = 0, float im = 0) : //konstruktor
  12.             re(re), im(im)
  13.     {
  14.     }
  15.     float real()
  16.     {
  17.         return re;
  18.     }
  19.     void real(float rr)
  20.     {
  21.         re = rr;
  22.     }
  23.     float img()
  24.     {
  25.         return im;
  26.     }
  27.     void img(float ii)
  28.     {
  29.         im = ii;
  30.     }
  31.     void print()
  32.     {
  33.         cout << mod() << "," << arg();
  34.     }
  35.         double mod()
  36.     {
  37.         return(sqrt(re*re+im*im));
  38.     }
  39.     double arg()
  40.     {
  41.         return atan2(im,re);
  42.     }
  43. };
  44. int main()
  45. {
  46. ////// zadanie 8
  47.   extended_complex *x = new extended_complex(77, -5); //dynamiczne tworzenie obiektu
  48.   extended_complex y = *x;  //przypisanie
  49.   y.print(); //wyswietlenie
  50.   delete x; //skasowanie dynamicznego obiektu
  51.   return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement