如何用c语言实现下列运算

来源:百度知道 编辑:UC知道 时间:2024/06/16 00:44:52
1 由输入实部和虚部生成一个复数
2 两个复数求和
3 两个复数求差
4 两个复数求积
5从已知复数中分离出实部
6从已知复数中分离出虚部
哪有tc 2.0下载?

#include <iostream>
#include <cmath>
class Complex
{

public:

Complex() : _real(0), _imag(0) {}
explicit Complex( double r) : _real(r), _imag(0) {}
Complex(double r, double i) : _real(r), _imag(i) {}

Complex& operator+=(const double& d)
{
_real += d;
return *this;
}

Complex& operator+=(const Complex& c)
{
_real += c._real;
_imag += c._imag;
return *this;
}

Complex& operator-=(const double &d)
{
_real -= d;
return *this;
}

Complex& operator-=(const Complex& c)
{
_real -= c._real;
_imag -= c._imag;
return *this;
}

Complex& operator*=(const double& d)
{
_real *= d;
_imag *= d;
return *this;
}

Complex& operator*=(const Complex& c)
{
double re = _real;
double im = _imag;
_real = re * c._real -