Aufgabe 6: Verkehrsmittel

This commit is contained in:
Jonas Urban 2026-04-29 17:08:29 +02:00
parent 23f603b64b
commit b685a3dfae
9 changed files with 125 additions and 1 deletions

View File

@ -0,0 +1,15 @@
#include "Luftfahrzeug.h"
#include "Verkehrsmittel.h"
#include <string>
#include <sstream>
using namespace std;
string Luftfahrzeug::text()
{
stringstream ausgabe;
ausgabe << "Luftfahrzeug - Position x: " << x << "; Position y: " << y << "; max. Höhe: " << max_hoehe;
return ausgabe.str();
}

View File

@ -0,0 +1,15 @@
#pragma once
#include <string>
#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();
};

14
6_Verkehrsmittel/PKW.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include "Verkehrsmittel.h"
#include "Radfahrzeug.h"
#include <string>
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();
};

View File

@ -0,0 +1,13 @@
#include "Radfahrzeug.h"
#include <sstream>
using namespace std;
string Radfahrzeug::text()
{
stringstream ausgabe;
ausgabe << "Radfahrzeug - Position x: " << x << "; Position y: " << y << "; Anzahl Räder: " << anzahl_raeder;
return ausgabe.str();
}

View File

@ -0,0 +1,14 @@
#pragma once
#include "Verkehrsmittel.h"
#include <string>
class Radfahrzeug : public Verkehrsmittel{
protected:
const int anzahl_raeder;
public:
Radfahrzeug() : anzahl_raeder(4) {}
Radfahrzeug(int anzahl_raeder) : anzahl_raeder(anzahl_raeder) {}
string text();
};

View File

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

View File

@ -0,0 +1,18 @@
#pragma once
#include <string>
#include <iostream>
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();
};

View File

@ -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);

15
6_Verkehrsmittel/pkw.cpp Normal file
View File

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