commit 3dce2315eedb3ba53d56d084f9748fd6220186be Author: regis37 Date: Tue Nov 25 08:58:33 2025 +0100 A.cpp compiliert, aber mit Fehlern diff --git a/A.cpp b/A.cpp new file mode 100644 index 0000000..a41b3fe --- /dev/null +++ b/A.cpp @@ -0,0 +1,19 @@ +#include "A.h" +#include +#include + +int A::counter = 0; + +std::string A::g(){ + std::stringstream ss; + ss<< "A::g-" << int(pow(i,e)); + return ss.str(); + } + +std::string A::f(){ + std::stringstream ss; + ss<< "A::f-" << int(pow(i,e)); + return ss.str(); +} + +int A::anzahlObjekte() { return counter; } \ No newline at end of file diff --git a/A.h b/A.h new file mode 100644 index 0000000..4db5c7e --- /dev/null +++ b/A.h @@ -0,0 +1,23 @@ +#pragma once +#include + + +class A{ + private: + + static int counter; + + protected: + std::string f(); + int i; + int e; + + public: + A(){}; + A(int i):i(i), e(1){}; + + std::string g(); + static int anzahlObjekte(); + + + }; \ No newline at end of file diff --git a/B.cpp b/B.cpp new file mode 100644 index 0000000..e994d87 --- /dev/null +++ b/B.cpp @@ -0,0 +1,8 @@ +#include "B.h" +#include + +std::string B::h(){ + std::stringstream ss; + ss<< "B::h-" << i << " " << A::f(); + return ss.str(); + } \ No newline at end of file diff --git a/B.h b/B.h new file mode 100644 index 0000000..63f779f --- /dev/null +++ b/B.h @@ -0,0 +1,14 @@ +#pragma once +#include "A.h" + +class B : public A{ + + private: + int i; + int e=2; + + public: + B(){}; + B(int i) : i(i){}; + std::string h(); +}; \ No newline at end of file diff --git a/C.cpp b/C.cpp new file mode 100644 index 0000000..016e8e4 --- /dev/null +++ b/C.cpp @@ -0,0 +1,10 @@ +#include "C.h" +#include + + +std::string C:: h(){ + std::stringstream ss; + ss<<"C::h-" << i << " " << A::f(); + return ss.str(); + + } \ No newline at end of file diff --git a/C.h b/C.h new file mode 100644 index 0000000..5a1bbd0 --- /dev/null +++ b/C.h @@ -0,0 +1,13 @@ +#pragma once +#include "A.h" + +class C : public A{ + + private: + int i; + int e=3; + public: + C(){}; + C(int i) : i(i){}; + std::string h(); +}; \ No newline at end of file diff --git a/D.cpp b/D.cpp new file mode 100644 index 0000000..39fd5f5 --- /dev/null +++ b/D.cpp @@ -0,0 +1,14 @@ +#include "D.h" +#include + +std::string D::g(){ + std::stringstream ss; + ss << "D::g-" << i; + return ss.str(); + } + +std::string D::h(){ + std::stringstream ss; + ss << "D::h-" << i <<" "<< B::h() <<" "<< C::h(); + return ss.str(); + } \ No newline at end of file diff --git a/D.h b/D.h new file mode 100644 index 0000000..f14eea4 --- /dev/null +++ b/D.h @@ -0,0 +1,15 @@ +#pragma once + +#include "B.h" +#include "C.h" + +class D: public B, public C{ + private: + int i; + int e=2; + + public: + D(int i) : i(i){} + std::string h(); + std::string g(); +}; \ No newline at end of file diff --git a/Prueffolge.cpp b/Prueffolge.cpp new file mode 100644 index 0000000..db20ed7 --- /dev/null +++ b/Prueffolge.cpp @@ -0,0 +1,68 @@ +/** +* $Author: $ +* $Rev: $ +* $Date: $ +* ACHTUNG: Diese Datei darf nicht verändert werden! +*/ +#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/Prueffolge.h b/Prueffolge.h new file mode 100644 index 0000000..0251a67 --- /dev/null +++ b/Prueffolge.h @@ -0,0 +1,47 @@ +/** +* $Author: $ +* $Rev: $ +* $Date: $ +* ACHTUNG: Diese Datei darf nicht verändert werden! +*/ +#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/PrueffolgeMehrfachvererbung.cpp b/PrueffolgeMehrfachvererbung.cpp new file mode 100644 index 0000000..83a7976 --- /dev/null +++ b/PrueffolgeMehrfachvererbung.cpp @@ -0,0 +1,99 @@ +/** +* $Author: MahrTh $ +* $Rev: 588 $ +* $Date: 2021-05-08 13:05:25 +0200 (Sa, 08. Mai 2021) $ +* ACHTUNG: Diese Datei darf nicht verändert werden! +*/ +#include "PrueffolgeMehrfachvererbung.h" +#include "A.h" +#include "B.h" +#include "C.h" +#include "D.h" +using namespace std; + +PrueffolgeMehrfachvererbung::PrueffolgeMehrfachvererbung() +{ + anmelden("Prüfe A", &pruefungA); + anmelden("Prüfe B", &pruefungB); + anmelden("Prüfe C", &pruefungC); + anmelden("Prüfe D", &pruefungD); + anmelden("Prüfe Anzahl A-Objekte", &pruefungAnzahlObjekte); + anmelden("Prüfe Objektgröße", &pruefungObjektgroesse); + anmelden("Prüfe Vererbungsbeziehung", &pruefungVererbung); +} + +void PrueffolgeMehrfachvererbung::pruefungA() +{ + A a1(1); + SICHERSTELLEN(a1.g().compare("A::g-1")==0); + A a2(2); + SICHERSTELLEN(a2.g().compare("A::g-2")==0); +} + +void PrueffolgeMehrfachvererbung::pruefungB() +{ + B b1(2); + SICHERSTELLEN(b1.g().compare("A::g-4")==0); + SICHERSTELLEN(b1.h().compare("B::h-2 A::f-4")==0); + B b2(3); + SICHERSTELLEN(b2.g().compare("A::g-9")==0); + SICHERSTELLEN(b2.h().compare("B::h-3 A::f-9")==0); +} + +void PrueffolgeMehrfachvererbung::pruefungC() +{ + C c1(3); + SICHERSTELLEN(c1.g().compare("A::g-27")==0); + SICHERSTELLEN(c1.h().compare("C::h-3 A::f-27")==0); + C c2(4); + SICHERSTELLEN(c2.g().compare("A::g-64")==0); + SICHERSTELLEN(c2.h().compare("C::h-4 A::f-64")==0); +} + +void PrueffolgeMehrfachvererbung::pruefungD() +{ + D d1(4); + SICHERSTELLEN(d1.g().compare("D::g-4")==0); + SICHERSTELLEN(d1.h().compare("D::h-4 B::h-4 A::f-16 C::h-4 A::f-64")==0); + D d2(5); + SICHERSTELLEN(d2.g().compare("D::g-5")==0); + SICHERSTELLEN(d2.h().compare("D::h-5 B::h-5 A::f-25 C::h-5 A::f-125")==0); +} + +void PrueffolgeMehrfachvererbung::pruefungAnzahlObjekte() +{ + { + SICHERSTELLEN(A::anzahlObjekte()==0); + A a(11); + B b(12); + C c(13); + D d(14); + SICHERSTELLEN(A::anzahlObjekte()==5); + } + SICHERSTELLEN(A::anzahlObjekte()==0); +} + +void PrueffolgeMehrfachvererbung::pruefungObjektgroesse() +{ + A a(21); + B b(22); + C c(23); + D d(24); + SICHERSTELLEN(sizeof(b) / sizeof(a) == 2); + SICHERSTELLEN(sizeof(c) / sizeof(a) == 2); + SICHERSTELLEN(sizeof(d) / sizeof(a) == 5); +} + +void PrueffolgeMehrfachvererbung::pruefungVererbung() +{ + B b(3); + C c(4); + D d(5); + A& ab = b; + A& ac = c; + B& bd = d; + SICHERSTELLEN(ab.g().compare("A::g-9")==0); + SICHERSTELLEN(ac.g().compare("A::g-64")==0); + SICHERSTELLEN(bd.g().compare("A::g-25")==0); +} + diff --git a/PrueffolgeMehrfachvererbung.h b/PrueffolgeMehrfachvererbung.h new file mode 100644 index 0000000..6c6af4c --- /dev/null +++ b/PrueffolgeMehrfachvererbung.h @@ -0,0 +1,22 @@ +/** +* $Author: $ +* $Rev: $ +* $Date: $ +* ACHTUNG: Diese Datei darf nicht verändert werden! +*/ +#pragma once +#include "Prueffolge.h" + +class PrueffolgeMehrfachvererbung : public Prueffolge +{ +public: + PrueffolgeMehrfachvererbung(); +private: + static void pruefungA(); + static void pruefungB(); + static void pruefungC(); + static void pruefungD(); + static void pruefungAnzahlObjekte(); + static void pruefungObjektgroesse(); + static void pruefungVererbung(); +}; diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..a627b76 --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +/** +* $Author: $ +* $Rev: $ +* $Date: $ +* ACHTUNG: Diese Datei darf nicht verändert werden! +*/ +#include "PrueffolgeMehrfachvererbung.h" +using namespace std; + +int main() { + PrueffolgeMehrfachvererbung prueffolge; + prueffolge.ausfuehren(); +} diff --git a/main.exe b/main.exe new file mode 100644 index 0000000..19c400a Binary files /dev/null and b/main.exe differ