Klasse Komplex
komplex.h
Go to the documentation of this file.
1 #ifndef KOMPLEX_H
2 #define KOMPLEX_H
3 #include <cmath>
4 #include <iostream>
5 //using namespace std;
6 
9 class Komplex
10 {
11 public:
13  Komplex();
18  // |-- Standardwert
19  Komplex(double re, double im=0.0); // Parameterkonstruktor mit ein oder zwei Argumenten
20 
24  //
25  Komplex(const Komplex& org); // Kopierkonstruktor
26 
28  virtual ~Komplex();
29 
36  Komplex& operator=(const Komplex& rhs); // Zuweisungsoperator
37 
38 
42  // |-- Membervariablen werden durch die Methode nicht veraendert!
43  double Get_re() const
44  {
45  return _re;
46  }
47 
51  void Set_re(double val)
52  {
53  _re = val;
54  }
55 
59  // |-- Membervariablen werden durch die Methode nicht veraendert!
60  double Get_im() const
61  {
62  return _im;
63  }
64 
68  void Set_im(double val)
69  {
70  _im = val;
71  }
72 
77  Komplex& operator+=(const Komplex& rhs);
78 
83  // |-- Membervariablen werden durch die Methode nicht veraendert!
84  Komplex operator+(const Komplex& rhs) const;
85 
89  double abs() const
90  {
91  return std::sqrt(_re*_re+_im*_im);
92  }
93 
94 protected:
95 private:
96  double _re;
97  double _im;
98 };
99 
100 // normale Funktionen
101 
106 std::ostream& operator<<(std::ostream& s, const Komplex& rhs);
107 
113 Komplex operator+(double lhs, const Komplex& rhs);
114 
115 
119 inline // otherwise liker problem
120 double abs(Komplex const& rhs)
121 {
122  return rhs.abs(); // call of Komplex::abs()
123 }
124 #endif // KOMPLEX_H
Komplex & operator+=(const Komplex &rhs)
Definition: komplex.cpp:40
void Set_re(double val)
Definition: komplex.h:51
std::ostream & operator<<(std::ostream &s, const Komplex &rhs)
virtual ~Komplex()
Definition: komplex.cpp:25
void Set_im(double val)
Definition: komplex.h:68
double abs() const
Definition: komplex.h:89
Komplex()
Definition: komplex.cpp:7
Definition: komplex.h:9
Komplex operator+(const Komplex &rhs) const
Definition: komplex.cpp:54
double Get_im() const
Definition: komplex.h:60
Komplex & operator=(const Komplex &rhs)
Assignment operator.
Definition: komplex.cpp:30
double Get_re() const
Definition: komplex.h:43