end 01 05
This commit is contained in:
parent
d4cfd72f97
commit
0dea92d24f
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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]);
|
||||
|
||||
|
||||
55
cpp01/ex06/Harl.cpp
Normal file
55
cpp01/ex06/Harl.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Harl.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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";
|
||||
}
|
||||
38
cpp01/ex06/Harl.hpp
Normal file
38
cpp01/ex06/Harl.hpp
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Harl.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <iostream>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
class Harl {
|
||||
|
||||
public:
|
||||
|
||||
Harl();
|
||||
~Harl();
|
||||
|
||||
void complain(std::string level);
|
||||
|
||||
private:
|
||||
|
||||
void debug(void);
|
||||
void info(void);
|
||||
void warning(void);
|
||||
void error(void);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
35
cpp01/ex06/Makefile
Normal file
35
cpp01/ex06/Makefile
Normal file
@ -0,0 +1,35 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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
|
||||
13
cpp01/ex06/main.cpp
Normal file
13
cpp01/ex06/main.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/06/21 23:40:41 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/21 23:40:55 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Harl.hpp"
|
||||
Loading…
Reference in New Issue
Block a user