Aufgabe 6: Verkehrsmittel
This commit is contained in:
parent
23f603b64b
commit
b685a3dfae
15
6_Verkehrsmittel/Luftfahrzeug.cpp
Normal file
15
6_Verkehrsmittel/Luftfahrzeug.cpp
Normal 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();
|
||||
}
|
||||
15
6_Verkehrsmittel/Luftfahrzeug.h
Normal file
15
6_Verkehrsmittel/Luftfahrzeug.h
Normal 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
14
6_Verkehrsmittel/PKW.h
Normal 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();
|
||||
};
|
||||
13
6_Verkehrsmittel/Radfahrzeug.cpp
Normal file
13
6_Verkehrsmittel/Radfahrzeug.cpp
Normal 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();
|
||||
}
|
||||
14
6_Verkehrsmittel/Radfahrzeug.h
Normal file
14
6_Verkehrsmittel/Radfahrzeug.h
Normal 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();
|
||||
};
|
||||
20
6_Verkehrsmittel/Verkehrsmittel.cpp
Normal file
20
6_Verkehrsmittel/Verkehrsmittel.cpp
Normal 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();
|
||||
}
|
||||
18
6_Verkehrsmittel/Verkehrsmittel.h
Normal file
18
6_Verkehrsmittel/Verkehrsmittel.h
Normal 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();
|
||||
};
|
||||
@ -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
15
6_Verkehrsmittel/pkw.cpp
Normal 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();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user