YXTS122 2016-03-11 08:04 采纳率: 100%
浏览 1398
已采纳

大神们,帮我看看代码哪里错了?

 #include<iostream>
using namespace std;
class Complex
{
private:
    double real,imag;
public:
    Complex(double _real=0.0,double _imag=0.0):real(_real),imag(_imag)
    {
    }
    Complex operator +(Complex &val)
    {
        Complex t;
        t.real=this->real+val.real;
        t.imag=this->imag+val.imag;
        return t;
    }
    /*不能引用局部变量Complex&operator+*/
    Complex operator -(Complex &val)
    {
        return Complex(real-val.real,imag-val.imag);
    }
    Complex operator *(Complex &val)
    {
        Complex t;
        t.real=this->real*val.real-this->imag*val.imag;
        t.imag=this->real*val.imag+this->imag*val.real;
        return t;
    }
    Complex operator *(double x)
    {
        return Complex(x*real,x*imag);
    }
    Complex operator ~()
    {
        return Complex(real,-1*imag);
    }
    friend istream &operator >>(istream &is,Complex &com)
    {
        cout<<"real:";
        is>>com.real;
        if (is)
        {
            cout<<"imag:";
            is>>com.imag;
            if (is)
                return is;
            else
                com=Complex();
        }
        else
             com=Complex();
        return is;
    }
    friend ostream &operator <<(ostream &os,Complex &com)
    {
        os<<"("<<com.real<<","<<com.imag<<"i)"<<endl;
        return os;
    }
};
int main()
{
    Complex a(3.0,4.0);
    Complex c;
    cout<<"输入一个复数(输入q就停止):\n";
    while (cin>>c)
    {
        cout<<"c is "<<c<<endl;
        cout<<"共轭复数:"<<~c<<endl;
        cout<<"a is "<<a<<endl;
        cout<<"a+c is "<<a+c<<endl;
        cout<<"a-c is "<<a-c<<endl;
        cout<<"a*c is "<<a*c<<endl;
        cout<<"2*c is "<<2*c<<endl;
        cout<<"输入一个复数(输入q就停止):\n";
    }
    cout<<"Done!\n";
    return 0;
}
 #include<stdio.h>
int main()
{
    int i,j=0,f=0,k;
    char s[100],a[100],e[100];
    gets(s);
    for (i=0;s[i]!='\0';i++)
    {
        if (s[i]>='0'&&s[i]<='9')
        {
            a[j++]=s[i];
            if (s[i+1]>='0'&&s[i+1]<='9')
                continue;
            if (j>=f)
            {
                for (k=0,f=0;k<j;k++,f++)
                     e[k]=a[j];
            }
            j=0;
        }
    }
    printf("%d\n",f);
    for (k=0;k<f;k++)
        printf("%c",e[k]);
    printf("\n");
    return 0;
}
  • 写回答

2条回答

  • 小灸舞 2016-03-11 08:23
    关注

    LZ上面那段程序:cout<<"2*c is "<<2*c<<endl; 改为cout<<"2*c is "<<c*2<<endl;
    2必须作为右操作数

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料