alles funktioniert, refactoring noch möglich

This commit is contained in:
Tobias Kachel 2026-05-14 16:23:33 +02:00
parent 12eaaaa18d
commit 3e50fa9c4d
8 changed files with 89 additions and 13 deletions

View File

@ -2,10 +2,14 @@
- Verkehrsmittel - Verkehrsmittel
- Posistion (int x, int y) - Posistion (int x, int y)
- bewegen(neue Posistion) - bewegen(neue Posistion)
- text()
- Luftfahrzeuge - Luftfahrzeuge
- max. Flughöhe - max. Flughöhe
- text()
- Radfahrzeuge - Radfahrzeuge
- Anzahl Räder - Anzahl Räder
- text()
- Pkw - Pkw
- Anzahl Türen - Anzahl Türen
- text()

View File

@ -1,8 +1,11 @@
#pragma once #pragma once
#include "Verkehrsmittel.h" #include "Verkehrsmittel.h"
class Luftfahrzeug : Verkehrsmittel{ class Luftfahrzeug : public Verkehrsmittel{
private: private:
int maxFlughöhe; int maxFlughöhe;
public: public:
Luftfahrzeug (int maxFlughöhe){
this->maxFlughöhe = maxFlughöhe;
};
std::string text(); std::string text();
}; };

View File

@ -1,9 +1,12 @@
#pragma once #pragma once
#include "Radfahrzeug.h"
#include "Verkehrsmittel.h" #include "Verkehrsmittel.h"
class PKW{ class PKW : public Radfahrzeug {
private: private:
int anzahlTüren; int anzahlTüren;
public:
std::string text(); public:
PKW(int raeder, int türen) : Radfahrzeug(raeder) { anzahlTüren = türen; }
std::string text();
}; };

View File

@ -1,9 +1,12 @@
#pragma once #pragma once
#include "Verkehrsmittel.h" #include "Verkehrsmittel.h"
class Radfahrzeug : Verkehrsmittel{ class Radfahrzeug : public Verkehrsmittel {
private: private:
int anzahlRäder; int anzahlRäder;
public:
std::string text(); public:
Radfahrzeug(int räder) { this->anzahlRäder = räder; }
std::string text();
int getRäder();
}; };

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <string> #include <string>
class Verkehrsmittel{ class Verkehrsmittel{
private: private:
int posX = 0; int posX = 0;
@ -9,4 +9,6 @@ class Verkehrsmittel{
public: public:
void bewege(int x, int y); void bewege(int x, int y);
virtual std::string text(); virtual std::string text();
int getX();
int getY();
}; };

View File

@ -1,9 +1,10 @@
#include <cassert> #include <cassert>
#include <iostream>
#include "Verkehrsmittel.h" #include "Verkehrsmittel.h"
#include "Luftfahrzeug.h" #include "Luftfahrzeug.h"
#include "Radfahrzeug.h" #include "Radfahrzeug.h"
#include "PKW.h" #include "PKW.h"
using namespace std;
int main() int main()
{ {
//Verkehrsmittel //Verkehrsmittel

View File

@ -0,0 +1,60 @@
#include "Luftfahrzeug.h"
#include "PKW.h"
#include "Radfahrzeug.h"
#include "Verkehrsmittel.h"
#include <sstream>
#include <string>
// 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();
}

BIN
6_Verkehrsmittel/verkehrsmittel Executable file

Binary file not shown.