diff --git a/cpp01/ex05/main.cpp b/cpp01/ex05/main.cpp index 346dc77..4b83a51 100644 --- a/cpp01/ex05/main.cpp +++ b/cpp01/ex05/main.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/21 22:06:54 by apommier #+# #+# */ -/* Updated: 2022/06/21 23:37:53 by apommier ### ########.fr */ +/* Updated: 2022/06/21 23:43:26 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,19 +17,19 @@ int main() Harl harl; std::string levelTab[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; - std::cout << "Debug level:\n"; + std::cout << "[ DEBUG ]\n"; harl.complain("DEBUG"); - std::cout << "\nInfo level:\n"; + std::cout << "\n[ INFO ]\n"; harl.complain("INFO"); - std::cout << "\nWarning level:\n"; + std::cout << "\n[ WARNING ]\n"; harl.complain("WARNING"); - std::cout << "\nError level:\n"; + std::cout << "\n[ ERROR ]\n"; harl.complain("ERROR"); - std::cout << "\nA lot of complaints\n"; + std::cout << "\n[ LotOfComplaints ]\n"; for (int i = 0; i < 20; i++) harl.complain(levelTab[std::rand() % 4]); diff --git a/cpp01/ex06/Harl.cpp b/cpp01/ex06/Harl.cpp new file mode 100644 index 0000000..e941a83 --- /dev/null +++ b/cpp01/ex06/Harl.cpp @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/21 23:39:20 by apommier #+# #+# */ +/* Updated: 2022/06/21 23:44:25 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +Harl::Harl() +{ + +} + +Harl::~Harl() +{ + +} + +void Harl::complain(std::string level) +{ + void (Harl::*complaint[])(void) = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error}; + std::string levelTab[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; + for (int i = 0; i < 4 ; i++) + { + void (Harl::*selectedComplaint)( void ) = complaint[i]; + if (level == levelTab[i]) + (this->*selectedComplaint)(); + } +} + +void Harl::debug() +{ + std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!\n"; +} + +void Harl::info() +{ + std::cout << "I cannot believe adding extra bacon costs more money. You didn’t putenough bacon in my burger! If you did, I wouldn’t be asking for more!\n"; +} + +void Harl::warning() +{ + std::cout << "I think I deserve to have some extra bacon for free. I’ve been coming for years whereas you started working here since last month.\n"; +} + +void Harl::error() +{ + std::cout << "This is unacceptable! I want to speak to the manager now.\n"; +} \ No newline at end of file diff --git a/cpp01/ex06/Harl.hpp b/cpp01/ex06/Harl.hpp new file mode 100644 index 0000000..0fa41e5 --- /dev/null +++ b/cpp01/ex06/Harl.hpp @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/21 23:39:11 by apommier #+# #+# */ +/* Updated: 2022/06/21 23:44:12 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HARL_HPP +# define HARL_HPP + +#include +#include +#include + +class Harl { + + public: + + Harl(); + ~Harl(); + + void complain(std::string level); + + private: + + void debug(void); + void info(void); + void warning(void); + void error(void); + +}; + +#endif \ No newline at end of file diff --git a/cpp01/ex06/Makefile b/cpp01/ex06/Makefile new file mode 100644 index 0000000..548f7b3 --- /dev/null +++ b/cpp01/ex06/Makefile @@ -0,0 +1,35 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2022/06/21 23:38:45 by apommier #+# #+# # +# Updated: 2022/06/21 23:40:23 by apommier ### ########.fr # +# # +# **************************************************************************** # + +NAME = harlFilter +SRCS = main.cpp\ + + +OBJS = ${SRCS:.cpp=.o} +CC = c++ +CFLAGS = -Wall -Wextra -Werror +RM = rm -rf + +${NAME}: ${OBJS} + ${CC} ${LIB} ${OBJS} -o ${NAME} + +all: ${NAME} + +clean: + @${RM} ${OBJS} + +fclean: clean + @${RM} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re \ No newline at end of file diff --git a/cpp01/ex06/main.cpp b/cpp01/ex06/main.cpp new file mode 100644 index 0000000..cb1a1af --- /dev/null +++ b/cpp01/ex06/main.cpp @@ -0,0 +1,13 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/21 23:40:41 by apommier #+# #+# */ +/* Updated: 2022/06/21 23:40:55 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" \ No newline at end of file