diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-13 10:33:05 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-13 10:33:05 +0200 |
| commit | 0f3240844dbd5a874e1565a988ef355ededab6a5 (patch) | |
| tree | efc1a1307863d173be17a12fbab6b84fe7d00960 /cpp01/ex03 | |
| parent | 629d52b1262879a346e9ca17567a8f483c60ba0a (diff) | |
| download | piscine_cpp-0f3240844dbd5a874e1565a988ef355ededab6a5.tar.gz piscine_cpp-0f3240844dbd5a874e1565a988ef355ededab6a5.tar.bz2 piscine_cpp-0f3240844dbd5a874e1565a988ef355ededab6a5.zip | |
Fixing cpp01
Diffstat (limited to 'cpp01/ex03')
| -rw-r--r-- | cpp01/ex03/Zombie.cpp | 19 | ||||
| -rw-r--r-- | cpp01/ex03/Zombie.hpp | 26 | ||||
| -rw-r--r-- | cpp01/ex03/ZombieHorde.cpp | 33 | ||||
| -rw-r--r-- | cpp01/ex03/ZombieHorde.hpp | 28 | ||||
| -rw-r--r-- | cpp01/ex03/main.cpp | 19 |
5 files changed, 94 insertions, 31 deletions
diff --git a/cpp01/ex03/Zombie.cpp b/cpp01/ex03/Zombie.cpp index 2ea23b6..40fb849 100644 --- a/cpp01/ex03/Zombie.cpp +++ b/cpp01/ex03/Zombie.cpp @@ -1,14 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 09:38:16 by charles #+# #+# */ +/* Updated: 2020/04/13 09:40:20 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include <iostream> #include "Zombie.hpp" -Zombie::Zombie(std::string n, std::string t) +Zombie::Zombie(std::string name, std::string type) + : m_name(name), m_type(type) { - name = n; - type = t; announce(); } void Zombie::announce() { - std::cout << "<" << name << " (" << type << ")> Braiiiiiiinnnssss..." << std::endl; + std::cout << "<" << m_name << " (" << m_type << ")> Braiiiiiiinnnssss..." << std::endl; } diff --git a/cpp01/ex03/Zombie.hpp b/cpp01/ex03/Zombie.hpp index 980ea49..5106c8f 100644 --- a/cpp01/ex03/Zombie.hpp +++ b/cpp01/ex03/Zombie.hpp @@ -1,17 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 09:40:26 by charles #+# #+# */ +/* Updated: 2020/04/13 09:40:49 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + #ifndef ZOMBIE_HPP # define ZOMBIE_HPP -#include <string> +# include <string> class Zombie { - public: - Zombie(std::string n, std::string t); - void announce(); +public: + Zombie(std::string name, std::string type); + void announce(); - private: - std::string name; - std::string type; +private: + std::string m_name; + std::string m_type; }; #endif diff --git a/cpp01/ex03/ZombieHorde.cpp b/cpp01/ex03/ZombieHorde.cpp index e8218b4..955355b 100644 --- a/cpp01/ex03/ZombieHorde.cpp +++ b/cpp01/ex03/ZombieHorde.cpp @@ -1,7 +1,19 @@ -#include <cstdlib> +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ZombieHorde.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 09:52:11 by charles #+# #+# */ +/* Updated: 2020/04/13 10:02:01 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "ZombieHorde.hpp" -ZombieHorde::ZombieHorde(int size) +ZombieHorde::ZombieHorde(int n) + : m_size(n) { std::string name_pool[10] = { "Jordan", @@ -21,21 +33,20 @@ ZombieHorde::ZombieHorde(int size) "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]); + m_horde = new Zombie*[m_size]; + for (size_t i = 0; i < m_size; i++) + m_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; + for (size_t i = 0; i < m_size; i++) + delete m_horde[i]; + delete [] m_horde; } void ZombieHorde::announce() { - for (int i = 0; i < horde_size; i++) - horde[i]->announce(); + for (size_t i = 0; i < m_size; i++) + m_horde[i]->announce(); } diff --git a/cpp01/ex03/ZombieHorde.hpp b/cpp01/ex03/ZombieHorde.hpp index 772bcc0..991c2ec 100644 --- a/cpp01/ex03/ZombieHorde.hpp +++ b/cpp01/ex03/ZombieHorde.hpp @@ -1,18 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ZombieHorde.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 09:52:18 by charles #+# #+# */ +/* Updated: 2020/04/13 09:59:53 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + #ifndef ZOMBIE_HORDE_HPP # define ZOMBIE_HORDE_HPP +# include <cstdlib> +# include <string> # include "Zombie.hpp" class ZombieHorde { - public: - ZombieHorde(int size); - void announce(); - ~ZombieHorde(); +public: + ZombieHorde(int n); + ~ZombieHorde(); + void announce(); - private: - int horde_size; - Zombie **horde; +private: + size_t m_size; + Zombie** m_horde; }; #endif diff --git a/cpp01/ex03/main.cpp b/cpp01/ex03/main.cpp index 896b05e..20db57c 100644 --- a/cpp01/ex03/main.cpp +++ b/cpp01/ex03/main.cpp @@ -1,4 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 09:56:14 by charles #+# #+# */ +/* Updated: 2020/04/13 09:58:56 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include <cstdlib> +#include <iostream> #include "Zombie.hpp" #include "ZombieHorde.hpp" @@ -6,10 +19,12 @@ int main() { srand(time(NULL)); - ZombieHorde horde = ZombieHorde(10); + std::cout << "Stack horde" << std::endl; + ZombieHorde horde(5); horde.announce(); - ZombieHorde *heap_horde = new ZombieHorde(10); + std::cout << std::endl << "Heap horde" << std::endl; + ZombieHorde *heap_horde = new ZombieHorde(7); heap_horde->announce(); delete heap_horde; } |
