「✨」 feat(More brainnzz): Finished More brainnnz
This commit is contained in:
56
ex01/Makefile
Normal file
56
ex01/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||
# Updated: 2024/11/04 18:53:24 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = zombie
|
||||
|
||||
CC = c++
|
||||
|
||||
OBJSDIR = obj/
|
||||
|
||||
SRCS = main.cpp \
|
||||
Zombie.cpp \
|
||||
zombieHorde.cpp
|
||||
|
||||
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||
|
||||
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP -g
|
||||
|
||||
RED = \033[0;31m
|
||||
GREEN = \033[0;32m
|
||||
YELLOW = \033[1;33m
|
||||
PURPLE = \e[0;35m
|
||||
NC = \033[0m
|
||||
DELETE = \x1B[2K\r
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
|
||||
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
|
||||
|
||||
$(OBJSDIR)%.o: %.cpp
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) $(FLAGS) -c $< -o $@
|
||||
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
|
||||
|
||||
clean:
|
||||
@rm -f $(OBJS)
|
||||
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
|
||||
|
||||
fclean: clean
|
||||
@rm -f $(NAME)
|
||||
@rm -Rf $(OBJSDIR)
|
||||
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: clean fclean all re
|
30
ex01/Zombie.cpp
Normal file
30
ex01/Zombie.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Zombie.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 11:40:41 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 18:47:10 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Zombie.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Zombie::Zombie() {
|
||||
std::cout << "Zombie born" << std::endl;
|
||||
}
|
||||
|
||||
void Zombie::setName(std::string newName) {
|
||||
this->name = newName;
|
||||
}
|
||||
|
||||
Zombie::~Zombie(void) {
|
||||
std::cout << this->name << " destroyed" << std::endl;
|
||||
}
|
||||
|
||||
void Zombie::announce(void) {
|
||||
std::cout << this->name << ": BraiiiiiiinnnzzzZ..." << std::endl;
|
||||
}
|
30
ex01/Zombie.hpp
Normal file
30
ex01/Zombie.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Zombie.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 10:52:33 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 18:54:32 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
# include <string>
|
||||
|
||||
# define uint8_t unsigned char
|
||||
|
||||
class Zombie {
|
||||
private:
|
||||
std::string name;
|
||||
public:
|
||||
void announce(void);
|
||||
void setName(std::string newName);
|
||||
|
||||
Zombie(void);
|
||||
~Zombie(void);
|
||||
};
|
||||
|
||||
Zombie *zombieHorde(int n, std::string name);
|
27
ex01/main.cpp
Normal file
27
ex01/main.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 11:41:07 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 18:59:15 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Zombie.hpp"
|
||||
|
||||
int main(void) {
|
||||
Zombie *horde;
|
||||
uint8_t i;
|
||||
|
||||
horde = zombieHorde(5, "Fabrice");
|
||||
i = 0;
|
||||
while (i < 5)
|
||||
{
|
||||
horde[i].announce();
|
||||
i++;
|
||||
}
|
||||
delete[] horde;
|
||||
}
|
26
ex01/zombieHorde.cpp
Normal file
26
ex01/zombieHorde.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* zombieHorde.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/04 17:48:42 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/04 18:43:09 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Zombie.hpp"
|
||||
|
||||
Zombie *zombieHorde(int n, std::string name) {
|
||||
Zombie *horde;
|
||||
uint8_t i;
|
||||
|
||||
horde = new Zombie[n]();
|
||||
i = 0;
|
||||
while (i < n) {
|
||||
horde[i].setName(name);
|
||||
i++;
|
||||
}
|
||||
return (horde);
|
||||
}
|
Reference in New Issue
Block a user