输入 1 2.3 4 3 -5 2 1 0 1 1 3 1 2 2 1 2 0 1 0 0 0 输出 (a)2.3+4i (b)3-5i (+):5.3-i (a)1 (b)1+i (-):-i (a)1+2i (b)2+i (*):5i (a)i (b)0 (-):i #include<iostream> #include<string> using namespace std; class complex { double real,iamg; public: complex(double r=0,double i=0) { real=r; iamg=i; } void set(double r,double i) { real=r; iamg=i; } void fun(int x,complex a,complex b) { if(x==1) { cout<<"(+):"; real=a.real+b.real; iamg=a.iamg+b.iamg; } else if(x==2) { cout<<"(-):"; real=a.real-b.real; iamg=a.iamg-b.iamg; } else if(x==3) { cout<<"(*):"; real=a.real*b.real-a.iamg*b.iamg; iamg=a.iamg+b.real+a.real*b.iamg; } } void show() { if(real==0&&iamg!=0) { if(iamg==1) { cout<<"i"<<endl; } else if(iamg==-1) { cout<<"-i"<<endl; } else cout<<iamg<<"i"<<endl; } else if(iamg==0) { cout<<real<<endl; } else if (real != 0 && iamg > 0) { if (iamg == 1) cout << real << "+i"<<endl; else cout << real << "+" << iamg << "i"<<endl; } else if (real != 0 && iamg < 0) { if (iamg == -1) cout << real << "-i"<<endl; else cout << real << iamg << "i"<<endl; } } }; int main() { int x; double real,iamg; complex a,b; while(cin>>x) { if(x==0) { return 0; } cin>>real>>iamg; complex co; a.set(real,iamg); cout<<"(a)"; a.show(); cin>>real>>iamg; b.set(real,iamg); cout<<"(b)"; b.show(); co.fun(x,a,b); co.show(); } }
0.0分
1 人评分
The 3n + 1 problem (C语言代码)浏览:603 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:756 |
判定字符位置 (C语言代码)浏览:849 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:1029 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:751 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:522 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:599 |
简单的a+b (C语言代码)浏览:667 |
简单的a+b (C语言代码)浏览:363 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:596 |