C++ program to add two complex numbers by passing objects to a function Test Case 1 Input (stdin) 7 -2 1 6 Expected Output 8+4i Test Case 2 Input (stdin) 70 -2 1 8 Expected Output 71+6i
#include<iostream> using namespace std; class complex { int re,im; public: void get() { cin>>re>>im; } void disp() { cout<<re<<"+"<<im<<"i"; } void sum(complex,complex); }; void complex::sum(complex c1,complex c2) { re=c1.re+c2.re; im=c1.im+c2.im; } int main() { complex c1,c2,c3; c1.get(); c2.get(); c3.sum(c1,c2); c3.disp(); }