COMPLEX NUMBER PROGRAM
COMPLEX NUMBER PROGRAM
#include<stdlib.h>
#include<math.h>
class complex
public:
float r,i;
complex()
r==0.0;
i==0.0;
complex(float a,float b)
r=a;
i=b;
a<<"\n"<<b.r<<"+"<<b.i<<"i";
input>>num.r>>num.i;
return input;
complex operator+(complex);
complex operator*(complex);
};
complex B;
B.r=r+A.r;
B.i=i+A.i;
return B;
complex B;
B.r=r+A.r;
B.i=i-A.i;
B.r=((r)*(A.r))-((i)*(A.i));
B.i=((r)*(A.i))+((A.r)*(i));
return B;
int main()
{
int ch;
complex A,B,C;
while(1)
cout<<"\n*************Menu*******************";
cout<<"\n1.Create constructor.";
cout<<"\n2.Accept nos.";
cout<<"\n3.Display nos.";
cout<<"\n4.Add nos.";
cout<<"\n5.Multiplication of numbers.";
cout<<"\n6.Exit";
cin>>ch;
switch(ch)
case 1:
cout<<A;
cout<<B;
break;
case 2:
cin>>A;
cin>>B;
break;
case 3:
break;
case 4:
C=A+B;
break;
case 5:
C=A*B;
break;
case 6:
exit(0);
return 0;
OUTPUT
/tmp/eyRe8iD5vC.o
*************Menu*******************
1.Create constructor.
2.Accept nos.
3.Display nos.
4.Add nos.
5.Multiplication of numbers.
6.Exit
0+0i
2.75813e-10+3.09267e-41i
*************Menu*******************
1.Create constructor.
2.Accept nos.
3.Display nos.
4.Add nos.
5.Multiplication of numbers.
6.Exit
30
*************Menu*******************
1.Create constructor.
2.Accept nos.
3.Display nos.
4.Add nos.
5.Multiplication of numbers.
6.Exit
3+5i
*************Menu*******************
1.Create constructor.
2.Accept nos.
3.Display nos.
4.Add nos.
5.Multiplication of numbers.
6.Exit
Addition is:
23+35i
*************Menu*******************
1.Create constructor.
2.Accept nos.
3.Display nos.
4.Add nos.
5.Multiplication of numbers.
6.Exit
Multiplication is:
-90+190i
*************Menu*******************
1.Create constructor.
2.Accept nos.
3.Display nos.
4.Add nos.
5.Multiplication of numbers.
6.Exit