From 07022df1253aa7ec7b1e65f9e13f566ff8b81c46 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 4 Nov 2024 16:42:43 +0100 Subject: [PATCH] update: module01/ex00 --- .gitignore | 2 + cpp00/ex00/.clangd | 1 + cpp00/ex01/.clangd | 1 + cpp00/ex01/Makefile | 4 +- cpp01/ex00/Makefile | 118 +++++++++++++++++++++++++++++++++++++ cpp01/ex00/Zombie.cpp | 28 +++++++++ cpp01/ex00/Zombie.hpp | 32 ++++++++++ cpp01/ex00/main.cpp | 22 +++++++ cpp01/ex00/newZombie.cpp | 19 ++++++ cpp01/ex00/randomChump.cpp | 19 ++++++ 10 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 cpp01/ex00/Makefile create mode 100644 cpp01/ex00/Zombie.cpp create mode 100644 cpp01/ex00/Zombie.hpp create mode 100644 cpp01/ex00/main.cpp create mode 100644 cpp01/ex00/newZombie.cpp create mode 100644 cpp01/ex00/randomChump.cpp diff --git a/.gitignore b/.gitignore index 66319c4..29c50fe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ build/ *.o phonebook megaphone +job_of_dream +BraiiiiiiinnnzzzZ diff --git a/cpp00/ex00/.clangd b/cpp00/ex00/.clangd index 66e66f6..2ea0e22 100644 --- a/cpp00/ex00/.clangd +++ b/cpp00/ex00/.clangd @@ -2,6 +2,7 @@ CompileFlags: Compiler: clang Add: - "-xc++" + - "-stdlib=libc++" - "-I/usr/local/include" - "-I/nix/store/pzmpyb9hxfv60vh0l67avr94h71nip1b-llvm-16.0.6-dev/include" - "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include" diff --git a/cpp00/ex01/.clangd b/cpp00/ex01/.clangd index 047219f..9974bf0 100644 --- a/cpp00/ex01/.clangd +++ b/cpp00/ex01/.clangd @@ -2,6 +2,7 @@ CompileFlags: Compiler: clang Add: - "-xc++" + - "-stdlib=libc++" - "-I/usr/local/include" - "-I/nix/store/pzmpyb9hxfv60vh0l67avr94h71nip1b-llvm-16.0.6-dev/include" - "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include" diff --git a/cpp00/ex01/Makefile b/cpp00/ex01/Makefile index 9232381..a275b70 100644 --- a/cpp00/ex01/Makefile +++ b/cpp00/ex01/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/10/21 15:58:19 by rparodi ### ########.fr # +# Updated: 2024/11/04 15:44:54 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -25,7 +25,7 @@ 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 +# CXXFLAGS += -D DEBUG=1 # Sources SRC = ./sources/contact.cpp\ ./sources/phonebook.cpp \ diff --git a/cpp01/ex00/Makefile b/cpp01/ex00/Makefile new file mode 100644 index 0000000..e7e935f --- /dev/null +++ b/cpp01/ex00/Makefile @@ -0,0 +1,118 @@ +# **************************************************************************** # + +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: rparodi +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # +# Updated: 2024/11/04 15:47:26 by rparodi ### ########.fr # +# # +# **************************************************************************** # + +# Variables + +# Name +NAME = BraiiiiiiinnnzzzZ + +# 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 \ + newZombie.cpp \ + randomChump.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/ex00/Zombie.cpp b/cpp01/ex00/Zombie.cpp new file mode 100644 index 0000000..07c4f9b --- /dev/null +++ b/cpp01/ex00/Zombie.cpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/04 16:10:21 by rparodi #+# #+# */ +/* Updated: 2024/11/04 16:34:30 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +Zombie::Zombie( std::string name ) +{ + _name = name; +} + +Zombie::~Zombie() +{ + std::cout << "Zombie's hunter: killed " << _name << std::endl; +} + +void Zombie::announce() +{ + std::cout << _name << ": BraiiiiiiinnnzzzZ..." << std::endl; +} diff --git a/cpp01/ex00/Zombie.hpp b/cpp01/ex00/Zombie.hpp new file mode 100644 index 0000000..500f67a --- /dev/null +++ b/cpp01/ex00/Zombie.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/04 16:03:03 by rparodi #+# #+# */ +/* Updated: 2024/11/04 16:31:17 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ZOMBIE_HPP +# define ZOMBIE_HPP + +#include +#include + +class Zombie +{ + public: + Zombie(std::string name); + ~Zombie(); + void announce(void); + private: + std::string _name; +}; + +Zombie* newZombie( std::string name ); +void randomChump( std::string name ); + +#endif diff --git a/cpp01/ex00/main.cpp b/cpp01/ex00/main.cpp new file mode 100644 index 0000000..8def09e --- /dev/null +++ b/cpp01/ex00/main.cpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/04 15:48:46 by rparodi #+# #+# */ +/* Updated: 2024/11/04 16:40:59 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" +int main() +{ + Zombie roger = Zombie("Roger"); + roger.announce(); + Zombie *nathe = newZombie("Na"); + nathe->announce(); + delete nathe; + randomChump("Brancheuh"); +} diff --git a/cpp01/ex00/newZombie.cpp b/cpp01/ex00/newZombie.cpp new file mode 100644 index 0000000..75b7616 --- /dev/null +++ b/cpp01/ex00/newZombie.cpp @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* newZombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/04 16:06:25 by rparodi #+# #+# */ +/* Updated: 2024/11/04 16:32:48 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +Zombie* newZombie( std::string name ) +{ + Zombie *ret = new Zombie(name); + return (ret); +} diff --git a/cpp01/ex00/randomChump.cpp b/cpp01/ex00/randomChump.cpp new file mode 100644 index 0000000..b8cf46b --- /dev/null +++ b/cpp01/ex00/randomChump.cpp @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* randomChump.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/04 16:31:29 by rparodi #+# #+# */ +/* Updated: 2024/11/04 16:32:51 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +void randomChump( std::string name ) +{ + Zombie temp = Zombie(name); + temp.announce(); +}