Advertisement
Dprogrammed1

cplus

Apr 1st, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2.     using namespace std;
  3.     class Complex
  4.     {
  5.         private:
  6.         float real;
  7.         float imag;
  8.         public:
  9.         Complex():real(0), imag(0){}
  10.         Complex operator ()(float re, float im)
  11.         {
  12.             real += re;
  13.             imag += im;
  14.             return *this;
  15.         }
  16.         Complex operator() (float re)
  17.         {
  18.             real += re;
  19.             return *this;
  20.         }
  21.         void display()
  22.         {
  23.             cout << "(" << real << "," << imag << ")" << endl;
  24.         }
  25.     };
  26.     int main()
  27.     {
  28.         Complex c1, c2;
  29.         c2 = c1(3.2, 5.3);
  30.         c1(6.5, 2.7);
  31.         c2(1.9);
  32.         cout << "c2=";c1.display();
  33.         cout << "c2=";c2.display();
  34.         return 0;
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement