Template class Komplex alt
komplex.h
Go to the documentation of this file.
1 #pragma once
2 #include <cmath> // sqrt()
3 #include <iostream>
4 //using namespace std;
5 
12 template <class T>
13 class Komplex
14 {
15 public:
19  // |-- Standardwert
20  Komplex(T re, T im=0.0); // Parameterkonstruktor mit ein oder zwei Argumenten
21 
22  Komplex(const Komplex<T>& orig) = default;
23  Komplex<T>& operator=(const Komplex<T>& rhs) = default;
24 
26  virtual ~Komplex();
30  // |-- Member der Instanz werden durch die Methode nicht veraendert!
31  T Get_re() const
32  {
33  return _re;
34  }
38  void Set_re(T val)
39  {
40  _re = val;
41  }
45  // |-- Member der Instanz werden durch die Methode nicht veraendert!
46  T Get_im() const
47  {
48  return _im;
49  }
53  void Set_im(T val)
54  {
55  _im = val;
56  }
57 
63 
68  // |-- Member der Instanz werden durch die Methode nicht veraendert!
69  Komplex<T> operator+(const Komplex<T>& rhs) const;
70 
71  bool operator<(const Komplex<T>& rhs) const
72  {
73  return _re < rhs._re || ( _re == rhs._re && _im < rhs._im );
74  }
75 
76  bool operator==(const Komplex<T>& rhs) const
77  {
78  return _re == rhs._re && _im == rhs._im ;
79  }
80 
81  bool operator>(const Komplex<T>& rhs) const
82  {
83  return !( *this < rhs || *this== rhs ) ;
84  }
85 
90 template <class S>
91 friend std::ostream& operator<<(std::ostream& s, const Komplex<S>& rhs);
92 
93 protected:
94 private:
95  T _re;
96  T _im;
97 };
98 
103 //
104 //template <class T>
105 //ostream& operator<<(ostream& s, const Komplex<T>& rhs);
106 //
107 // /** Addiert zu einer reellen Zahl eine komplexe Zahl
108 // * \param[in] lhs relle Zahl
109 // * \param[in] rhs komplexe Zahl
110 // * \return \p lhs + \p rhs
111 // */
112 //template <class T>
113 //Komplex<T> operator+(T lhs, const Komplex<T>& rhs);
114 
115 
116 template <class T>
117 T abs(const Komplex<T>& rhs)
118 {
119  return std::sqrt(rhs.Get_re()*rhs.Get_re()+rhs.Get_im()*rhs.Get_im());
120 }
121 
122 #include "komplex.tpp"
bool operator<(const Komplex< T > &rhs) const
Definition: komplex.h:71
Komplex(T re, T im=0.0)
bool operator==(const Komplex< T > &rhs) const
Definition: komplex.h:76
T Get_im() const
Definition: komplex.h:46
Komplex< T > & operator+=(const Komplex< T > &rhs)
friend std::ostream & operator<<(std::ostream &s, const Komplex< S > &rhs)
Komplex(const Komplex< T > &orig)=default
virtual ~Komplex()
T Get_re() const
Definition: komplex.h:31
Komplex< T > operator+(const Komplex< T > &rhs) const
void Set_re(T val)
Definition: komplex.h:38
void Set_im(T val)
Definition: komplex.h:53
bool operator>(const Komplex< T > &rhs) const
Definition: komplex.h:81
Komplex< T > & operator=(const Komplex< T > &rhs)=default
T abs(const Komplex< T > &rhs)
Definition: komplex.h:117