C++-Logo.wine
C++

C++ program to overload ‘+’ operator to find the sum of two complex numbers

#include<iostream.h>
#include<conio.h>
class add
{
public:
inta,b;
add(intr,int i)
{
a=r;
b=i;
}
add()
{
}
add operator +(add);
void disp();
};
add add::operator + (add t1)
{
add t2;
t2.a=a+t1.a;
t2.b=b+t2.b;
return t2;
}
void add :: disp()
{
cout<<” \n RESULT=” <<a<<”and”<<b;
}
void main()
{
clrscr();
add pix1(12,4);
add pix2(82,4);
add pix3;
pix3=pix1+pix2;
pix3.disp();
getch();
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.