My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to add, sub, mul ,and divide two complex numbers using classes

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
class complex
{
 double a,b,c,d;
 public:
 void setdata();
 void add();
 void subt();
 void mult();
 void divd();
 };
 double x,y;
 void complex::setdata()
 {
  cout<<"for first number"<<endl;
  cout<<"enter real part ";
  cin>>a;
  cout<< "enter imiginary part ";
  cin>>b;
  cout<<endl;
  cout<<"for second number"<<endl;
  cout<<"enter real part ";
  cin>>c;
  cout<<"enter imiginary part ";
  cin>>d;
  cout<<endl;
  }
  void complex::add()
  {
   x=a+c;
   y=b+d;
   cout<<"addition of complex number is "<<x<<"  "<<y<<"i"<<endl;
   }
  void complex::subt()
  {
    x=a-c;
    y=b-d;
    cout<<"subtraction of complel number is "<<x<<"  "<<y<<"i"<<endl;
   }
  void complex::mult()
   {
    x=(a*c)-(b*d);
    y=(b*c)+(a*d);
    cout<<"multiple of complex number is "<<x<<"  "<<y<<"i"<<endl;
    }
   void complex::divd()
   {
    x=((a*c)+(b*d))/((c*c)+(d*d));
    y=((b*c)-(a*d))/((c*c)+(d*d));
    cout<<"divident number is "<<x<<"  "<<y<<"i"<<endl;
    }
  void main()
  {
   clrscr();
   complex c1;
   c1.setdata();
   c1.add();
   c1.subt();
   c1.mult();
   c1.divd();
   getch();
   }

0 comments: