From 8f9c3d8093cba3204e3ead853ee36820a201a1e7 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 10 Nov 2022 11:59:16 +0100 Subject: week 1 van oop2 klaar --- oop2w1/HuiswerkWeek1.dat | Bin 0 -> 72 bytes oop2w1/ProcessFile.cpp | 36 ++++++++++++++++++++++++++++++++++++ oop2w1/ProcessFile.h | 25 +++++++++++++++++++++++++ oop2w1/ProcessFile.hpp | 13 +++++++++++++ oop2w1/main.cpp | 28 ++++++++++++++++++++++++++++ oop2w1/makefile | 1 + 6 files changed, 103 insertions(+) create mode 100644 oop2w1/HuiswerkWeek1.dat create mode 100644 oop2w1/ProcessFile.cpp create mode 100644 oop2w1/ProcessFile.h create mode 100644 oop2w1/ProcessFile.hpp create mode 100644 oop2w1/main.cpp create mode 120000 oop2w1/makefile diff --git a/oop2w1/HuiswerkWeek1.dat b/oop2w1/HuiswerkWeek1.dat new file mode 100644 index 0000000..7df850f Binary files /dev/null and b/oop2w1/HuiswerkWeek1.dat differ diff --git a/oop2w1/ProcessFile.cpp b/oop2w1/ProcessFile.cpp new file mode 100644 index 0000000..7f3629f --- /dev/null +++ b/oop2w1/ProcessFile.cpp @@ -0,0 +1,36 @@ +#include "ProcessFile.h" + +ProcessFile::ProcessFile() { } +ProcessFile::~ProcessFile() { } + +void ProcessFile::process(std::ifstream &file) { + uint32_t grootte = 0; + file.read((char*) &grootte, sizeof(uint32_t)); + for (unsigned int i = 0; i < grootte; i++) { + enum GETAL type; + file.read((char*) &type, sizeof(enum GETAL)); + + switch(type) { + case LONG: { + read_and_print(file); + break; + } + case SHORT: { + read_and_print(file); + break; + } + case DOUBLE: { + read_and_print(file); + break; + } + case FLOAT: { + read_and_print(file); + break; + } + default: { + break; + } + } + } +} + diff --git a/oop2w1/ProcessFile.h b/oop2w1/ProcessFile.h new file mode 100644 index 0000000..983f2ed --- /dev/null +++ b/oop2w1/ProcessFile.h @@ -0,0 +1,25 @@ +#pragma once + +/* + * DO NOT ADAPT THIS FILE!!! + */ + + +#include + +class ProcessFile +{ +public: + ProcessFile(); + virtual ~ProcessFile(); + +public: + virtual void process( std::ifstream& ); + +private: + enum GETAL { LONG=1, SHORT, DOUBLE, FLOAT }; + template + void read_and_print(std::ifstream &file); +}; + +#include "ProcessFile.hpp" diff --git a/oop2w1/ProcessFile.hpp b/oop2w1/ProcessFile.hpp new file mode 100644 index 0000000..37b82d4 --- /dev/null +++ b/oop2w1/ProcessFile.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include + +#include "ProcessFile.h" + +template +void ProcessFile::read_and_print(std::ifstream &file) { + T waarde; + file.read((char*) &waarde, sizeof(T)); + std::cout << waarde << std::endl; +} + diff --git a/oop2w1/main.cpp b/oop2w1/main.cpp new file mode 100644 index 0000000..e9d3197 --- /dev/null +++ b/oop2w1/main.cpp @@ -0,0 +1,28 @@ +/* + * DO NOT ADAPT THIS FILE!!! + */ + +#include "ProcessFile.h" + +#include +#include + +#define szFilename "HuiswerkWeek1.dat" + +int main() +{ + std::ifstream cInput( szFilename, std::ios::in | std::ios::binary ); + ProcessFile cProcessFile; + + if ( cInput ) + { + cProcessFile.process( cInput ); + + cInput.close(); + } + + std::cin.get(); + + return 0; +} + diff --git a/oop2w1/makefile b/oop2w1/makefile new file mode 120000 index 0000000..a4e84c6 --- /dev/null +++ b/oop2w1/makefile @@ -0,0 +1 @@ +../week.mk \ No newline at end of file -- cgit v1.2.3