init: ex00-02

This commit is contained in:
Camille Chauvet
2023-05-23 15:38:05 +00:00
commit f1d178366c
18 changed files with 236 additions and 0 deletions

25
ex01/Makefile Normal file
View File

@ -0,0 +1,25 @@
CXX = c++
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
SRCDIR = src
OBJDIR = obj
BINDIR = bin
EXECUTABLE = zombie
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
all: $(BINDIR)/$(EXECUTABLE)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
$(BINDIR)/$(EXECUTABLE): $(OBJS)
$(CXX) $(CXXFLAGS) $^ -o $@
clean:
rm -rf $(OBJDIR)/*.o
fclean: clean
rm -fr $(BINDIR)/$(EXECUTABLE)
re: fclean all

BIN
ex01/bin/zombie Executable file

Binary file not shown.

30
ex01/src/Zombie.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "Zombie.hpp"
#include <string>
#include <iostream>
Zombie::Zombie(std::string name)
{
this->name = name;
std::cout << this->name << ": " << "Zombie()" << std::endl;
}
Zombie::Zombie()
{
this->name = "";
std::cout << this->name << ": " << "Zombie()" << std::endl;
}
Zombie::~Zombie()
{
std::cout << this->name << ": " << "~Zombie()" << std::endl;
}
void Zombie::announce() const
{
std::cout << this->name << ": " << "BraiiiiiiinnnzzzZ..." << std::endl;
}
void Zombie::setName(std::string name)
{
this->name = name;
}

18
ex01/src/Zombie.hpp Normal file
View File

@ -0,0 +1,18 @@
#include <string>
class Zombie {
private:
std::string name;
public:
Zombie(std::string name);
Zombie();
~Zombie();
void setName(std::string name);
void announce(void) const;
};
Zombie* zombieHorde(int N, std::string name);

13
ex01/src/main.cpp Normal file
View File

@ -0,0 +1,13 @@
#include "Zombie.hpp"
int main()
{
Zombie* jean;
Zombie pierre("Pierre");
jean = new Zombie("jean");
jean->announce();
delete jean;
jean = zombieHorde(3, "jean");
delete[] jean;
}

15
ex01/src/zombieHorde.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "Zombie.hpp"
#include <cstddef>
Zombie* zombieHorde(int N, std::string name)
{
size_t i;
Zombie *zombies;
if (0 > N)
return (NULL);
zombies = new Zombie[N];
for (i = 0; i < (size_t) N; i++)
zombies[i].setName(name);
return (zombies);
}