g la chiassss

This commit is contained in:
Camille Chauvet 2023-07-31 18:03:40 +02:00
parent cebe9f6ea7
commit 35cbcfd02d
4 changed files with 103 additions and 0 deletions

25
ex06/Makefile Normal file
View File

@ -0,0 +1,25 @@
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
SRCDIR = src
OBJDIR = obj
NAME = ex06
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(NAME)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p obj
$(CXX) $(CPPFLAGS) -c $< -o $@
$(NAME): $(OBJS)
$(CXX) $(CPPFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(NAME)
re: fclean all

51
ex06/src/Harl.cpp Normal file
View File

@ -0,0 +1,51 @@
#include "Harl.hpp"
#include <iostream>
void Harl::complain(std::string level)
{
static const std::string strings[4] = {
"DEBUG",
"INFO",
"WARNING",
"ERROR"
};
size_t i = 0;
for (; i < 4; i++)
if (strings[i] == level)
break;
switch(i) {
case 0:
debug();
case 1:
info();
case 2:
warning();
case 3:
error();
break;
default:
std::cout << "Not a level" << std::endl;
break;
}
}
void Harl::debug()
{
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-special-ketchup burger. I really do !" << std::endl;
}
void Harl::info()
{
std::cout << "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 !" << std::endl;
}
void Harl::warning()
{
std::cout << "I think I deserve to have some extra bacon for free. Ive been coming for years whereas you started working here since last month." << std::endl;
}
void Harl::error()
{
std::cout << "This is unacceptable ! I want to speak to the manager now." << std::endl;
}

17
ex06/src/Harl.hpp Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <string>
class Harl
{
private:
void debug();
void info();
void warning();
void error();
public:
void complain(std::string level);
};
typedef void (Harl::*HarlMethod)();

10
ex06/src/main.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "Harl.hpp"
int main(int argc, char **argv)
{
if (argc <= 1)
return 1;
Harl harl;
harl.complain(argv[1]);
return 0;
}