Advertisement
Josif_tepe

Untitled

Dec 28th, 2023
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class Complex {
  5. private:
  6.     double real, img;
  7. public:
  8.     Complex(double _real, double _img) {
  9.         real = _real;
  10.         img = _img;
  11.     }
  12.     Complex operator + (Complex c) {
  13.         Complex res(real + c.real, img + c.img);
  14.         return res;
  15.     }
  16.     void print() {
  17.         cout << real << "+" << img << "i" << endl;
  18.     }
  19. };
  20. int main() {
  21.  
  22.     Complex c(10, 20);
  23.     Complex c1(10, 20);
  24.    
  25.     c = c + c1;
  26.     c.print();
  27.    return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement