diff --git a/ex01/.gitignore b/ex01/.gitignore new file mode 100644 index 0000000..b678b9e --- /dev/null +++ b/ex01/.gitignore @@ -0,0 +1 @@ +ex01 diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..8d193b4 --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,40 @@ +NAME = ex01 +ifeq ($(CPPFLAGS),) + CPPFLAGS = -Wall -Wextra -Werror -std=c++98 -g +endif +ifeq ($(CXX),) + CXX = c++ +endif +# g++ is the default on 42 computers +ifeq ($(CXX),g++) + CXX = c++ +endif +srcs = \ + Zombie.cpp \ + zombieHorde.cpp \ + +main_objs = main.o $(srcs:.cpp=.o) +all_objs = $(main_objs) +deps = $(all_objs:.o=.d) + +all: $(NAME) + +-include $(deps) + +$(NAME): $(main_objs) + $(CXX) $(CPPFLAGS) -o $@ $^ + +%.o: %.cpp + $(CXX) -c $(CPPFLAGS) -o $*.o $*.cpp + $(CXX) -MM $(CPPFLAGS) -MT $*.o $*.cpp > $*.d + +clean: + find . -name '*.o' -print -delete + find . -name '*.d' -print -delete + +fclean: clean + rm -f $(NAME) + +re: + +make fclean + +make all diff --git a/ex01/Zombie.cpp b/ex01/Zombie.cpp new file mode 100644 index 0000000..b20b74e --- /dev/null +++ b/ex01/Zombie.cpp @@ -0,0 +1,12 @@ +#include "Zombie.hpp" +#include + +void Zombie::announce(void) { + std::cout << name << ": " << "BraiiiiiiinnnzzzZ..." << std::endl; +} + +void Zombie::setName(std::string name) { this->name = name; } + +Zombie::Zombie() {} + +Zombie::~Zombie() { std::cout << name << " is heading out." << std::endl; } diff --git a/ex01/Zombie.hpp b/ex01/Zombie.hpp new file mode 100644 index 0000000..ad94a04 --- /dev/null +++ b/ex01/Zombie.hpp @@ -0,0 +1,21 @@ +#ifndef ZOMBIE_HPP +#define ZOMBIE_HPP + +#include + +class Zombie { +public: + Zombie(); + Zombie(std::string name); + ~Zombie(); + + void announce(void); + void setName(std::string name); + +private: + std::string name; +}; + +Zombie *zombieHorde(int n, std::string name); + +#endif diff --git a/ex01/main.cpp b/ex01/main.cpp new file mode 100644 index 0000000..afd99ee --- /dev/null +++ b/ex01/main.cpp @@ -0,0 +1,11 @@ +#include "Zombie.hpp" + +int main(void) { + int n = 10; + Zombie *horde = zombieHorde(n, "Jefferson Barnett"); + for (int i = 0; i < n; i++) { + horde[i].announce(); + } + delete[] horde; + return 0; +} diff --git a/ex01/zombieHorde.cpp b/ex01/zombieHorde.cpp new file mode 100644 index 0000000..9a08048 --- /dev/null +++ b/ex01/zombieHorde.cpp @@ -0,0 +1,9 @@ +#include "Zombie.hpp" + +Zombie *zombieHorde(int n, std::string name) { + Zombie *horde = new Zombie[n]; + for (int i = 0; i < n; i++) { + horde[i].setName(name); + } + return horde; +}