diff options
| author | Dominik Kaiser | 2025-02-12 13:28:42 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2025-02-12 13:28:42 +0100 |
| commit | 92a665752945aa7731ad51fa66ecac768064c51e (patch) | |
| tree | 0f98445db173155287411578baeea8d80ad85112 /ex06 | |
| parent | 368088666e4de671a3309a49cdd0dc6b2f30c003 (diff) | |
| download | cpp01-92a665752945aa7731ad51fa66ecac768064c51e.tar.gz cpp01-92a665752945aa7731ad51fa66ecac768064c51e.zip | |
Copy files from ex05 to ex06
Diffstat (limited to 'ex06')
| -rw-r--r-- | ex06/Harl.cpp | 55 | ||||
| -rw-r--r-- | ex06/Harl.hpp | 28 | ||||
| -rw-r--r-- | ex06/Makefile | 50 | ||||
| -rw-r--r-- | ex06/main.cpp | 24 |
4 files changed, 157 insertions, 0 deletions
diff --git a/ex06/Harl.cpp b/ex06/Harl.cpp new file mode 100644 index 0000000..fcad030 --- /dev/null +++ b/ex06/Harl.cpp @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/12 10:37:12 by dkaiser #+# #+# */ +/* Updated: 2025/02/12 11:29:15 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" +#include <iostream> + +void Harl::complain(std::string level) +{ + std::string levels[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; + void (Harl::*funcs[4])() = {&Harl::debug, + &Harl::info, + &Harl::warning, + &Harl::error}; + for (int i = 0; i < 4; i++) + { + if (level == levels[i]) + (this->*funcs[i])(); + } +} + +void Harl::debug(void) +{ + std::cout << "I love having extra bacon for my "; + std::cout << "7XL-double-cheese-triple-pickle-special-ketchup burger. "; + std::cout << "I really do!" << std::endl; +} + +void Harl::info(void) +{ + std::cout << "I cannot believe adding extra bacon costs more money. "; + std::cout << "You didn’t put enough bacon in my burger! "; + std::cout << "If you did, I wouldn’t be asking for more!" << std::endl; +} + +void Harl::warning(void) +{ + std::cout << "I think I deserve to have some extra bacon for free. "; + std::cout << "I’ve been coming for years whereas you "; + std::cout << "started working here since last month." << std::endl; +} + +void Harl::error(void) +{ + std::cout << "This is unacceptable! I want to speak to the manager now."; + std::cout << std::endl; +} diff --git a/ex06/Harl.hpp b/ex06/Harl.hpp new file mode 100644 index 0000000..ade7f98 --- /dev/null +++ b/ex06/Harl.hpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/12 10:36:43 by dkaiser #+# #+# */ +/* Updated: 2025/02/12 11:36:33 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HARL_H_ +#define HARL_H_ + +#include <string> +class Harl +{ + public: + void complain(std::string level); + private: + void debug(void); + void info(void); + void warning(void); + void error(void); +}; + +#endif diff --git a/ex06/Makefile b/ex06/Makefile new file mode 100644 index 0000000..2696d22 --- /dev/null +++ b/ex06/Makefile @@ -0,0 +1,50 @@ +################################################################################ +################################## VARIABLES ################################### +################################################################################ + +NAME := harl + +CC = c++ +CFLAGS = -Wall -Wextra -Werror -std=c++17 +HEADERS = -I. + +SRC := main.cpp Harl.cpp + +OBJ_DIR := _obj +OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.cpp=%.o)) + +################################################################################ +#################################### RULES ##################################### +################################################################################ + +all: $(NAME) + +$(NAME): $(OBJ) + @$(CC) $(CFLAGS) $^ -o $@ $(HEADERS) + @echo "[$(NAME)] Created binary." + +$(OBJ_DIR)/%.o: %.cpp + @if [ ! -d "$(dir $@)" ]; then \ + mkdir -p $(dir $@); \ + fi + @$(CC) $(CFLAGS) -c $< -o $@ $(HEADERS) + @echo "[$(NAME)] Compiled $<." + +clean: + @if [ -d "$(OBJ_DIR)" ]; then \ + rm -rf $(OBJ_DIR); \ + echo "[$(NAME)] Removed object files."; \ + fi + +fclean: clean + @if [ -f "$(NAME)" ]; then \ + rm -f $(NAME); \ + echo "[$(NAME)] Removed binary."; \ + fi + +re: fclean all + +.PHONY: all clean fclean re + +################################################################################ +################################################################################ diff --git a/ex06/main.cpp b/ex06/main.cpp new file mode 100644 index 0000000..1180187 --- /dev/null +++ b/ex06/main.cpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/12 10:35:53 by dkaiser #+# #+# */ +/* Updated: 2025/02/12 11:35:27 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +int main(void) +{ + Harl harl = Harl(); + + harl.complain("DEBUG"); + harl.complain("INFO"); + harl.complain("WARNING"); + harl.complain("ERROR"); + harl.complain("Invalid Input"); +} |
