重载了复数类的 加减乘除, 取模,虚部,实部,夹角,共轭, 指数,对数,开根,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
关注
打赏