爱问知识人 爱问教育 医院库

c 关于复数的加减乘除运算,求高手啊!

首页

c 关于复数的加减乘除运算,求高手啊!

设计一个C语言的strcut Complex用于表示复数,一个复数包含两个部分,实部real和虚部imag,两个部分都为int类型。
a) 定义init方法用于将复数类型的变量初始化为1 1i;
b) 定义multiplyComplex方法用于将两个复数相乘,返回相乘得到的复数;
c) 定义printComplex方法按照(real, imag)的格式打印一个复数
d) 在main方法中测试上面的结构和相关方法。

提交回答

全部答案

    2018-03-08 12:37:50
  •   #include 
    #include
    using namespace std;
    class CComplex
    {
    #define err 0。
      00000001
    double _x,_y;
    public:
    CComplex(double x=0,double y=0):_x(x),_y(y){}
    CComplex operator (const CComplex&z);
    CComplex operator-(const CComplex&z);
    CComplex operator*(const CComplex&z);
    CComplex operator/(const CComplex&z);
    friend ostream&operator >(istream&is,CComplex&z);
    };
    int main()
    {
    CComplex z1(0,1。
      2);
    CComplex z2(1,1。2);
    cout>z1;
    couterr)
    couterr?" i":"i");
    else if(fabs(z。
      _y 1)err)
    couterr?" ":"")>(istream&is,CComplex&z)
    {
    is>>z。_x>>z。_y;
    return is;
    }
    //运行一下就知道怎么用了。
      

    在***

    2018-03-08 12:37:50

类似问题

换一换

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):