From b685a3dfae77ea1b7c4d9fff850cfd58259ac7c6 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 29 Apr 2026 17:08:29 +0200 Subject: [PATCH] Aufgabe 6: Verkehrsmittel --- 6_Verkehrsmittel/Luftfahrzeug.cpp | 15 +++++++++++++++ 6_Verkehrsmittel/Luftfahrzeug.h | 15 +++++++++++++++ 6_Verkehrsmittel/PKW.h | 14 ++++++++++++++ 6_Verkehrsmittel/Radfahrzeug.cpp | 13 +++++++++++++ 6_Verkehrsmittel/Radfahrzeug.h | 14 ++++++++++++++ 6_Verkehrsmittel/Verkehrsmittel.cpp | 20 ++++++++++++++++++++ 6_Verkehrsmittel/Verkehrsmittel.h | 18 ++++++++++++++++++ 6_Verkehrsmittel/check.cpp | 2 +- 6_Verkehrsmittel/pkw.cpp | 15 +++++++++++++++ 9 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 6_Verkehrsmittel/Luftfahrzeug.cpp create mode 100644 6_Verkehrsmittel/Luftfahrzeug.h create mode 100644 6_Verkehrsmittel/PKW.h create mode 100644 6_Verkehrsmittel/Radfahrzeug.cpp create mode 100644 6_Verkehrsmittel/Radfahrzeug.h create mode 100644 6_Verkehrsmittel/Verkehrsmittel.cpp create mode 100644 6_Verkehrsmittel/Verkehrsmittel.h create mode 100644 6_Verkehrsmittel/pkw.cpp diff --git a/6_Verkehrsmittel/Luftfahrzeug.cpp b/6_Verkehrsmittel/Luftfahrzeug.cpp new file mode 100644 index 0000000..7e30d98 --- /dev/null +++ b/6_Verkehrsmittel/Luftfahrzeug.cpp @@ -0,0 +1,15 @@ +#include "Luftfahrzeug.h" +#include "Verkehrsmittel.h" +#include +#include + +using namespace std; + +string Luftfahrzeug::text() +{ + stringstream ausgabe; + + ausgabe << "Luftfahrzeug - Position x: " << x << "; Position y: " << y << "; max. Höhe: " << max_hoehe; + + return ausgabe.str(); +} \ No newline at end of file diff --git a/6_Verkehrsmittel/Luftfahrzeug.h b/6_Verkehrsmittel/Luftfahrzeug.h new file mode 100644 index 0000000..9ef8ccb --- /dev/null +++ b/6_Verkehrsmittel/Luftfahrzeug.h @@ -0,0 +1,15 @@ +#pragma once +#include +#include "Verkehrsmittel.h" + +class Luftfahrzeug : public Verkehrsmittel{ + int max_hoehe; + int z; + + public: + Luftfahrzeug() : max_hoehe(0), z(0) {} + Luftfahrzeug(int max_hoehe) : max_hoehe(max_hoehe), z(0) {} + Luftfahrzeug(int max_hoehe, int z) : max_hoehe(max_hoehe), z(z) {} + + std::string text(); +}; \ No newline at end of file diff --git a/6_Verkehrsmittel/PKW.h b/6_Verkehrsmittel/PKW.h new file mode 100644 index 0000000..610fef9 --- /dev/null +++ b/6_Verkehrsmittel/PKW.h @@ -0,0 +1,14 @@ +#pragma once +#include "Verkehrsmittel.h" +#include "Radfahrzeug.h" +#include + +class PKW : public Radfahrzeug{ + const int anzahl_tueren; + + public: + PKW() : Radfahrzeug(4), anzahl_tueren(4) {} + PKW(int anzahl_raeder, int anzahl_tueren) : Radfahrzeug(anzahl_raeder), anzahl_tueren(anzahl_tueren) {} + + string text(); +}; \ No newline at end of file diff --git a/6_Verkehrsmittel/Radfahrzeug.cpp b/6_Verkehrsmittel/Radfahrzeug.cpp new file mode 100644 index 0000000..a2960e6 --- /dev/null +++ b/6_Verkehrsmittel/Radfahrzeug.cpp @@ -0,0 +1,13 @@ +#include "Radfahrzeug.h" +#include + +using namespace std; + +string Radfahrzeug::text() +{ + stringstream ausgabe; + + ausgabe << "Radfahrzeug - Position x: " << x << "; Position y: " << y << "; Anzahl Räder: " << anzahl_raeder; + + return ausgabe.str(); +} \ No newline at end of file diff --git a/6_Verkehrsmittel/Radfahrzeug.h b/6_Verkehrsmittel/Radfahrzeug.h new file mode 100644 index 0000000..c6c4d43 --- /dev/null +++ b/6_Verkehrsmittel/Radfahrzeug.h @@ -0,0 +1,14 @@ +#pragma once +#include "Verkehrsmittel.h" +#include + +class Radfahrzeug : public Verkehrsmittel{ + protected: + const int anzahl_raeder; + + public: + Radfahrzeug() : anzahl_raeder(4) {} + Radfahrzeug(int anzahl_raeder) : anzahl_raeder(anzahl_raeder) {} + + string text(); +}; \ No newline at end of file diff --git a/6_Verkehrsmittel/Verkehrsmittel.cpp b/6_Verkehrsmittel/Verkehrsmittel.cpp new file mode 100644 index 0000000..6cdd19d --- /dev/null +++ b/6_Verkehrsmittel/Verkehrsmittel.cpp @@ -0,0 +1,20 @@ +#include "Verkehrsmittel.h" +#include +#include + +using namespace std; + +void Verkehrsmittel::bewege(int zielx, int ziely) +{ + x = zielx; + y = ziely; +} + +string Verkehrsmittel::text() +{ + stringstream ausgabe; + + ausgabe << "Verkehrsmittel - Position x: " << x << "; Position y: " << y; + + return ausgabe.str(); +} diff --git a/6_Verkehrsmittel/Verkehrsmittel.h b/6_Verkehrsmittel/Verkehrsmittel.h new file mode 100644 index 0000000..d7f6723 --- /dev/null +++ b/6_Verkehrsmittel/Verkehrsmittel.h @@ -0,0 +1,18 @@ +#pragma once +#include +#include +using namespace std; + +class Verkehrsmittel{ + protected: + int x; + int y; + + public: + + Verkehrsmittel () : x(0), y(0) {} + Verkehrsmittel(int x, int y) : x(x), y(y) {} + + void bewege(int zielx, int ziely); + string text(); +}; \ No newline at end of file diff --git a/6_Verkehrsmittel/check.cpp b/6_Verkehrsmittel/check.cpp index cdd37ed..129dae2 100644 --- a/6_Verkehrsmittel/check.cpp +++ b/6_Verkehrsmittel/check.cpp @@ -7,7 +7,7 @@ int main() { //Verkehrsmittel - Verkehrsmittel verkehrsmittel; + Verkehrsmittel verkehrsmittel; cout << verkehrsmittel.text() << endl; assert(verkehrsmittel.text().compare("Verkehrsmittel - Position x: 0; Position y: 0") == 0 && "String must be: Verkehrsmittel - Position x: 0; Position y: 0"); verkehrsmittel.bewege(10,10); diff --git a/6_Verkehrsmittel/pkw.cpp b/6_Verkehrsmittel/pkw.cpp new file mode 100644 index 0000000..514e355 --- /dev/null +++ b/6_Verkehrsmittel/pkw.cpp @@ -0,0 +1,15 @@ +#include "PKW.h" +#include "Verkehrsmittel.h" +#include "Radfahrzeug.h" +#include + +using namespace std; + +string PKW::text() +{ + stringstream ausgabe; + + ausgabe << "PKW - Position x: " << x << "; Position y: " << y << "; Anzahl Räder: " << anzahl_raeder << "; Anzahl Türen: " << anzahl_tueren; + + return ausgabe.str(); +} \ No newline at end of file