Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 08 / Complex
diff options
context:
space:
mode:
Commit8cf1283a4ffb9fe1901c29c087fa376de82726af (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2022-02-19 23:30:52 +0200
Committer
 angeld55 <angel_dimitriev@abv.bg>
2022-02-19 23:30:52 +0200
Filesabdfe6bf526100dcce87a88563100e02adf7605e /Sem. 08/Complex
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.tar
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.tar.gz
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.zip
Parentd73a7ec225516657dec74472a0491330e9999217 (diff)
clean up
3 files changed, 0 insertions, 145 deletions
-rw-r--r--Sem. 08/Complex/Complex.cpp102
-rw-r--r--Sem. 08/Complex/Complex.h34
-rw-r--r--Sem. 08/Complex/Source.cpp9
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::ostream& operator<<(std::ostream& ofs, const Complex& r) {
-
- return ofs << r.real << ' ' << r.im << 'i';
-}
-
-// за да можем да правим cin>>c1 или да четем от файл и др.
-std::istream& operator>>(std::istream& ifs, Complex& r) {
-
- return ifs >> r.real >> r.im;
-}
diff --git a/Sem. 08/Complex/Complex.h b/Sem. 08/Complex/Complex.h
deleted file mode 100644
index d76a2f3..0000000
--- a/Sem. 08/Complex/Complex.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#include <iostream>
-class Complex
-{
-private:
- double real;
- double im;
-
-public:
- Complex();
- Complex(double real, double im);
-
- Complex getConjugated() const; //връща комплексно спрегнатото число на текущия обект.
-
- //assignment operators
- // a+=b Към а се добавя стойността на b. а се променя , b не се. Операцията ще върне a за да може да се правят верижни изрази (a+=b+=c)
- Complex& operator+=(const Complex&);
- Complex& operator-=(const Complex&);
- Complex& operator*=(const Complex&);
- Complex& operator/=(const Complex&);
-
-
-
- //stream opeartors ( std::cout>> c1) (std::cin<<c1 )
- friend std::ostream& operator<<(std::ostream&, const Complex&);
- friend std::istream& operator>>(std::istream&, Complex&);
-
-};
-// a+b. Операторът връща НОВА променлива(Complex), която е резултатът от операцията.
-Complex operator+(const Complex&, const Complex&);
-Complex operator-(const Complex&, const Complex&);
-Complex operator*(const Complex&, const Complex&);
-Complex operator/(const Complex&, const Complex&);
-
-
diff --git a/Sem. 08/Complex/Source.cpp b/Sem. 08/Complex/Source.cpp
deleted file mode 100644
index 32f9e17..0000000
--- a/Sem. 08/Complex/Source.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "Complex.h"
-
-int main()
-{
- Complex c(3, 4);
- Complex c2(3, 4);
-
- std::cout << c* c2;
-}