1
0

」 feat(Harl 2.0): Ex05 finished

This commit is contained in:
2024-11-09 17:43:25 +01:00
parent c2089dac6d
commit e292dcc32e
5 changed files with 148 additions and 0 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ zombieHorde
thisisabrain
violence
sed
harl

55
ex05/Makefile Normal file
View File

@ -0,0 +1,55 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
# Updated: 2024/11/09 16:15:35 by adjoly ### ########.fr #
# #
# **************************************************************************** #
NAME = harl
CC = c++
OBJSDIR = obj/
SRCS = main.cpp \
harl.cpp
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
PURPLE = \e[0;35m
NC = \033[0m
DELETE = \x1B[2K\r
all: $(NAME)
$(NAME): $(OBJS)
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
$(OBJSDIR)%.o: %.cpp
@mkdir -p $(@D)
@$(CC) $(FLAGS) -c $< -o $@
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
clean:
@rm -f $(OBJS)
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
fclean: clean
@rm -f $(NAME)
@rm -Rf $(OBJSDIR)
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
re: fclean all
.PHONY: clean fclean all re

42
ex05/harl.cpp Normal file
View File

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* harl.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/09 17:15:01 by adjoly #+# #+# */
/* Updated: 2024/11/09 17:39:12 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "harl.hpp"
#include <iostream>
void Harl::complain(std::string level) {
std::string complainLevel[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
void (Harl::*func[4])(void) = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
uint8_t i = 0;
while (i < 4 && level != complainLevel[i])
i++;
if (i < 4)
(this->*func[i])();
return ;
}
void Harl::debug(void) {
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!" << std::endl;
}
void Harl::info(void) {
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(void) {
std::cout << "I think I deserve to have some extra bacon for free. Ive been coming for years whereas you 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::endl;
}

28
ex05/harl.hpp Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/09 16:13:40 by adjoly #+# #+# */
/* Updated: 2024/11/09 17:35:57 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <string>
#define uint8_t unsigned char
class Harl {
private:
void debug(void);
void info(void);
void warning(void);
void error(void);
public:
void complain(std::string level);
};

22
ex05/main.cpp Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/09 16:12:06 by adjoly #+# #+# */
/* Updated: 2024/11/09 17:42:31 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "harl.hpp"
int main(void) {
Harl harl;
/* harl.complain("INFO"); */
/* harl.complain("DEBUG"); */
harl.complain("WARNING");
/* harl.complain("ERROR"); */
}