complex.h

来自「ThinkingC++中文版」· C头文件 代码 · 共 37 行

H
37
字号
#include "iostream.h"


class complex{
private:   
	double rpart;
    double ipart;
public:     
	complex() //complex a;
	{
		rpart = ipart = 0.0;
	}
	complex(double rp,double ip) //complex b(1.1,2.2);
	{  
		rpart=rp;   
		ipart=ip; 
	}			  
	
	complex(double d)//complex c(3.3);
	{
		rpart = d;
		ipart=0.0;
	}

	const complex add(const complex& com);
	const complex operator+(const complex& com); //成员函数版
//  friend const complex operator+(const complex& x, const complex& y);//友员函数版
	friend const complex operator*( const complex& x, const complex& y);

	complex operator-();//单目减  ,不能写成const complex operator-()  因为:-a+b
	void print();

	friend ostream& operator<<(ostream& os, const complex& com);
    friend istream& operator>>(istream& is, complex& com);

};

⌨️ 快捷键说明

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