Complex Class

Description:

Perform addition operation on complex data using class and object. The program should ask for real and imaginary part of two complex numbers, and display the real and imaginary parts of their sum. Test Case 1 Input (stdin) 10 5 5 3 Expected Output 10+5i 5+3i 15+8i Test Case 2 Input (stdin) 11 4 5 6 Expected Output 11+4i 5+6i 16+10i

Program :

#include <iostream>
using namespace std;
class complex
{
 int re,im;
 public:
  void get()
  {
   cin>>re>>im;
  }
  void disp()
  {
   cout<<re<<"+"<<im<<"i"<<'\n';
 
  }
  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;
// cout<<"Enter 1st complex no.:";
 c1.get();
// cout<<"Enter 2nd complex no.:";
 c2.get();
 //cout<<"The 1st complex no. is";
 c1.disp();
 //cout<<"\nThe 2nd complex no. is";
 c2.disp();
 c3.sum(c1,c2);
 //cout<<"\nThe resultant complex no. is";
 c3.disp();
 
}