This blog aims at helping you learn C, Java and TASM programming languages and thus enabling you to use its immense possibilities in the computing world.It features Step by step instructions on doing a C program ,Complete Source Codes of C, Java and TASM Programs ,sample program downloads,programming tutorials and general tips for programmers.

Thursday, January 12, 2012

Operator Overloading in C++ to add,substract,multiply and divide two Complex Numbers

Operator Overloading is a technique of polymorphism by which an operator(+,- etc) can be used to do different types of operations.
eg:+ can be used to add two integers say a and b using sum=a+b similarly two floating point numbers say fa,fb by fs=fa+fb.
In this example +,-,*,- operators are overloaded to add,subtract, multiply and divide two complex numbers.
First a class named complex is created which has overloaded operators like + specified by a function 'complex operator +(complex c2)' which can used to add two complex numbers like c3=c1+c2 where c1,c2 and c3 are complex numbers.The complete source in C++ to implement operator overloading is provided below