This commit is contained in:
Angel Ortigosa Perez
2025-09-07 10:03:17 +02:00
commit 859690063b
30 changed files with 846 additions and 0 deletions

58
ex05/Harl/Harl.cpp Normal file
View File

@@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
void Harl::debug( void )
{
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!";
std::cout << 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::cout << 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 just last month.";
std::cout << std::endl;
}
void Harl::error( void )
{
std::cout << "This is unacceptable! I want to speak to the manager now.";
std::cout << std::endl;
}
void Harl::complain( std::string level )
{
int i;
typedef void (Harl::*HarlFunc)();
i = 0;
std::string levels[]= {"DEBUG", "INFO", "WARNING", "ERROR"};
HarlFunc funcs[] = { &Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
while (i < 4)
{
if (level == levels[i])
{
(this->*funcs[i])();
break ;
}
i++;
}
}

32
ex05/Harl/Harl.hpp Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HARL_HPP
# define HARL_HPP
# include <iostream>
class Harl
{
private:
void debug( void );
void info( void );
void warning( void );
void error( void );
public:
void complain( std::string level );
};
#endif

BIN
ex05/Harl/Harl.o Normal file

Binary file not shown.

26
ex05/Makefile Normal file
View File

@@ -0,0 +1,26 @@
NAME=harl
SRCS=main.cpp Harl/Harl.cpp
OBJS=$(SRCS:.cpp=.o)
CC=g++
CFLAGS=-Wall -Wextra -Werror -std=c++98
all: $(NAME)
$(NAME): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(NAME)
%.o: %.cpp
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJS)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY: all clean fclean re

BIN
ex05/harl Executable file

Binary file not shown.

24
ex05/main.cpp Normal file
View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 15:23:33 by aortigos #+# #+# */
/* Updated: 2025/09/06 15:48:52 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl/Harl.hpp"
int main(int argc, char **argv)
{
Harl h;
if (argc == 2)
h.complain(argv[1]);
else
std::cout << "Uso: ./harl {DEBUG | INFO | WARNING | ERROR}" << std::endl;
return (0);
}

BIN
ex05/main.o Normal file

Binary file not shown.