From ffae2cb77bfb3263146a2de0deedf6528d4df461 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 9 Nov 2022 11:48:12 +0100 Subject: repository aanpassen voor oop2 --- oop1w5/StringWeek5.cpp | 12 ++++++++++++ oop1w5/StringWeek5.h | 16 ++++++++++++++++ oop1w5/StringWeek5.hpp | 12 ++++++++++++ oop1w5/main.cpp | 20 ++++++++++++++++++++ oop1w5/makefile | 1 + 5 files changed, 61 insertions(+) create mode 100644 oop1w5/StringWeek5.cpp create mode 100644 oop1w5/StringWeek5.h create mode 100644 oop1w5/StringWeek5.hpp create mode 100644 oop1w5/main.cpp create mode 120000 oop1w5/makefile (limited to 'oop1w5') diff --git a/oop1w5/StringWeek5.cpp b/oop1w5/StringWeek5.cpp new file mode 100644 index 0000000..ae8ba9f --- /dev/null +++ b/oop1w5/StringWeek5.cpp @@ -0,0 +1,12 @@ +#include + +#include "StringWeek5.h" + +void StringWeek5::removeAll(const std::string& remove) { + this->text = std::regex_replace(this->text, std::regex(remove), ""); +} + +const std::string& StringWeek5::getText() const { + return this->text; +} + diff --git a/oop1w5/StringWeek5.h b/oop1w5/StringWeek5.h new file mode 100644 index 0000000..8c2bdac --- /dev/null +++ b/oop1w5/StringWeek5.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +class StringWeek5 { +public: + template + void add(const T& value); + void removeAll(const std::string& remove); + const std::string& getText() const; +private: + std::string text; +}; + +#include "StringWeek5.hpp" diff --git a/oop1w5/StringWeek5.hpp b/oop1w5/StringWeek5.hpp new file mode 100644 index 0000000..ed71e75 --- /dev/null +++ b/oop1w5/StringWeek5.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "StringWeek5.h" +#include + +template +void StringWeek5::add(const T& value) { + std::stringstream value_str(""); + value_str << value; + this->text.append(value_str.str()); +} + diff --git a/oop1w5/main.cpp b/oop1w5/main.cpp new file mode 100644 index 0000000..a2603fa --- /dev/null +++ b/oop1w5/main.cpp @@ -0,0 +1,20 @@ +#include "StringWeek5.h" + +#include + +int main() { + StringWeek5 myString; + + myString.add("hallo allemaal "); + myString.add(42); + myString.add(" "); + myString.add(3.14159265358979); + + std::cout << myString.getText() << std::endl; + + myString.removeAll("all"); + + std::cout << myString.getText() << std::endl << std::endl; + + return 0; +} diff --git a/oop1w5/makefile b/oop1w5/makefile new file mode 120000 index 0000000..a4e84c6 --- /dev/null +++ b/oop1w5/makefile @@ -0,0 +1 @@ +../week.mk \ No newline at end of file -- cgit v1.2.3