利用操作符重载实现虚数类

啥也不说了直接上代码 小哥我的态度很好吧
//2、利用操作符重载给出一个完整的复数类的定义。
#include 
using namespace std;
class Complex{
	double real;
	double imag;
public:
	Complex(){real = 0;imag = 0;}
	Complex (double r,double i){real = r;imag = i;}
	Complex operator +(Complex &c);
	Complex operator -(Complex &c);
	Complex operator *(Complex &c);
	Complex operator /(Complex &c);
	void show();

};
Complex Complex::operator+(Complex &c){
	double r = real+c.real;
	double i = imag+c.imag;
	return Complex(r,i);
}
Complex Complex::operator-(Complex&c){
	double r = real-c.real;
	double i = imag-c.imag;
	return Complex(r,i);
}
Complex Complex::operator*(Complex &c){
	double r = real*c.real-imag*c.imag;
	double i = imag*c.real+real*c.imag;
	return Complex(r,i);
}
Complex Complex::operator/(Complex &c){
	if (c.imag==0&&c.real==0)
	{
		cout<<"请输入正确的除数"<

你可能感兴趣的:(C++)