ajout sujets et fini ex01 d01
This commit is contained in:
63
d01/ex01/Makefile
Normal file
63
d01/ex01/Makefile
Normal file
@@ -0,0 +1,63 @@
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
# . name = value . name is case sensitive #
|
||||
# VARIABLES . or name = value \ . use VPATH only for .c #
|
||||
# . value . or .cpp #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
|
||||
NAME = zombie
|
||||
|
||||
CC = clang++
|
||||
CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 -g3
|
||||
|
||||
VPATH = $(D_SRCS)
|
||||
|
||||
LIBS =
|
||||
|
||||
INCLUDES = -I$(D_HEADERS)
|
||||
|
||||
D_SRCS = .
|
||||
SRCS = main.cpp \
|
||||
Zombie.cpp \
|
||||
ZombieHorde.cpp
|
||||
|
||||
D_HEADERS = .
|
||||
HEADERS = Zombie.hpp
|
||||
|
||||
D_OBJS = builds
|
||||
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
|
||||
|
||||
RM_D_OBJS = rm -rf $(D_OBJS)
|
||||
ifeq "$(D_OBJS)" "."
|
||||
RM_D_OBJS =
|
||||
endif
|
||||
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
# . target: prerequisites . $@ : target #
|
||||
# RULES . recipe . $< : 1st prerequisite #
|
||||
# . recipe . $^ : all prerequisites #
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(D_OBJS)/%.o: %.cpp | $(D_OBJS)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(D_OBJS):
|
||||
mkdir $@
|
||||
|
||||
$(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
$(RM_D_OBJS)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY : all clean fclean re bonus run valgrind
|
||||
26
d01/ex01/Zombie.cpp
Normal file
26
d01/ex01/Zombie.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "Zombie.hpp"
|
||||
|
||||
Zombie::Zombie() {
|
||||
|
||||
std::cout << this->_name << " has been created" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
Zombie::~Zombie() {
|
||||
|
||||
std::cout << this->_name << " has been destroyed" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void Zombie::announce( void ) {
|
||||
|
||||
std::cout << this->_name << ": BraiiiiiiinnnzzzZ..." << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void Zombie::put_name( std::string name ) {
|
||||
|
||||
this->_name = name;
|
||||
|
||||
}
|
||||
|
||||
23
d01/ex01/Zombie.hpp
Normal file
23
d01/ex01/Zombie.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef ZOMBIE_HPP
|
||||
# define ZOMBIE_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class Zombie {
|
||||
|
||||
public:
|
||||
|
||||
Zombie();
|
||||
~Zombie();
|
||||
|
||||
void announce( void );
|
||||
void put_name( std::string name );
|
||||
|
||||
private:
|
||||
|
||||
std::string _name;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
12
d01/ex01/ZombieHorde.cpp
Normal file
12
d01/ex01/ZombieHorde.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "Zombie.hpp"
|
||||
|
||||
Zombie* zombieHorde( int N, std::string name ) {
|
||||
|
||||
Zombie *zomboz = new Zombie[N];
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
zomboz[i].put_name( name );
|
||||
|
||||
return zomboz;
|
||||
|
||||
}
|
||||
17
d01/ex01/main.cpp
Normal file
17
d01/ex01/main.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "Zombie.hpp"
|
||||
|
||||
Zombie* zombieHorde( int N, std::string name );
|
||||
#define z_nb 8
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Zombie* zombi;
|
||||
|
||||
zombi = zombieHorde( z_nb, "rambou" );
|
||||
for (int i = 0; i < z_nb; i++) {
|
||||
zombi[i].announce();
|
||||
}
|
||||
delete [] zombi;
|
||||
|
||||
return (0);
|
||||
}
|
||||
BIN
d01/fr.subject.pdf
Normal file
BIN
d01/fr.subject.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user