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

📄 complex.cpp

📁 多项式与常数和多项式之间的加减乘除等运算
💻 CPP
字号:
//////////////////////////////////////////////////////////////////////
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -