悲风起南鸣


私信TA

用户名:0211122686

访问量:657

签 名:

等  级
排  名 8723
经  验 1143
参赛次数 0
文章发表 6
年  龄 0
在职情况 学生
学  校 宁夏大学
专  业

  自我简介:

输入
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 人评分

  评论区