From afe7337bd1230dfbed207ead0655f3b8a2362180 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 12 Sep 2022 10:20:36 +0200 Subject: week 3 huiswerk toegevoegd --- week-3/ETer.cpp | 5 +++++ week-3/ETer.h | 10 ++++++++++ week-3/IBeroep.cpp | 2 ++ week-3/IBeroep.h | 13 +++++++++++++ week-3/Persoon.cpp | 14 ++++++++++++++ week-3/Persoon.h | 15 +++++++++++++++ week-3/TIer.cpp | 5 +++++ week-3/TIer.h | 10 ++++++++++ week-3/main.cpp | 18 ++++++++++++++++++ week-3/makefile | 24 ++++++++++++++++++++++++ 10 files changed, 116 insertions(+) create mode 100644 week-3/ETer.cpp create mode 100644 week-3/ETer.h create mode 100644 week-3/IBeroep.cpp create mode 100644 week-3/IBeroep.h create mode 100644 week-3/Persoon.cpp create mode 100644 week-3/Persoon.h create mode 100644 week-3/TIer.cpp create mode 100644 week-3/TIer.h create mode 100644 week-3/main.cpp create mode 100644 week-3/makefile 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 + +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 + +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 + +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 + +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 + +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 + -- cgit v1.2.3