The following menu driven C++ program uses operator overloading to to perform Addition,Subtraction,Multiplication and Division of two complex numbers.Here Operators +,-,* and / are overloaded to perform the required operations with the desired objects.

eg:a*b in the terms of overloading means is to perform the '*' Operation associated with object a on object b.

The Complete Source Code is given below.If you have any Queries Just Comment on the Post.

eg:a*b in the terms of overloading means is to perform the '*' Operation associated with object a on object b.

The Complete Source Code is given below.If you have any Queries Just Comment on the Post.

```
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class complex
{
int i,r;
public:
void read()
{
cout<<"\nEnter Real Part:";
cin>>r;
cout<<"Enter Imaginary Part:";
cin>>i;
}
void display()
{
cout<<"\n= "<<r<<"+"<<i<<"i";
}
complex operator+(complex a2)
{
complex a;
a.r=r+a2.r;
a.i=i+a2.i;
return a;
}
complex operator-(complex a2)
{
complex a;
a.r=r-a2.r;
a.i=i-a2.i;
return a;
}
complex operator*(complex a2)
{
complex a;
a.r=(r*a2.r)-(i*a2.i);
a.i=(r*a2.i)+(i*a2.r);
return a;
}
complex operator/(complex a2)
{
complex a;
a.r=((r*a2.r)+(i*a2.i))/((a2.r*a2.r)+(a2.i*a2.i));
a.i=((i*a2.r)-(r*a2.i))/((a2.r*a2.r)+(a2.i*a2.i));
return a;
}
};
void main()
{
int ch;
clrscr();
complex a,b,c;
do
{
cout<<"\n1.Addition 2.Substraction";
cout<<" 3.Mulitplication 4.Division 5.Exit\n";
cout<<"\nEnter the choice :";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter The First Complex Number:";
a.read();
a.display();
cout<<"\nEnter The Second Complex Number:";
b.read();
b.display();
c=a+b;
c.display();
break;
case 2:
cout<<"\nEnter The First Complex Number:";
a.read();
a.display();
cout<<"\nEnter The Second Complex Number:";
b.read();
b.display();
c=b-a;
c.display();
break;
case 3:
cout<<"\nEnter The First Complex Number:";
a.read();
a.display();
cout<<"\nEnter The Second Complex Number:";
b.read();
b.display();
c=a*b;
c.display();
break;
case 4:
cout<<"\nEnter The First Complex Number:";
a.read();
a.display();
cout<<"\nEnter The Second Complex Number:";
b.read();
b.display();
c=a/b;
c.display();
break;
}
}while(ch!=5);
getch();
}
```

Thankz buddy..! helped a lot

why should we use objects in member functions when it can directly access its data members?

nice !!

hey can someone please write this complex number program for me? i would greatly appreciate it. write a C++ programme to carry out mathematical operations on complex numbers without using the predefined complex function available with your compiler. The operations to be carried out on both complex and polar form numbers must include but not be limited to:

Addition and subtraction of two or more vectors

Multiplication and division

Converting from complex form to polar form

Converting from polar form to complex form

Conjugate and modulus of the complex number

Your solution should include at least two classes, one Complex and the other Polar.

The mathematical operations should be able to operate on both types of numbers at the same time, e.g.:

Complex A, x;

Polar B, y;

x = A + B;

y = A * B;

||=== Build: Debug in Tutorials (compiler: GNU GCC Compiler) ===|

D:\C++\Tutorials\main.cpp|2|fatal error: conio: No such file or directory|

||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

i get this erroe

thanks for helping me complete my holiday homework

This comment has been removed by the author.

Please anyone help me to understanding the logic of "/" operator.

It does not working :-(

Write a program using function to find the product of complex numbers. Use structure to store the complex numbers. The function takes the two complex numbers as argument and returns the complex numbers.

Great and Useful Article.

Java Online Course

Java Online Training

Java EE training

Java Course in Chennai

Java Training in Chennai

Java Training Institutes in Chennai

Java Interview Questions

Java Interview Questions

Programming is combination of intelligent and creative work. Programmers can do anything with code. The entire Programming tutorials that you mention here on this blog are awesome. Beginners Heap also provides latest tutorials of Programming from beginning to advance level.

Be with us to learn programming in new and creative way.

How to perform with only addition and multiplication operator using c#program

How to perform with only addition and multiplication operator using c#program