feat: adding the module01/ex01
This commit is contained in:
parent
07022df125
commit
c7e3b1ab02
6 changed files with 251 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -5,3 +5,4 @@ phonebook
|
||||||
megaphone
|
megaphone
|
||||||
job_of_dream
|
job_of_dream
|
||||||
BraiiiiiiinnnzzzZ
|
BraiiiiiiinnnzzzZ
|
||||||
|
moar_brainz!
|
||||||
|
|
|
||||||
117
cpp01/ex01/Makefile
Normal file
117
cpp01/ex01/Makefile
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# 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}
|
||||||
33
cpp01/ex01/Zombie.cpp
Normal file
33
cpp01/ex01/Zombie.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Zombie.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
33
cpp01/ex01/Zombie.hpp
Normal file
33
cpp01/ex01/Zombie.hpp
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Zombie.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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 <cstdlib>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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
|
||||||
44
cpp01/ex01/main.cpp
Normal file
44
cpp01/ex01/main.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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] << " <name> <size>" << 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;
|
||||||
|
}
|
||||||
23
cpp01/ex01/zombieHorde.cpp
Normal file
23
cpp01/ex01/zombieHorde.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* zombieHorde.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue