answersLogoWhite

0

#include<iostream.h> #include<conio.h> class complex { int a,b; public: void read() { cout<<"\n\nEnter the REAL PART : "; cin>>a; cout<<"\n\nEnter the IMAGINARY PART : "; cin>>b; } complex operator +(complex c2) { complex c3; c3.a=a+c2.a; c3.b=b+c2.b; return c3; } complex operator -(complex c2) { complex c3; c3.a=a-c2.a; c3.b=b-c2.b; return c3; } complex operator *(complex c2) { complex c3; c3.a=(a*c2.a)-(b*c2.b); c3.b=(b*c2.a)+(a*c2.b); return c3; } complex operator /(complex c2) { complex c3; c3.a=((a*c2.a)+(b*c2.b))/((c2.a*c2.a)+(c2.b*c2.b)); c3.b=((b*c2.a)-(a*c2.b))/((c2.a*c2.a)+(c2.b*c2.b)); return c3; } void display() { cout<<a<<"+"<<b<<"i"; } }; void main() { complex c1,c2,c3; int choice,cont; do { clrscr(); cout<<"\t\tCOMPLEX NUMBERS\n\n1.ADDITION\n\n2.SUBTRACTION\n\n3.MULTIPLICATION\n\n4.DIVISION"; cout<<"\n\nEnter your choice : "; cin>>choice; if(choice==1choice==2choice==3choice==4) { cout<<"\n\nEnter the First Complex Number"; c1.read(); cout<<"\n\nEnter the Second Complex Number"; c2.read(); } switch(choice) { case 1 : c3=c1+c2; cout<<"\n\nSUM = "; c3.display(); break; case 2 : c3=c1-c2; cout<<"\n\nResult = "; c3.display(); break; case 3 : c3=c1*c2; cout<<"\n\nPRODUCT = "; c3.display(); break; case 4 : c3=c1/c2; cout<<"\n\nQOUTIENT = "; c3.display(); break; default : cout<<"\n\nUndefined Choice"; } cout<<"\n\nDo You Want to Continue?(1-Y,0-N)"; cin>>cont; }while(cont==1); getch(); }

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

RossRoss
Every question is just a happy little opportunity.
Chat with Ross
BeauBeau
You're doing better than you think!
Chat with Beau
BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake

Add your answer:

Earn +20 pts
Q: Write a program to find sum of two complex numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp