diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-09-12 10:20:36 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-09-12 10:20:36 +0200 |
commit | afe7337bd1230dfbed207ead0655f3b8a2362180 (patch) | |
tree | efd1f6740a7d6ddf2b2bfeb0565244ce113b2f17 | |
parent | e15333e1987bda84fd787eec8e78ea98f95a77a7 (diff) |
week 3 huiswerk toegevoegd
-rw-r--r-- | week-3/ETer.cpp | 5 | ||||
-rw-r--r-- | week-3/ETer.h | 10 | ||||
-rw-r--r-- | week-3/IBeroep.cpp | 2 | ||||
-rw-r--r-- | week-3/IBeroep.h | 13 | ||||
-rw-r--r-- | week-3/Persoon.cpp | 14 | ||||
-rw-r--r-- | week-3/Persoon.h | 15 | ||||
-rw-r--r-- | week-3/TIer.cpp | 5 | ||||
-rw-r--r-- | week-3/TIer.h | 10 | ||||
-rw-r--r-- | week-3/main.cpp | 18 | ||||
-rw-r--r-- | week-3/makefile | 24 |
10 files changed, 116 insertions, 0 deletions
diff --git a/week-3/ETer.cpp b/week-3/ETer.cpp new file mode 100644 index 0000000..f2eebd0 --- /dev/null +++ b/week-3/ETer.cpp @@ -0,0 +1,5 @@ +#include "ETer.h" + +std::string ETer::getNaam() const { + return "ET-er"; +} diff --git a/week-3/ETer.h b/week-3/ETer.h new file mode 100644 index 0000000..9f7ac8f --- /dev/null +++ b/week-3/ETer.h @@ -0,0 +1,10 @@ +#pragma once + +#include "IBeroep.h" +#include <string> + +class ETer : public IBeroep { + public: + virtual std::string getNaam() const; +}; + diff --git a/week-3/IBeroep.cpp b/week-3/IBeroep.cpp new file mode 100644 index 0000000..9e4f97e --- /dev/null +++ b/week-3/IBeroep.cpp @@ -0,0 +1,2 @@ +#include "IBeroep.h" + diff --git a/week-3/IBeroep.h b/week-3/IBeroep.h new file mode 100644 index 0000000..8812010 --- /dev/null +++ b/week-3/IBeroep.h @@ -0,0 +1,13 @@ +#pragma once
+
+#include <string>
+
+class IBeroep
+{
+public:
+ IBeroep() {}
+ virtual ~IBeroep() {}
+
+public:
+ virtual std::string getNaam() const = 0;
+};
diff --git a/week-3/Persoon.cpp b/week-3/Persoon.cpp new file mode 100644 index 0000000..f66e1f9 --- /dev/null +++ b/week-3/Persoon.cpp @@ -0,0 +1,14 @@ +#include "Persoon.h" + +Persoon::Persoon() { + _beroep = NULL; +} + +void Persoon::setBeroep(IBeroep* beroep) { + _beroep = beroep; +} + +std::string Persoon::getBeroep() { + if (_beroep == NULL) return "geen beroep"; + return _beroep->getNaam(); +} diff --git a/week-3/Persoon.h b/week-3/Persoon.h new file mode 100644 index 0000000..88c742d --- /dev/null +++ b/week-3/Persoon.h @@ -0,0 +1,15 @@ +#pragma once + +#include "IBeroep.h" +#include <string> + +class Persoon { + private: + IBeroep* _beroep; + + public: + virtual void setBeroep(IBeroep* beroep); + virtual std::string getBeroep(); + Persoon(); +}; + diff --git a/week-3/TIer.cpp b/week-3/TIer.cpp new file mode 100644 index 0000000..801f417 --- /dev/null +++ b/week-3/TIer.cpp @@ -0,0 +1,5 @@ +#include "TIer.h" + +std::string TIer::getNaam() const { + return "TI-er"; +} diff --git a/week-3/TIer.h b/week-3/TIer.h new file mode 100644 index 0000000..35147e4 --- /dev/null +++ b/week-3/TIer.h @@ -0,0 +1,10 @@ +#pragma once + +#include "IBeroep.h" +#include <string> + +class TIer : public IBeroep { + public: + virtual std::string getNaam() const; +}; + diff --git a/week-3/main.cpp b/week-3/main.cpp new file mode 100644 index 0000000..b6b5019 --- /dev/null +++ b/week-3/main.cpp @@ -0,0 +1,18 @@ +#include "Persoon.h"
+#include "TIer.h"
+#include "ETer.h"
+
+#include <iostream>
+
+int main()
+{
+ Persoon persoon;
+
+ std::cout << persoon.getBeroep() << std::endl; // resultaat: geen beroep
+ persoon.setBeroep( new TIer );
+ std::cout << persoon.getBeroep() << std::endl; // resultaat: TI-er
+ persoon.setBeroep( new ETer );
+ std::cout << persoon.getBeroep() << std::endl; // resultaat: ET-er
+
+ return 0;
+}
diff --git a/week-3/makefile b/week-3/makefile new file mode 100644 index 0000000..3b71b5b --- /dev/null +++ b/week-3/makefile @@ -0,0 +1,24 @@ +CC = gcc +LD = gcc +RM = rm -f +TARGET = main + +LFLAGS += -lstdc++ + +SRCS := $(wildcard *.cpp) +OBJS := $(patsubst %.cpp,%.o, $(SRCS)) + +all: main + +%.o: %.cpp + $(CC) -c $(CFLAGS) $< -o $@ + +$(TARGET): $(OBJS) + $(LD) $^ $(LFLAGS) -o $@ + +clean: + $(RM) $(TARGET) $(OBJS) + +compile_commands: clean + compiledb make + |