Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "complex.h"
- complex::~complex(){}
- complex::complex(float x, float y){
- cout << "complex number created.\n";
- this->x = x;
- this->y = y;
- }
- float complex::abs(){
- return sqrt(this->x*this->x + this->y*this->y);
- }
- complex* complex::conjugate(){
- complex* ptr = new complex(this->x, -this->y);
- return ptr;
- }
- complex* complex::operator+(const complex& z){
- complex* res = new complex(this->x + z.x, this->y + z.y);
- return res;
- }
- complex* complex::operator-(const complex& z){
- complex* res = new complex(this->x - z.x, this->y - z.y);
- return res;
- }
- complex* complex::operator*(const complex& z){
- complex* res = new complex;
- res->x = this->x * z.x - this->y * z.y;
- res->y = this->x * z.y + this->y * z.x;
- return res;
- }
- complex* complex::operator/(const complex& z){
- complex* ptr = new complex;
- ptr->x = (this->x*z.x + this->y*z.y) / (z.x*z.x + z.y*z.y);
- ptr->y = (-this->x*z.y + this->y*z.x) / (z.x*z.x + z.y*z.y);
- return ptr;
- }
- complex* complex::operator+(float z){
- complex* res = new complex(this->x + z, this->y);
- return res;
- }
- complex* complex::operator-(float z){
- complex* res = new complex(this->x - z, this->y);
- return res;
- }
- complex* complex::operator*(float z){
- complex* res = new complex;
- res->x = this->x * z;
- res->y = this->y * z;
- return res;
- }
- complex* complex::operator/(float z){
- complex* ptr = new complex;
- ptr->x = this->x / z;
- ptr->y = this->y / z;
- return ptr;
- }
- complex* complex::operator+=(const complex& z){
- this->x += z.x;
- this->y += z.y;
- return this;
- }
- complex* complex::operator-=(const complex& z){
- this->x -= z.x;
- this->y -= z.y;
- return this;
- }
- complex* complex::operator*=(const complex& z){
- float x = this->x * z.x - this->y * z.y;
- float y = this->x * z.y + this->y * z.x;
- this->x = x; this->y = y;
- return this;
- }
- complex* complex::operator/=(const complex& z){
- float x = (this->x*z.x + this->y*z.y) / (z.x*z.x + z.y*z.y);
- float y = (-this->x*z.y + this->y*z.x) / (z.x*z.x + z.y*z.y);
- this->x = x; this->y = y;
- return this;
- }
- complex* complex::operator+=(float z){
- this->x += z;
- return this;
- }
- complex* complex::operator-=(float z){
- this->x -= z;
- return this;
- }
- complex* complex::operator*=(float z){
- this->x *= z;
- this->y *= z;
- return this;
- }
- complex* complex::operator/=(float z){
- this->x /= z;
- this->y /= z;
- return this;
- }
- ostream& operator<<(ostream& out, const complex& z){
- out << z.x << "+" << z.y << "i";
- return out;
- }
- istream& operator>>(istream& in, complex& z){
- cout << "x: ";
- in >> z.x;
- cout << "y: ";
- in >> z.y;
- return in;
- }
- complex* complex::e() {
- complex* ptr = new complex;
- ptr->x = (float)exp(x)*(float)cos(y);
- ptr->y = (float)exp(x)*(float)sin(y);
- return ptr;
- }
- complex* complex::sinus() {
- complex* ptr = new complex;
- ptr->x = (float)sin(x)*(float)cosh(y);
- ptr->y = (float)cos(x)*(float)sinh(y);
- return ptr;
- }
- complex* complex::cosinus() {
- complex* ptr = new complex;
- ptr->x = (float)cos(x)*(float)cosh(y);
- ptr->y = -(float)sin(x)*(float)sinh(y);
- return ptr;
- }
- complex* complex::tangent() {
- complex* ptr = sinus();
- complex* ptr2 = cosinus();
- complex* ptr3 = *ptr / *ptr2;
- delete ptr, ptr2;
- return ptr3;
- }
- complex* complex::reciprocal(){
- float scale = x*x + y*y;
- complex* ptr = new complex(x / scale, -y / scale);
- return ptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment