Finished the ex06 and the module 01

This commit is contained in:
Raphael 2024-11-06 20:11:33 +01:00
parent 618ebf8777
commit 7565eabf9b
8 changed files with 244 additions and 4 deletions

68
cpp01/ex06/Harl.cpp Normal file
View file

@ -0,0 +1,68 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/06 17:41:03 by rparodi #+# #+# */
/* Updated: 2024/11/06 20:10:59 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
Harl::Harl(){}
Harl::~Harl(){}
void Harl::debug()
{
std::cout << "[DEBUG]" << std::endl << DEBUG_MSG << std::endl;
Harl::info();
}
void Harl::info()
{
std::cout << "[INFO]" << std::endl << INFO_MSG << std::endl;
Harl::warning();
}
void Harl::warning()
{
std::cout << "[WARNING]" << std::endl << WARN_MSG << std::endl;
Harl::error();
}
void Harl::error()
{
std::cout << "[ERROR]" << std::endl << ERROR_MSG << std::endl;
}
void Harl::complain(std::string level)
{
std::string categorie[] = {"DEBUG", "INFO", "WARNING", "ERROR"};
size_t i;
for (i = 0; i < 4; i++)
if (level == categorie[i])
break ;
switch (i)
{
case 0:
this->debug();
break;
case 1:
this->info();
break;
case 2:
this->warning();
break;
case 3:
this->error();
break;
default:
return ;
}
}

37
cpp01/ex06/Harl.hpp Normal file
View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/06 17:37:15 by rparodi #+# #+# */
/* Updated: 2024/11/06 19:43:33 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HARL_HPP
#define HARL_HPP
#include <string>
#include <iostream>
#define DEBUG_MSG "I love having extra bacon for my 7XL-double-cheese-triple-pickle-special- ketchup burger. I really do!"
#define ERROR_MSG "This is unacceptable! I want to speak to the manager now."
#define INFO_MSG "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!"
#define WARN_MSG "I think I deserve to have some extra bacon for free. Ive been coming for years whereas you started working here since last month."
class Harl
{
public:
Harl();
~Harl();
void complain(std::string level);
private:
void debug(void);
void info(void);
void warning(void);
void error(void);
};
#endif

109
cpp01/ex06/Makefile Normal file
View file

@ -0,0 +1,109 @@
# **************************************************************************** #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2024/11/06 19:44:47 by rparodi ### ########.fr #
# #
# **************************************************************************** #
# Variables
# Name
NAME = harlFilter
# Commands
CXX = c++
RM = rm -rf
# Flags
# Mandatory flags for 42 cpp
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
# Flags to debug and have the dependences (can be removed for correction)
CXXFLAGS += -MMD -g3
# Flag to debug (TO REMOVE)
# CXXFLAGS += -D DEBUG=1
# Sources
SRC = Harl.cpp \
main.cpp
# Objects
OBJDIRNAME = ./build
OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.cpp=.o))
# Colors
GREEN = \033[32m
GREY = \033[0;90m
RED = \033[0;31m
GOLD = \033[38;5;220m
END = \033[0m
# Rules
# All (make all)
all: header $(NAME) footer
# Clean (make clean)
clean:
@printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n'
@printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n'
@$(RM) $(OBJDIRNAME)
# Clean (make fclean)
fclean: clean
@printf '$(GREY) Removing $(END)$(RED)Program$(END)\n'
@$(RM) $(NAME)
@echo ""
# Restart (make re)
re: header fclean all
# Dependences for all
$(NAME): $(OBJ)
@mkdir -p $(OBJDIRNAME)
@printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n'
@$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ)
# Creating the objects
$(OBJDIRNAME)/%.o: %.cpp
@mkdir -p $(dir $@)
@printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n'
@$(CXX) $(CXXFLAGS) -o $@ -c $<
# Header
header:
@clear
@printf '\n\n'
@printf '$(GOLD) ******* ****** ******* $(END)\n'
@printf '$(GOLD) ****** *** ******* $(END)\n'
@printf '$(GOLD) ******* * ******* $(END)\n'
@printf '$(GOLD) ****** ******* $(END)\n'
@printf '$(GOLD) ******* ******* $(END)\n'
@printf '$(GOLD) ******************* ******* * $(END)\n'
@printf '$(GOLD) ******************* ******* *** $(END)\n'
@printf '$(GOLD) ****** ******* ****** $(END)\n'
@printf '$(GOLD) ****** $(END)\n'
@printf '$(GOLD) ****** $(END)\n'
@printf '$(GREY) Made by rparodi$(END)\n\n'
# Footer
footer:
@printf "\n"
@printf "$(GOLD) ,_ _,$(END)\n"
@printf "$(GOLD) | \\___//|$(END)\n"
@printf "$(GOLD) |=6 6=|$(END)\n"
@printf "$(GOLD) \\=._Y_.=/$(END)\n"
@printf "$(GOLD) ) \` ( ,$(END)\n"
@printf "$(GOLD) / \\ (('$(END)\n"
@printf "$(GOLD) | | ))$(END)\n"
@printf "$(GOLD) /| | | |\\_//$(END)\n"
@printf "$(GOLD) \\| |._.| |/-\`$(END)\n"
@printf "$(GOLD) '\"' '\"'$(END)\n"
@printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n'
# Phony
.PHONY: all bonus clean fclean re
-include ${OBJ:.o=.d}

BIN
cpp01/ex06/harlFilter Executable file

Binary file not shown.

26
cpp01/ex06/main.cpp Normal file
View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/06 18:11:42 by rparodi #+# #+# */
/* Updated: 2024/11/06 19:50:18 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
int main(int argc, char *argv[])
{
if (argc != 2)
{
std::cerr << "Error:\nThanks to follow this syntax: " << argv[0] << " <args>" << std::endl;
return (1);
}
Harl not_happy_peapol;
std::string choice(argv[1]);
not_happy_peapol.complain(choice);
}