From adb4076e576af4990051ff18f2afd017619d077e Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 23 Nov 2022 10:20:31 +0100 Subject: huiswerk week 3 klaar --- oop2w3/A.cpp | 25 +++++++++++++++++++++++++ oop2w3/A.h | 12 ++++++++++++ oop2w3/B.cpp | 28 ++++++++++++++++++++++++++++ oop2w3/B.h | 17 +++++++++++++++++ oop2w3/C.cpp | 11 +++++++++++ oop2w3/C.h | 8 ++++++++ oop2w3/main.cpp | 15 +++++++++++++++ oop2w3/makefile | 1 + 8 files changed, 117 insertions(+) create mode 100644 oop2w3/A.cpp create mode 100644 oop2w3/A.h create mode 100644 oop2w3/B.cpp create mode 100644 oop2w3/B.h create mode 100644 oop2w3/C.cpp create mode 100644 oop2w3/C.h create mode 100644 oop2w3/main.cpp create mode 120000 oop2w3/makefile (limited to 'oop2w3') diff --git a/oop2w3/A.cpp b/oop2w3/A.cpp new file mode 100644 index 0000000..b6f0d57 --- /dev/null +++ b/oop2w3/A.cpp @@ -0,0 +1,25 @@ +#include + +#include "A.h" + +A::A() { + std::cout << "A::A()" << std::endl; + _b = nullptr; +} + +void A::actie1(int n) { + std::cout << "A::actie1(" << n << ")" << std::endl; + for (unsigned int i = 0; i <= n; i++) { + if (i % 2 == 0) { + _b->even(); + } else { + _b->odd(i); + } + } +} + +void A::setB(B b) { + std::cout << "A::setB(b)" << std::endl; + _b = &b; +} + diff --git a/oop2w3/A.h b/oop2w3/A.h new file mode 100644 index 0000000..c0caae4 --- /dev/null +++ b/oop2w3/A.h @@ -0,0 +1,12 @@ +#pragma once + +#include "B.h" + +class A { + private: + B* _b; + public: + A(); + virtual void setB(B b); + virtual void actie1(int n); +}; diff --git a/oop2w3/B.cpp b/oop2w3/B.cpp new file mode 100644 index 0000000..6eb4bd2 --- /dev/null +++ b/oop2w3/B.cpp @@ -0,0 +1,28 @@ +#include + +#include "A.h" +#include "B.h" + +B::B(A a) { + std::cout << "B::B(a)" << std::endl; + _a = &a; + _c = new C(); +} + +void B::even() { + std::cout << "B::even()" << std::endl; +} + +void B::odd(int i) { + std::cout << "B::odd(" << i << ")" << std::endl; +} + +void B::actie2(int i) { + std::cout << "B::actie2(" << i << ")" << std::endl; + actie3(); + if (i < 3) _c->actie4(); +} + +void B::actie3() { + std::cout << "B::actie3()" << std::endl; +} diff --git a/oop2w3/B.h b/oop2w3/B.h new file mode 100644 index 0000000..081dc8b --- /dev/null +++ b/oop2w3/B.h @@ -0,0 +1,17 @@ +#pragma once + +class A; +#include "C.h" + +class B { + private: + A* _a; + C* _c; + public: + B(A a); + virtual void even(); + virtual void odd(int i); + virtual void actie2(int i); + virtual void actie3(); +}; + diff --git a/oop2w3/C.cpp b/oop2w3/C.cpp new file mode 100644 index 0000000..6a0fadd --- /dev/null +++ b/oop2w3/C.cpp @@ -0,0 +1,11 @@ +#include + +#include "C.h" + +C::C() { + std::cout << "C::C()" << std::endl; +} + +void C::actie4() { + std::cout << "C::actie4()" << std::endl; +} diff --git a/oop2w3/C.h b/oop2w3/C.h new file mode 100644 index 0000000..1e22eb1 --- /dev/null +++ b/oop2w3/C.h @@ -0,0 +1,8 @@ +#pragma once + +class C { + public: + C(); + virtual void actie4(); +}; + diff --git a/oop2w3/main.cpp b/oop2w3/main.cpp new file mode 100644 index 0000000..90a88b6 --- /dev/null +++ b/oop2w3/main.cpp @@ -0,0 +1,15 @@ +#include + +#include "A.h" +#include "B.h" + +int main() { + std::cout << "main()" << std::endl; + int n = 2; + A a; + B b(a); + a.setB(b); + a.actie1(n); + b.actie2(n); + return 0; +} diff --git a/oop2w3/makefile b/oop2w3/makefile new file mode 120000 index 0000000..a4e84c6 --- /dev/null +++ b/oop2w3/makefile @@ -0,0 +1 @@ +../week.mk \ No newline at end of file -- cgit v1.2.3