complex.cpp

来自「it can help you use C++ program we」· C++ 代码 · 共 53 行

CPP
53
字号
#include <iostream.h>
#include "complex.h"

CComplex& CComplex::operator =(const CComplex& c)
{
	// 判断是否自复制
	if(this == &c)
		return *this;
	real = c.real;
	image = c.image;
	return *this;
}

CComplex CComplex::operator +(const CComplex& c)
{
	CComplex	temp;
	temp.real = real + c.real;
	temp.image = image + c.image;
	return temp;
}

CComplex  CComplex::operator -(const CComplex &c)
{
	CComplex	temp;
	temp.real =this->real - c.real;
	temp.image = this->image - c.image;
	return temp;
}

CComplex &CComplex::operator ++()			//前缀
{
	real ++;
	image ++;
	return *this;
}

CComplex  CComplex::operator ++(int a)		//后缀 
{
	CComplex  temp;
	temp.real = real;
	temp.image = image;
	real++;
	image++;
	return temp; 
} 

ostream& operator<<(ostream& stream, CComplex c)
{
	cout<<c.image;
	stream<<"("<<c.real<<"+"<<c.image<<"i)";	//以格式(a+bi)显示
	return stream; 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?