| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 435 人关注过本帖
标题:怎么解啊!!!!!
只看楼主 加入收藏
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
快速回复:怎么解啊!!!!!
数据加载中...
 
   



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

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