feat(ex01): it works

This commit is contained in:
Khaïs COLIN 2025-05-12 12:03:57 +02:00
parent b9ff91c653
commit 1a167101bb
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
6 changed files with 94 additions and 0 deletions

1
ex01/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
ex01

40
ex01/Makefile Normal file
View file

@ -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

12
ex01/Zombie.cpp Normal file
View file

@ -0,0 +1,12 @@
#include "Zombie.hpp"
#include <iostream>
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; }

21
ex01/Zombie.hpp Normal file
View file

@ -0,0 +1,21 @@
#ifndef ZOMBIE_HPP
#define ZOMBIE_HPP
#include <string>
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

11
ex01/main.cpp Normal file
View file

@ -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;
}

9
ex01/zombieHorde.cpp Normal file
View file

@ -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;
}