uebung2
Vunic_01_Klassen_Namespace.cpp@2:45235e48ddd6, 2020-04-28 (annotated)
- Committer:
- fatima365
- Date:
- Tue Apr 28 12:46:51 2020 +0000
- Revision:
- 2:45235e48ddd6
- Parent:
- 1:ce6d8e5dd0dd
tinf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fatima365 | 1:ce6d8e5dd0dd | 1 | #include <stdio.h> |
fatima365 | 1:ce6d8e5dd0dd | 2 | #include <iostream> |
fatima365 | 1:ce6d8e5dd0dd | 3 | |
fatima365 | 1:ce6d8e5dd0dd | 4 | using namespace std; |
fatima365 | 1:ce6d8e5dd0dd | 5 | |
fatima365 | 1:ce6d8e5dd0dd | 6 | enum eckig {ja, nein}; |
fatima365 | 1:ce6d8e5dd0dd | 7 | |
fatima365 | 1:ce6d8e5dd0dd | 8 | namespace vunic { |
fatima365 | 1:ce6d8e5dd0dd | 9 | |
fatima365 | 1:ce6d8e5dd0dd | 10 | class Kreis |
fatima365 | 1:ce6d8e5dd0dd | 11 | { |
fatima365 | 1:ce6d8e5dd0dd | 12 | private: |
fatima365 | 1:ce6d8e5dd0dd | 13 | float m_radius; |
fatima365 | 1:ce6d8e5dd0dd | 14 | eckig m_hat_ecken; |
fatima365 | 1:ce6d8e5dd0dd | 15 | |
fatima365 | 1:ce6d8e5dd0dd | 16 | public: |
fatima365 | 1:ce6d8e5dd0dd | 17 | Kreis(float radius); |
fatima365 | 1:ce6d8e5dd0dd | 18 | Kreis(); |
fatima365 | 1:ce6d8e5dd0dd | 19 | Kreis(eckig x); |
fatima365 | 1:ce6d8e5dd0dd | 20 | |
fatima365 | 1:ce6d8e5dd0dd | 21 | int neu(); |
fatima365 | 1:ce6d8e5dd0dd | 22 | float berechneUmfang(); |
fatima365 | 1:ce6d8e5dd0dd | 23 | eckig hat_ecken(); |
fatima365 | 1:ce6d8e5dd0dd | 24 | |
fatima365 | 1:ce6d8e5dd0dd | 25 | }; |
fatima365 | 1:ce6d8e5dd0dd | 26 | |
fatima365 | 1:ce6d8e5dd0dd | 27 | Kreis::Kreis(float radius) { |
fatima365 | 1:ce6d8e5dd0dd | 28 | m_radius = radius; |
fatima365 | 1:ce6d8e5dd0dd | 29 | m_hat_ecken = nein; |
fatima365 | 1:ce6d8e5dd0dd | 30 | } |
fatima365 | 1:ce6d8e5dd0dd | 31 | |
fatima365 | 1:ce6d8e5dd0dd | 32 | Kreis::Kreis() { |
fatima365 | 1:ce6d8e5dd0dd | 33 | m_radius = 0; |
fatima365 | 1:ce6d8e5dd0dd | 34 | m_hat_ecken = nein; |
fatima365 | 1:ce6d8e5dd0dd | 35 | } |
fatima365 | 1:ce6d8e5dd0dd | 36 | Kreis::Kreis(eckig x){ |
fatima365 | 1:ce6d8e5dd0dd | 37 | m_radius = 3; |
fatima365 | 1:ce6d8e5dd0dd | 38 | m_hat_ecken =x; |
fatima365 | 1:ce6d8e5dd0dd | 39 | } |
fatima365 | 1:ce6d8e5dd0dd | 40 | |
fatima365 | 1:ce6d8e5dd0dd | 41 | float Kreis::berechneUmfang() { |
fatima365 | 1:ce6d8e5dd0dd | 42 | return (m_radius * m_radius * 3.1415);} |
fatima365 | 1:ce6d8e5dd0dd | 43 | |
fatima365 | 1:ce6d8e5dd0dd | 44 | eckig Kreis::hat_ecken(){ |
fatima365 | 1:ce6d8e5dd0dd | 45 | return m_hat_ecken; |
fatima365 | 1:ce6d8e5dd0dd | 46 | } |
fatima365 | 1:ce6d8e5dd0dd | 47 | } |
fatima365 | 1:ce6d8e5dd0dd | 48 | |
fatima365 | 1:ce6d8e5dd0dd | 49 | int main () |
fatima365 | 1:ce6d8e5dd0dd | 50 | { |
fatima365 | 1:ce6d8e5dd0dd | 51 | using namespace vunic; |
fatima365 | 1:ce6d8e5dd0dd | 52 | Kreis meineForm(2.0); |
fatima365 | 1:ce6d8e5dd0dd | 53 | float um = meineForm.berechneUmfang(); |
fatima365 | 1:ce6d8e5dd0dd | 54 | printf ("Der Umfang beträgt: %f\n", um); |
fatima365 | 1:ce6d8e5dd0dd | 55 | |
fatima365 | 1:ce6d8e5dd0dd | 56 | Kreis meinKreis(); |
fatima365 | 1:ce6d8e5dd0dd | 57 | eckig eck = nein; |
fatima365 | 1:ce6d8e5dd0dd | 58 | Kreis kr (eck); |
fatima365 | 1:ce6d8e5dd0dd | 59 | printf ("Ecken: %i\n", kr); |
fatima365 | 1:ce6d8e5dd0dd | 60 | |
fatima365 | 1:ce6d8e5dd0dd | 61 | eckig ergebnis = kr.hat_ecken(); |
fatima365 | 1:ce6d8e5dd0dd | 62 | printf ("Ergebnis: %i\n", ergebnis); |
fatima365 | 1:ce6d8e5dd0dd | 63 | |
fatima365 | 1:ce6d8e5dd0dd | 64 | return 0; |
fatima365 | 1:ce6d8e5dd0dd | 65 | } |