aboutsummaryrefslogtreecommitdiff
path: root/cpp01/ex02
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-11-09 11:26:50 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-11-09 11:26:50 +0100
commitb799c007a1b6911fcbe5141429ea541e1277ebdd (patch)
treed70ad0826ad2fc2d635adf9afecf89af0838d20b /cpp01/ex02
parent1e9d90bdf9ef5fc05093d3449d883597c7f896de (diff)
downloadpiscine_cpp-b799c007a1b6911fcbe5141429ea541e1277ebdd.tar.gz
piscine_cpp-b799c007a1b6911fcbe5141429ea541e1277ebdd.tar.bz2
piscine_cpp-b799c007a1b6911fcbe5141429ea541e1277ebdd.zip
Fixing some edge cases in cpp00 and cpp01, Updated formatting
Diffstat (limited to 'cpp01/ex02')
-rw-r--r--cpp01/ex02/Zombie.cpp12
-rw-r--r--cpp01/ex02/Zombie.hpp6
-rw-r--r--cpp01/ex02/ZombieEvent.cpp8
-rw-r--r--cpp01/ex02/ZombieEvent.hpp6
-rw-r--r--cpp01/ex02/main.cpp23
5 files changed, 36 insertions, 19 deletions
diff --git a/cpp01/ex02/Zombie.cpp b/cpp01/ex02/Zombie.cpp
index 40fb849..3736101 100644
--- a/cpp01/ex02/Zombie.cpp
+++ b/cpp01/ex02/Zombie.cpp
@@ -6,17 +6,21 @@
/* 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 */
+/* Updated: 2020/11/09 10:27:15 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#include <iostream>
#include "Zombie.hpp"
-Zombie::Zombie(std::string name, std::string type)
+Zombie::Zombie(std::string const& name, std::string const& type)
: m_name(name), m_type(type)
{
- announce();
+ announce();
+}
+
+Zombie::~Zombie()
+{
+ std::cout << "<" << m_name << " (" << m_type << ")> AAAAARG... ME DYING" << std::endl;
}
void Zombie::announce()
diff --git a/cpp01/ex02/Zombie.hpp b/cpp01/ex02/Zombie.hpp
index 5106c8f..bed4873 100644
--- a/cpp01/ex02/Zombie.hpp
+++ b/cpp01/ex02/Zombie.hpp
@@ -6,19 +6,21 @@
/* 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 */
+/* Updated: 2020/11/09 10:26:25 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
+# include <iostream>
# include <string>
class Zombie
{
public:
- Zombie(std::string name, std::string type);
+ Zombie(std::string const& name, std::string const& type);
+ ~Zombie();
void announce();
private:
diff --git a/cpp01/ex02/ZombieEvent.cpp b/cpp01/ex02/ZombieEvent.cpp
index acb8dd0..44d2c04 100644
--- a/cpp01/ex02/ZombieEvent.cpp
+++ b/cpp01/ex02/ZombieEvent.cpp
@@ -6,15 +6,15 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:41:33 by charles #+# #+# */
-/* Updated: 2020/04/13 09:49:36 by charles ### ########.fr */
+/* Updated: 2020/11/09 10:25:24 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "ZombieEvent.hpp"
-void ZombieEvent::setZombieType(std::string storedType)
+void ZombieEvent::setZombieType(std::string const& type)
{
- m_storedType = storedType;
+ m_storedType = type;
}
Zombie* ZombieEvent::newZombie(std::string name)
@@ -36,5 +36,5 @@ Zombie* ZombieEvent::randomChump()
"yo",
"rideaux"
};
- return new Zombie(pool[rand() % 10], m_storedType);
+ return newZombie(pool[rand() % 10]);
}
diff --git a/cpp01/ex02/ZombieEvent.hpp b/cpp01/ex02/ZombieEvent.hpp
index 7b2fe79..0d0e0ec 100644
--- a/cpp01/ex02/ZombieEvent.hpp
+++ b/cpp01/ex02/ZombieEvent.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:42:36 by charles #+# #+# */
-/* Updated: 2020/04/13 09:45:36 by charles ### ########.fr */
+/* Updated: 2020/11/09 10:10:57 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,8 +20,8 @@
class ZombieEvent
{
public:
- void setZombieType(std::string type);
- Zombie* newZombie(std::string name);
+ void setZombieType(std::string const& type);
+ Zombie* newZombie(std::string name); // subject prototype without const&
Zombie* randomChump();
private:
diff --git a/cpp01/ex02/main.cpp b/cpp01/ex02/main.cpp
index 291fddb..e8fb2c9 100644
--- a/cpp01/ex02/main.cpp
+++ b/cpp01/ex02/main.cpp
@@ -6,29 +6,40 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:47:21 by charles #+# #+# */
-/* Updated: 2020/04/13 09:48:29 by charles ### ########.fr */
+/* Updated: 2020/11/09 10:33:18 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <cstdlib>
+#include <ctime>
+#include <fstream>
#include "Zombie.hpp"
#include "ZombieEvent.hpp"
int main()
{
- Zombie* z;
+ Zombie* z;
ZombieEvent zevent;
- Zombie zStack("onTheStack", "IdontLikeHeap");
+ Zombie zStack("onTheStack", "IdontLikeHeap");
- srand(time(NULL));
- zevent.setZombieType("standard");
+ int seed;
+ std::ifstream devRandom("/dev/random");
+ if (devRandom.is_open())
+ {
+ devRandom.read((char*)&seed, sizeof(int));
+ devRandom.close();
+ }
+ else
+ seed = time(NULL);
+ srand(seed);
+ zevent.setZombieType("NotRandom");
z = zevent.newZombie("jean");
+ zevent.setZombieType("random");
delete z;
for (int i = 0; i < 5; i++)
{
z = zevent.randomChump();
delete z;
}
-
return 0;
}