Advertisement
rowers

zespolone

Nov 27th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #ifndef ZESPOLONA_H_INCLUDED
  2. #define ZESPOLONA_H_INCLUDED
  3.  
  4. class Zespolona
  5. {
  6.     public:
  7.         float re,im;
  8.  
  9.         Zespolona (float re_ = 0, float im_ = 0)
  10.         {
  11.             re = re_;
  12.             im = im_;
  13.         }
  14.  
  15.         void dodaj (Zespolona &z) //dodaj2
  16.         {
  17.             re += z.re;
  18.             im += z.im;
  19.         }
  20.  
  21.         void dodaj (Zespolona &z1, Zespolona &z2) //dodaj3
  22.         {
  23.             re += z1.re + z2.re;
  24.             im += z1.im + z2.im;
  25.         }
  26.  
  27.         void operator += (Zespolona &z)
  28.         {
  29.             re += z.re;
  30.             im += z.im;
  31.         }
  32.  
  33.         Zespolona operator + (Zespolona &z)
  34.         {
  35.             Zespolona z_;
  36.             z_.re = re + z.re;
  37.             z_.im = im + z.im;
  38.             return z_;
  39.         }
  40.  
  41.         bool operator == (Zespolona &z)
  42.         {
  43.             if ((re == z.re) && (im == z.im))
  44.             {
  45.                 std::cout << "true" << std::endl;
  46.                 return true;
  47.             }
  48.             else
  49.             {
  50.                 std::cout << "false" << std::endl;
  51.                 return false;
  52.             }
  53.         }
  54. };
  55.  
  56. #endif // ZESPOLONA_H_INCLUDED
  57.  
  58. ///////////////main
  59.  
  60. #include <iostream>
  61. #include "zespolona.h"
  62.  
  63. using namespace std;
  64.  
  65. int main()
  66. {
  67.     Zespolona a(1,1);
  68.     Zespolona b(2,2);
  69.     Zespolona c(3,3);
  70.  
  71.     cout << "a.im: " << a.im << " , a.re: " << a.re << endl;
  72.     cout << "b.im: " << b.im << " , b.re: " << b.re << endl;
  73.     cout << "c.im: " << c.im << " , c.re: " << c.re << endl;
  74.     cout << endl;
  75.  
  76.     cout << "a += b" << endl;
  77.     a += b;
  78.     //a.dodaj(b);
  79.     cout << "a.im: " << a.im << " , a.re: " << a.re << endl;
  80.     cout << endl;
  81.  
  82.     cout << "b = a + c" << endl;
  83.     b = a + c;
  84.     //a.dodaj(b,c);
  85.     cout << "b.im: " << b.im << " , b.re: " << b.re << endl;
  86.     cout << endl;
  87.  
  88.     cout << "a == c" << endl;
  89.     a == c;
  90.     cout << endl;
  91.  
  92.     cout << "b == c" << endl;
  93.     b == c;
  94.  
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement