end 01 05
This commit is contained in:
parent
87a2582eef
commit
d4cfd72f97
55
cpp01/ex05/Harl.cpp
Normal file
55
cpp01/ex05/Harl.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Harl.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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";
|
||||||
|
}
|
||||||
38
cpp01/ex05/Harl.hpp
Normal file
38
cpp01/ex05/Harl.hpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Harl.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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 <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
|
||||||
36
cpp01/ex05/Makefile
Normal file
36
cpp01/ex05/Makefile
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# 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
|
||||||
37
cpp01/ex05/main.cpp
Normal file
37
cpp01/ex05/main.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* 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 */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user