aboutsummaryrefslogtreecommitdiff
path: root/oop1w6
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-11-09 11:48:12 +0100
committerlonkaars <loek@pipeframe.xyz>2022-11-09 11:48:12 +0100
commitffae2cb77bfb3263146a2de0deedf6528d4df461 (patch)
tree88e4b61087069f8ce5badadbc6264d20b8a051d5 /oop1w6
parentd797758769d033c64babdf77ea6b64262f792b23 (diff)
repository aanpassen voor oop2
Diffstat (limited to 'oop1w6')
-rw-r--r--oop1w6/Punt.cpp17
-rw-r--r--oop1w6/Punt.h17
-rw-r--r--oop1w6/PuntContainer.cpp72
-rw-r--r--oop1w6/PuntContainer.h35
-rw-r--r--oop1w6/main.cpp23
l---------oop1w6/makefile1
6 files changed, 165 insertions, 0 deletions
diff --git a/oop1w6/Punt.cpp b/oop1w6/Punt.cpp
new file mode 100644
index 0000000..707047e
--- /dev/null
+++ b/oop1w6/Punt.cpp
@@ -0,0 +1,17 @@
+#include "Punt.h"
+
+Punt::Punt() {
+ this->x = this->y = this->z = 0;
+}
+
+Punt::Punt(int x, int y, int z) {
+ this->x = x;
+ this->y = y;
+ this->z = z;
+}
+
+std::ostream& operator << ( std::ostream& output, const Punt& punt ) {
+ output << "(" << punt.x << "," << punt.y << "," << punt.z << ")";
+ return output;
+}
+
diff --git a/oop1w6/Punt.h b/oop1w6/Punt.h
new file mode 100644
index 0000000..b56e798
--- /dev/null
+++ b/oop1w6/Punt.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <iostream>
+
+class Punt
+{
+private:
+ Punt();
+ Punt( int x, int y, int z );
+
+ friend std::ostream& operator << ( std::ostream& output, const Punt& punt );
+
+private:
+ int x, y, z;
+
+ friend class PuntContainer;
+};
diff --git a/oop1w6/PuntContainer.cpp b/oop1w6/PuntContainer.cpp
new file mode 100644
index 0000000..e673472
--- /dev/null
+++ b/oop1w6/PuntContainer.cpp
@@ -0,0 +1,72 @@
+#include <memory>
+
+#include "PuntContainer.h"
+#include "Punt.h"
+
+int PuntContainer::checkX(const Punt& punt1, const Punt& punt2) {
+ return punt1.x - punt2.x;
+}
+
+int PuntContainer::checkY(const Punt& punt1, const Punt& punt2) {
+ return punt1.y - punt2.y;
+}
+
+int PuntContainer::checkZ(const Punt& punt1, const Punt& punt2) {
+ return punt1.z - punt2.z;
+}
+
+int PuntContainer::checkX2(const Punt& punt1, const Punt& punt2) const {
+ return punt1.x - punt2.x;
+}
+
+int PuntContainer::checkY2(const Punt& punt1, const Punt& punt2) const {
+ return punt1.y - punt2.y;
+}
+
+int PuntContainer::checkZ2(const Punt& punt1, const Punt& punt2) const {
+ return punt1.z - punt2.z;
+}
+
+PuntContainer::PuntContainer() {
+ this->puntRij = (Punt*) malloc(sizeof(Punt) * 10);
+ this->grootte = 0;
+}
+
+PuntContainer::~PuntContainer() {
+ free(this->puntRij);
+}
+
+void PuntContainer::add(int x, int y, int z) {
+ puntRij[grootte].x = x;
+ puntRij[grootte].y = y;
+ puntRij[grootte].z = z;
+ grootte++;
+}
+
+void PuntContainer::sort1(int (*fnCompare)(const Punt&, const Punt&)) {
+ for ( uint32_t outer = grootte-1; outer > 0; outer-- )
+ for ( uint32_t inner=0; inner < outer; inner++ )
+ if ( (*fnCompare)(puntRij[inner],puntRij[inner+1]) > 0 ) {
+ Punt temp = puntRij[inner];
+ puntRij[inner] = puntRij[inner+1];
+ puntRij[inner+1] = temp;
+ }
+}
+
+void PuntContainer::sort2(int (PuntContainer::*fnCompare)(const Punt&, const Punt&) const) {
+ for ( uint32_t outer = grootte-1; outer > 0; outer-- )
+ for ( uint32_t inner=0; inner < outer; inner++ ) {
+ if ( (*this.*fnCompare)(puntRij[inner],puntRij[inner+1]) > 0 ) {
+ Punt temp = puntRij[inner];
+ puntRij[inner] = puntRij[inner+1];
+ puntRij[inner+1] = temp;
+ }
+ }
+}
+
+void PuntContainer::showAll() {
+ for (uint32_t i = 0; i < this->grootte; i++)
+ std::cout << this->puntRij[i] << std::endl;
+ std::cout << std::endl;
+}
+
diff --git a/oop1w6/PuntContainer.h b/oop1w6/PuntContainer.h
new file mode 100644
index 0000000..58c7875
--- /dev/null
+++ b/oop1w6/PuntContainer.h
@@ -0,0 +1,35 @@
+#pragma once
+
+class Punt;
+
+#include <cstdint>
+
+class PuntContainer
+{
+public:
+ PuntContainer();
+ virtual ~PuntContainer();
+
+public:
+ virtual void add( int x, int y, int z );
+
+ virtual void sort1( int (*)( const Punt&, const Punt&) );
+ virtual void sort2( int (PuntContainer::*)( const Punt&, const Punt&) const );
+
+ virtual void showAll();
+
+public:
+ static int checkX( const Punt& punt1, const Punt& punt2 );
+ static int checkY( const Punt& punt1, const Punt& punt2 );
+ static int checkZ( const Punt& punt1, const Punt& punt2 );
+
+public:
+ virtual int checkX2( const Punt& punt1, const Punt& punt2 ) const;
+ virtual int checkY2( const Punt& punt1, const Punt& punt2 ) const;
+ virtual int checkZ2( const Punt& punt1, const Punt& punt2 ) const;
+
+private:
+ Punt* puntRij;
+ uint32_t grootte;
+};
+
diff --git a/oop1w6/main.cpp b/oop1w6/main.cpp
new file mode 100644
index 0000000..701ac33
--- /dev/null
+++ b/oop1w6/main.cpp
@@ -0,0 +1,23 @@
+#include "PuntContainer.h"
+
+#include <iostream>
+
+int main()
+{
+ PuntContainer container;
+
+ container.add( 1, 3, 4 );
+ container.add( 3, 2, 1 );
+ container.add( 2, 4, 2 );
+
+ container.sort2( &PuntContainer::checkZ2 );
+ container.showAll();
+
+ container.sort2( &PuntContainer::checkY2 );
+ container.showAll();
+
+ container.sort2( &PuntContainer::checkX2 );
+ container.showAll();
+
+ return 0;
+}
diff --git a/oop1w6/makefile b/oop1w6/makefile
new file mode 120000
index 0000000..a4e84c6
--- /dev/null
+++ b/oop1w6/makefile
@@ -0,0 +1 @@
+../week.mk \ No newline at end of file