#include #include using namespace std; class complex{ private : float x,y; public: complex() {x=0;y=0;} complex(float a) {x=a;y=0;} complex(float a, float b) {x=a;y=b;} float real_part() { return x;} float imaginary_part() {return y;} void display(); void set(float a) {x=a;y=0;} void set(float a, float b) {x=a;y=b;} void get_from_user(); }; void complex :: display(){ cout <<"(" << x << ") + i(" << y << ")\n"; } void complex :: get_from_user() { float x,y; cout << "Input real part \n"; cin >> x; cout << "Input imaginary part \n"; cin >> y; set(x,y); } complex sum(complex z1, complex z2) { complex s; float x,y; x = z1.real_part() + z2.real_part(); y = z1.imaginary_part() + z2.imaginary_part(); s.set(x,y); return s; } complex operator +(complex z1, complex z2) { complex s; float x,y; x = z1.real_part() + z2.real_part(); y = z1.imaginary_part() + z2.imaginary_part(); s.set(x,y); return s; } int main() { complex z1, z2, z3, z4; cout << "Input the first complex number \n"; z1.get_from_user(); cout << "Input the second complex number \n"; z2.get_from_user(); z3 = z1 + z2; cout << "The sum is \n"; z3.display(); z4 = (z1 + z2) + z3; cout << "The supersum is \n"; z4.display(); return 0; }