| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 735 人关注过本帖
标题:为什么我编的复数类不能执行除法运算了 ,能编译 ,不能生成
只看楼主 加入收藏
q236763612
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-10-22
收藏
 问题点数:0 回复次数:3 
为什么我编的复数类不能执行除法运算了 ,能编译 ,不能生成
不能执行除法运算了  有生成错误   哪位大哥能帮帮我哈哈!

#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:13
debroa723
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:23
帖 子:862
专家分:1954
注 册:2008-10-12
收藏
得分:0 
~Complex()



  Real=a.Real ;
  Image=a.Image ;
这里是怎么回事?

    a.SetComplex ();
    b.SetComplex ();
这两句又是怎么回事,类Complex没有看到有SetComplex 成员函数.

建议楼主把类的相关概念搞搞清楚.
2008-11-11 23:11
shen476102493
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-11-12
收藏
得分:0 
jf
为什么我发现这么多的错误啊,事实上,我有好几个地方看不懂
2008-11-12 11:18
q236763612
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-10-22
收藏
得分: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()
{}
Complex( const Complex& a)
{

  Real=a.Real ;
  Image=a.Image ;
}
void SetComplex()
{
    cin>>Real;
    cin>>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-12 14:35
快速回复:为什么我编的复数类不能执行除法运算了 ,能编译 ,不能生成
数据加载中...
 
   



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

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