diff --git a/cpp01/ex05/Harl.cpp b/cpp01/ex05/Harl.cpp new file mode 100644 index 0000000..ec995d1 --- /dev/null +++ b/cpp01/ex05/Harl.cpp @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/21 22:07:00 by apommier #+# #+# */ +/* Updated: 2022/06/21 23:23:28 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/ex05/Harl.hpp b/cpp01/ex05/Harl.hpp new file mode 100644 index 0000000..e137074 --- /dev/null +++ b/cpp01/ex05/Harl.hpp @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/21 22:07:08 by apommier #+# #+# */ +/* Updated: 2022/06/21 23:35:01 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/ex05/Makefile b/cpp01/ex05/Makefile new file mode 100644 index 0000000..b8710e1 --- /dev/null +++ b/cpp01/ex05/Makefile @@ -0,0 +1,36 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2022/06/21 22:05:40 by apommier #+# #+# # +# Updated: 2022/06/21 23:10:46 by apommier ### ########.fr # +# # +# **************************************************************************** # + +NAME = a.out +SRCS = main.cpp\ + Harl.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/ex05/main.cpp b/cpp01/ex05/main.cpp new file mode 100644 index 0000000..346dc77 --- /dev/null +++ b/cpp01/ex05/main.cpp @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/21 22:06:54 by apommier #+# #+# */ +/* Updated: 2022/06/21 23:37:53 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +int main() +{ + Harl harl; + std::string levelTab[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; + + std::cout << "Debug level:\n"; + harl.complain("DEBUG"); + + std::cout << "\nInfo level:\n"; + harl.complain("INFO"); + + std::cout << "\nWarning level:\n"; + harl.complain("WARNING"); + + std::cout << "\nError level:\n"; + harl.complain("ERROR"); + + std::cout << "\nA lot of complaints\n"; + for (int i = 0; i < 20; i++) + harl.complain(levelTab[std::rand() % 4]); + + return (0); +} \ No newline at end of file