From 8cf1283a4ffb9fe1901c29c087fa376de82726af Mon Sep 17 00:00:00 2001 From: angeld55 Date: Sat, 19 Feb 2022 23:30:52 +0200 Subject: clean up --- Sem. 08/Complex/Complex.cpp | 102 -------------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 Sem. 08/Complex/Complex.cpp (limited to 'Sem. 08/Complex/Complex.cpp') diff --git a/Sem. 08/Complex/Complex.cpp b/Sem. 08/Complex/Complex.cpp deleted file mode 100644 index c604d0a..0000000 --- a/Sem. 08/Complex/Complex.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "Complex.h" - -Complex::Complex() -{ - real = 0; - im = 0; -} -Complex::Complex(double real, double im) -{ - this->real = real; - this->im = im; -} -Complex& Complex::operator+=(const Complex& other) -{ - real += other.real; - im += other.im; - return *this; -} -Complex& Complex::operator-=(const Complex& other) -{ - real -= other.real; - im -= other.im; - return *this; -} -Complex& Complex::operator*=(const Complex& other) -{ - int oldReal = real; - real = real*other.real - im*other.im; - im = oldReal*other.im + im * other.real; - return *this; -} -Complex& Complex::operator/=(const Complex& other) // a/=b -{ - Complex Conjugated = other.getConjugated(); //взимаме комплексно спрегнатата на другата дроб (b) - - Complex otherCopy(other);// копираме другата (b), за да не я промяняме. - - //Умножаваме двете по комплексно спрегнатата. - *this *= Conjugated; - otherCopy *= Conjugated; //Тук трябва да остане само реална част. - - if (otherCopy.real != 0) - { - real /= otherCopy.real; - im /= otherCopy.real; - } - - return *this; -} - - -//След дефинирането на +=, -=, *= и /=, можем лесно да дефинираме +, -, * и /, преизползвайки вече написаните опратори. -Complex operator+(const Complex& lhs, const Complex& rhs) { //a+b - - Complex result(lhs); // Създаваме нов обект, който е копие на a (използваме копи-конструктора) - result += rhs; //към копието на a, добавяме b (Използваме вече дефинирания оператор +=) - - return result; -} -//Операторите -, *, / са аналогични с +. -Complex operator-(const Complex& lhs, const Complex& rhs) { - Complex result(lhs); - result -= rhs; - - return result; -} - -Complex operator*(const Complex& lhs, const Complex& rhs) { - - Complex result(lhs); - result *= rhs; - - return result; -} - -Complex operator/(const Complex& lhs, const Complex& rhs) { - - Complex result(lhs); - result /= rhs; - - return result; -} - -Complex Complex::getConjugated() const -{ - Complex result(*this); - result.im *= -1; - - return result; -} - -// за да можем да правим cout<>c1 или да четем от файл и др. -std::istream& operator>>(std::istream& ifs, Complex& r) { - - return ifs >> r.real >> r.im; -} -- cgit v1.3.1-23-gd82d