谁会C++啊!!急求!

来源:百度知道 编辑:UC知道 时间:2024/05/12 06:45:24
用友元函数实现一个完善的复数类,重载+,-,*,/,=,+=,-=,*=,/=,并使其可以和double型数据混合运算,要求画出类图,写出你的设计文档(比如应指出运算符函数的返回值类型及为何必是此返回类型等)
下周就要考C++了!
我还完全不会呢!
要死了!
谁会啊??!!
我要烦烦烦烦死了!!!!!
谁可以帮帮我!!
谢谢二楼的大人,可是有一处错!而且重载+,-,*,/,=,+=,-=,*=,/=,并使其可以和double型数据混合运算。大人做的好像不完整!
请大人们将完整答案告知!真的是很着急!
在此谢谢各位大人啦!
在26号之前告诉答案!谢谢!

#ifndef COMPLEX_H
#define COMPLEX_H

// 修改时间: 2003年7月24日 21:00

#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;
}