You are viewing a single comment's thread. Return to all comments →
using namespace std; class Complex { public: int real, imag; // Constructor of initially value set Complex(int r = 0, int i = 0) { real = r; imag = i; } // Complex overloading Complex operator + (Complex const &obj) { Complex res; res.real = real + obj.real; res.imag = imag + obj.imag; return res; } void display() { cout << real << "+" << imag << "i" << endl; } };
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ Complex c1(3, 4), c2(5, 6);
Complex c3 = c1 + c2; c3.display(); return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Overload Operators
You are viewing a single comment's thread. Return to all comments →
include
include
include
include
include
using namespace std; class Complex { public: int real, imag; // Constructor of initially value set Complex(int r = 0, int i = 0) { real = r; imag = i; } // Complex overloading Complex operator + (Complex const &obj) { Complex res; res.real = real + obj.real; res.imag = imag + obj.imag; return res; } void display() { cout << real << "+" << imag << "i" << endl; } };
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ Complex c1(3, 4), c2(5, 6);
}