feat(ex01): it works
This commit is contained in:
parent
b9ff91c653
commit
1a167101bb
6 changed files with 94 additions and 0 deletions
1
ex01/.gitignore
vendored
Normal file
1
ex01/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ex01
|
||||||
40
ex01/Makefile
Normal file
40
ex01/Makefile
Normal 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
12
ex01/Zombie.cpp
Normal 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
21
ex01/Zombie.hpp
Normal 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
11
ex01/main.cpp
Normal 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
9
ex01/zombieHorde.cpp
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue