标题:怎么解啊!!!!!
只看楼主
FIO
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-12-11
 问题点数:0 回复次数:0 
怎么解啊!!!!!
#include<iostream.h>
class complex
{
float x;
float y;
public:
    complex()
    {
    x=0;
    y=0;
    }
complex(float vx,float vy)
{x=vx;
y=vy;
}
void print();
    friend complex operator +(complex a,complex b);
    friend complex operator -(complex a,complex b);
    friend complex operator *(complex a,complex b);
    friend complex operator /(complex a,complex b);
};
//void complex::print()
//{
//    cout<<x;
//    if(y>0) cout<<"+";
//    if(y!=0)cout<<y<<"i\n";
//}

void complex::print()
{
    if(x==0&&y==0)
        cout<<"the complex is"<<0<<endl;
    else
    {
        if(y>0)
            if(x)
                cout<<"the complex is"<<x<<"+"<<"i"<<endl;
            else cout<<"the complex is"<<y<<"*i"<<endl;
            if(y<0)
            {if(x)
            cout<<"the complex is"<<x<<y<<"*i"<<endl;
            else cout<<"the complex is"<<y<<"*i"<<endl;
            }
            if(y==0)
                cout<<"x"<<endl;
}
 complex operator+(complex a,complex b)
z    {complex temp;
    temp.x=a.x+b.x;
    temp.y=a.y+b.y;
    return temp;
    }
complex operator-(complex a,complex b)
    {complex temp;
    temp.x=a.x-b.x;
    temp.y=a.y-b.y;
    return temp;
    }
 complex operator*(complex a,complex b)
    {complex temp;
    temp.x=a.x*b.x-a.y*b.y;
    temp.y=a.y*b.y+a.x*b.x;
    return temp;
    }
 complex operator/(complex a,complex b)
    {complex temp;
    float tt;
    tt=1/(b.x*b.x+a.y*b.y);
    temp.x=(a.x*b.x+a.y*b.y)*tt;
    temp.y=(b.x*a.y-a.x*b.y)*tt;
    return temp;
    }
}
 main()
{
     cin>>x1>>y1>>;
     cin>>x2>>y2>>;
    complex a1(float x1,float y1);
    complex a2(float x2,float y2),a3;
     //complex a1(1,1),a2(2,2),a3;
    a3=a1+a2;
    a3.print();
    a3=a2-a1;
    a3.print();
    a3=a1*a3;
    a3.print();
    a3=a1/a2;
    a3.print();
    return 1;
}
搜索更多相关主题的帖子: complex include public friend 
2007-12-14 20:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-192490-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.170608 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved