From b799c007a1b6911fcbe5141429ea541e1277ebdd Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Mon, 9 Nov 2020 11:26:50 +0100 Subject: Fixing some edge cases in cpp00 and cpp01, Updated formatting --- cpp01/ex02/Zombie.cpp | 12 ++++++++---- cpp01/ex02/Zombie.hpp | 6 ++++-- cpp01/ex02/ZombieEvent.cpp | 8 ++++---- cpp01/ex02/ZombieEvent.hpp | 6 +++--- cpp01/ex02/main.cpp | 23 +++++++++++++++++------ 5 files changed, 36 insertions(+), 19 deletions(-) (limited to 'cpp01/ex02') 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 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 #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 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 # include 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 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 +#include +#include #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; } -- cgit