intra to gitea

This commit is contained in:
root 2025-11-15 22:11:19 +00:00
commit f54385c2da
31 changed files with 1135 additions and 0 deletions

22
ex00/Main.cpp Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 13:51:42 by lfirmin #+# #+# */
/* Updated: 2025/07/01 15:26:03 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
int main(void)
{
Zombie *zombie = newZombie("Jean-Philippe");
zombie->announce();
randomChump("Jean-Michel");
delete zombie;
return 0;
}

53
ex00/Makefile Normal file
View File

@ -0,0 +1,53 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/07/01 13:54:05 by lfirmin #+# #+# #
# Updated: 2025/07/01 16:43:28 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
C++ = c++
C++_FLAGS = -Wall -Wextra -Werror -std=c++98
OBJDIR = obj
INFILES = Main.cpp\
Zombie.cpp\
NewZombie.cpp\
RandomChump.cpp\
OBJFILES = $(addprefix $(OBJDIR)/, $(INFILES:.cpp=.o))
NAME = BraiiiiiiinnnzzzZ
all: $(NAME)
$(OBJDIR):
@echo "📁 Creating obj directory..."
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
@echo "🧠 Compiling $< ..."
@$(C++) $(C++_FLAGS) -c $< -o $@
@echo "$@ ready!"
$(NAME): $(OBJFILES)
@echo "🔗 Linking $(NAME) ..."
@$(C++) $(C++_FLAGS) $(OBJFILES) -o $(NAME)
@echo "🎉 $(NAME) is ready to hunt brains!"
clean:
@echo "🧹 Cleaning object files..."
@rm -rf $(OBJDIR)
@echo "✨ Objects cleaned!"
fclean: clean
@echo "🗑️ Removing $(NAME)..."
@rm -f $(NAME)
@echo "💀 Full clean complete!"
re: fclean all
.PHONY: all clean fclean re

19
ex00/NewZombie.cpp Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* newZombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 13:51:04 by lfirmin #+# #+# */
/* Updated: 2025/07/01 13:51:06 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie* newZombie( std::string name )
{
Zombie *zombie = new Zombie(name);
return zombie;
}

20
ex00/RandomChump.cpp Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* randomChump.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 13:51:06 by lfirmin #+# #+# */
/* Updated: 2025/07/01 13:51:07 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
void randomChump( std::string name )
{
Zombie zombie(name);
zombie.announce();
return;
}

33
ex00/Zombie.cpp Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 13:51:10 by lfirmin #+# #+# */
/* Updated: 2025/07/01 13:51:11 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie::Zombie(void) : _name("Zombie")
{
return;
}
Zombie::Zombie(std::string name) : _name(name)
{
return;
}
Zombie::~Zombie(void)
{
std::cout << _name << " is dead" << std::endl;
}
void Zombie::announce(void)
{
std::cout << this->_name << ": BraiiiiiiinnnzzzZ..." << std::endl;
}

32
ex00/Zombie.hpp Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 13:51:00 by lfirmin #+# #+# */
/* Updated: 2025/07/02 10:30:55 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
# include <iostream>
class Zombie
{
private:
std::string _name;
public:
Zombie(void);
Zombie(std::string name);
~Zombie();
void announce(void);
};
Zombie* newZombie( std::string name );
void randomChump( std::string name );
#endif

31
ex01/Main.cpp Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 13:51:42 by lfirmin #+# #+# */
/* Updated: 2025/07/01 15:26:30 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
int main(void)
{
Zombie *horde;
int i = 0;
int N = 3;
horde = zombieHorde(N, "Jean-Philippe");
while (i < N)
{
std::cout << "Index " << i << ": ";
horde[i].announce();
i++;
}
delete[] horde;
return (0);
}

51
ex01/Makefile Normal file
View File

@ -0,0 +1,51 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/07/01 13:54:05 by lfirmin #+# #+# #
# Updated: 2025/07/01 16:43:02 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
C++ = c++
C++_FLAGS = -Wall -Wextra -Werror -std=c++98
OBJDIR = obj
INFILES = Main.cpp\
Zombie.cpp\
ZombieHorde.cpp\
OBJFILES = $(addprefix $(OBJDIR)/, $(INFILES:.cpp=.o))
NAME = MaxiBraiiiiiiinnnzzzZ
all: $(NAME)
$(OBJDIR):
@echo "📁 Creating obj directory..."
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
@echo "🧠 Compiling $< ..."
@$(C++) $(C++_FLAGS) -c $< -o $@
$(NAME): $(OBJFILES)
@echo "🔗 Linking $(NAME) ..."
@$(C++) $(C++_FLAGS) $(OBJFILES) -o $(NAME)
@echo "🎉 $(NAME) is ready to hunt brains!"
clean:
@echo "🧹 Cleaning object files..."
@rm -rf $(OBJDIR)
@echo "✨ Objects cleaned!"
fclean: clean
@echo "🗑️ Removing $(NAME)..."
@rm -f $(NAME)
@echo "💀 Full clean complete!"
re: fclean all
.PHONY: all clean fclean re

33
ex01/Zombie.cpp Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 13:51:10 by lfirmin #+# #+# */
/* Updated: 2025/07/01 15:24:33 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie::Zombie(void) : _name("Zombie")
{
return;
}
Zombie::Zombie(std::string name) : _name(name)
{
return;
}
Zombie::~Zombie(void)
{
return;
}
void Zombie::announce(void)
{
std::cout << this->_name << ": BraiiiiiiinnnzzzZ..." << std::endl;
}

30
ex01/Zombie.hpp Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 13:51:00 by lfirmin #+# #+# */
/* Updated: 2025/07/01 15:20:18 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
# include <iostream>
class Zombie
{
private:
std::string _name;
public:
Zombie(void);
Zombie(std::string name);
~Zombie();
void announce(void);
};
Zombie* zombieHorde( int N, std::string name );
#endif

27
ex01/ZombieHorde.cpp Normal file
View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* zombieHorde.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 15:16:32 by lfirmin #+# #+# */
/* Updated: 2025/07/01 15:22:26 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie* zombieHorde( int N, std::string name )
{
int i = 0;
Zombie *zombieHorde;
zombieHorde = new Zombie[N];
while (i < N)
{
zombieHorde[i] = Zombie(name);
i++;
}
return zombieHorde;
}

28
ex02/Main.cpp Executable file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 16:27:39 by lfirmin #+# #+# */
/* Updated: 2025/07/01 16:34:32 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
# include <iostream>
int main(void)
{
std::string str = "HI THIS IS BRAIN";
std::string *stringPTR = &str;
std::string &stringREF = str;
std::cout << "Memory address of str: " << &str << std::endl;
std::cout << "Memory address of stringPTR: " << stringPTR << std::endl;
std::cout << "Memory address of stringREF: " << &stringREF << std::endl;
std::cout << "Value of str: " << str << std::endl;
std::cout << "Value of stringPTR: " << *stringPTR << std::endl;
std::cout << "Value of stringREF: " << stringREF << std::endl;
}

47
ex02/Makefile Normal file
View File

@ -0,0 +1,47 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/07/01 13:54:05 by lfirmin #+# #+# #
# Updated: 2025/07/01 16:57:18 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -std=c++98
OBJDIR = obj
SOURCES = main.cpp
OBJECTS = $(SOURCES:%.cpp=$(OBJDIR)/%.o)
NAME = brain
all: $(NAME)
$(OBJDIR):
@echo "📁 Creating obj directory..."
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
@echo "🧠 Compiling $< ..."
@$(CXX) $(CXXFLAGS) -c $< -o $@
$(NAME): $(OBJECTS)
@echo "🔗 Linking $(NAME) ..."
@$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME)
@echo "🎉 $(NAME) is ready to hunt brains!"
clean:
@echo "🧹 Cleaning object files..."
@rm -rf $(OBJDIR)
@echo "✨ Objects cleaned!"
fclean: clean
@echo "🗑️ Removing $(NAME)..."
@rm -f $(NAME)
@echo "💀 Full clean complete!"
re: fclean all
.PHONY: all clean fclean re

16
ex03/HumanA.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "HumanA.hpp"
HumanA::HumanA(std::string name, Weapon &weapon) : _name(name), _weapon(weapon)
{
return;
}
HumanA::~HumanA(void)
{
return;
}
void HumanA::attack()
{
std::cout << _name << " attacks with their " << _weapon.getType() << std::endl;
}

17
ex03/HumanA.hpp Normal file
View File

@ -0,0 +1,17 @@
#ifndef HUMANA_HPP
# define HUMANA_HPP
# include "Weapon.hpp"
class HumanA
{
private:
std::string _name;
Weapon &_weapon;
public:
HumanA(std::string name, Weapon &weapon);
~HumanA();
void attack();
};
#endif

25
ex03/HumanB.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "HumanB.hpp"
HumanB::HumanB(std::string name) : _name(name), _weapon(NULL)
{
return;
}
HumanB::~HumanB(void)
{
return;
}
void HumanB::attack()
{
if (_weapon == NULL) {
std::cout << _name << " has no weapon to attack with!" << std::endl;
return;
}
std::cout << _name << " attacks with their " << _weapon->getType() << std::endl;
}
void HumanB::setWeapon(Weapon &weapon)
{
_weapon = &weapon;
}

18
ex03/HumanB.hpp Normal file
View File

@ -0,0 +1,18 @@
#ifndef HUMANB_HPP
# define HUMANB_HPP
# include "Weapon.hpp"
class HumanB
{
private:
std::string _name;
Weapon *_weapon;
public:
HumanB(std::string name);
~HumanB();
void attack();
void setWeapon(Weapon &weapon);
};
#endif

37
ex03/Main.cpp Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 16:53:34 by lfirmin #+# #+# */
/* Updated: 2025/07/01 16:53:45 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include <string>
#include <iostream>
#include "Weapon.hpp"
#include "HumanA.hpp"
#include "HumanB.hpp"
int main()
{
{
Weapon club = Weapon("crude spiked club");
HumanA bob("Bob", club);
bob.attack();
club.setType("some other type of club");
bob.attack();
}
{
Weapon club = Weapon("crude spiked club");
HumanB jim("Jim");
jim.setWeapon(club);
jim.attack();
club.setType("some other type of club");
jim.attack();
}
return 0;
}

47
ex03/Makefile Normal file
View File

@ -0,0 +1,47 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/07/01 13:54:05 by lfirmin #+# #+# #
# Updated: 2025/07/01 16:57:18 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -std=c++98
SOURCES = Main.cpp Weapon.cpp HumanA.cpp HumanB.cpp
OBJDIR = obj
OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o))
NAME = violence
all: $(NAME)
$(OBJDIR):
@echo "📁 Creating obj directory..."
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
@echo "🧠 Compiling $< ..."
@$(CXX) $(CXXFLAGS) -c $< -o $@
$(NAME): $(OBJECTS)
@echo "🔗 Linking $(NAME) ..."
@$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME)
@echo "🎉 $(NAME) is ready to hunt brains!"
clean:
@echo "🧹 Cleaning object files..."
@rm -rf $(OBJDIR)
@echo "✨ Objects cleaned!"
fclean: clean
@echo "🗑️ Removing $(NAME)..."
@rm -f $(NAME)
@echo "💀 Full clean complete!"
re: fclean all
.PHONY: all clean fclean re

25
ex03/Weapon.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "Weapon.hpp"
Weapon::Weapon()
{
}
Weapon::Weapon(std::string type)
{
setType(type);
}
Weapon::~Weapon()
{
}
void Weapon::setType(std::string type)
{
_type = type;
}
const std::string &Weapon::getType() const
{
return (_type);
}

19
ex03/Weapon.hpp Normal file
View File

@ -0,0 +1,19 @@
#ifndef WEAPON_HPP
# define WEAPON_HPP
# include <iostream>
class Weapon
{
private:
std::string _type;
public:
Weapon();
Weapon(std::string type);
~Weapon();
void setType(std::string type);
const std::string &getType() const;
};
#endif

103
ex04/Main.cpp Normal file
View File

@ -0,0 +1,103 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/01 23:30:01 by lfirmin #+# #+# */
/* Updated: 2025/07/01 23:48:50 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include <string>
#include <iostream>
#include <fstream>
static int open_files(std::string nameInputFile, std::string nameOutputfile,
std::ifstream *inputFile, std::ofstream *outputFile)
{
(*inputFile).open(nameInputFile.c_str(), std::fstream::in);
if (!inputFile->is_open()) // ou if (!(*inputFile))
{
std::cerr << "Failed to open input file!" << std::endl;
return (1);
}
(*outputFile).open(nameOutputfile.c_str(), std::fstream::out);
if (!outputFile->is_open()) // ou if (!(*outputFile))
{
std::cerr << "Failed to open output file!" << std::endl;
(*inputFile).close();
return (1);
}
return (0);
}
static void read_and_replace(char **argv, std::ifstream *inputFile, std::ofstream *outputFile)
{
std::string to_find;
std::string to_replace;
std::string line;
std::string::size_type found;
size_t end_last_found;
std::string replaced_line;
to_find = *(argv + 2);
to_replace = *(argv + 3);
end_last_found = 0;
while(std::getline(*inputFile, line))
{
if (to_find.empty())
{
if (!(*inputFile).eof())
*outputFile << line << std::endl;
else
*outputFile << line;
}
else
{
replaced_line.clear();
end_last_found = 0;
found = line.find(to_find);
if (found != std::string::npos)
{
while (found != std::string::npos)
{
replaced_line.append(line,end_last_found,found - end_last_found);
replaced_line += to_replace;
end_last_found = found + to_find.length();
found = line.find(to_find, end_last_found);
if (found == std::string::npos)
replaced_line.append(line, end_last_found,line.length());
}
}
else
replaced_line = line;
if (!(*inputFile).eof())
*outputFile << replaced_line << std::endl;
else
*outputFile << replaced_line;
}
}
}
int main(int argc, char **argv)
{
std::string nameInputFile;
std::string nameOutputfile;
std::ifstream inputFile;
std::ofstream outputFile;
if (argc != 4)
return (std::cerr << "./sed <Filename> <S1> <S2>" << std::endl, 0);
nameInputFile = argv[1];
nameOutputfile = nameOutputfile + argv[1] + ".replace";
if (open_files(nameInputFile, nameOutputfile, &inputFile, &outputFile))
return (1);
read_and_replace(argv, &inputFile, &outputFile);
inputFile.close();
outputFile.close();
return (0);
}

48
ex04/Makefile Normal file
View File

@ -0,0 +1,48 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/07/01 13:54:05 by lfirmin #+# #+# #
# Updated: 2025/07/01 23:43:34 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -std=c++98
OBJDIR = obj
SOURCES = Main.cpp
OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o))
NAME = sed
all: $(NAME)
$(OBJDIR):
@echo "📁 Creating obj directory..."
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
@echo "🧠 Compiling $< ..."
@$(CXX) $(CXXFLAGS) -c $< -o $@
@echo "$@ ready!"
$(NAME): $(OBJECTS)
@echo "🔗 Linking $(NAME) ..."
@$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME)
@echo "🎉 $(NAME) is ready to hunt brains!"
clean:
@echo "🧹 Cleaning object files..."
@rm -rf $(OBJDIR)
@echo "✨ Objects cleaned!"
fclean: clean
@echo "🗑️ Removing $(NAME)..."
@rm -f $(NAME)
@echo "💀 Full clean complete!"
re: fclean all
.PHONY: all clean fclean re

59
ex05/Harl.cpp Normal file
View File

@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/02 10:04:24 by lfirmin #+# #+# */
/* Updated: 2025/07/02 10:05:57 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
Harl::Harl()
{
}
Harl::~Harl()
{
}
void Harl::_debug(void)
{
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!" << std::endl;
}
void Harl::_info(void)
{
std::cout << "I cannot believe adding extra bacon costs more money. You didn't put enough bacon in my burger! If you did, I wouldn't be asking for more!" << std::endl;
}
void Harl::_warning(void)
{
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." << std::endl;
}
void Harl::_error(void)
{
std::cout << "This is unacceptable! I want to speak to the manager now." << std::endl;
}
void Harl::complain(std::string level)
{
int i;
std::string levels[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
void (Harl::*fptr[4])() = {&Harl::_debug, &Harl::_info, &Harl::_warning, &Harl::_error};
i = 0;
while (i < 4)
{
if (level == levels[i])
{
(this->*fptr[i])();
return;
}
i++;
}
std::cout << "No Valid Level.\n";
}

32
ex05/Harl.hpp Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/02 10:03:59 by lfirmin #+# #+# */
/* Updated: 2025/07/02 10:04:08 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HARL_HPP
# define HARL_HPP
#include <iostream>
class Harl
{
private:
void _debug(void);
void _info(void);
void _warning(void);
void _error(void);
public:
Harl();
~Harl();
void complain(std::string level) ;
};
#endif

30
ex05/Main.cpp Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/02 10:08:12 by lfirmin #+# #+# */
/* Updated: 2025/07/02 10:08:56 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
int main (void)
{
Harl harl;
std::cout << std::endl << "====DEBUG Level====" << std::endl;
harl.complain("DEBUG");
std::cout << std::endl << "====INFO Level====" << std::endl;;
harl.complain("INFO");
std::cout << std::endl << "====WARNING Level====" << std::endl;
harl.complain("WARNING");
std::cout << std::endl << "====ERROR Level====" << std::endl;
harl.complain("ERROR");
std::cout << std::endl << "====No valid Level====" << std::endl;
harl.complain("ALARM");
return (0);
}

48
ex05/Makefile Normal file
View File

@ -0,0 +1,48 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/07/01 13:54:05 by lfirmin #+# #+# #
# Updated: 2025/07/02 10:09:25 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -std=c++98
OBJDIR = obj
SOURCES = Main.cpp Harl.cpp
OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o))
NAME = harl
all: $(NAME)
$(OBJDIR):
@echo "📁 Creating obj directory..."
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
@echo "🧠 Compiling $< ..."
@$(CXX) $(CXXFLAGS) -c $< -o $@
@echo "$@ ready!"
$(NAME): $(OBJECTS)
@echo "🔗 Linking $(NAME) ..."
@$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME)
@echo "🎉 $(NAME) is ready to hunt brains!"
clean:
@echo "🧹 Cleaning object files..."
@rm -rf $(OBJDIR)
@echo "✨ Objects cleaned!"
fclean: clean
@echo "🗑️ Removing $(NAME)..."
@rm -f $(NAME)
@echo "💀 Full clean complete!"
re: fclean all
.PHONY: all clean fclean re

77
ex06/Harl.cpp Normal file
View File

@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/02 10:04:24 by lfirmin #+# #+# */
/* Updated: 2025/07/02 10:25:30 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
Harl::Harl()
{
}
Harl::~Harl()
{
}
void Harl::_debug(void)
{
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!\n" << std::endl;
}
void Harl::_info(void)
{
std::cout << "I cannot believe adding extra bacon costs more money. You didn't put enough bacon in my burger! If you did, I wouldn't be asking for more!\n" << std::endl;
}
void Harl::_warning(void)
{
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" << std::endl;
}
void Harl::_error(void)
{
std::cout << "This is unacceptable! I want to speak to the manager now.\n" << std::endl;
}
void Harl::complain(std::string level)
{
int i;
std::string levels[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
i = 0;
if (!level.compare(levels[0]) || i == 1)
{
std::cout << "[ DEBUG ]" << std::endl;
Harl::_debug();
i = 1;
}
if (!level.compare(levels[1]) || i == 1)
{
std::cout << "[ INFO ]" << std::endl;
Harl::_info();
i = 1;
}
if (!level.compare(levels[2]) || i == 1)
{
std::cout << "[ WARNING ]" << std::endl;
Harl::_warning();
i = 1;
}
if (!level.compare(levels[3]) || i == 1)
{
std::cout << "[ ERROR ]" << std::endl;
Harl::_error();
i = 1;
}
else
{
std::cout << "No Valid Level.\n";
return ;
}
}

32
ex06/Harl.hpp Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/02 10:03:59 by lfirmin #+# #+# */
/* Updated: 2025/07/02 10:04:08 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HARL_HPP
# define HARL_HPP
#include <iostream>
class Harl
{
private:
void _debug(void);
void _info(void);
void _warning(void);
void _error(void);
public:
Harl();
~Harl();
void complain(std::string level) ;
};
#endif

28
ex06/Main.cpp Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/02 10:08:12 by lfirmin #+# #+# */
/* Updated: 2025/07/02 10:13:05 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
int main (int argc, char **argv)
{
std::string level;
Harl harl;
if (argc != 2)
{
std::cout << "Usage : ./harlfilter <level>\n";
return (0);
}
level = argv[1];
harl.complain(level);
return (0);
}

48
ex06/Makefile Normal file
View File

@ -0,0 +1,48 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2025/07/01 13:54:05 by lfirmin #+# #+# #
# Updated: 2025/07/02 10:25:55 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -std=c++98
OBJDIR = obj
SOURCES = Main.cpp Harl.cpp
OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o))
NAME = harlfilter
all: $(NAME)
$(OBJDIR):
@echo "📁 Creating obj directory..."
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
@echo "🧠 Compiling $< ..."
@$(CXX) $(CXXFLAGS) -c $< -o $@
@echo "$@ ready!"
$(NAME): $(OBJECTS)
@echo "🔗 Linking $(NAME) ..."
@$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME)
@echo "🎉 $(NAME) is ready to hunt brains!"
clean:
@echo "🧹 Cleaning object files..."
@rm -rf $(OBJDIR)
@echo "✨ Objects cleaned!"
fclean: clean
@echo "🗑️ Removing $(NAME)..."
@rm -f $(NAME)
@echo "💀 Full clean complete!"
re: fclean all
.PHONY: all clean fclean re