重载了复数类的 加减乘除, 取模,虚部,实部,夹角,共轭, 指数,对数,开根,sin,cos, 以及输出运算符, 自加,自减运算符, 比较运算符,
Complex.h
#pragma once
#include
#include
#include
using namespace std;
class Complex
{
public:
Complex();
Complex(double xr,double xi);
void setR(double xr);
void setI(double xi);
void print();
Complex operator+(Complex y);
Complex operator-(Complex y);
Complex operator*(Complex y);
Complex operator/(Complex y);
Complex operator!();
Complex operator+(double c);
Complex operator-(double c);
Complex operator*(double c);
Complex operator/(double c);
Complex operator^(int t);
friend Complex operator+(double c, Complex x);
friend Complex operator-(double c, Complex x);
friend Complex operator*(double c, Complex x);
friend Complex operator/(double c, Complex x);
friend Complex operator-(Complex y);
/*friend Complex operator++(Complex y);*/
/*void operator++();
void operator--();
void operator++(int);
void operator--(int);*/
Complex operator++();
Complex operator--();
Complex operator++(int);
Complex operator--(int);
friend double Re(Complex x);
friend double Im(Complex x);
friend double Mod(Complex x);
friend double Eta(Complex x);
friend Complex Sqrt(Complex x);
friend Complex Cos(Complex x);
friend Complex Sin(Complex x);
friend Complex Ln(Complex x);
friend Complex Unit(Complex x);
friend ostream& operatori == 0) { cout r += 1;
this->i += 1;
}
Complex Complex::operator--(int) {
return *this;
this->r -= 1;
this->i -= 1;
}
Complex Complex::operator+(double c) {
Complex x(this->r + c, this->i);
return x;
}
Complex Complex::operator-(double c) {
Complex x(this->r - c, this->i);
return x;
}
Complex Complex::operator*(double c) {
Complex x(this->r * c, this->i * c);
return x;
}
Complex Complex::operator/(double c){
Complex x(this->r / c, this->i / c);
return x;
}
Complex operator+(double c, Complex x) {
Complex y(x.r + c, x.i);
return y;
}
Complex operator-(double c, Complex x) {
Complex y(x.r - c, x.i);
return y;
}
Complex operator*(double c, Complex x) {
Complex y(x.r * c, x.i * c);
return y;
}
Complex operator/(double c, Complex x) {
return c * (!x) / (x*(!x));
}
double Re(Complex x) { return x.r; };
double Im(Complex x) { return x.i; };
double Mod(Complex x) { return sqrt(Re(x*(!x))); }
double Eta(Complex x) { return acos(Unit(x).r); }
Complex Sqrt(Complex x) {
Exp e;
Complex i(0, 1);
Complex y = sqrt(Mod(x))*(e^((Eta(x)/2)*i));
return y;
}
Complex Cos(Complex x) {
Exp e;
Complex y = ((e^x) + (e ^ (-x)))/2;
return y;
}
Complex Sin(Complex x) {
Exp e;
Complex i(0, 1);
Complex y = ((e^x) - (e ^ (-x))) / (2*i);
return y;
}
Complex Ln(Complex x) {
Complex y(log(Mod(x)),Eta(x));
return y;
}
Complex Unit(Complex x) { return x / Mod(x); }
ostream& operator
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?