-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex_operators.h
More file actions
40 lines (32 loc) · 1.09 KB
/
complex_operators.h
File metadata and controls
40 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include<iostream>
using namespace std;
//复数类
class Complex
{
public:
//构造函数
Complex(double r = 0.0, double i = 0.0) { re = r; im = i; }
//运算符重载
friend Complex operator + (Complex& c1, Complex& c2);
friend Complex operator + (double& d1, Complex& c2);
friend Complex operator + (Complex& c1, double& d2);
friend Complex operator - (Complex& c1, Complex& c2);
friend Complex operator - (double& d1, Complex& c2);
friend Complex operator - (Complex& c1, double& d2);
friend Complex operator * (Complex& c1, Complex& c2);
friend Complex operator * (double& d1, Complex& c2);
friend Complex operator * (Complex& c1, double& d2);
friend Complex operator / (Complex& c1, Complex& c2);
friend Complex operator / (double& d1, Complex& c2);
friend Complex operator / (Complex& c1, double& d2);
//虚数单位用j表示
friend ostream& operator << (ostream& out, Complex& c1);
friend istream& operator >> (istream& in, Complex& c1);
Complex operator !();
//常用操作
//求模值
double modulus();
public: //为了单独访问实部
double re, im;
};