diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e55699f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,41 @@ +{ + "files.associations": { + "algorithm": "cpp", + "cmath": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "list": "cpp", + "memory": "cpp", + "new": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "utility": "cpp", + "xfacet": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocinfo": "cpp", + "xlocnum": "cpp", + "xmemory": "cpp", + "xmemory0": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xutility": "cpp" + } +} \ No newline at end of file diff --git a/Opdracht_2/AnalogeMeter.cpp b/Opdracht_2/AnalogeMeter.cpp new file mode 100644 index 0000000..f865630 --- /dev/null +++ b/Opdracht_2/AnalogeMeter.cpp @@ -0,0 +1,14 @@ +#include "AnalogeMeter.h" +#include "Snelheid.h" +#include + +using namespace std; + +AnalogeMeter::AnalogeMeter(Snelheid* s):Observer(s){ + +} + +void AnalogeMeter::update() +{ + cout << "Analoog: " << dynamic_cast(getSubject())->geef(); +} \ No newline at end of file diff --git a/Opdracht_2/AnalogeMeter.h b/Opdracht_2/AnalogeMeter.h new file mode 100644 index 0000000..15d2a2f --- /dev/null +++ b/Opdracht_2/AnalogeMeter.h @@ -0,0 +1,16 @@ +#ifndef _AnalogeMeter_H +#define _AnalogeMeter_H + +#include "Observer.h" + +using namespace std; + +class Snelheid; + +class AnalogeMeter : public Observer{ + public: + AnalogeMeter(Snelheid*); + virtual void update(); +}; + +#endif diff --git a/Opdracht_2/Auto.cpp b/Opdracht_2/Auto.cpp new file mode 100644 index 0000000..1da26d8 --- /dev/null +++ b/Opdracht_2/Auto.cpp @@ -0,0 +1,9 @@ +#include "Auto.h" +#include "Snelheid.h" + +Auto::Auto(Snelheid*s) : S(s){ +} + +void Auto::meetSnelheid(){ + S->meet(); +} diff --git a/Opdracht_2/Auto.h b/Opdracht_2/Auto.h new file mode 100644 index 0000000..c841e7f --- /dev/null +++ b/Opdracht_2/Auto.h @@ -0,0 +1,16 @@ +#ifndef _Auto_H +#define _Auto_H + +using namespace std; + +class Snelheid; + +class Auto{ + private: + Snelheid* S; + public: + Auto(Snelheid*); + virtual void meetSnelheid(); +}; + +#endif \ No newline at end of file diff --git a/Opdracht_2/DigitaleMeter.cpp b/Opdracht_2/DigitaleMeter.cpp new file mode 100644 index 0000000..6fd58c8 --- /dev/null +++ b/Opdracht_2/DigitaleMeter.cpp @@ -0,0 +1,11 @@ +#include "DigitaleMeter.h" +#include +#include "Snelheid.h" + +DigitaleMeter::DigitaleMeter(Snelheid* s): Observer(s){ + +} + +void DigitaleMeter::update(){ + cout << "Digitaal " << dynamic_cast (getSubject()) -> geef(); +} \ No newline at end of file diff --git a/Opdracht_2/Observer.cpp b/Opdracht_2/Observer.cpp new file mode 100644 index 0000000..eb440a8 --- /dev/null +++ b/Opdracht_2/Observer.cpp @@ -0,0 +1,13 @@ +#include "observer.h" + +void Subject::notify ( ){ +for ( list::iterator i=L.begin( ); i!=L.end( ); ++i ) (*i)->update( ); +} + +Observer::Observer ( Subject* s ) : S(s){ +getSubject( )->insert(this); +} + +Observer::~Observer ( ){ +getSubject( )->remove ( this ); +} \ No newline at end of file diff --git a/Opdracht_2/Observer.h b/Opdracht_2/Observer.h new file mode 100644 index 0000000..21d8f6a --- /dev/null +++ b/Opdracht_2/Observer.h @@ -0,0 +1,26 @@ +#ifndef __Observer_H +#define __Observer_H + +#include + +using namespace std; + +class Subject; + +class Observer{ + private: Subject* S; + protected: Subject* getSubject ( ) const { return S; } + public: Observer (Subject* s); + virtual ~Observer ( ); + virtual void update ( ) = 0; +}; + +class Subject{ + private: list L; + protected: virtual void notify ( ); + public: Subject ( ) { } + virtual ~Subject ( ) { } + virtual void insert (Observer* s) { L.push_front(s); } + virtual void remove (Observer* s) { L.remove(s); } +}; +#endif \ No newline at end of file diff --git a/Opdracht_2/Snelheid.cpp b/Opdracht_2/Snelheid.cpp new file mode 100644 index 0000000..5846756 --- /dev/null +++ b/Opdracht_2/Snelheid.cpp @@ -0,0 +1,11 @@ +#include "Snelheid.h" +#include + +void Snelheid::meet(){ + cin >> Waarde; + notify(); +} + +float Snelheid::geef(){ + return Waarde; +} \ No newline at end of file diff --git a/Opdracht_2/Snelheid.h b/Opdracht_2/Snelheid.h new file mode 100644 index 0000000..ddde283 --- /dev/null +++ b/Opdracht_2/Snelheid.h @@ -0,0 +1,15 @@ +#ifndef __Snelheid_H +#define __Snelheid_H + +#include "Observer.h" + +using namespace std; + +class Snelheid : public Subject{ + private: + float Waarde; + public: + virtual void meet(); + virtual float geef(); +}; +#endif \ No newline at end of file diff --git a/Opdracht_2/class_1a.drawio b/Opdracht_2/class_1a.drawio deleted file mode 100644 index 429406a..0000000 --- a/Opdracht_2/class_1a.drawio +++ /dev/null @@ -1,268 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Opdracht_2/class_2a.drawio b/Opdracht_2/class_2a.drawio new file mode 100644 index 0000000..44b1777 --- /dev/null +++ b/Opdracht_2/class_2a.drawio @@ -0,0 +1,700 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Opdracht_2/main.cpp b/Opdracht_2/main.cpp index e69de29..b6942d9 100644 --- a/Opdracht_2/main.cpp +++ b/Opdracht_2/main.cpp @@ -0,0 +1,13 @@ +#include "Snelheid.h" +#include "AnalogeMeter.h" +#include "DigitaleMeter.h" +#include "Auto.h" + +int main ( ){ + Snelheid S; + DigitaleMeter DM ( &S ); + AnalogeMeter AM ( &S ); + Auto A ( &S ); + A.meetSnelheid ( ); + return 0; +} \ No newline at end of file