Class Komplex + STL
komplex.h
Go to the documentation of this file.
1 #pragma once
2 #include <cmath> // hypot()
3 #include <iostream>
4 
7 class Komplex
8 {
9 public:
11  Komplex();
16  // |-- Standardwert
17  Komplex(double re, double im=0.0); // Parameterkonstruktor mit ein oder zwei Argumenten
18 
19  // See rule of five
20  // https://en.cppreference.com/w/cpp/language/rule_of_three
21  //
22  Komplex(const Komplex& org) = default; // Copykonstruktor
23  Komplex( Komplex&& org) = default; // Movekonstruktor
24  Komplex& operator=(const Komplex& rhs) = default; // Copy-Zuweisungsoperator
25  Komplex& operator=( Komplex&& rhs) = default; // Move-Zuweisungsoperator
26  ~Komplex() = default; // Destruktor
27 
31  // |-- Membervariablen werden durch die Methode nicht veraendert!
32  double Get_re() const
33  {
34  return _re;
35  }
36 
40  void Set_re(double val)
41  {
42  _re = val;
43  }
44 
48  // |-- Membervariablen werden durch die Methode nicht veraendert!
49  double Get_im() const
50  {
51  return _im;
52  }
53 
57  void Set_im(double val)
58  {
59  _im = val;
60  }
61 
66  Komplex& operator+=(const Komplex& rhs);
67 
72  // |-- Membervariablen werden durch die Methode nicht veraendert!
73  //Komplex operator+(const Komplex& rhs) const;
74 
80  // |-- Membervariablen werden durch die Methode nicht veraendert!
81  bool operator<(const Komplex& rhs) const
82  {
83  return _re < rhs._re;
84  }
85 
91  // |-- Membervariablen werden durch die Methode nicht veraendert!
92  double abs() const
93  {
94  return std::hypot(_re,_im);
95  }
96 
97 protected:
98 private:
99  double _re;
100  double _im;
101 };
102 
103 // normale Funktionen
104 
110 std::ostream& operator<<(std::ostream& s, const Komplex& rhs);
111 
117 std::istream& operator>>(std::istream& s, Komplex& rhs);
118 
119 
125 inline
126 Komplex operator+(const Komplex& lhs, const Komplex& rhs)
127 {
128  Komplex tmp(lhs);
129  return tmp+=rhs;
130 }
131 
132 
Definition: komplex.h:8
Komplex & operator=(Komplex &&rhs)=default
Komplex()
Definition: komplex.cpp:8
bool operator<(const Komplex &rhs) const
Definition: komplex.h:81
void Set_re(double val)
Definition: komplex.h:40
double abs() const
Definition: komplex.h:92
Komplex & operator=(const Komplex &rhs)=default
void Set_im(double val)
Definition: komplex.h:57
double Get_im() const
Definition: komplex.h:49
Komplex & operator+=(const Komplex &rhs)
Definition: komplex.cpp:16
Komplex(const Komplex &org)=default
Komplex(Komplex &&org)=default
double Get_re() const
Definition: komplex.h:32
~Komplex()=default
std::istream & operator>>(std::istream &s, Komplex &rhs)
std::ostream & operator<<(std::ostream &s, const Komplex &rhs)
Komplex operator+(const Komplex &lhs, const Komplex &rhs)
Definition: komplex.h:126