This commit is contained in:
Frank Mayer 2024-11-23 14:28:27 +01:00
parent d281783d58
commit 5dd8a33f1c
Signed by: tsukinoko-kun
GPG Key ID: 427B3E61E69C2E51
6 changed files with 18 additions and 3 deletions

8
.gitignore vendored
View File

@ -13,3 +13,11 @@ CMakeUserPresets.json
.DS_Store
my_project
.ccls-cache
*.out
*.o
*.a
*.so
*.dylib
*.dll
*.exe
*.zip

View File

@ -19,4 +19,4 @@ Fahrzeug::Fahrzeug(std::string hersteller, std::string modell,
this->ladungInProzent = ladungInProzent;
}
Fahrzeug::Fahrzeug() {}
Fahrzeug::Fahrzeug() = default;

View File

@ -1,5 +1,6 @@
#include "Fuhrpark_1.h"
#include "Fahrzeug.h"
#include <iostream>
#include <stdexcept>
void Fuhrpark_1::Add(const Fahrzeug &arg) {
@ -12,7 +13,10 @@ void Fuhrpark_1::Add(const Fahrzeug &arg) {
}
void Fuhrpark_1::Print() const {
std::cout << "Fuhrpark 1:" << std::endl;
for (size_t i = 0; i < anzElem; ++i) {
std::cout << "Fahrzeug " << i + 1 << ":" << std::endl;
pFuhrpark[i]->Print();
}
std::cout << std::endl;
}

View File

@ -10,7 +10,7 @@ public:
private:
static const size_t Max_Elems = 100;
size_t anzElem;
size_t anzElem = 0;
Fahrzeug *pFuhrpark[Max_Elems];
};

View File

@ -1,12 +1,16 @@
#include "Fuhrpark_2.h"
#include "Fahrzeug.h"
#include <iostream>
void Fuhrpark_2::Add(const Fahrzeug &arg) {
pFuhrpark->push_back(new Fahrzeug(arg));
}
void Fuhrpark_2::Print() const {
std::cout << "Fuhrpark 2:" << std::endl;
for (size_t i = 0; i < pFuhrpark->size(); ++i) {
std::cout << "Fahrzeug " << i + 1 << ":" << std::endl;
(*pFuhrpark)[i]->Print();
}
std::cout << std::endl;
}

View File

@ -11,7 +11,6 @@ int main() {
f2.Add(ts);
Fahrzeug pt("Porsche", "Taycan", "M-5678", 400, 90);
pt.Print();
f1.Add(pt);
f2.Add(pt);