C++ Program to add two complex number
Operator overloading is the process by which pre-defined symbols like “+”, “-”, “<=” gets additional meaning.
This program is used to add two complex number using operator overloading.
#include<iostream.h>
#include<conio.h<
Class sample
{
Private:
Int x, y;
Public:
Void getdata ()
{
Cout<<”\n Enter value of x and y of complex number”;
Cin>>x>>y;
}
Sample operator + (sample obj)
{
Obj.y = x+obj.x;
Obj.y =y +obj.y;
Return (obj);
}
Void display ()
{
Cout<<”\n Additional of two complex numbers”;
Cout<<x<<”+I”<<y;
}
};
Void main ()
{
Sample obj1, obj2, obj3;
Obj1. Getdata ();
Obj2.getdat ();
Obj3=obj1+obj2;
Obj3.display ();
getch ();
}
Related posts:
- Overloading Binary Operator Overloading binary operator An operator requiring two operand is called...
- C++ Program showing assignment operator overloading The symbol ‘=’ is used as Assignment operators. It is...
- C++ Program showing constructor overloading Constructor is a member function with the same name as...
- C++ Program Using Friend Function Friend function is used to access private, public and protected...
- Inline Function Inline Function The inline function is designed to speed up...