定义一个复数类CComplex,通过重载运算符 + ,直接实现两个复数之间的加法运算。

2025-02-25 11:12:26
推荐回答(1个)
回答1:

#include
using namespace std;
class CComplex
{
float real;
float image;
public:
CComplex operator+(CComplex &a);
CComplex(int x=0,float y=0){real=x;image=y;}
void Output(){cout<
};
CComplex CComplex::operator+(CComplex&a)
{
return CComplex(real+a.real,image+a.image);
}
void main()
{
CComplex c1(3f,5f);
CComplex c2(2f,4f);
CComplex c;
c=c1+c2;
c.Output();
}

这个就是运行在vc6.0的啊