输入
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 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复