aboutsummaryrefslogtreecommitdiff
path: root/cpp01/ex03
diff options
context:
space:
mode:
Diffstat (limited to 'cpp01/ex03')
-rw-r--r--cpp01/ex03/Zombie.cpp16
-rw-r--r--cpp01/ex03/Zombie.hpp6
-rw-r--r--cpp01/ex03/ZombieHorde.cpp13
-rw-r--r--cpp01/ex03/ZombieHorde.hpp6
-rw-r--r--cpp01/ex03/main.cpp4
5 files changed, 33 insertions, 12 deletions
diff --git a/cpp01/ex03/Zombie.cpp b/cpp01/ex03/Zombie.cpp
index 79f6ad2..a8104d4 100644
--- a/cpp01/ex03/Zombie.cpp
+++ b/cpp01/ex03/Zombie.cpp
@@ -6,13 +6,17 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:38:16 by charles #+# #+# */
-/* Updated: 2020/11/09 10:38:44 by cacharle ### ########.fr */
+/* Updated: 2020/11/09 12:53:44 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include "Zombie.hpp"
+Zombie::Zombie()
+ : m_name(""), m_type("")
+{}
+
Zombie::Zombie(std::string const& name, std::string const& type)
: m_name(name), m_type(type)
{
@@ -28,3 +32,13 @@ void Zombie::announce()
{
std::cout << "<" << m_name << " (" << m_type << ")> Braiiiiiiinnnssss..." << std::endl;
}
+
+void Zombie::setName(std::string const& name)
+{
+ m_name = name;
+}
+
+void Zombie::setType(std::string const& type)
+{
+ m_type = type;
+}
diff --git a/cpp01/ex03/Zombie.hpp b/cpp01/ex03/Zombie.hpp
index e87200e..8300459 100644
--- a/cpp01/ex03/Zombie.hpp
+++ b/cpp01/ex03/Zombie.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:40:26 by charles #+# #+# */
-/* Updated: 2020/11/09 10:38:52 by cacharle ### ########.fr */
+/* Updated: 2020/11/09 12:53:45 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,9 +18,13 @@
class Zombie
{
public:
+ Zombie();
Zombie(std::string const& name, std::string const& type);
~Zombie();
void announce();
+ void setName(std::string const& name);
+ void setType(std::string const& type);
+
private:
std::string m_name;
diff --git a/cpp01/ex03/ZombieHorde.cpp b/cpp01/ex03/ZombieHorde.cpp
index 0492fb3..c0eb974 100644
--- a/cpp01/ex03/ZombieHorde.cpp
+++ b/cpp01/ex03/ZombieHorde.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:52:11 by charles #+# #+# */
-/* Updated: 2020/11/09 10:57:08 by cacharle ### ########.fr */
+/* Updated: 2020/11/09 12:58:23 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -39,17 +39,18 @@ ZombieHorde::ZombieHorde(int n)
"earth",
"wind"
};
- m_horde = new Zombie*[m_size];
+ 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]);
+ {
+ m_horde[i].setName(name_pool[rand() % 10]);
+ m_horde[i].setType(type_pool[rand() % 4]);
+ }
}
ZombieHorde::~ZombieHorde()
{
if (m_horde == NULL)
return;
- for (size_t i = 0; i < m_size; i++)
- delete m_horde[i];
delete [] m_horde;
}
@@ -58,5 +59,5 @@ void ZombieHorde::announce()
if (m_horde == NULL)
return;
for (size_t i = 0; i < m_size; i++)
- m_horde[i]->announce();
+ m_horde[i].announce();
}
diff --git a/cpp01/ex03/ZombieHorde.hpp b/cpp01/ex03/ZombieHorde.hpp
index bb6bbde..c6bd496 100644
--- a/cpp01/ex03/ZombieHorde.hpp
+++ b/cpp01/ex03/ZombieHorde.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:52:18 by charles #+# #+# */
-/* Updated: 2020/11/09 10:53:45 by cacharle ### ########.fr */
+/* Updated: 2020/11/09 12:45:34 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,8 +26,8 @@ public:
void announce();
private:
- size_t m_size;
- Zombie** m_horde;
+ size_t m_size;
+ Zombie* m_horde;
};
#endif
diff --git a/cpp01/ex03/main.cpp b/cpp01/ex03/main.cpp
index cef8577..12a0045 100644
--- a/cpp01/ex03/main.cpp
+++ b/cpp01/ex03/main.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:56:14 by charles #+# #+# */
-/* Updated: 2020/11/09 10:57:25 by cacharle ### ########.fr */
+/* Updated: 2020/11/09 12:54:36 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -48,5 +48,7 @@ int main()
negative_horde->announce();
delete negative_horde;
+
+ std::cout << std::endl << "=== Stack horde destroyed ===" << std::endl;
return 0;
}