Pages

Tuesday, August 20, 2013

Complex and Imaginary

#include<iostream.h>
#include<conio.h>

class complex
{
 int real;
 int img;
 public:
  complex()
   {
     real=0; img=0;
   }
  complex(int r,int i)
   {
    real=r; img=i;
   }
  void getdata()
   {
     cout<<"Complex No"<<endl;
     cout<<"Real:";
     cin>>real;
     cout<<"Imaginary:";
     cin>>img; 
   }

   void showcomplex()
   {
     cout<<real<<"+i"<<img<<endl;
   }
 void add_complex(complex,complex);
};

void complex::add_complex(complex c1,complex c2)
{
  real=c1.real+c2.real;
  img=c1.img+c2.img;
}

/*main*/
 int main()
{
  complex c1,c2,c3;
 
  c1.getdata();
  c2.getdata(); 
  c3.add_complex(c1,c2);
  cout<<"c1:";
  c1.showcomplex();
 cout<<"c2:";
 c2.showcomplex();
 cout<<"c3:";
 c3.showcomplex();
getch();
}

No comments:

Post a Comment