initial commit

This commit is contained in:
Jonas Urban 2026-04-09 15:03:00 +02:00
commit c978250c80
44 changed files with 1277 additions and 0 deletions

BIN
10_Ausgabe/Ausgabe01.pdf Normal file

Binary file not shown.

105
10_Ausgabe/code/main.cpp Normal file
View File

@ -0,0 +1,105 @@
#include <iostream>
#include <string>
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;
}

BIN
1_Grundlagen/Grundlagen.pdf Normal file

Binary file not shown.

View File

@ -0,0 +1,35 @@
#include<cstdio>
#include<cstdlib>
#include<cassert>
#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);
}

View File

@ -0,0 +1,5 @@
#include "linker.h"
void ausgabe(int ausgabeWert){
std::cout << "Ausgabe" << ausgabeWert;
}

View File

@ -0,0 +1,11 @@
#include <iostream>
using namespace std;
int main() {
int fehler;
cout << fehler
}
//AsemblerCode mit -S und erzeugteDatei.s

View File

@ -0,0 +1,6 @@
int main(){
int array[3];
for(int i = 0; i <= 3; i++){ //Es wird außerhalb des Arrays geschrieben -> Laufzeitfehler
array[i] = i;
}
}

View File

@ -0,0 +1,7 @@
#include "linker.h"
int main(){
int ausgabeWert = 1;
ausgabe(ausgabeWert); //Falscher Funktionsname
}

View File

@ -0,0 +1,3 @@
#include <iostream>
void ausgabe(int ausgabeWert);

View File

@ -0,0 +1,8 @@
#include <iostream>
#include "fehler.h" //Nicht benötigte Datei entfernen, Fehler da Datei nicht existiert
using namespace std;
int main(){
cout << "Dies ist ein präporzessor Fehler";
}

View File

@ -0,0 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
#include "matrix.h"
int ***build_matrix(int nx, int ny, int nz)
{
int ***matrix;
matrix = (int ***)malloc(nz * sizeof(int **));
if(!matrix)
return 0;
for (int z = 0; z < nz; z++)
{
matrix[z] = (int **)malloc(ny * sizeof(int *));
if(!matrix[z])
return 0;
for (int y = 0; y < ny; y++)
{
matrix[z][y] = (int *)malloc(nx * sizeof(int));
if(!matrix[z][y])
return 0;
for (int x = 0; x < nx; x++)
{
matrix[z][y][x] = (z + 1) * 100 + (y + 1) * 10 + x + 1;
}
}
}
return matrix;
}
void print_matrix(int ***matrix, int nx, int ny, int nz)
{
for (int z = 0; z < nz; z++)
{
for (int y = 0; y < ny; y++)
{
for (int x = 0; x < nx; x++)
{
printf("%i ", matrix[z][y][x]);
}
printf("\n");
}
printf("\n");
}
}
void free_matrix(int ***matrix, int ny, int nz)
{
for (int z = 0; z < nz; z++)
{
for (int y = 0; y < ny; y++)
{
free(matrix[z][y]);
}
free(matrix[z]);
}
free(matrix);
}

View File

@ -0,0 +1,8 @@
#ifndef MATRIX_H
#define MATRIX_H
int ***build_matrix(int nx, int ny, int nz);
void print_matrix(int ***matrix, int nx, int ny, int nz);
void free_matrix(int ***matrix, int ny, int nz);
#endif

Binary file not shown.

View File

@ -0,0 +1,76 @@
#include <iostream>
#include <cmath>
#include <cassert>
#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;
}
}
}

View File

@ -0,0 +1,46 @@
#include <iostream>
#include "flugkurve01.h"
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;
}
}
}

View File

@ -0,0 +1,19 @@
#ifndef FLUGKURVE01_H
#define FLUGKURVE01_H
struct Vektor{
float x;
float y;
};
struct Koerper{
float masse;
Vektor position;
Vektor geschwindigkeit;
};
Vektor mulVektor(Vektor vektor, int mul);
Vektor addVektor(Vektor vektor1, Vektor vektor2);
Koerper bewegeKoerper(Koerper koerper, Vektor bewegung, float dt);
void ausgabeKoerper(Koerper koerper);
#endif

View File

@ -0,0 +1,40 @@
#include <iostream>
#include "flugkurve01.h"
using namespace std;
Vektor mulVektor(Vektor vektor, int mul)
{
vektor.x *= mul;
vektor.y *= mul;
return vektor;
}
Vektor addVektor(Vektor vektor1, Vektor vektor2)
{
Vektor result;
result.x = vektor1.x + vektor2.x;
result.y = vektor1.y + vektor2.y;
return result;
}
Koerper bewegeKoerper(Koerper koerper, Vektor gesamtkraft, float dt)
{
// Beschleunigung = bewegung / masse
koerper.geschwindigkeit.x += dt * gesamtkraft.x / koerper.masse;
koerper.geschwindigkeit.y += dt * gesamtkraft.y / koerper.masse;
// Neue Position
koerper.position.x += dt * koerper.geschwindigkeit.x;
koerper.position.y += dt * koerper.geschwindigkeit.y;
return koerper;
}
void ausgabeKoerper(Koerper koerper)
{
cout << "(" << koerper.position.x << "," << koerper.position.y << ") ";
cout << "Geschwindigkeit: (" << koerper.geschwindigkeit.x << ", " << koerper.geschwindigkeit.y << ")" << endl;
}

BIN
3_Summe/Summe.pdf Normal file

Binary file not shown.

21
3_Summe/code/check.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <vector>
#include <cassert>
#include <iostream>
#include "summe.h"
using namespace std;
void function_check() {
// berechneSumme
vector<int> 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();
}

10
3_Summe/code/main.cpp Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
#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);
}

8
3_Summe/code/summe.cpp Normal file
View File

@ -0,0 +1,8 @@
#include "summe.h"
float berechneSumme(const float* const wert, int anzahlWerte)
{
return (anzahlWerte) ? *wert+berechneSumme(wert+1, anzahlWerte-1) : 0;
}

12
3_Summe/code/summe.h Normal file
View File

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

Binary file not shown.

View File

@ -0,0 +1,77 @@
#include <iostream>
#include <cmath>
#include <cassert>
#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;
}
}
}

View File

@ -0,0 +1,45 @@
#include <iostream>
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;
}
}
}

Binary file not shown.

View File

@ -0,0 +1,82 @@
#include <iostream>
#include <cmath>
#include <cassert>
#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;
}
}
}

View File

@ -0,0 +1,7 @@
#include <string>
#include <iostream>
#include <sstream>
#include "flugkurve03.h"
using namespace std;
//to be implemented

View File

@ -0,0 +1,4 @@
#include <string>
using namespace std;
// to be defined

Binary file not shown.

View File

@ -0,0 +1,46 @@
#include <cassert>
#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");
}

BIN
7_Musiker/Musiker.pdf Normal file

Binary file not shown.

63
7_Musiker/code/main.cpp Normal file
View File

@ -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 <cstdlib>
#include <ctime>
#include <climits>
#include <iostream>
#include <string>
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; i<n; i++)
{
cout << "Wie heißt der " << i+1 << ". Musiker? ";
string name;
getline(cin,name);
Musiker* musiker = new Musiker(name);
orchester.hinzufuegen(musiker);
musiker->weiseInstrumentZu(musikinstrumentZufaelligErzeugen());
}
cout << "+++ Das Konzert beginnt\n";
orchester.spielen();
cout << "+++ Applaus\n";
}

BIN
8_9_Atomkern/Atomkern.pdf Normal file

Binary file not shown.

View File

@ -0,0 +1,68 @@
/**
* OPR-Praktikum SS 2012
* Aufgabe 9
* @author Thomas Mahr
*/
#include "Prueffolge.h"
#include <iostream>
#include <sstream>
using namespace std;
Prueffolge::Prueffolge()
{
}
Prueffolge::~Prueffolge()
{
for(list<Prueffall*>::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<Prueffall*>::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();
}

View File

@ -0,0 +1,47 @@
/**
* OPR-Praktikum SS 2012
* Aufgabe 9
* @author Thomas Mahr
*/
#pragma once
#include <list>
#include <string>
#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<Prueffall*> prueffaelle;
};

View File

@ -0,0 +1,92 @@
/**
* OPR-Praktikum SS 2012
* Aufgabe 9
* @author Thomas Mahr
*/
#include "PrueffolgeAtomkern.h"
#include "Atomkern.h"
#include <sstream>
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);
}

View File

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

View File

@ -0,0 +1,13 @@
/**
* OPR-Praktikum SS 2012
* Aufgabe 9
* @author Thomas Mahr
*/
#include "PrueffolgeAtomkern.h"
int main()
{
PrueffolgeAtomkern prueffolgeAtomkern;
prueffolgeAtomkern.ausfuehren();
}

View File

@ -0,0 +1,68 @@
/**
* OPR-Praktikum SS 2012
* Aufgabe 9
* @author Thomas Mahr
*/
#include "Prueffolge.h"
#include <iostream>
#include <sstream>
using namespace std;
Prueffolge::Prueffolge()
{
}
Prueffolge::~Prueffolge()
{
for(list<Prueffall*>::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<Prueffall*>::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();
}

View File

@ -0,0 +1,47 @@
/**
* OPR-Praktikum SS 2012
* Aufgabe 9
* @author Thomas Mahr
*/
#pragma once
#include <list>
#include <string>
#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<Prueffall*> prueffaelle;
};

View File

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

View File

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

View File

@ -0,0 +1,13 @@
/**
* OPR-Praktikum SS 2012
* Aufgabe 9
* @author Thomas Mahr
*/
#include "PrueffolgeReaktor.h"
int main()
{
PrueffolgeReaktor prueffolgeReaktor;
prueffolgeReaktor.ausfuehren();
}