diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-09-28 13:16:16 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-09-28 13:22:10 +0200 |
commit | 5c8d2ae4da91571f92f26d6e8352538c043e6b56 (patch) | |
tree | c285e6428af294551d33510c699addcedffe766a | |
parent | 841697f039dc5670f53ec6597ef6f639eeebcb5a (diff) |
week 5 huiswerk toegevoegd
-rw-r--r-- | week-5/StringWeek5.cpp | 12 | ||||
-rw-r--r-- | week-5/StringWeek5.h | 16 | ||||
-rw-r--r-- | week-5/StringWeek5.hpp | 12 | ||||
-rw-r--r-- | week-5/main.cpp | 20 | ||||
-rw-r--r-- | week-5/makefile | 24 |
5 files changed, 84 insertions, 0 deletions
diff --git a/week-5/StringWeek5.cpp b/week-5/StringWeek5.cpp new file mode 100644 index 0000000..ae8ba9f --- /dev/null +++ b/week-5/StringWeek5.cpp @@ -0,0 +1,12 @@ +#include <regex> + +#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/week-5/StringWeek5.h b/week-5/StringWeek5.h new file mode 100644 index 0000000..8c2bdac --- /dev/null +++ b/week-5/StringWeek5.h @@ -0,0 +1,16 @@ +#pragma once + +#include <string> +#include <sstream> + +class StringWeek5 { +public: + template <class T> + 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/week-5/StringWeek5.hpp b/week-5/StringWeek5.hpp new file mode 100644 index 0000000..ed71e75 --- /dev/null +++ b/week-5/StringWeek5.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "StringWeek5.h" +#include <string> + +template <typename T> +void StringWeek5::add(const T& value) { + std::stringstream value_str(""); + value_str << value; + this->text.append(value_str.str()); +} + diff --git a/week-5/main.cpp b/week-5/main.cpp new file mode 100644 index 0000000..a2603fa --- /dev/null +++ b/week-5/main.cpp @@ -0,0 +1,20 @@ +#include "StringWeek5.h" + +#include <iostream> + +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/week-5/makefile b/week-5/makefile new file mode 100644 index 0000000..3b71b5b --- /dev/null +++ b/week-5/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 + |