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

📄 complextype.cpp

📁 data+structures+using+c的源码
💻 CPP
字号:

//Implementation file complexType.cpp

#include <iostream>
using namespace std;

#include "complexType.h"

ostream& operator<<(ostream& osObject, const complexType& complex)
{
	osObject<<"(";						//Step a
	osObject<<complex.realPart;			//Step b
	osObject<<", ";						//Step c
	osObject<<complex.imaginaryPart;	//Step d
	osObject<<")";						//Step e

	return osObject;			
}

istream& operator>> (istream& isObject, complexType& complex)
{
	char ch;

	isObject>>ch;                     //Step a
	isObject>>complex.realPart;       //Step b
	isObject>>ch;                     //Step c
	isObject>>complex.imaginaryPart;  //Step d
	isObject>>ch;                     //Step e

	return isObject;			
}


bool complexType::operator==(const complexType& otherComplex) const
{
	return(realPart == otherComplex.realPart && 
	      imaginaryPart == otherComplex.imaginaryPart);
}

void complexType::setComplex(const double& real, const double& imag)
{
	realPart = real;
	imaginaryPart = imag;
}

	//constructor 
complexType::complexType(double real, double imag)
{
     setComplex(real, imag);
}

	//Overload the operator +	
complexType complexType::operator+
 	                (const complexType& otherComplex) const
{
	complexType temp;

	temp.realPart = realPart + otherComplex.realPart;
	temp.imaginaryPart = imaginaryPart 
	                     + otherComplex.imaginaryPart;

	return temp;
}

	//Overload the operator *
complexType complexType::operator*
 				 (const complexType& otherComplex) const
{
   complexType temp;

   temp.realPart = (realPart * otherComplex.realPart) -
                   (imaginaryPart * otherComplex.imaginaryPart);
   temp.imaginaryPart = (realPart * otherComplex.imaginaryPart)  
	                  + (imaginaryPart * otherComplex.realPart);
   return temp;
}

⌨️ 快捷键说明

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