标题:为什么我编的复数类不能执行除法运算了 ,能编译 ,不能生成
取消只看楼主
q236763612
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-10-22
 问题点数:0 回复次数:0 
为什么我编的复数类不能执行除法运算了 ,能编译 ,不能生成
不能执行除法运算了  有生成错误   哪位大哥能帮帮我哈哈!

#include<iostream>

#include<cassert>
using namespace std;
class Complex
{
private:
    int Real ;
    int Image;
public:
Complex(int r=0, int i=0)
:Real(r),Image(i)
{}
~Complex()



  Real=a.Real ;
  Image=a.Image ;
}
Complex& operator=(const Complex& a)
{
    assert(this!=&a);
   Real=a.Real;
  Image=a.Image ;
  return *this;
}
void print()
{
    cout<<Real<<"+"<<Image<<"i"<<endl;
}
friend Complex Add(const Complex& a, const Complex& b);
friend Complex Div(const Complex& a, const Complex& b);
};
Complex Add( const Complex& a, const Complex& b)
{
    return Complex (a.Real +b.Real ,a.Image+b.Image );

}
Complex Div ( const Complex& a , const Complex& b)
{
    assert( b.Real *b.Image !=0);
  return  Complex ( (a.Real *b.Real +a.Image*b.Image)/(b.Real*b.Real  +b.Image*b.Image), (a.Image *b.Real -a.Real *b.Image)/(b.Real*b.Real  +b.Image*b.Image ));
}
int  main ()
{
    Complex a,b,c;
  a.SetComplex ();
  b.SetComplex ();
  c=Div (a,b);
  c.print();
}

不能执行除法运算了  有生成错误   哪位大哥能帮帮我哈哈!
代码如下
#include<iostream>
#include<cassert>
using namespace std;
class Complex
{
private:
    int Real ;
    int Image;
public:
Complex(int r=0, int i=0)
:Real(r),Image(i)
{}
~Complex()



  Real=a.Real ;
  Image=a.Image ;
}
Complex& operator=(const Complex& a)
{
    assert(this!=&a);
   Real=a.Real;
  Image=a.Image ;
  return *this;
}
void print()
{
    cout<<Real<<"+"<<Image<<"i"<<endl;
}
friend Complex Add(const Complex& a, const Complex& b);
friend Complex Div(const Complex& a, const Complex& b);
};
Complex Add( const Complex& a, const Complex& b)
{
    return Complex (a.Real +b.Real ,a.Image+b.Image );

}
Complex Div ( const Complex& a , const Complex& b)
{
    assert( b.Real *b.Image !=0);
  return  Complex ( (a.Real *b.Real +a.Image*b.Image)/(b.Real*b.Real  +b.Image*b.Image), (a.Image *b.Real -a.Real *b.Image)/(b.Real*b.Real  +b.Image*b.Image ));
}
int  main ()
{
    Complex a,b,c;
  a.SetComplex ();
  b.SetComplex ();
  c=Div (a,b);
  c.print();
}
搜索更多相关主题的帖子: 除法 运算 编译 
2008-11-11 11:12



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




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

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