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

📄 complex.cpp

📁 ThinkingC++中文版
💻 CPP
字号:
#include "complex.h"
#include "math.h"
#include "iostream.h"

//全局函数
const complex operator+( const complex& x, const complex& y) //y是加数,x是被加数
{
	complex temp(x.rpart+y.rpart,x.ipart+y.ipart);
    return temp;
}


const complex operator*( const complex& x, const complex& y) 
{
	complex temp(sqrt(x.rpart+y.rpart),sqrt(x.ipart+y.ipart));
    return temp;
}


ostream& operator<<(ostream& os, const complex& com)
{
    os << "(" << com.rpart;
	if(com.ipart)
		os << "," << com.ipart << "i";
	os << ")" << endl;
	return os;
}

//cout << a; complier翻译成operator<<(cout,a)
//cout << a << b ;complier翻译成operator<<( operator<<(cout,a),b );

istream& operator>>(istream& is, complex& com)
{
	is >> com.rpart >>com.ipart;
	return is;
}


⌨️ 快捷键说明

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