#include "CKomplex.h" #include // Konstruktor mit zwei Argumenten für a + b*j CKomplex::CKomplex() : real(0), imag(0) { } // Konstruktor mit zwei Argumenten für a + b*j CKomplex::CKomplex(double a, double b) : real(a), imag(b) { } // Konstruktor mit einem Argument für e^(j*phi) CKomplex::CKomplex(double phi) : real(cos(phi)), imag(sin(phi)) { } // Methode zur Rückgabe des Realteils double CKomplex::re() const { return real; } // Methode zur Rückgabe des Imaginärteils double CKomplex::im() const { return imag; } // Überladene Methode für die Addition von zwei komplexen Zahlen CKomplex CKomplex::operator+(const CKomplex &other) const { double a = real + other.real; double b = imag + other.imag; return CKomplex(a, b); } // Überladene Methode für die Subtraktion von zwei komplexen Zahlen CKomplex CKomplex::operator-(const CKomplex &other) const { double a = real - other.real; double b = imag - other.imag; return CKomplex(a, b);} // Überladene Methode für die Multiplikation von zwei komplexen Zahlen CKomplex CKomplex::operator*(const CKomplex &other) const { double a = real * other.real - imag * other.imag; double b = real * other.imag + imag * other.real; return CKomplex(a, b); } // Überladene Methode für die Multiplikation einer double-Zahl mit einer komplexen Zahl CKomplex CKomplex::operator*(double scalar) const { double a = real * scalar; double b = imag * scalar; return CKomplex(a, b); } // Methode zur Berechnung des Betrags der komplexen Zahl double CKomplex::abs() const { return sqrt(real * real + imag * imag); }