Class Komplex + STL
Loading...
Searching...
No Matches
komplex.h
Go to the documentation of this file.
1#pragma once
2#include <cmath> // hypot()
3#include <iostream>
4
7class Komplex
8{
9public:
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
73 // |-- Membervariablen werden durch die Methode nicht veraendert!
74 bool operator<(const Komplex& rhs) const
75 {
76 return _re < rhs._re;
77 }
78
84 // |-- Membervariablen werden durch die Methode nicht veraendert!
85 double abs() const
86 {
87 return std::hypot(_re,_im);
88 }
89
90protected:
91private:
92 double _re;
93 double _im;
94};
95
96// normale Funktionen
97
103std::ostream& operator<<(std::ostream& s, const Komplex& rhs);
104
110std::istream& operator>>(std::istream& s, Komplex& rhs);
111
112
118inline // Implementierung im Header
119Komplex operator+(const Komplex& lhs, const Komplex& rhs)
120{
121 Komplex tmp(lhs);
122 return tmp+=rhs;
123}
124
125
Komplex()
Definition komplex.cpp:8
bool operator<(const Komplex &rhs) const
Definition komplex.h:74
void Set_re(double val)
Definition komplex.h:40
double abs() const
Definition komplex.h:85
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 & operator=(Komplex &&rhs)=default
Komplex(Komplex &&org)=default
double Get_re() const
Definition komplex.h:32
~Komplex()=default
std::ostream & operator<<(std::ostream &s, const Komplex &rhs)
std::istream & operator>>(std::istream &s, Komplex &rhs)
Komplex operator+(const Komplex &lhs, const Komplex &rhs)
Definition komplex.h:119