不知道你学拉重载没,我下面的程序用拉这个
#include
class COMPLEX{
public:
COMPLEX (double r=0,double i=0);
COMPLEX (const COMPLEX& other);
void print();
COMPLEX add(const COMPLEX& other);
COMPLEX subtract(const COMPLEX& other);
protected:
double real,image;
};
COMPLEX::COMPLEX(double r,double i)
{real=r;
image=i;
return;
}
COMPLEX::COMPLEX(const COMPLEX& other)
{
real=other.real;
image=other.image;
return;
}
void COMLEX::print()
{
cout< if(image>0)cout<<"+"< else if(image<0)cout< cout<<"\n";
return;
}
COMPLEX COMPLEX::add(const COMPLEX& other)
{
real=real+other.real;
image=image+other.image;
return *this;
}
COMPLEX COMPLEX::subtract(const COMPLEX& other)
{
real=real-other.real;
image=image-other.image;
return *this;
}
int main()
{这里面的主函数我就不写拉,你自己要定义怎样的就自己写上去就行拉..}
写的不好别见怪哈.
--------------------next---------------------
阅读(1145) | 评论(0) | 转发(0) |