PROGRAM FOR OPERATOR OVERLOADING USING MEMBER FUNCTION

//program for operator overloading using member function

#include<iostream.h>
#include<conio.h>
class c
{
  float a,b;
  public:
     c(){}
     c(float x,float y)
     {
       a=x;
       b=y;
     }
     c operator +(c);
     void display();
};
      void c::display()
     {
       cout<<a<<"+"<<b<<"i"<<endl;
     }
c c::operator+(c pc)
{
  c t;
  t.a=a+pc.a;
  t.b=b+pc.b;
  return(t);
}
void main()
{
   c c1,c2,c3;
   clrscr();
   c1=c(1.2,2.3);
   c2=c(1.2,2.5);
   c3=c1+c2;
   c1.display();
   c2.display();
   c3.display();
   getch();
}

Comments

Popular Posts