Write a program to find COMPLEX NUMBER using pass by value

/*
  COMPLEX NUMBER:
    (a+bi)

WAP to add 2 complex number
*/

#include<iostream>
using namespace std;

class Complex
{
   int a,b;
 
   public:
         void accept()
{
cout<<"\n\n Enter a and b values: ";
cin>>a>>b;
}

void display()
{
if(b>0)
{
  cout<<"\n\n"<<a<<"+"<<b<<"i";
}
else
{
  cout<<"\n\n"<<a<<b<<"i";
}
    }
   
    Complex add(Complex c1,Complex c2);
};

Complex Complex::add(Complex c1,Complex c2)
{
Complex c3;

c3.a=c1.a+c2.a;
c3.b=c1.b+c2.b;

return c3;
}

int main()
{
Complex c1,c2,c3;
   
    c1.accept();
c2.accept();

c1.display();
c2.display();

c3=c1.add(c1,c2);

c3.display();

return 0;
}

Previous
Next Post »