commit 4332bbab5f9450e2731901faf6d3883a64a94a41 Author: kachelto100370 Date: Sun Mar 22 11:58:10 2026 +0100 inital commit. Set up all the exercises diff --git a/10_Ausgabe.zip b/10_Ausgabe.zip new file mode 100644 index 0000000..2176fbb Binary files /dev/null and b/10_Ausgabe.zip differ diff --git a/10_Ausgabe/Ausgabe01.pdf b/10_Ausgabe/Ausgabe01.pdf new file mode 100644 index 0000000..c5375f5 Binary files /dev/null and b/10_Ausgabe/Ausgabe01.pdf differ diff --git a/10_Ausgabe/code/main.cpp b/10_Ausgabe/code/main.cpp new file mode 100644 index 0000000..025a43f --- /dev/null +++ b/10_Ausgabe/code/main.cpp @@ -0,0 +1,105 @@ +#include +#include +using namespace std; + +class A +{ +public: + void a() {} +}; + +class B : public A +{ +public: + B(string s="") + { + id = ++idStat; + this->s = s; + info("B()"); + } + virtual ~B() + { + info("~B()"); + } + void a() + { + s += "1"; + info("B::a()"); + } + virtual void b() + { + s += "2"; + info("B::b()"); + } + void b() const + { + info("B::b() const"); + } + static int liefereIdStat() + { + return idStat; + } +protected: + string s; + void info(const string& text) const + { + cout << id << ": " << text << " " << s << endl; + } +private: + int id; + static int idStat; +}; + +int B::idStat = 0; + +class C : public B +{ +public: + C() : B("C") + { + info("C()"); + } + virtual ~C() + { + info("~C()"); + } + void a() + { + s += "3"; + info("C::a()"); + } + void b() + { + s += "4"; + info("C::b()"); + } +}; + +int main() +{ + A a; + a.a(); + cout << "vvv " << B::liefereIdStat() << endl; + B b; + b.b(); + cout << "www " << b.liefereIdStat() << endl; + C* c[2]; + c[0] = new C; + c[1] = new C; + c[0]->a(); + c[1]->b(); + delete c[0]; + delete c[1]; + const C c2; + cout << "xxx " << C::liefereIdStat() << endl; + A* ac = new C; + ac->a(); + delete ac; + cout << "yyy " << B::liefereIdStat() << endl; + B* bc = new C; + bc->a(); + bc->b(); + delete bc; + cout << "zzz " << B::liefereIdStat() << endl; +} + diff --git a/1_Grundlagen.zip b/1_Grundlagen.zip new file mode 100644 index 0000000..ff2fa89 Binary files /dev/null and b/1_Grundlagen.zip differ diff --git a/1_Grundlagen/Grundlagen.pdf b/1_Grundlagen/Grundlagen.pdf new file mode 100644 index 0000000..e6094c1 Binary files /dev/null and b/1_Grundlagen/Grundlagen.pdf differ diff --git a/1_Grundlagen/code/check.cpp b/1_Grundlagen/code/check.cpp new file mode 100644 index 0000000..baaf6bb --- /dev/null +++ b/1_Grundlagen/code/check.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include "matrix.h" + +int main() +{ + // First example + int nz=3; + int nx=3; + int ny=3; + + int*** matrix = build_matrix(nx, ny, nz); + + assert(matrix[0][0][0] == 111 && "matrix[0][0][0] must be 111 after assignment"); + assert(matrix[2][2][2] == 333 && "matrix[2][2][2] must be 333 after assignment"); + + print_matrix(matrix, nx, ny, nz); + + free_matrix(matrix, ny, nz); + + nz=3; + nx=1; + ny=2; + + // Second example + matrix = build_matrix(nx, ny, nz); + + assert(matrix[0][0][0] == 111 && "matrix[0][0][0] must be 111 after assignment"); + assert(matrix[2][1][0] == 321 && "matrix[2][1][0] must be 321 after assignment"); + + print_matrix(matrix, nx, ny, nz); + + free_matrix(matrix, ny, nz); +} diff --git a/1_Grundlagen/code/matrix.cpp b/1_Grundlagen/code/matrix.cpp new file mode 100644 index 0000000..4b165ff --- /dev/null +++ b/1_Grundlagen/code/matrix.cpp @@ -0,0 +1,34 @@ +#include +#include + +int main() +{ + const int nx=3; + const int ny=2; + int** matrix; + + matrix = (int**)malloc(ny*sizeof(int*)); + for(int y=0; y +#include +#include +#include "flugkurve01.h" +using namespace std; + +void function_checks() { + // mulVektor + Vektor test_vec = {10, 11}; + Vektor result = mulVektor(test_vec, -3); + assert(fabs(result.x + 30) < 0.1 && "Result must be -30"); + assert(fabs(result.y + 33) < 0.1 && "Result must be -33"); + cout << "mulVektor erfolgreich" << endl; + + // addVektor + Vektor test_vec_2 = {-10, 31}; + result = addVektor(test_vec, test_vec_2); + assert(fabs(result.x + 0) < 0.1 && "Result must be 0"); + assert(fabs(result.y - 42) < 0.1 && "Result must be 42"); + cout << "addVektor erfolgreich" << endl; + + // bewegeKoerper + Koerper koerper; + koerper.masse = 10; + koerper.position = { 0, 0 }; + koerper.geschwindigkeit = { 10, 10 }; + Vektor bewegung = {1, -1}; + koerper = bewegeKoerper(koerper, bewegung, 7); + assert(fabs(koerper.geschwindigkeit.x - 10.7) < 0.1 && "Result must be 10.7"); + assert(fabs(koerper.geschwindigkeit.y - 9.3) < 0.1 && "Result must be 9.3"); + assert(fabs(koerper.position.x - 74.9) < 0.1 && "Result must be 74.9"); + assert(fabs(koerper.position.y - 65.1) < 0.1 && "Result must be 65.1"); + cout << "bewegeKoerper erfolgreich" << endl; +} + +int main() +{ + cout << "Funktionsüberprüfung" << endl; + + // Function checks + function_checks(); + + // Check whole program + cout << "Simulation" << endl; + Koerper koerper; + koerper.masse = 10; + koerper.position = { 0, 0 }; + koerper.geschwindigkeit = { 10, 10 }; + // Parametrierung der auf den Körper wirkende Kräfte: + const Vektor BESCHLEUNIGUNG_GRAVITATION = {0, -9.81}; // [m/s^2] + const float REIBUNGSKOEFFIZIENT = -5; // [kg/s] + // Sorgt dafür, dass 2 Nachkommastellen angezeigt werden: + cout << fixed; + cout.precision(2); + // Simulation: + const float dt = 0.1; + for(;;) + { + cout << "Position des Körpers: "; + ausgabeKoerper(koerper); + cout << endl; + // Bestimmung der Kraft + Vektor reibungskraft = mulVektor(koerper.geschwindigkeit, + REIBUNGSKOEFFIZIENT); + Vektor anziehungskraft = mulVektor(BESCHLEUNIGUNG_GRAVITATION, + koerper.masse); + Vektor gesamtkraft = addVektor(reibungskraft,anziehungskraft); + // Ermittlung der neuen Position und neuen Geschwindigkeit + koerper = bewegeKoerper(koerper,gesamtkraft,dt); + if(koerper.position.y<=0) + { + break; + } + } + +} diff --git a/2_Flugkurve01/code/flugkurve01.cpp b/2_Flugkurve01/code/flugkurve01.cpp new file mode 100644 index 0000000..16b80f4 --- /dev/null +++ b/2_Flugkurve01/code/flugkurve01.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +int main() +{ + // Körper: + float masse = 10; // [kg] + float xPosition = 0; // [m] + float yPosition = 0; // [m] + float xGeschwindigkeit = 10; // [m/s] + float yGeschwindigkeit = 10; // [m/s] + + // Parametrierung der auf den Körper wirkende Kräfte: + const float X_BESCHLEUNIGUNG_GRAVITATION = 0; // [m/s^2] + const float Y_BESCHLEUNIGUNG_GRAVITATION = -9.81; // [m/s^2] + const float REIBUNGSKOEFFIZIENT = -5; // [kg/s] + + // Sorgt dafür, dass 2 Nachkommastellen angezeigt werden: + cout << fixed; + cout.precision(2); + + // Simulation: + const float dt = 0.1; // [s] + for(;;) + { + cout << "(" << xPosition << "," << yPosition << ")" << endl; + + // Berechnung der Beschleunigung aus der Kraft + float xBeschleunigung = xGeschwindigkeit * REIBUNGSKOEFFIZIENT / masse + X_BESCHLEUNIGUNG_GRAVITATION; + float yBeschleunigung = yGeschwindigkeit * REIBUNGSKOEFFIZIENT / masse + Y_BESCHLEUNIGUNG_GRAVITATION; + + // Ermittlung der neuen Geschwindigkeit + xGeschwindigkeit += dt * xBeschleunigung; + yGeschwindigkeit += dt * yBeschleunigung; + + // Ermittlung der neuen Position + xPosition += dt * xGeschwindigkeit; + yPosition += dt * yGeschwindigkeit; + + if(yPosition<=0) + { + break; + } + } +} diff --git a/3_Summe.zip b/3_Summe.zip new file mode 100644 index 0000000..e474ce9 Binary files /dev/null and b/3_Summe.zip differ diff --git a/3_Summe/Summe.pdf b/3_Summe/Summe.pdf new file mode 100644 index 0000000..47a001d Binary files /dev/null and b/3_Summe/Summe.pdf differ diff --git a/3_Summe/code/check.cpp b/3_Summe/code/check.cpp new file mode 100644 index 0000000..8397d78 --- /dev/null +++ b/3_Summe/code/check.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +#include "summe.h" +using namespace std; + +void function_check() { + // berechneSumme + vector myvector = {4, 7, -3, 10}; + int result = berechneSumme(myvector); + assert(result == 18 && "Result must be 18"); + cout << "berechneSumme erfolgreich" << endl; +} + +int main() +{ + cout << "Funktionsüberprüfung" << endl; + + // Function checks + function_check(); +} diff --git a/3_Summe/code/main.cpp b/3_Summe/code/main.cpp new file mode 100644 index 0000000..8d4c443 --- /dev/null +++ b/3_Summe/code/main.cpp @@ -0,0 +1,10 @@ +#include +#include "summe.h" + +int main() +{ + const int N = 4; + const float daten[N] = {1.0f,2.0f,3.0f,4.0f}; + float summe = berechneSumme(daten,N); + printf("Summe = %f\n", summe); +} diff --git a/3_Summe/code/summe.cpp b/3_Summe/code/summe.cpp new file mode 100644 index 0000000..7038832 --- /dev/null +++ b/3_Summe/code/summe.cpp @@ -0,0 +1,8 @@ +#include "summe.h" + +float berechneSumme(const float* const wert, int anzahlWerte) +{ + return (anzahlWerte) ? *wert+berechneSumme(wert+1, anzahlWerte-1) : 0; +} + + diff --git a/3_Summe/code/summe.h b/3_Summe/code/summe.h new file mode 100644 index 0000000..67bf774 --- /dev/null +++ b/3_Summe/code/summe.h @@ -0,0 +1,12 @@ +#ifndef __SUMME_H +#define __SUMME_H + +/** +* Berechnet die Summe ueber eine Menge von Werten. +* @param wert Werte +* @param anzahlWerte Anzahl der Werte +* @return Summe +*/ +float berechneSumme(const float* const wert, int anzahlWerte); + +#endif diff --git a/4_Flugkurve02.zip b/4_Flugkurve02.zip new file mode 100644 index 0000000..ac7d34e Binary files /dev/null and b/4_Flugkurve02.zip differ diff --git a/4_Flugkurve02/Flugkurve02.pdf b/4_Flugkurve02/Flugkurve02.pdf new file mode 100644 index 0000000..5b6dfc9 Binary files /dev/null and b/4_Flugkurve02/Flugkurve02.pdf differ diff --git a/4_Flugkurve02/code/check.cpp b/4_Flugkurve02/code/check.cpp new file mode 100644 index 0000000..46d48f7 --- /dev/null +++ b/4_Flugkurve02/code/check.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include "flugkurve02.h" +using namespace std; + +void function_checks() { + // mulVektor + Vektor test_vec = {10, 11}; + Vektor result = mulVektor(test_vec, -3); + assert(fabs(result.x + 30) < 0.1 && "Result must be -30"); + assert(fabs(result.y + 33) < 0.1 && "Result must be -33"); + cout << "mulVektor erfolgreich" << endl; + + // addVektor + Vektor test_vec_2 = {-10, 31}; + result = addVektor(test_vec, test_vec_2); + assert(fabs(result.x + 0) < 0.1 && "Result must be 0"); + assert(fabs(result.y - 42) < 0.1 && "Result must be 42"); + cout << "addVektor erfolgreich" << endl; + + // bewegeKoerper + Koerper koerper; + koerper.masse = 10; + koerper.position = { 0, 0 }; + koerper.geschwindigkeit = { 10, 10 }; + Vektor bewegung = {1, -1}; + const float dt = 7.0; + koerper = bewegeKoerper(koerper, bewegung, dt); + assert(fabs(koerper.geschwindigkeit.x - 10.7) < 0.1 && "Result must be 10.7"); + assert(fabs(koerper.geschwindigkeit.y - 9.3) < 0.1 && "Result must be 9.3"); + assert(fabs(koerper.position.x - 74.9) < 0.1 && "Result must be 74.9"); + assert(fabs(koerper.position.y - 65.1) < 0.1 && "Result must be 65.1"); + cout << "bewegeKoerper erfolgreich" << endl; +} + +int main() +{ + cout << "Funktionsüberprüfung" << endl; + + // Function checks + function_checks(); + + // Check whole program + cout << "Simulation" << endl; + Koerper koerper; + koerper.masse = 10; + koerper.position = { 0, 0 }; + koerper.geschwindigkeit = { 10, 10 }; + // Parametrierung der auf den Körper wirkende Kräfte: + const Vektor BESCHLEUNIGUNG_GRAVITATION = {0, -9.81}; // [m/s^2] + const float REIBUNGSKOEFFIZIENT = -5; // [kg/s] + // Sorgt dafür, dass 2 Nachkommastellen angezeigt werden: + cout << fixed; + cout.precision(2); + // Simulation: + const float dt = 0.1; + for(;;) + { + cout << "Position des Körpers: "; + ausgabeKoerper(koerper); + cout << endl; + // Bestimmung der Kraft + Vektor reibungskraft = mulVektor(koerper.geschwindigkeit, + REIBUNGSKOEFFIZIENT); + Vektor anziehungskraft = mulVektor(BESCHLEUNIGUNG_GRAVITATION, + koerper.masse); + Vektor gesamtkraft = addVektor(reibungskraft,anziehungskraft); + // Ermittlung der neuen Position und neuen Geschwindigkeit + koerper = bewegeKoerper(koerper,gesamtkraft,dt); + if(koerper.position.y<=0) + { + break; + } + } + +} diff --git a/4_Flugkurve02/code/flugkurve02.cpp b/4_Flugkurve02/code/flugkurve02.cpp new file mode 100644 index 0000000..16b80f4 --- /dev/null +++ b/4_Flugkurve02/code/flugkurve02.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +int main() +{ + // Körper: + float masse = 10; // [kg] + float xPosition = 0; // [m] + float yPosition = 0; // [m] + float xGeschwindigkeit = 10; // [m/s] + float yGeschwindigkeit = 10; // [m/s] + + // Parametrierung der auf den Körper wirkende Kräfte: + const float X_BESCHLEUNIGUNG_GRAVITATION = 0; // [m/s^2] + const float Y_BESCHLEUNIGUNG_GRAVITATION = -9.81; // [m/s^2] + const float REIBUNGSKOEFFIZIENT = -5; // [kg/s] + + // Sorgt dafür, dass 2 Nachkommastellen angezeigt werden: + cout << fixed; + cout.precision(2); + + // Simulation: + const float dt = 0.1; // [s] + for(;;) + { + cout << "(" << xPosition << "," << yPosition << ")" << endl; + + // Berechnung der Beschleunigung aus der Kraft + float xBeschleunigung = xGeschwindigkeit * REIBUNGSKOEFFIZIENT / masse + X_BESCHLEUNIGUNG_GRAVITATION; + float yBeschleunigung = yGeschwindigkeit * REIBUNGSKOEFFIZIENT / masse + Y_BESCHLEUNIGUNG_GRAVITATION; + + // Ermittlung der neuen Geschwindigkeit + xGeschwindigkeit += dt * xBeschleunigung; + yGeschwindigkeit += dt * yBeschleunigung; + + // Ermittlung der neuen Position + xPosition += dt * xGeschwindigkeit; + yPosition += dt * yGeschwindigkeit; + + if(yPosition<=0) + { + break; + } + } +} diff --git a/5_Flugkurve03.zip b/5_Flugkurve03.zip new file mode 100644 index 0000000..093c0b3 Binary files /dev/null and b/5_Flugkurve03.zip differ diff --git a/5_Flugkurve03/Flugkurve03.pdf b/5_Flugkurve03/Flugkurve03.pdf new file mode 100644 index 0000000..0cb369c Binary files /dev/null and b/5_Flugkurve03/Flugkurve03.pdf differ diff --git a/5_Flugkurve03/code/check.cpp b/5_Flugkurve03/code/check.cpp new file mode 100644 index 0000000..e4053d1 --- /dev/null +++ b/5_Flugkurve03/code/check.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include "flugkurve03.h" +using namespace std; + +void function_checks() { + // Vektor init + Vektor test_vec = {10, 11}; + assert(fabs(test_vec.x - 10) < 0.1 && "x must be 10"); + assert(fabs(test_vec.y - 11) < 0.1 && "x must be 11"); + cout << "Vektor init erfolgreich" << endl; + // Vektor mul + test_vec.mul(2.0); + assert(fabs(test_vec.x - 20) < 0.1 && "x must be 20"); + assert(fabs(test_vec.y - 22) < 0.1 && "x must be 22"); + cout << "Vektor mul erfolgreich" << endl; + // Vektor add + Vektor test_vec_2 = {1, 2}; + test_vec.add(test_vec_2); + assert(fabs(test_vec.x - 21) < 0.1 && "x must be 21"); + assert(fabs(test_vec.y - 24) < 0.1 && "x must be 24"); + cout << "Vektor add erfolgreich" << endl; + // Koerper init + getter + float masse = 10; + Vektor position = {2, 3}; + Vektor geschwindigkeit = {10, 11}; + Koerper koerper = {masse, position, geschwindigkeit}; + assert(fabs(koerper.liefereMasse() - 10) < 0.1 && "Mass must be 10"); + assert(fabs(koerper.lieferePosition().x - 2) < 0.1 && "Position: x must be 2"); + assert(fabs(koerper.lieferePosition().y - 3) < 0.1 && "Position: y must be 3"); + assert(fabs(koerper.liefereGeschwindigkeit().x - 10) < 0.1 && "Velocity: x must be 10"); + assert(fabs(koerper.liefereGeschwindigkeit().y - 11) < 0.1 && "Velocity: y must be 11"); + cout << "Koerper init + getter erfolgreich" << endl; + // Koerper bewegen + Vektor beschleunigung = {-2, -9}; + float dt = 0.1; + koerper.bewegen(beschleunigung, dt); + assert(fabs(koerper.liefereMasse() - 10) < 0.1 && "Mass must be 10"); + assert(fabs(koerper.lieferePosition().x - 2.98) < 0.1 && "Position: x must be 2.98"); + assert(fabs(koerper.lieferePosition().y - 4.01) < 0.1 && "Position: y must be 4.01"); + assert(fabs(koerper.liefereGeschwindigkeit().x - 9.8) < 0.1 && "Velocity: x must be 9.8"); + assert(fabs(koerper.liefereGeschwindigkeit().y - 10.1) < 0.1 && "Velocity: y must be 10.1"); + cout << "Koerper bewegen erfolgreich" << endl; +} + +int main() +{ + cout << "Funktionsüberprüfung" << endl; + + // Function checks + function_checks(); + + // Check whole program + cout << "Simulation" << endl; + // Körper: + const float MASSE = 10; + const Vektor START_POSITION = {0,0}; + const Vektor START_GESCHWINDIGKEIT = {10,10}; + Koerper koerper(MASSE,START_POSITION,START_GESCHWINDIGKEIT); + // Parametrierung der auf den Körper wirkende Kräfte: + const Vektor BESCHLEUNIGUNG_GRAVITATION = {0, -9.81}; // [m/s^2] + const float REIBUNGSKOEFFIZIENT = -5; // [kg/s] + // Simulation: + const float dt = 0.1; + for(;;) + { + cout << "Position des Körpers: " << koerper.text() << endl; + // Bestimmung der neuen Beschleunigung + Vektor beschleunigung; + beschleunigung = koerper.liefereGeschwindigkeit(); + beschleunigung.mul(REIBUNGSKOEFFIZIENT/koerper.liefereMasse()); + beschleunigung.add(BESCHLEUNIGUNG_GRAVITATION); + // Ermittlung der neuen Position und neuen Geschwindigkeit + koerper.bewegen(beschleunigung,dt); + if(koerper.lieferePosition().y<=0) + { + break; + } + } + +} diff --git a/5_Flugkurve03/code/flugkurve03.cpp b/5_Flugkurve03/code/flugkurve03.cpp new file mode 100644 index 0000000..cfc05ef --- /dev/null +++ b/5_Flugkurve03/code/flugkurve03.cpp @@ -0,0 +1,7 @@ +#include +#include +#include +#include "flugkurve03.h" +using namespace std; + +//to be implemented diff --git a/5_Flugkurve03/code/flugkurve03.h b/5_Flugkurve03/code/flugkurve03.h new file mode 100644 index 0000000..acb5909 --- /dev/null +++ b/5_Flugkurve03/code/flugkurve03.h @@ -0,0 +1,4 @@ +#include +using namespace std; + +// to be defined diff --git a/6_Verkehrsmittel.zip b/6_Verkehrsmittel.zip new file mode 100644 index 0000000..fe4a608 Binary files /dev/null and b/6_Verkehrsmittel.zip differ diff --git a/6_Verkehrsmittel/6_Verkehrsmittel.pdf b/6_Verkehrsmittel/6_Verkehrsmittel.pdf new file mode 100644 index 0000000..d377896 Binary files /dev/null and b/6_Verkehrsmittel/6_Verkehrsmittel.pdf differ diff --git a/6_Verkehrsmittel/check.cpp b/6_Verkehrsmittel/check.cpp new file mode 100644 index 0000000..cdd37ed --- /dev/null +++ b/6_Verkehrsmittel/check.cpp @@ -0,0 +1,46 @@ +#include +#include "Verkehrsmittel.h" +#include "Luftfahrzeug.h" +#include "Radfahrzeug.h" +#include "PKW.h" + +int main() +{ + //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); + cout << verkehrsmittel.text() << endl; + assert(verkehrsmittel.text().compare("Verkehrsmittel - Position x: 10; Position y: 10") == 0 && "String must be: Verkehrsmittel - Position x: 10; Position y: 10"); + + //Luftfahrzeug + Luftfahrzeug luft(10000); + cout << luft.text() << endl; + assert(luft.text().compare("Luftfahrzeug - Position x: 0; Position y: 0; max. Höhe: 10000") == 0 && + "String must be: Luftfahrzeug - Position x: 0; Position y: 0; max. Höhe: 10000"); + luft.bewege(11,11); + cout << luft.text() << endl; + assert(luft.text().compare("Luftfahrzeug - Position x: 11; Position y: 11; max. Höhe: 10000") == 0 && + "String must be: Luftfahrzeug - Position x: 11; Position y: 11; max. Höhe: 10000"); + + //Radfahrzeug + Radfahrzeug rad(4); + cout << rad.text() << endl; + assert(rad.text().compare("Radfahrzeug - Position x: 0; Position y: 0; Anzahl Räder: 4") == 0 && + "String must be: Radfahrzeug - Position x: 0; Position y: 0; Anzahl Räder: 4"); + rad.bewege(14,14); + cout << rad.text() << endl; + assert(rad.text().compare("Radfahrzeug - Position x: 14; Position y: 14; Anzahl Räder: 4") == 0 && + "String must be: Radfahrzeug - Position x: 14; Position y: 14; Anzahl Räder: 4"); + + //PKW + PKW pkw(4, 5); + cout << pkw.text() << endl; + assert(pkw.text().compare("PKW - Position x: 0; Position y: 0; Anzahl Räder: 4; Anzahl Türen: 5") == 0 && + "String must be: PKW - Position x: 0; Position y: 0; Anzahl Räder: 4; Anzahl Türen: 5"); + pkw.bewege(-11,-11); + cout << pkw.text() << endl; + assert(pkw.text().compare("PKW - Position x: -11; Position y: -11; Anzahl Räder: 4; Anzahl Türen: 5") == 0 && + "String must be: PKW - Position x: -11; Position y: -11; Anzahl Räder: 4; Anzahl Türen: 5"); +} diff --git a/7_Musiker.zip b/7_Musiker.zip new file mode 100644 index 0000000..e1b1bf3 Binary files /dev/null and b/7_Musiker.zip differ diff --git a/7_Musiker/Musiker.pdf b/7_Musiker/Musiker.pdf new file mode 100644 index 0000000..999b0ac Binary files /dev/null and b/7_Musiker/Musiker.pdf differ diff --git a/7_Musiker/code/main.cpp b/7_Musiker/code/main.cpp new file mode 100644 index 0000000..6d9efec --- /dev/null +++ b/7_Musiker/code/main.cpp @@ -0,0 +1,63 @@ +/** + * OPR-Praktikum SS 2013 + * Aufgabe 5 + * Vorgegebene Datei + * Autor: Thomas Mahr + **/ + +#include "Klavier.h" +#include "Trompete.h" +#include "Orchester.h" +#include +#include +#include +#include +#include +using namespace std; + +Musikinstrument* musikinstrumentZufaelligErzeugen() +{ + Musikinstrument* musikinstrument; + int r = rand()%3; + switch(r) + { + case 0: + musikinstrument = new Klavier(); + break; + case 1: + musikinstrument = new Trompete(); + break; + default: + musikinstrument = new Musikinstrument(); + break; + } + return musikinstrument; +} + +int main() +{ + srand(time(0)); + + Orchester orchester; + + int n; + cout << "Wieviele Musiker sollen im Orchester spielen? "; + cin >> n; + cin.ignore(INT_MAX,'\n'); // entfernt übriggebliebenen Zeilenumbruch der letzten Eingabe + + cout << "+++ Orchester mit " << n << " Musikern besetzen\n"; + for(int i=0; iweiseInstrumentZu(musikinstrumentZufaelligErzeugen()); + } + + cout << "+++ Das Konzert beginnt\n"; + orchester.spielen(); + + cout << "+++ Applaus\n"; +} diff --git a/8_9_Atomkern.zip b/8_9_Atomkern.zip new file mode 100644 index 0000000..b84431b Binary files /dev/null and b/8_9_Atomkern.zip differ diff --git a/8_9_Atomkern/Atomkern.pdf b/8_9_Atomkern/Atomkern.pdf new file mode 100644 index 0000000..4d327c0 Binary files /dev/null and b/8_9_Atomkern/Atomkern.pdf differ diff --git a/8_9_Atomkern/code/Atomkern/Prueffolge.cpp b/8_9_Atomkern/code/Atomkern/Prueffolge.cpp new file mode 100644 index 0000000..3116b9d --- /dev/null +++ b/8_9_Atomkern/code/Atomkern/Prueffolge.cpp @@ -0,0 +1,68 @@ +/** + * OPR-Praktikum SS 2012 + * Aufgabe 9 + * @author Thomas Mahr + */ + +#include "Prueffolge.h" +#include +#include +using namespace std; + +Prueffolge::Prueffolge() +{ +} + +Prueffolge::~Prueffolge() +{ + for(list::iterator it=prueffaelle.begin(); it!=prueffaelle.end(); it++) + { + delete *it; + } +} + +void Prueffolge::anmelden(std::string bezeichnung, Prueffunktion test) +{ + Prueffall* tf = new Prueffall(bezeichnung,test); + tf->funktion = test; + prueffaelle.push_back(tf); +} + + +void Prueffolge::ausfuehren() +{ + int zaehlerTestBestanden = 0; + for(list::iterator it=prueffaelle.begin(); it!=prueffaelle.end(); it++) + { + cout << "PRUEFUNG " << (*it)->bezeichnung << ": "; + try + { + (*it)->funktion(); + zaehlerTestBestanden++; + cout << "ERFOLGREICH\n"; + } + catch(Fehler f) + { + cout << f.beschreibung() << endl; + } + } + + cout << zaehlerTestBestanden << " von " << prueffaelle.size() << " Pruefungen erfolgreich\n"; +} + +void Prueffolge::sicherstellen(bool b, std::string dateiName, int zeile) +{ + if(!b) + { + throw Fehler(dateiName, zeile); + } +} + + +string Prueffolge::Fehler::beschreibung() +{ + stringstream s; + s << "FEHLER in " << dateiName << " Zeile " << zeile; + return s.str(); +} + diff --git a/8_9_Atomkern/code/Atomkern/Prueffolge.h b/8_9_Atomkern/code/Atomkern/Prueffolge.h new file mode 100644 index 0000000..442bae8 --- /dev/null +++ b/8_9_Atomkern/code/Atomkern/Prueffolge.h @@ -0,0 +1,47 @@ +/** + * OPR-Praktikum SS 2012 + * Aufgabe 9 + * @author Thomas Mahr + */ + +#pragma once +#include +#include + +#define SICHERSTELLEN(exp) ( sicherstellen(exp, __FILE__, __LINE__) ) + +class Prueffolge +{ +public: + + Prueffolge(); + virtual ~Prueffolge(); + void ausfuehren(); + +protected: + + typedef void (*Prueffunktion)(); + + struct Fehler + { + std::string dateiName; + int zeile; + Fehler(std::string dateiName, int zeile) : dateiName(dateiName), zeile(zeile) {} + std::string beschreibung(); + }; + + struct Prueffall + { + std::string bezeichnung; + Prueffunktion funktion; + Prueffall(std::string bezeichnung, Prueffunktion funktion) : bezeichnung(bezeichnung), funktion(funktion) {} + }; + + void anmelden(std::string bezeichnung, Prueffunktion test); + + static void sicherstellen(bool b, std::string dateiName, int zeile); + +private: + + std::list prueffaelle; +}; diff --git a/8_9_Atomkern/code/Atomkern/PrueffolgeAtomkern.cpp b/8_9_Atomkern/code/Atomkern/PrueffolgeAtomkern.cpp new file mode 100644 index 0000000..6e883f9 --- /dev/null +++ b/8_9_Atomkern/code/Atomkern/PrueffolgeAtomkern.cpp @@ -0,0 +1,92 @@ +/** + * OPR-Praktikum SS 2012 + * Aufgabe 9 + * @author Thomas Mahr + */ + +#include "PrueffolgeAtomkern.h" +#include "Atomkern.h" +#include +using namespace std; + +PrueffolgeAtomkern::PrueffolgeAtomkern() +{ + anmelden("Atomkern erstellen", &pruefungAtomkernErstellen); + anmelden("Atomkern ausgeben", &pruefungAusgabe); + anmelden("Proton", &pruefungProton); + anmelden("Neutron", &pruefungNeutron); + anmelden("operator+=", &pruefungOperatorPlusGleich); + anmelden("operator-=", &pruefungOperatorMinusGleich); + anmelden("Kernfusion", &pruefungKernfusion); + anmelden("Kernspaltung", &pruefungKernspaltung); +} + +void PrueffolgeAtomkern::pruefungAtomkernErstellen() +{ + Atomkern kern("Pu",239,94); + SICHERSTELLEN(kern.symbol()=="Pu"); + SICHERSTELLEN(kern.ordnungszahl()==94); + SICHERSTELLEN(kern.massenzahl()==239); +} + +void PrueffolgeAtomkern::pruefungAusgabe() +{ + Atomkern kern("C",12,6); + stringstream s; + s << "Atomkern = " << kern << "."; + SICHERSTELLEN(s.str()=="Atomkern = C(12,6)."); +} + +void PrueffolgeAtomkern::pruefungProton() +{ + SICHERSTELLEN(Atomkern::PROTON.ordnungszahl()==1); + SICHERSTELLEN(Atomkern::PROTON.massenzahl()==1); +} + +void PrueffolgeAtomkern::pruefungNeutron() +{ + SICHERSTELLEN(Atomkern::NEUTRON.ordnungszahl()==0); + SICHERSTELLEN(Atomkern::NEUTRON.massenzahl()==1); +} + +void PrueffolgeAtomkern::pruefungOperatorPlusGleich() +{ + Atomkern kern("C",12,6); + kern += Atomkern::NEUTRON; + SICHERSTELLEN(kern.ordnungszahl()==6); + SICHERSTELLEN(kern.massenzahl()==13); + kern += Atomkern::PROTON; + SICHERSTELLEN(kern.ordnungszahl()==7); + SICHERSTELLEN(kern.massenzahl()==14); +} + +void PrueffolgeAtomkern::pruefungOperatorMinusGleich() +{ + Atomkern kern("C",12,6); + kern -= Atomkern::NEUTRON; + SICHERSTELLEN(kern.ordnungszahl()==6); + SICHERSTELLEN(kern.massenzahl()==11); + kern -= Atomkern::PROTON; + SICHERSTELLEN(kern.ordnungszahl()==5); + SICHERSTELLEN(kern.massenzahl()==10); +} + +void PrueffolgeAtomkern::pruefungKernfusion() +{ + const Atomkern DEUTERIUM("D",2,1); + const Atomkern TRITIUM("T",3,1); + const Atomkern HELIUM("He",4,2); + Atomkern ergebnis = DEUTERIUM + TRITIUM - Atomkern::NEUTRON; + SICHERSTELLEN(ergebnis.ordnungszahl()==2); + SICHERSTELLEN(ergebnis.massenzahl()==4); + SICHERSTELLEN(ergebnis==HELIUM); +} + +void PrueffolgeAtomkern::pruefungKernspaltung() +{ + const Atomkern PLUTONIUM("Pu",239,94); + const Atomkern BARIUM("Ba",144,56); + const Atomkern STRONTIUM("Sr",94,38); + SICHERSTELLEN(PLUTONIUM + Atomkern::NEUTRON == BARIUM + STRONTIUM + 2*Atomkern::NEUTRON); +} + diff --git a/8_9_Atomkern/code/Atomkern/PrueffolgeAtomkern.h b/8_9_Atomkern/code/Atomkern/PrueffolgeAtomkern.h new file mode 100644 index 0000000..7833570 --- /dev/null +++ b/8_9_Atomkern/code/Atomkern/PrueffolgeAtomkern.h @@ -0,0 +1,26 @@ +/** + * OPR-Praktikum SS 2012 + * Aufgabe 9 + * @author Thomas Mahr + */ + +#pragma once +#include "Prueffolge.h" + +class PrueffolgeAtomkern : public Prueffolge +{ +public: + + PrueffolgeAtomkern(); + +private: + + static void pruefungAtomkernErstellen(); + static void pruefungAusgabe(); + static void pruefungProton(); + static void pruefungNeutron(); + static void pruefungOperatorPlusGleich(); + static void pruefungOperatorMinusGleich(); + static void pruefungKernfusion(); + static void pruefungKernspaltung(); +}; diff --git a/8_9_Atomkern/code/Atomkern/main.cpp b/8_9_Atomkern/code/Atomkern/main.cpp new file mode 100644 index 0000000..4f826c6 --- /dev/null +++ b/8_9_Atomkern/code/Atomkern/main.cpp @@ -0,0 +1,13 @@ +/** + * OPR-Praktikum SS 2012 + * Aufgabe 9 + * @author Thomas Mahr + */ + +#include "PrueffolgeAtomkern.h" + +int main() +{ + PrueffolgeAtomkern prueffolgeAtomkern; + prueffolgeAtomkern.ausfuehren(); +} diff --git a/8_9_Atomkern/code/Reaktor/Prueffolge.cpp b/8_9_Atomkern/code/Reaktor/Prueffolge.cpp new file mode 100644 index 0000000..3116b9d --- /dev/null +++ b/8_9_Atomkern/code/Reaktor/Prueffolge.cpp @@ -0,0 +1,68 @@ +/** + * OPR-Praktikum SS 2012 + * Aufgabe 9 + * @author Thomas Mahr + */ + +#include "Prueffolge.h" +#include +#include +using namespace std; + +Prueffolge::Prueffolge() +{ +} + +Prueffolge::~Prueffolge() +{ + for(list::iterator it=prueffaelle.begin(); it!=prueffaelle.end(); it++) + { + delete *it; + } +} + +void Prueffolge::anmelden(std::string bezeichnung, Prueffunktion test) +{ + Prueffall* tf = new Prueffall(bezeichnung,test); + tf->funktion = test; + prueffaelle.push_back(tf); +} + + +void Prueffolge::ausfuehren() +{ + int zaehlerTestBestanden = 0; + for(list::iterator it=prueffaelle.begin(); it!=prueffaelle.end(); it++) + { + cout << "PRUEFUNG " << (*it)->bezeichnung << ": "; + try + { + (*it)->funktion(); + zaehlerTestBestanden++; + cout << "ERFOLGREICH\n"; + } + catch(Fehler f) + { + cout << f.beschreibung() << endl; + } + } + + cout << zaehlerTestBestanden << " von " << prueffaelle.size() << " Pruefungen erfolgreich\n"; +} + +void Prueffolge::sicherstellen(bool b, std::string dateiName, int zeile) +{ + if(!b) + { + throw Fehler(dateiName, zeile); + } +} + + +string Prueffolge::Fehler::beschreibung() +{ + stringstream s; + s << "FEHLER in " << dateiName << " Zeile " << zeile; + return s.str(); +} + diff --git a/8_9_Atomkern/code/Reaktor/Prueffolge.h b/8_9_Atomkern/code/Reaktor/Prueffolge.h new file mode 100644 index 0000000..442bae8 --- /dev/null +++ b/8_9_Atomkern/code/Reaktor/Prueffolge.h @@ -0,0 +1,47 @@ +/** + * OPR-Praktikum SS 2012 + * Aufgabe 9 + * @author Thomas Mahr + */ + +#pragma once +#include +#include + +#define SICHERSTELLEN(exp) ( sicherstellen(exp, __FILE__, __LINE__) ) + +class Prueffolge +{ +public: + + Prueffolge(); + virtual ~Prueffolge(); + void ausfuehren(); + +protected: + + typedef void (*Prueffunktion)(); + + struct Fehler + { + std::string dateiName; + int zeile; + Fehler(std::string dateiName, int zeile) : dateiName(dateiName), zeile(zeile) {} + std::string beschreibung(); + }; + + struct Prueffall + { + std::string bezeichnung; + Prueffunktion funktion; + Prueffall(std::string bezeichnung, Prueffunktion funktion) : bezeichnung(bezeichnung), funktion(funktion) {} + }; + + void anmelden(std::string bezeichnung, Prueffunktion test); + + static void sicherstellen(bool b, std::string dateiName, int zeile); + +private: + + std::list prueffaelle; +}; diff --git a/8_9_Atomkern/code/Reaktor/PrueffolgeReaktor.cpp b/8_9_Atomkern/code/Reaktor/PrueffolgeReaktor.cpp new file mode 100644 index 0000000..21f4872 --- /dev/null +++ b/8_9_Atomkern/code/Reaktor/PrueffolgeReaktor.cpp @@ -0,0 +1,71 @@ +/** + * OPR-Praktikum SS 2012 + * Aufgabe 9 + * @author Thomas Mahr + */ + +#include "PrueffolgeReaktor.h" +#include "Atomkern.h" +#include "Reaktor.h" +using namespace std; + +const Atomkern PrueffolgeReaktor::DEUTERIUM("D",2,1); +const Atomkern PrueffolgeReaktor::TRITIUM("T",3,1); +const Atomkern PrueffolgeReaktor::HELIUM4("He",4,2); + +PrueffolgeReaktor::PrueffolgeReaktor() +{ + anmelden("Reaktor erstellen", &pruefungReaktorErstellen); + anmelden("Reaktor befuellen und komplett entleeren", &pruefungReaktorBetrieb1); + anmelden("Kernfusion mit Wasserstoff", &pruefungReaktorBetrieb2); + anmelden("Kernspaltung mit Plutonium", &pruefungReaktorBetrieb3); +} + +void PrueffolgeReaktor::pruefungReaktorErstellen() +{ + Reaktor reaktor; + // Ein gerade erstellter Reaktor enthält kein Kernmaterial + SICHERSTELLEN(*reaktor==Atomkern(0,0)); +} + +void PrueffolgeReaktor::pruefungReaktorBetrieb1() +{ + Reaktor reaktor; + // Reaktor mit Deuterium füllen + reaktor < DEUTERIUM; + SICHERSTELLEN(*reaktor==DEUTERIUM); + // Reaktor mit Tritium füllen + reaktor < TRITIUM; + // Auf (instabiles) Fusionsprodukt prüfen + SICHERSTELLEN(*reaktor==Atomkern(5,2)); + // Reaktor komplett entleeren + ~reaktor; + SICHERSTELLEN(*reaktor==Atomkern(0,0)); +} + +void PrueffolgeReaktor::pruefungReaktorBetrieb2() +{ + Reaktor reaktor; + // Bei der Verschmelzung von Deuterium mit Tritium wird ein Neutron frei. + reaktor < DEUTERIUM < TRITIUM > Atomkern::NEUTRON; + // Zurück bleibt Helium. + SICHERSTELLEN(*reaktor==HELIUM4); +} + +void PrueffolgeReaktor::pruefungReaktorBetrieb3() +{ + Reaktor reaktor; + const Atomkern PLUTONIUM("Pu",239,94); + const Atomkern BARIUM("Ba",144,56); + const Atomkern STRONTIUM("Sr",94,38); + + // Plutonium spaltet sich bei Wechselwirkung mit einem Neutron in Barium und Strontium und gibt dabei zwei Neutronen frei. + reaktor < PLUTONIUM < Atomkern::NEUTRON; + SICHERSTELLEN(*reaktor==Atomkern(240,94)); + reaktor > BARIUM > STRONTIUM > 2*Atomkern::NEUTRON; + SICHERSTELLEN(*reaktor==Atomkern(0,0)); + + // Komplette Reaktion in einem Aufruf: + reaktor < PLUTONIUM < Atomkern::NEUTRON > BARIUM > STRONTIUM > 2*Atomkern::NEUTRON; + SICHERSTELLEN(*reaktor==Atomkern(0,0)); +} diff --git a/8_9_Atomkern/code/Reaktor/PrueffolgeReaktor.h b/8_9_Atomkern/code/Reaktor/PrueffolgeReaktor.h new file mode 100644 index 0000000..422d907 --- /dev/null +++ b/8_9_Atomkern/code/Reaktor/PrueffolgeReaktor.h @@ -0,0 +1,28 @@ +/** + * OPR-Praktikum SS 2012 + * Aufgabe 9 + * @author Thomas Mahr + */ + +#pragma once +#include "Prueffolge.h" +class Atomkern; + +class PrueffolgeReaktor : public Prueffolge +{ +public: + + PrueffolgeReaktor(); + +private: + + static const Atomkern DEUTERIUM; + static const Atomkern TRITIUM; + static const Atomkern HELIUM4; + + static void pruefungReaktorErstellen(); + static void pruefungReaktorBetrieb1(); + static void pruefungReaktorBetrieb2(); + static void pruefungReaktorBetrieb3(); +}; + diff --git a/8_9_Atomkern/code/Reaktor/main.cpp b/8_9_Atomkern/code/Reaktor/main.cpp new file mode 100644 index 0000000..2bfeab8 --- /dev/null +++ b/8_9_Atomkern/code/Reaktor/main.cpp @@ -0,0 +1,13 @@ +/** + * OPR-Praktikum SS 2012 + * Aufgabe 9 + * @author Thomas Mahr + */ + +#include "PrueffolgeReaktor.h" + +int main() +{ + PrueffolgeReaktor prueffolgeReaktor; + prueffolgeReaktor.ausfuehren(); +} diff --git a/Plan.docx b/Plan.docx new file mode 100644 index 0000000..6183bfa Binary files /dev/null and b/Plan.docx differ diff --git a/Versuche.zip b/Versuche.zip new file mode 100644 index 0000000..ec9807d Binary files /dev/null and b/Versuche.zip differ