From 2b01bd9f8450d5d03afd73c891dd2933b5c56c16 Mon Sep 17 00:00:00 2001 From: Shaquille Soekhlal Date: Fri, 28 Apr 2023 13:36:57 +0200 Subject: [PATCH] Opdracht 2 code en design af* --- .vscode/settings.json | 41 ++ Opdracht_2/AnalogeMeter.cpp | 14 + Opdracht_2/AnalogeMeter.h | 16 + Opdracht_2/Auto.cpp | 9 + Opdracht_2/Auto.h | 16 + Opdracht_2/DigitaleMeter.cpp | 11 + Opdracht_2/Observer.cpp | 13 + Opdracht_2/Observer.h | 26 ++ Opdracht_2/Snelheid.cpp | 11 + Opdracht_2/Snelheid.h | 15 + Opdracht_2/class_1a.drawio | 268 -------------- Opdracht_2/class_2a.drawio | 700 +++++++++++++++++++++++++++++++++++ Opdracht_2/main.cpp | 13 + 13 files changed, 885 insertions(+), 268 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 Opdracht_2/AnalogeMeter.cpp create mode 100644 Opdracht_2/AnalogeMeter.h create mode 100644 Opdracht_2/Auto.cpp create mode 100644 Opdracht_2/Auto.h create mode 100644 Opdracht_2/DigitaleMeter.cpp create mode 100644 Opdracht_2/Observer.cpp create mode 100644 Opdracht_2/Observer.h create mode 100644 Opdracht_2/Snelheid.cpp create mode 100644 Opdracht_2/Snelheid.h delete mode 100644 Opdracht_2/class_1a.drawio create mode 100644 Opdracht_2/class_2a.drawio 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