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

📄 12vi.cpp

📁 C/C++程序设计导论(第二版)》程序源文件
💻 CPP
字号:
// complex3.cpp  Implementation file for class Complex using
// overloaded arithmetic and insertion, extraction operators
#include <iostream.h>
#include "complex3.h"

// `+' operator  Returns the sum of the owner and the parameter
Complex Complex::operator + (Complex x)
{	Complex temp;
	temp.real = real + x.real;
	temp.imag = imag + x.imag;
	return (temp);
}

// `-' operator  Returns the diff. between the owner and parameter
Complex Complex::operator - (Complex x)
{	Complex temp;
	temp.real = real - x.real;
	temp.imag = imag - x.imag;
	return (temp);
}

// `*' operator  Returns the product of  the owner and the parameter
Complex Complex::operator * ( Complex x)
{	Complex temp;
	temp.real = (real*x.real) - (imag*x.imag);
	temp.imag = (imag * x.real) + (real * x.imag);
	return (temp);
}

// InputC()  Input a complex pair into owner
void Complex::InputC (istream& in)
{	char i, paren, comma;
	in >> paren >> real >> comma >> imag >> i >> paren;
}

// OutputC()  Output the owner as a complex pair
void Complex::OutputC (ostream& out)
{	out << '(' << real << ',' << imag << "i)" << endl;
}

// wrapper function for the extraction `>>' operator
istream& operator >> (istream& in, Complex& x)
{	x.InputC (in);
	return (in);
}

// wrapper function for the insertion `<<' operator
ostream& operator << (ostream& out, Complex x)
{	x.OutputC (out);
	return (out);
}

⌨️ 快捷键说明

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