diff --git a/6_Verkehrsmittel/Klassenplanung.md b/6_Verkehrsmittel/Klassenplanung.md index c1f4524..cf65638 100644 --- a/6_Verkehrsmittel/Klassenplanung.md +++ b/6_Verkehrsmittel/Klassenplanung.md @@ -2,10 +2,14 @@ - Verkehrsmittel - Posistion (int x, int y) - bewegen(neue Posistion) + - text() - Luftfahrzeuge - max. Flughöhe + - text() - Radfahrzeuge - Anzahl Räder + - text() - Pkw - Anzahl Türen + - text() diff --git a/6_Verkehrsmittel/Luftfahrzeug.h b/6_Verkehrsmittel/Luftfahrzeug.h index f99347b..4af94c3 100644 --- a/6_Verkehrsmittel/Luftfahrzeug.h +++ b/6_Verkehrsmittel/Luftfahrzeug.h @@ -1,8 +1,11 @@ #pragma once #include "Verkehrsmittel.h" -class Luftfahrzeug : Verkehrsmittel{ +class Luftfahrzeug : public Verkehrsmittel{ private: int maxFlughöhe; public: + Luftfahrzeug (int maxFlughöhe){ + this->maxFlughöhe = maxFlughöhe; + }; std::string text(); }; diff --git a/6_Verkehrsmittel/PKW.h b/6_Verkehrsmittel/PKW.h index 1240706..d88d209 100644 --- a/6_Verkehrsmittel/PKW.h +++ b/6_Verkehrsmittel/PKW.h @@ -1,9 +1,12 @@ #pragma once +#include "Radfahrzeug.h" #include "Verkehrsmittel.h" -class PKW{ - private: - int anzahlTüren; - public: - std::string text(); +class PKW : public Radfahrzeug { +private: + int anzahlTüren; + +public: + PKW(int raeder, int türen) : Radfahrzeug(raeder) { anzahlTüren = türen; } + std::string text(); }; diff --git a/6_Verkehrsmittel/Radfahrzeug.h b/6_Verkehrsmittel/Radfahrzeug.h index 96568cb..8931db5 100644 --- a/6_Verkehrsmittel/Radfahrzeug.h +++ b/6_Verkehrsmittel/Radfahrzeug.h @@ -1,9 +1,12 @@ #pragma once #include "Verkehrsmittel.h" -class Radfahrzeug : Verkehrsmittel{ - private: - int anzahlRäder; - public: - std::string text(); +class Radfahrzeug : public Verkehrsmittel { +private: + int anzahlRäder; + +public: + Radfahrzeug(int räder) { this->anzahlRäder = räder; } + std::string text(); + int getRäder(); }; diff --git a/6_Verkehrsmittel/Verkehrsmittel.h b/6_Verkehrsmittel/Verkehrsmittel.h index 1223a79..e4042d5 100644 --- a/6_Verkehrsmittel/Verkehrsmittel.h +++ b/6_Verkehrsmittel/Verkehrsmittel.h @@ -1,6 +1,6 @@ #pragma once - #include + class Verkehrsmittel{ private: int posX = 0; @@ -9,4 +9,6 @@ class Verkehrsmittel{ public: void bewege(int x, int y); virtual std::string text(); + int getX(); + int getY(); }; diff --git a/6_Verkehrsmittel/check.cpp b/6_Verkehrsmittel/check.cpp index cdd37ed..6eb025d 100644 --- a/6_Verkehrsmittel/check.cpp +++ b/6_Verkehrsmittel/check.cpp @@ -1,9 +1,10 @@ #include +#include #include "Verkehrsmittel.h" #include "Luftfahrzeug.h" #include "Radfahrzeug.h" #include "PKW.h" - +using namespace std; int main() { //Verkehrsmittel diff --git a/6_Verkehrsmittel/implementierung.cpp b/6_Verkehrsmittel/implementierung.cpp new file mode 100644 index 0000000..c085c81 --- /dev/null +++ b/6_Verkehrsmittel/implementierung.cpp @@ -0,0 +1,60 @@ +#include "Luftfahrzeug.h" +#include "PKW.h" +#include "Radfahrzeug.h" +#include "Verkehrsmittel.h" +#include +#include +// Verkehrsmittel - Position x: 0; Position y: 0 +int Verkehrsmittel::getX() { return posX; } +int Verkehrsmittel::getY() { return posY; } +int Radfahrzeug::getRäder() { return anzahlRäder; } + +void Verkehrsmittel::bewege(int x, int y) { + this->posX = x; + this->posY = y; +} + +std::string Verkehrsmittel::text() { + std::string Xstring = std::to_string(getX()); + std::string Ystring = std::to_string(getY()); + std::string Fahrzeug = "Verkehrsmittel"; + std::stringstream output; + output << Fahrzeug << " - " << "Position x: " << Xstring + << "; Position y: " << Ystring; + return output.str(); +} + +std::string Luftfahrzeug::text() { + std::string Xstring = std::to_string(getX()); + std::string Ystring = std::to_string(getY()); + std::string FlughöheString = std::to_string(maxFlughöhe); + std::string Fahrzeug = "Luftfahrzeug"; + std::stringstream output; + output << Fahrzeug << " - " << "Position x: " << Xstring + << "; Position y: " << Ystring << "; max. Höhe: " << FlughöheString; + return output.str(); +} + +std::string Radfahrzeug::text() { + std::string Xstring = std::to_string(getX()); + std::string Ystring = std::to_string(getY()); + std::string RäderString = std::to_string(anzahlRäder); + std::string Fahrzeug = "Radfahrzeug"; + std::stringstream output; + output << Fahrzeug << " - " << "Position x: " << Xstring + << "; Position y: " << Ystring << "; Anzahl Räder: " << RäderString; + return output.str(); +} + +std::string PKW::text() { + std::string Xstring = std::to_string(getX()); + std::string Ystring = std::to_string(getY()); + std::string Räderstring = std::to_string(getRäder()); + std::string TürenString = std::to_string(anzahlTüren); + std::string Fahrzeug = "PKW"; + std::stringstream output; + output << Fahrzeug << " - " << "Position x: " << Xstring + << "; Position y: " << Ystring << "; Anzahl Räder: " << Räderstring + << "; Anzahl Türen: " << TürenString; + return output.str(); +} diff --git a/6_Verkehrsmittel/verkehrsmittel b/6_Verkehrsmittel/verkehrsmittel new file mode 100755 index 0000000..d62db59 Binary files /dev/null and b/6_Verkehrsmittel/verkehrsmittel differ