From f54385c2da39e6d237839f04724eac1f704b2aed Mon Sep 17 00:00:00 2001 From: root Date: Sat, 15 Nov 2025 22:11:19 +0000 Subject: [PATCH] intra to gitea --- ex00/Main.cpp | 22 +++++++++ ex00/Makefile | 53 ++++++++++++++++++++++ ex00/NewZombie.cpp | 19 ++++++++ ex00/RandomChump.cpp | 20 +++++++++ ex00/Zombie.cpp | 33 ++++++++++++++ ex00/Zombie.hpp | 32 ++++++++++++++ ex01/Main.cpp | 31 +++++++++++++ ex01/Makefile | 51 +++++++++++++++++++++ ex01/Zombie.cpp | 33 ++++++++++++++ ex01/Zombie.hpp | 30 +++++++++++++ ex01/ZombieHorde.cpp | 27 ++++++++++++ ex02/Main.cpp | 28 ++++++++++++ ex02/Makefile | 47 ++++++++++++++++++++ ex03/HumanA.cpp | 16 +++++++ ex03/HumanA.hpp | 17 +++++++ ex03/HumanB.cpp | 25 +++++++++++ ex03/HumanB.hpp | 18 ++++++++ ex03/Main.cpp | 37 ++++++++++++++++ ex03/Makefile | 47 ++++++++++++++++++++ ex03/Weapon.cpp | 25 +++++++++++ ex03/Weapon.hpp | 19 ++++++++ ex04/Main.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++ ex04/Makefile | 48 ++++++++++++++++++++ ex05/Harl.cpp | 59 +++++++++++++++++++++++++ ex05/Harl.hpp | 32 ++++++++++++++ ex05/Main.cpp | 30 +++++++++++++ ex05/Makefile | 48 ++++++++++++++++++++ ex06/Harl.cpp | 77 ++++++++++++++++++++++++++++++++ ex06/Harl.hpp | 32 ++++++++++++++ ex06/Main.cpp | 28 ++++++++++++ ex06/Makefile | 48 ++++++++++++++++++++ 31 files changed, 1135 insertions(+) create mode 100644 ex00/Main.cpp create mode 100644 ex00/Makefile create mode 100644 ex00/NewZombie.cpp create mode 100644 ex00/RandomChump.cpp create mode 100644 ex00/Zombie.cpp create mode 100644 ex00/Zombie.hpp create mode 100644 ex01/Main.cpp create mode 100644 ex01/Makefile create mode 100644 ex01/Zombie.cpp create mode 100644 ex01/Zombie.hpp create mode 100644 ex01/ZombieHorde.cpp create mode 100755 ex02/Main.cpp create mode 100644 ex02/Makefile create mode 100644 ex03/HumanA.cpp create mode 100644 ex03/HumanA.hpp create mode 100644 ex03/HumanB.cpp create mode 100644 ex03/HumanB.hpp create mode 100644 ex03/Main.cpp create mode 100644 ex03/Makefile create mode 100644 ex03/Weapon.cpp create mode 100644 ex03/Weapon.hpp create mode 100644 ex04/Main.cpp create mode 100644 ex04/Makefile create mode 100644 ex05/Harl.cpp create mode 100644 ex05/Harl.hpp create mode 100644 ex05/Main.cpp create mode 100644 ex05/Makefile create mode 100644 ex06/Harl.cpp create mode 100644 ex06/Harl.hpp create mode 100644 ex06/Main.cpp create mode 100644 ex06/Makefile diff --git a/ex00/Main.cpp b/ex00/Main.cpp new file mode 100644 index 0000000..d60eba2 --- /dev/null +++ b/ex00/Main.cpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..5397432 --- /dev/null +++ b/ex00/Makefile @@ -0,0 +1,53 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: lfirmin +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/ex00/NewZombie.cpp b/ex00/NewZombie.cpp new file mode 100644 index 0000000..d373170 --- /dev/null +++ b/ex00/NewZombie.cpp @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* newZombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} \ No newline at end of file diff --git a/ex00/RandomChump.cpp b/ex00/RandomChump.cpp new file mode 100644 index 0000000..45bb208 --- /dev/null +++ b/ex00/RandomChump.cpp @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* randomChump.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/ex00/Zombie.cpp b/ex00/Zombie.cpp new file mode 100644 index 0000000..706891e --- /dev/null +++ b/ex00/Zombie.cpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/ex00/Zombie.hpp b/ex00/Zombie.hpp new file mode 100644 index 0000000..45b8072 --- /dev/null +++ b/ex00/Zombie.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +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 diff --git a/ex01/Main.cpp b/ex01/Main.cpp new file mode 100644 index 0000000..19eccbb --- /dev/null +++ b/ex01/Main.cpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..be06d48 --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,51 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: lfirmin +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/ex01/Zombie.cpp b/ex01/Zombie.cpp new file mode 100644 index 0000000..f2cbf34 --- /dev/null +++ b/ex01/Zombie.cpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} \ No newline at end of file diff --git a/ex01/Zombie.hpp b/ex01/Zombie.hpp new file mode 100644 index 0000000..78da97f --- /dev/null +++ b/ex01/Zombie.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +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 \ No newline at end of file diff --git a/ex01/ZombieHorde.cpp b/ex01/ZombieHorde.cpp new file mode 100644 index 0000000..1095fd1 --- /dev/null +++ b/ex01/ZombieHorde.cpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* zombieHorde.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} \ No newline at end of file diff --git a/ex02/Main.cpp b/ex02/Main.cpp new file mode 100755 index 0000000..733c668 --- /dev/null +++ b/ex02/Main.cpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/07/01 16:27:39 by lfirmin #+# #+# */ +/* Updated: 2025/07/01 16:34:32 by lfirmin ### ########.fr */ +/* */ +/* ************************************************************************** */ + +# include +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; + +} \ No newline at end of file diff --git a/ex02/Makefile b/ex02/Makefile new file mode 100644 index 0000000..7a9298a --- /dev/null +++ b/ex02/Makefile @@ -0,0 +1,47 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: lfirmin +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/ex03/HumanA.cpp b/ex03/HumanA.cpp new file mode 100644 index 0000000..7a73912 --- /dev/null +++ b/ex03/HumanA.cpp @@ -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; +} \ No newline at end of file diff --git a/ex03/HumanA.hpp b/ex03/HumanA.hpp new file mode 100644 index 0000000..00f1e27 --- /dev/null +++ b/ex03/HumanA.hpp @@ -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 \ No newline at end of file diff --git a/ex03/HumanB.cpp b/ex03/HumanB.cpp new file mode 100644 index 0000000..38eb3c5 --- /dev/null +++ b/ex03/HumanB.cpp @@ -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; +} diff --git a/ex03/HumanB.hpp b/ex03/HumanB.hpp new file mode 100644 index 0000000..4c802a6 --- /dev/null +++ b/ex03/HumanB.hpp @@ -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 \ No newline at end of file diff --git a/ex03/Main.cpp b/ex03/Main.cpp new file mode 100644 index 0000000..99e99ec --- /dev/null +++ b/ex03/Main.cpp @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/07/01 16:53:34 by lfirmin #+# #+# */ +/* Updated: 2025/07/01 16:53:45 by lfirmin ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#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; +} diff --git a/ex03/Makefile b/ex03/Makefile new file mode 100644 index 0000000..cb68719 --- /dev/null +++ b/ex03/Makefile @@ -0,0 +1,47 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: lfirmin +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/ex03/Weapon.cpp b/ex03/Weapon.cpp new file mode 100644 index 0000000..22b42cd --- /dev/null +++ b/ex03/Weapon.cpp @@ -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); +} \ No newline at end of file diff --git a/ex03/Weapon.hpp b/ex03/Weapon.hpp new file mode 100644 index 0000000..4a428c9 --- /dev/null +++ b/ex03/Weapon.hpp @@ -0,0 +1,19 @@ +#ifndef WEAPON_HPP +# define WEAPON_HPP + +# include + +class Weapon +{ + private: + std::string _type; + public: + Weapon(); + Weapon(std::string type); + ~Weapon(); + + void setType(std::string type); + const std::string &getType() const; +}; + +#endif \ No newline at end of file diff --git a/ex04/Main.cpp b/ex04/Main.cpp new file mode 100644 index 0000000..f0ee8d6 --- /dev/null +++ b/ex04/Main.cpp @@ -0,0 +1,103 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/07/01 23:30:01 by lfirmin #+# #+# */ +/* Updated: 2025/07/01 23:48:50 by lfirmin ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +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 " << 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); +} diff --git a/ex04/Makefile b/ex04/Makefile new file mode 100644 index 0000000..9025f00 --- /dev/null +++ b/ex04/Makefile @@ -0,0 +1,48 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: lfirmin +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/ex05/Harl.cpp b/ex05/Harl.cpp new file mode 100644 index 0000000..c36c1a1 --- /dev/null +++ b/ex05/Harl.cpp @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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"; +} \ No newline at end of file diff --git a/ex05/Harl.hpp b/ex05/Harl.hpp new file mode 100644 index 0000000..1005825 --- /dev/null +++ b/ex05/Harl.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +class Harl +{ + private: + void _debug(void); + void _info(void); + void _warning(void); + void _error(void); + + public: + Harl(); + ~Harl(); + + void complain(std::string level) ; +}; +#endif \ No newline at end of file diff --git a/ex05/Main.cpp b/ex05/Main.cpp new file mode 100644 index 0000000..793c978 --- /dev/null +++ b/ex05/Main.cpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/ex05/Makefile b/ex05/Makefile new file mode 100644 index 0000000..b241fb2 --- /dev/null +++ b/ex05/Makefile @@ -0,0 +1,48 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: lfirmin +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/ex06/Harl.cpp b/ex06/Harl.cpp new file mode 100644 index 0000000..6fb3bd1 --- /dev/null +++ b/ex06/Harl.cpp @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 ; + } +} \ No newline at end of file diff --git a/ex06/Harl.hpp b/ex06/Harl.hpp new file mode 100644 index 0000000..1005825 --- /dev/null +++ b/ex06/Harl.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +class Harl +{ + private: + void _debug(void); + void _info(void); + void _warning(void); + void _error(void); + + public: + Harl(); + ~Harl(); + + void complain(std::string level) ; +}; +#endif \ No newline at end of file diff --git a/ex06/Main.cpp b/ex06/Main.cpp new file mode 100644 index 0000000..da36a7a --- /dev/null +++ b/ex06/Main.cpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lfirmin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 \n"; + return (0); + } + level = argv[1]; + harl.complain(level); + return (0); +} \ No newline at end of file diff --git a/ex06/Makefile b/ex06/Makefile new file mode 100644 index 0000000..95def9c --- /dev/null +++ b/ex06/Makefile @@ -0,0 +1,48 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: lfirmin +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file