diff options
Diffstat (limited to 'cpp01/ex03')
| -rw-r--r-- | cpp01/ex03/Zombie.cpp | 14 | ||||
| -rw-r--r-- | cpp01/ex03/Zombie.hpp | 17 | ||||
| -rw-r--r-- | cpp01/ex03/ZombieHorde.cpp | 41 | ||||
| -rw-r--r-- | cpp01/ex03/ZombieHorde.hpp | 18 | ||||
| -rw-r--r-- | cpp01/ex03/main.cpp | 15 |
5 files changed, 105 insertions, 0 deletions
diff --git a/cpp01/ex03/Zombie.cpp b/cpp01/ex03/Zombie.cpp new file mode 100644 index 0000000..2ea23b6 --- /dev/null +++ b/cpp01/ex03/Zombie.cpp @@ -0,0 +1,14 @@ +#include <iostream> +#include "Zombie.hpp" + +Zombie::Zombie(std::string n, std::string t) +{ + name = n; + type = t; + announce(); +} + +void Zombie::announce() +{ + std::cout << "<" << name << " (" << type << ")> Braiiiiiiinnnssss..." << std::endl; +} diff --git a/cpp01/ex03/Zombie.hpp b/cpp01/ex03/Zombie.hpp new file mode 100644 index 0000000..980ea49 --- /dev/null +++ b/cpp01/ex03/Zombie.hpp @@ -0,0 +1,17 @@ +#ifndef ZOMBIE_HPP +# define ZOMBIE_HPP + +#include <string> + +class Zombie +{ + public: + Zombie(std::string n, std::string t); + void announce(); + + private: + std::string name; + std::string type; +}; + +#endif diff --git a/cpp01/ex03/ZombieHorde.cpp b/cpp01/ex03/ZombieHorde.cpp new file mode 100644 index 0000000..e8218b4 --- /dev/null +++ b/cpp01/ex03/ZombieHorde.cpp @@ -0,0 +1,41 @@ +#include <cstdlib> +#include "ZombieHorde.hpp" + +ZombieHorde::ZombieHorde(int size) +{ + std::string name_pool[10] = { + "Jordan", + "Mr.poopybutthole", + "Jean-Denis", + "Table", + "Charle", + "Abe", + "James", + "Homer", + "yo", + "rideaux" + }; + std::string type_pool[4] = { + "fire", + "water", + "earth", + "wind" + }; + horde = new Zombie*[size]; + horde_size = size; + for (int i = 0; i < size; i++) + horde[i] = new Zombie(name_pool[rand() % 10], type_pool[rand() % 4]); +} + +ZombieHorde::~ZombieHorde() +{ + for (int i = 0; i < horde_size; i++) + delete horde[i]; + delete [] horde; +} + +void ZombieHorde::announce() +{ + for (int i = 0; i < horde_size; i++) + horde[i]->announce(); +} diff --git a/cpp01/ex03/ZombieHorde.hpp b/cpp01/ex03/ZombieHorde.hpp new file mode 100644 index 0000000..772bcc0 --- /dev/null +++ b/cpp01/ex03/ZombieHorde.hpp @@ -0,0 +1,18 @@ +#ifndef ZOMBIE_HORDE_HPP +# define ZOMBIE_HORDE_HPP + +# include "Zombie.hpp" + +class ZombieHorde +{ + public: + ZombieHorde(int size); + void announce(); + ~ZombieHorde(); + + private: + int horde_size; + Zombie **horde; +}; + +#endif diff --git a/cpp01/ex03/main.cpp b/cpp01/ex03/main.cpp new file mode 100644 index 0000000..896b05e --- /dev/null +++ b/cpp01/ex03/main.cpp @@ -0,0 +1,15 @@ +#include <cstdlib> +#include "Zombie.hpp" +#include "ZombieHorde.hpp" + +int main() +{ + srand(time(NULL)); + + ZombieHorde horde = ZombieHorde(10); + horde.announce(); + + ZombieHorde *heap_horde = new ZombieHorde(10); + heap_horde->announce(); + delete heap_horde; +} |
