⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complex.cpp

📁 这是编程之道C-C++中的源代码,很简练,可以用于相关教学和重新熟悉C-C++时使用
💻 CPP
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -