C++ Program of complex number Unknown 10:35 structure Edit Adding ,subtracting,multiplication, division of Complex number#include<fstream.h> #include<iostream.h> #include<string.h> using namespace std; struct complex { int a1,a2,b1,b2,c1,c2,d; }; int add(complex &ad) { ad.c1=ad.a1+ad.b1; ad.c2=ad.a2+ad.b2; } int sub(complex &ad) { ad.c1=ad.a1-ad.b1; ad.c2=ad.a2-ad.b2; } int mult(complex &ad) { ad.c1=(ad.a1*ad.b1)-(ad.a2*ad.b2); ad.c2=(ad.a1*ad.b2)+(ad.a2*ad.b1); } int div(complex ad) { ad.c1=(ad.a1*ad.b1)-(ad.a2*(ad.b2*-1)); ad.c2=(ad.a1*ad.b2)+(ad.a2*(ad.b1*-1)); ad.d=(ad.b1*ad.b1)+(ad.b2*ad.b2); if(ad.c2>=0) cout<< "Your Division is ["<<ad.c1<<"-"<<ad.c2<<"i]/"<<ad.d<<endl; else cout<< "Your Division is ["<<ad.c1<<ad.c2<<"i]/"<<ad.d<<endl; } int main() { complex oo; cout<<" PRogram for [add],[subtract],[multiplition],[Divison] of Complex NUmber"<<endl<<endl; int real,imag,choose,real1; cout<<" Choose OPtion "<<endl<<endl; cout<<" (0) Add (1)subtraction (2)multipilcation (3) Division "<<endl<<endl; cout<<"Enter Choice plz ===="; cin>>choose; string opp[5]={"Add","Subtraction","Mutliplicatrion","Division"}; cout<<" Enter 1 number "<<endl<<endl; cout<<" Enter real part == "; cin>>oo.a1; cout<<"\n"; cout<<" Enter imagnary part == "; cin>>oo.a2; cout<<" Enter 2 number "<<endl<<endl; cout<<" Enter real part == "; cin>>oo.b1; cout<<"\n"; cout<<" Enter imagnary part == "; cin>>oo.b2; if(choose<=2) { if(choose==0) { add(oo); } if(choose==1) { sub(oo); } if(choose==2) { mult(oo); } if(oo.c2>=0) cout<< "Your "<<opp[choose]<<" is ["<<oo.c1<<"+"<<oo.c2<<"i]"<<endl; else cout<< "Your "<<opp[choose]<<" is ["<<oo.c1<<oo.c2<<"i]"<<endl; } if(choose==3) { div(oo); } } <<<<<<< ________________ >>>>>>>> Share on Facebook Share on Twitter Share on Google Plus About Unknown This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel. RELATED POSTS
0 comments:
Post a Comment