complex.cpp

来自「矩阵类 简单的矩阵类的编写」· C++ 代码 · 共 107 行

CPP
107
字号
// complex.cpp: implementation of the Complex class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "complex.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Complex::Complex(double x, double y)
:m_dReal(x), m_dImage(y)
{
}

Complex::Complex(Complex &x)
{
	this->m_dReal = x.m_dReal;
	this->m_dImage = x.m_dImage;
}

Complex::~Complex()
{

}

Complex operator *(Complex& x, Complex& y)
{
	return x;
		//Complex(x.m_dReal+y.m_dReal, x.m_dImage+y.m_dImage);
}


void Complex::SetReal(double x)
{
	this->m_dReal = x;
}

void Complex::SetImage(double x)
{
	this->m_dImage  = x;  
}

double Complex::GetReal()
{
	return this->m_dReal;
}
double Complex::GetImage()
{
	return this->m_dImage;
}

Complex operator -(Complex& x, Complex& y)
{
	Complex r;
	r.m_dReal = x.m_dReal -y.m_dReal;
	r.m_dImage = x.m_dImage -y.m_dImage;
	return r;
}

Complex operator --(Complex& x)//前置
{
	x.m_dReal--;
	return x;
}

Complex operator --(Complex& x, int) //后置
{
	Complex temp(x);
//	temp.m_dReal = x.m_dReal;
//	temp.m_dImage = x.m_dImage;
	x.m_dReal--;
	return temp;
}



Complex Complex::operator ++(void)//前置
{
	this->m_dReal++;
	return *this;
}
Complex Complex::operator ++(int) //后置
{
	Complex temp(*this);
//	temp.m_dReal = this->m_dReal;
//	temp.m_dImage = this->m_dImage;
	this->m_dReal ++;
	return temp;
}

int Complex::operator !()
{	
	if (*this == 0)
		return 1;
	else 
		return 0;
}

int Complex::operator ==(Complex op)
{
	if((m_dReal == op.m_dReal)&&(m_dImage == op.m_dImage))
		return 1;
	else
		return 0;
}

⌨️ 快捷键说明

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