A.cpp compiliert, aber mit Fehlern
This commit is contained in:
commit
3dce2315ee
19
A.cpp
Normal file
19
A.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "A.h"
|
||||
#include <sstream>
|
||||
#include <math.h>
|
||||
|
||||
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; }
|
||||
23
A.h
Normal file
23
A.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
|
||||
|
||||
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();
|
||||
|
||||
|
||||
};
|
||||
8
B.cpp
Normal file
8
B.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "B.h"
|
||||
#include <sstream>
|
||||
|
||||
std::string B::h(){
|
||||
std::stringstream ss;
|
||||
ss<< "B::h-" << i << " " << A::f();
|
||||
return ss.str();
|
||||
}
|
||||
14
B.h
Normal file
14
B.h
Normal file
@ -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();
|
||||
};
|
||||
10
C.cpp
Normal file
10
C.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "C.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
std::string C:: h(){
|
||||
std::stringstream ss;
|
||||
ss<<"C::h-" << i << " " << A::f();
|
||||
return ss.str();
|
||||
|
||||
}
|
||||
13
C.h
Normal file
13
C.h
Normal file
@ -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();
|
||||
};
|
||||
14
D.cpp
Normal file
14
D.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "D.h"
|
||||
#include <sstream>
|
||||
|
||||
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();
|
||||
}
|
||||
15
D.h
Normal file
15
D.h
Normal file
@ -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();
|
||||
};
|
||||
68
Prueffolge.cpp
Normal file
68
Prueffolge.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* $Author: $
|
||||
* $Rev: $
|
||||
* $Date: $
|
||||
* ACHTUNG: Diese Datei darf nicht verändert werden!
|
||||
*/
|
||||
#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();
|
||||
}
|
||||
|
||||
47
Prueffolge.h
Normal file
47
Prueffolge.h
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* $Author: $
|
||||
* $Rev: $
|
||||
* $Date: $
|
||||
* ACHTUNG: Diese Datei darf nicht verändert werden!
|
||||
*/
|
||||
#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;
|
||||
};
|
||||
99
PrueffolgeMehrfachvererbung.cpp
Normal file
99
PrueffolgeMehrfachvererbung.cpp
Normal file
@ -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);
|
||||
}
|
||||
|
||||
22
PrueffolgeMehrfachvererbung.h
Normal file
22
PrueffolgeMehrfachvererbung.h
Normal file
@ -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();
|
||||
};
|
||||
13
main.cpp
Normal file
13
main.cpp
Normal file
@ -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();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user