This commit is contained in:
whaffman 2025-03-24 12:58:34 +01:00
parent 5cef88bae1
commit 1dc7d86a71
17 changed files with 301 additions and 6 deletions

50
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,50 @@
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"fstream": "cpp"
}
}

View File

@ -6,12 +6,12 @@
# By: whaffman <whaffman@student.codam.nl> +#+ #
# +#+ #
# Created: 2025/03/19 16:44:48 by whaffman #+# #+# #
# Updated: 2025/03/21 15:17:22 by whaffman ######## odam.nl #
# Updated: 2025/03/23 14:02:26 by whaffman ######## odam.nl #
# #
# **************************************************************************** #
NAME =
SRC =
NAME = Replacer
SRC = Replacer.cpp main.cpp
-include ../common.mk

BIN
ex04/Replacer Executable file

Binary file not shown.

BIN
ex04/Replacer.o Normal file

Binary file not shown.

29
ex04/inc/Replacer.hpp Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* Replacer.hpp :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/03/23 13:26:27 by whaffman #+# #+# */
/* Updated: 2025/03/23 14:04:08 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#pragma once
#include <string>
class Replacer
{
private:
std::string oldString;
std::string newString;
Replacer();
public:
~Replacer();
Replacer(std::string const &oldString, std::string const &newString);
std::string process(std::string const &input) const;
};

BIN
ex04/main.o Normal file

Binary file not shown.

52
ex04/src/Replacer.cpp Normal file
View File

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* Replacer.cpp :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/03/23 13:30:57 by whaffman #+# #+# */
/* Updated: 2025/03/23 14:05:40 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include <string>
#include <iostream>
#include "Replacer.hpp"
Replacer::Replacer()
{
}
Replacer::~Replacer()
{
}
Replacer::Replacer(std::string const &oldString, std::string const &newString) : oldString(oldString), newString(newString)
{
}
std::string Replacer::process(std::string const &input) const
{
std::string result = "";
size_t i = 0;
size_t j = 0;
for (i = 0; i < input.size(); i++)
{
j = 0;
while (i + j < input.size() && input[i + j] == oldString[j])
j++;
if (j == oldString.size())
{
result += newString;
i += j - 1;
}
else
result += input[i];
}
return result;
}

47
ex04/src/main.cpp Normal file
View File

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.cpp :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/03/23 13:59:46 by whaffman #+# #+# */
/* Updated: 2025/03/23 14:28:19 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include <iostream>
#include <fstream>
#include <string>
#include "Replacer.hpp"
int main(int argc, char *argv[])
{
std::ifstream inFile;
std::fstream outFile;
std::string outFileName;
std::string line;
if (argc != 4)
std::cout << "Usage: ./Replacer <filename> <old string> <new string>" << std::endl;
inFile.open(argv[1], std::ios::in);
if (!inFile.is_open())
std::cout << "Can't open In file" << std::endl;
outFileName = argv[1];
outFileName += ".replace";
outFile.open(outFileName, std::ios::out);
if (!outFile.is_open())
std::cout << "Can't open OUT file" << std::endl;
Replacer replacer(argv[2], argv[3]);
while(std::getline(inFile, line))
{
outFile << replacer.process(line);
if (!inFile.eof())
outFile << std::endl;
}
}

2
ex04/testfile Normal file
View File

@ -0,0 +1,2 @@
Dit is een test, maar niet zomaar een test
Dit is een test, maar niet zomaar een test

2
ex04/testfile.replace Normal file
View File

@ -0,0 +1,2 @@
Dit is een proef, maar niet zomaar een proef
Dit is een proef, maar niet zomaar een proef

BIN
ex05/Harl Executable file

Binary file not shown.

BIN
ex05/Harl.o Normal file

Binary file not shown.

View File

@ -6,12 +6,12 @@
# By: whaffman <whaffman@student.codam.nl> +#+ #
# +#+ #
# Created: 2025/03/19 16:44:48 by whaffman #+# #+# #
# Updated: 2025/03/21 15:17:22 by whaffman ######## odam.nl #
# Updated: 2025/03/23 15:40:09 by whaffman ######## odam.nl #
# #
# **************************************************************************** #
NAME =
SRC =
NAME = Harl
SRC = Harl.cpp main.cpp
-include ../common.mk

28
ex05/inc/Harl.hpp Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* Harl.hpp :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/03/23 15:06:27 by whaffman #+# #+# */
/* Updated: 2025/03/23 15:35:07 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include <iostream>
class Harl
{
private:
std::string levels[4];
void (Harl::*levelFunc[4])();
void info();
void debug();
void warning();
void error();
public:
Harl();
~Harl();
void complain(std::string level);
};

BIN
ex05/main.o Normal file

Binary file not shown.

62
ex05/src/Harl.cpp Normal file
View File

@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* Harl.cpp :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/03/23 15:09:28 by whaffman #+# #+# */
/* Updated: 2025/03/23 15:44:03 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
Harl::Harl()
{
levels[0] = "DEBUG";
levels[1] = "INFO";
levels[2] = "WARNING";
levels[3] = "ERROR";
levelFunc[0] = &Harl::debug;
levelFunc[1] = &Harl::info;
levelFunc[2] = &Harl::warning;
levelFunc[3] = &Harl::error;
}
Harl::~Harl() {}
void Harl::debug()
{
std::cout << "[DEBUG]" << std::endl;
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-special-ketchup burger. I really do!" << std::endl;
}
void Harl::info()
{
std::cout << "[INFO]" << std::endl;
std::cout << "I cannot believe adding extra bacon costs more money. You didnt put enough bacon in my burger! If you did, I wouldnt be asking for more!" << std::endl;
}
void Harl::warning()
{
std::cout << "[WARNING]" << std::endl;
std::cout << "I think I deserve to have some extra bacon for free. Ive been coming for years, whereas you started working here just last month." << std::endl;
}
void Harl::error()
{
std::cout << "[ERROR]" << std::endl;
std::cout << "This is unacceptable! I want to speak to the manager now." << std::endl;
}
void Harl::complain(std::string level)
{
for (int i = 0; i < 4; i++)
{
if (level == levels[i])
{
(this->*levelFunc[i])();
return ;
}
}
std::cout << "I don't know anymorre what to complain about" << std::endl;
}

23
ex05/src/main.cpp Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.cpp :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/03/23 15:38:32 by whaffman #+# #+# */
/* Updated: 2025/03/23 15:44:11 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
int main(void)
{
Harl harl;
harl.complain("DEBUG");
harl.complain("INFO");
harl.complain("WARNING");
harl.complain("ERROR");
harl.complain("TEST");
}