diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-12 20:20:12 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-12 20:20:12 +0100 |
| commit | 7d6a4c877de8048ec5fbea4a563b3d09c8976105 (patch) | |
| tree | a62206e21b3b678d0da6350978e2f6db7cc31fbe /cpp01/ex02 | |
| parent | 7080f89bb2800917bfd9a560046a1ab7505f819e (diff) | |
| download | piscine_cpp-7d6a4c877de8048ec5fbea4a563b3d09c8976105.tar.gz piscine_cpp-7d6a4c877de8048ec5fbea4a563b3d09c8976105.tar.bz2 piscine_cpp-7d6a4c877de8048ec5fbea4a563b3d09c8976105.zip | |
cpp01 00 -> 04
Diffstat (limited to 'cpp01/ex02')
| -rw-r--r-- | cpp01/ex02/Zombie.cpp | 14 | ||||
| -rw-r--r-- | cpp01/ex02/Zombie.hpp | 17 | ||||
| -rw-r--r-- | cpp01/ex02/ZombieEvent.cpp | 29 | ||||
| -rw-r--r-- | cpp01/ex02/ZombieEvent.hpp | 18 | ||||
| -rw-r--r-- | cpp01/ex02/main.cpp | 20 |
5 files changed, 98 insertions, 0 deletions
diff --git a/cpp01/ex02/Zombie.cpp b/cpp01/ex02/Zombie.cpp new file mode 100644 index 0000000..2ea23b6 --- /dev/null +++ b/cpp01/ex02/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/ex02/Zombie.hpp b/cpp01/ex02/Zombie.hpp new file mode 100644 index 0000000..980ea49 --- /dev/null +++ b/cpp01/ex02/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/ex02/ZombieEvent.cpp b/cpp01/ex02/ZombieEvent.cpp new file mode 100644 index 0000000..6775138 --- /dev/null +++ b/cpp01/ex02/ZombieEvent.cpp @@ -0,0 +1,29 @@ +#include <cstdlib> +#include "ZombieEvent.hpp" + +void ZombieEvent::setZombieType(std::string type) +{ + stored_type = type; +} + +Zombie *ZombieEvent::newZombie(std::string name) +{ + return new Zombie(name, stored_type); +} + +Zombie *ZombieEvent::randomChump() +{ + std::string pool[10] = { + "Jordan", + "Mr.poopybutthole", + "Jean-Denis", + "Table", + "Charle", + "Abe", + "James", + "Homer", + "yo", + "rideaux" + }; + return new Zombie(pool[rand() % 10], stored_type); +} diff --git a/cpp01/ex02/ZombieEvent.hpp b/cpp01/ex02/ZombieEvent.hpp new file mode 100644 index 0000000..869207e --- /dev/null +++ b/cpp01/ex02/ZombieEvent.hpp @@ -0,0 +1,18 @@ +#ifndef ZOMBIE_EVENT_HPP +# define ZOMBIE_EVENT_HPP + +#include <string> +#include "Zombie.hpp" + +class ZombieEvent +{ + public: + void setZombieType(std::string type); + Zombie *newZombie(std::string name); + Zombie *randomChump(); + + private: + std::string stored_type; +}; + +#endif diff --git a/cpp01/ex02/main.cpp b/cpp01/ex02/main.cpp new file mode 100644 index 0000000..1df20d2 --- /dev/null +++ b/cpp01/ex02/main.cpp @@ -0,0 +1,20 @@ +#include <cstdlib> +#include "Zombie.hpp" +#include "ZombieEvent.hpp" + +int main() +{ + Zombie *z; + ZombieEvent zevent; + + srand(time(NULL)); + zevent.setZombieType("standard"); + z = zevent.newZombie("jean"); + delete z; + for (int i = 0; i < 5; i++) + { + z = zevent.randomChump(); + delete z; + } + return 0; +} |
