Tuesday, March 17, 2015

program to demonstrate the overloading of binary arithmetic operator. (C plusplus or C++)

Aim: Write a program to demonstrate the overloading of binary arithmetic operator.
Ans:

#include<iostream.h>
#include<conio.h>
class  A
{
int x,y;
public:
            void  in()
            {

                        cout<<"Enter real and imaginary parts\n";
                        cin>>x>>y;
            }
A operator  +(A obj)
{
            A T;
            T.x=x +obj.x;
            T.y=y +obj.y;
            return(T);
}
void  show()
{
            cout<<"RESULT IS  "<<x<<"+i"<<y;
}
};
void  main()
{
clrscr();
A o1,o2,o3;
o1.in();
o2.in();
o3=o1+o2;
o3.show();
getch();
}



No comments:

Post a Comment