complex.cpp

来自「多项式与常数和多项式之间的加减乘除等运算」· C++ 代码 · 共 104 行

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

#include <iostream>
#include "complex.h"

using namespace std;

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

//////////////////////////////////////////////////////////////////////
// default constructor 
//////////////////////////////////////////////////////////////////////
complex::complex()
{
	real = 0;
	imag = 0;
}

//////////////////////////////////////////////////////////////////////
// default destructor 
//////////////////////////////////////////////////////////////////////
complex::~complex()
{}


//////////////////////////////////////////////////////////////////////
//	setReal
//
//	sets real part of complex number to value
//
//	parameter:	double value 
//	return:		void
//////////////////////////////////////////////////////////////////////
void complex::setReal(double value)
{
	real = value;
}

//////////////////////////////////////////////////////////////////////
//	setImag
//
//	sets imaginary part of complex number to value
//
//	parameter:	double value 
//	return:		void
//////////////////////////////////////////////////////////////////////
void complex::setImag(double value)
{
	imag = value;
}

//////////////////////////////////////////////////////////////////////
//	getReal()
//	
//	returns real part of complex number
// 
//	parameter:	none
//	return:		real part of complex number
//////////////////////////////////////////////////////////////////////
double complex::getReal()
{
	return real;
}

//////////////////////////////////////////////////////////////////////
//	getImag()
//	
//	returns imaginary part of complex number
// 
//	parameter:	none
//	return:		imaginary part of complex number
//////////////////////////////////////////////////////////////////////
double complex::getImag()
{	
	return imag;
}

//////////////////////////////////////////////////////////////////////
//	print()
//
//	displays complex number on the screen, if imaginary part is zero 
//	then only real part is displayed, ff imaginary part is negative 
//	then "+" is omitted
//
//	Parameter:	none
//	Return:		void
//////////////////////////////////////////////////////////////////////
void complex::print()
{
	if (imag!=0)
	{
		cout<<"("<<real;
		if (imag>0)
			cout<<"+";
		cout<<imag<<"i)";
	}
	else cout<<real;
}

⌨️ 快捷键说明

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