diff --git a/.gitignore b/.gitignore index 29c50fe..ffeb66c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ phonebook megaphone job_of_dream BraiiiiiiinnnzzzZ +moar_brainz! diff --git a/cpp01/ex01/Makefile b/cpp01/ex01/Makefile new file mode 100644 index 0000000..aa72fe9 --- /dev/null +++ b/cpp01/ex01/Makefile @@ -0,0 +1,117 @@ +# **************************************************************************** # + +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: rparodi +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # +# Updated: 2024/11/04 19:50:07 by rparodi ### ########.fr # +# # +# **************************************************************************** # + +# Variables + +# Name +NAME = moar_brainz! + +# Commands +CXX = c++ +RM = rm -rf + +# Flags +# Mandatory flags for 42 cpp +CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/ +# Flags to debug and have the dependences (can be removed for correction) +CXXFLAGS += -MMD -g3 +# Flag to debug (TO REMOVE) +# CXXFLAGS += -D DEBUG=1 +# Sources +SRC = Zombie.cpp \ + zombieHorde.cpp \ + main.cpp + +# Objects +OBJDIRNAME = ./build +OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.cpp=.o)) + +# Colors +GREEN = \033[32m +GREY = \033[0;90m +RED = \033[0;31m +GOLD = \033[38;5;220m +END = \033[0m + +# Rules + +# All (make all) +all: header $(NAME) footer + +# Bonus (make bonus) +bonus: header $(OBJ) footer + @mkdir -p $(OBJDIRNAME) + @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' + @$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ) + +# Clean (make clean) +clean: + @printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n' + @printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n' + @$(RM) $(OBJDIRNAME) + +# Clean (make fclean) +fclean: clean + @printf '$(GREY) Removing $(END)$(RED)Program$(END)\n' + @$(RM) $(NAME) + @echo "" + +# Restart (make re) +re: header fclean all + +# Dependences for all +$(NAME): $(OBJ) + @mkdir -p $(OBJDIRNAME) + @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' + @$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ) + +# Creating the objects +$(OBJDIRNAME)/%.o: %.cpp + @mkdir -p $(dir $@) + @printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n' + @$(CXX) $(CXXFLAGS) -o $@ -c $< + +# Header +header: + @clear + @printf '\n\n' + @printf '$(GOLD) ******* ****** ******* $(END)\n' + @printf '$(GOLD) ****** *** ******* $(END)\n' + @printf '$(GOLD) ******* * ******* $(END)\n' + @printf '$(GOLD) ****** ******* $(END)\n' + @printf '$(GOLD) ******* ******* $(END)\n' + @printf '$(GOLD) ******************* ******* * $(END)\n' + @printf '$(GOLD) ******************* ******* *** $(END)\n' + @printf '$(GOLD) ****** ******* ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GREY) Made by rparodi$(END)\n\n' + +# Footer +footer: + @printf "\n" + @printf "$(GOLD) ,_ _,$(END)\n" + @printf "$(GOLD) | \\___//|$(END)\n" + @printf "$(GOLD) |=6 6=|$(END)\n" + @printf "$(GOLD) \\=._Y_.=/$(END)\n" + @printf "$(GOLD) ) \` ( ,$(END)\n" + @printf "$(GOLD) / \\ (('$(END)\n" + @printf "$(GOLD) | | ))$(END)\n" + @printf "$(GOLD) /| | | |\\_//$(END)\n" + @printf "$(GOLD) \\| |._.| |/-\`$(END)\n" + @printf "$(GOLD) '\"' '\"'$(END)\n" + @printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n' + +# Phony +.PHONY: all bonus clean fclean re + +-include ${OBJ:.o=.d} diff --git a/cpp01/ex01/Zombie.cpp b/cpp01/ex01/Zombie.cpp new file mode 100644 index 0000000..38ab78f --- /dev/null +++ b/cpp01/ex01/Zombie.cpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/04 16:10:21 by rparodi #+# #+# */ +/* Updated: 2024/11/04 20:22:57 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +Zombie::Zombie() +{ + //Can't use the default keyword :c +} + +Zombie::~Zombie() +{ + std::cout << "Zombie's hunter: killed " << _name << std::endl; +} + +void Zombie::setName( std::string name ) +{ + _name = name; +} + +void Zombie::announce() +{ + std::cout << _name << ": BraiiiiiiinnnzzzZ..." << std::endl; +} diff --git a/cpp01/ex01/Zombie.hpp b/cpp01/ex01/Zombie.hpp new file mode 100644 index 0000000..357ff4f --- /dev/null +++ b/cpp01/ex01/Zombie.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/04 16:03:03 by rparodi #+# #+# */ +/* Updated: 2024/11/04 20:38:39 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ZOMBIE_HPP +# define ZOMBIE_HPP + +#include +#include +#include + +class Zombie +{ + public: + Zombie(); + ~Zombie(); + void announce(void); + void setName( std::string name ); + private: + std::string _name; +}; + +Zombie* zombieHorde( int N, std::string name ); + +#endif diff --git a/cpp01/ex01/main.cpp b/cpp01/ex01/main.cpp new file mode 100644 index 0000000..d8d8a98 --- /dev/null +++ b/cpp01/ex01/main.cpp @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/04 15:48:46 by rparodi #+# #+# */ +/* Updated: 2024/11/04 20:38:40 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +int main(int argc, char *argv[]) +{ + if (argc != 3) + { + std::cerr << "Error:\nYou have to use a numeric argument !\nRemember the syntax:\n\t" << argv[0] << " " << std::endl; + return 1; + } + std::string str(argv[2]); + if (str.length() > 10) + { + std::cerr << "Error:\nYou can only have an integer in parameters" << std::endl; + return 2; + } + int size = std::atoll(argv[2]); + std::string name = std::string(argv[1]); + if (size <= 0) + { + std::cerr << "Error:\nThe number have to be positive" << std::endl; + return 3; + } + + Zombie *horde = zombieHorde(size, name); + if (!horde) + return 4; + + for (int i = 0; i < size; i++) + horde[i].announce(); + + delete [] horde; +} diff --git a/cpp01/ex01/zombieHorde.cpp b/cpp01/ex01/zombieHorde.cpp new file mode 100644 index 0000000..4ef1c23 --- /dev/null +++ b/cpp01/ex01/zombieHorde.cpp @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* zombieHorde.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/04 19:50:26 by rparodi #+# #+# */ +/* Updated: 2024/11/04 20:28:10 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +Zombie* zombieHorde( int N, std::string name ) +{ + Zombie *horde = new Zombie[N]; + if (!horde) + return (NULL); + for (int i = 0; i < N; i++) + horde[i].setName(name); + return (horde); +}