From 4fe07a69f4dc45a431131a457a79c30f7643d8d1 Mon Sep 17 00:00:00 2001 From: Shaquille Soekhlal Date: Tue, 25 Apr 2023 15:15:39 +0200 Subject: [PATCH] Opdracht 1 --- .vscode/launch.json | 7 ++++++ .vscode/tasks.json | 48 ++++++++++++++++++++++++++++++++++++++++ Opdracht_1/Interface.cpp | 5 +++++ Opdracht_1/Interface.h | 14 ++++++++++++ Opdracht_1/Positie.cpp | 22 ++++++++++++++++++ Opdracht_1/Positie.h | 18 +++++++++++++++ Opdracht_1/Robot.cpp | 18 +++++++++++++++ Opdracht_1/Robot.h | 18 +++++++++++++++ Opdracht_1/class.drawio | 43 +++++++++++++++++++++++++++++++++++ Opdracht_1/main.cpp | 10 +++++++++ 10 files changed, 203 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 Opdracht_1/Interface.cpp create mode 100644 Opdracht_1/Interface.h create mode 100644 Opdracht_1/Positie.cpp create mode 100644 Opdracht_1/Positie.h create mode 100644 Opdracht_1/Robot.cpp create mode 100644 Opdracht_1/Robot.h create mode 100644 Opdracht_1/class.drawio create mode 100644 Opdracht_1/main.cpp diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..889478e --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,48 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: cl.exe build active file", + "command": "cl.exe", + "args": [ + "/Zi", + "/EHsc", + "/nologo", + "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe", + "${file}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$msCompile" + ], + "group": "build", + "detail": "Task generated by Debugger." + }, + { + "type": "cppbuild", + "label": "C/C++: g++.exe build active file", + "command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/Opdracht_1/Interface.cpp b/Opdracht_1/Interface.cpp new file mode 100644 index 0000000..abceb10 --- /dev/null +++ b/Opdracht_1/Interface.cpp @@ -0,0 +1,5 @@ +#include "Interface.h" + +Interface::Interface(){ + +} \ No newline at end of file diff --git a/Opdracht_1/Interface.h b/Opdracht_1/Interface.h new file mode 100644 index 0000000..e0391b6 --- /dev/null +++ b/Opdracht_1/Interface.h @@ -0,0 +1,14 @@ +#ifndef INTERFACE_H +#define INTERFACE_H + +class Interface +{ +private: +public: +Interface(); +virtual ~Interface(){}; +virtual int x() = 0; +virtual int y() = 0; +virtual void move(int, int) = 0; +}; +#endif \ No newline at end of file diff --git a/Opdracht_1/Positie.cpp b/Opdracht_1/Positie.cpp new file mode 100644 index 0000000..f72c8e7 --- /dev/null +++ b/Opdracht_1/Positie.cpp @@ -0,0 +1,22 @@ +#include "Positie.h" + +Positie::Positie(int x, int y): X(x), Y(y){ + +} + +Positie::~Positie(){ + +} + +int Positie::x(){ + return X; +} + +int Positie::y(){ + return Y; +} + +void Positie::move(int dx, int dy){ + X = X+dx; + Y = Y+dy; +} \ No newline at end of file diff --git a/Opdracht_1/Positie.h b/Opdracht_1/Positie.h new file mode 100644 index 0000000..a736854 --- /dev/null +++ b/Opdracht_1/Positie.h @@ -0,0 +1,18 @@ +#include "Interface.h" + +#ifndef Positie_H +#define Positie_H + +class Positie : public Interface{ +private: + int X; + int Y; +public: + Positie (int, int); + ~Positie(); + virtual int x(); + virtual int y(); + virtual void move (int, int); +}; + +#endif \ No newline at end of file diff --git a/Opdracht_1/Robot.cpp b/Opdracht_1/Robot.cpp new file mode 100644 index 0000000..394bb79 --- /dev/null +++ b/Opdracht_1/Robot.cpp @@ -0,0 +1,18 @@ +#include "Robot.h" +#include "Positie.h" + +#include + +Robot::Robot(Interface *Pos): P(Pos){ + +} + +Robot::~Robot(){} + +void Robot::run(){ + P->move(10,20); +} + +void Robot::show(){ + std::cout << P->x() << P->y(); +} \ No newline at end of file diff --git a/Opdracht_1/Robot.h b/Opdracht_1/Robot.h new file mode 100644 index 0000000..bb7dd56 --- /dev/null +++ b/Opdracht_1/Robot.h @@ -0,0 +1,18 @@ +class Positie; +class Interface; + +#ifndef Robot_H +#define Robot_H + +class Robot{ +private: +Interface *P; +//Positie *P = dynamic_cast(I); +public: + Robot (Interface*); + virtual ~Robot(); + void run(); + void show(); +}; + +#endif \ No newline at end of file diff --git a/Opdracht_1/class.drawio b/Opdracht_1/class.drawio new file mode 100644 index 0000000..047a98c --- /dev/null +++ b/Opdracht_1/class.drawio @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Opdracht_1/main.cpp b/Opdracht_1/main.cpp new file mode 100644 index 0000000..c8c141d --- /dev/null +++ b/Opdracht_1/main.cpp @@ -0,0 +1,10 @@ +#include "Positie.h" +#include "Robot.h" + +int main ( ){ + Positie P ( 5, 10 ); + Robot R ( &P ); + R.run ( ); + R.show ( ); + return 0; +} \ No newline at end of file