aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--cpp00/ex00/Makefile12
-rw-r--r--cpp00/ex00/megaphone.cpp12
-rw-r--r--cpp00/ex01/Contact.hpp10
-rw-r--r--cpp00/ex01/PhoneBook.cpp12
-rw-r--r--cpp00/ex01/PhoneBook.hpp14
-rw-r--r--cpp00/ex01/main.cpp7
-rw-r--r--cpp00/ex02/.keep0
-rw-r--r--cpp01/ex00/Pony.cpp22
-rw-r--r--cpp01/ex00/Pony.hpp10
-rw-r--r--cpp01/ex00/main.cpp9
-rw-r--r--cpp01/ex01/ex01.cpp2
-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
-rw-r--r--cpp01/ex03/Zombie.cpp9
-rw-r--r--cpp01/ex03/Zombie.hpp5
-rw-r--r--cpp01/ex03/ZombieHorde.cpp12
-rw-r--r--cpp01/ex03/ZombieHorde.hpp7
-rw-r--r--cpp01/ex03/main.cpp30
-rw-r--r--cpp01/ex04/ex04.cpp4
-rw-r--r--cpp01/ex05/Human.cpp11
-rw-r--r--cpp01/ex05/Human.hpp6
-rw-r--r--cpp01/ex05/main.cpp6
-rw-r--r--cpp01/ex06/HumanA.cpp7
-rw-r--r--cpp01/ex06/HumanA.hpp6
-rw-r--r--cpp01/ex06/HumanB.cpp12
-rw-r--r--cpp01/ex06/HumanB.hpp6
-rw-r--r--cpp01/ex06/Weapon.cpp11
-rw-r--r--cpp01/ex06/Weapon.hpp8
-rw-r--r--cpp01/ex06/main.cpp2
-rw-r--r--cpp01/ex07/Makefile4
-rw-r--r--cpp01/ex07/main.cpp13
35 files changed, 207 insertions, 118 deletions
diff --git a/.gitignore b/.gitignore
index 9b6809c..e7fbed8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*.o
+*.dSYM
a.out
megaphone
crapyphonebook
diff --git a/cpp00/ex00/Makefile b/cpp00/ex00/Makefile
index 466a51e..2bfc080 100644
--- a/cpp00/ex00/Makefile
+++ b/cpp00/ex00/Makefile
@@ -1,3 +1,15 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# Makefile :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/11/09 09:16:44 by cacharle #+# #+# #
+# Updated: 2020/11/09 09:16:45 by cacharle ### ########.fr #
+# #
+# ############################################################################ #
+
RM = rm -f
CC = clang++
diff --git a/cpp00/ex00/megaphone.cpp b/cpp00/ex00/megaphone.cpp
index 32b4d14..1956510 100644
--- a/cpp00/ex00/megaphone.cpp
+++ b/cpp00/ex00/megaphone.cpp
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* megaphone.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/11/09 09:15:55 by cacharle #+# #+# */
+/* Updated: 2020/11/09 09:16:00 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include <iostream>
#include <cctype>
diff --git a/cpp00/ex01/Contact.hpp b/cpp00/ex01/Contact.hpp
index d9fbee6..4717e55 100644
--- a/cpp00/ex01/Contact.hpp
+++ b/cpp00/ex01/Contact.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 07:23:11 by charles #+# #+# */
-/* Updated: 2020/04/13 08:57:01 by charles ### ########.fr */
+/* Updated: 2020/11/09 09:30:12 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,12 +22,12 @@ class Contact
{
public:
static Contact prompt();
- void preview() const;
- void put() const;
+ void preview() const;
+ void put() const;
private:
- static void promptString(std::string promptString, std::string &s);
- static void promptInt(std::string promptString, int &i);
+ static void promptString(std::string promptString, std::string& s);
+ static void promptInt(std::string promptString, int& i);
static std::string trimedName(std::string name);
struct Address
diff --git a/cpp00/ex01/PhoneBook.cpp b/cpp00/ex01/PhoneBook.cpp
index a47307f..a28ce36 100644
--- a/cpp00/ex01/PhoneBook.cpp
+++ b/cpp00/ex01/PhoneBook.cpp
@@ -6,23 +6,23 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 07:23:13 by charles #+# #+# */
-/* Updated: 2020/04/13 08:43:05 by charles ### ########.fr */
+/* Updated: 2020/11/09 09:29:37 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "PhoneBook.hpp"
-PhoneBook::PhoneBook(): m_size(0)
-{
-}
+PhoneBook::PhoneBook() : m_size(0) {}
void PhoneBook::add(Contact contact)
{
+ if (m_size >= CONTACTS_SIZE)
+ return;
m_contacts[m_size] = contact;
m_size++;
}
-Contact const &PhoneBook::get(int index) const
+Contact const& PhoneBook::get(size_t index) const
{
return m_contacts[index];
}
@@ -32,7 +32,7 @@ size_t PhoneBook::getSize() const
return m_size;
}
-std::ostream &operator<<(std::ostream &out, PhoneBook const &p)
+std::ostream& operator<<(std::ostream& out, PhoneBook const& p)
{
for (size_t i = 0; i < p.getSize(); i++)
{
diff --git a/cpp00/ex01/PhoneBook.hpp b/cpp00/ex01/PhoneBook.hpp
index 8510710..abf83be 100644
--- a/cpp00/ex01/PhoneBook.hpp
+++ b/cpp00/ex01/PhoneBook.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:06:23 by charles #+# #+# */
-/* Updated: 2020/04/13 09:06:39 by charles ### ########.fr */
+/* Updated: 2020/11/09 09:28:38 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,16 +22,16 @@ class PhoneBook
{
public:
PhoneBook();
- void add(Contact contact);
- Contact* search(std::string needle);
- size_t getSize() const;
- Contact const &get(int index) const;
+ void add(Contact contact);
+ Contact* search(std::string needle);
+ size_t getSize() const;
+ Contact const& get(size_t index) const;
private:
Contact m_contacts[CONTACTS_SIZE];
- int m_size;
+ size_t m_size;
};
-std::ostream &operator<<(std::ostream &out, PhoneBook const &p);
+std::ostream& operator<<(std::ostream& out, PhoneBook const& p);
#endif
diff --git a/cpp00/ex01/main.cpp b/cpp00/ex01/main.cpp
index 5734d38..8b04fe2 100644
--- a/cpp00/ex01/main.cpp
+++ b/cpp00/ex01/main.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 07:23:15 by charles #+# #+# */
-/* Updated: 2020/04/13 09:18:04 by charles ### ########.fr */
+/* Updated: 2020/11/09 09:22:22 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,8 +18,7 @@
int main()
{
std::string input;
- PhoneBook phoneBook;
- int tmp;
+ PhoneBook phoneBook;
while (true)
{
@@ -40,7 +39,7 @@ int main()
else if (input == "SEARCH")
{
std::cout << phoneBook << std::flush;
- tmp = getInt();
+ int tmp = getInt();
if (tmp < 0 || size_t(tmp) >= phoneBook.getSize())
std::cout << "Error: Not valid index: " << tmp << std::endl;
else
diff --git a/cpp00/ex02/.keep b/cpp00/ex02/.keep
deleted file mode 100644
index e69de29..0000000
--- a/cpp00/ex02/.keep
+++ /dev/null
diff --git a/cpp01/ex00/Pony.cpp b/cpp01/ex00/Pony.cpp
index b45f0e1..1b8df61 100644
--- a/cpp01/ex00/Pony.cpp
+++ b/cpp01/ex00/Pony.cpp
@@ -6,28 +6,34 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:06:06 by charles #+# #+# */
-/* Updated: 2020/04/13 09:33:59 by charles ### ########.fr */
+/* Updated: 2020/11/09 09:57:26 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#include <iostream>
#include "Pony.hpp"
-Pony::Pony(int weight, int maxSpeed)
- : m_weight(weight), m_maxSpeed(maxSpeed)
+Pony::Pony(std::string const& name, int weight, int maxSpeed)
+ : m_name(name), m_weight(weight), m_maxSpeed(maxSpeed)
{
+ std::cout << "Hey there, my name is " << m_name << " and you?" << std::endl;
+}
+
+Pony::~Pony()
+{
+ std::cout << "Oh no, I'M DYING! They called me " << m_name << "." << std::endl;
}
void Pony::sayHello()
{
- std::cout << "Hi, I'm a pony, I weight " << m_weight
- << " and my speed limit is " << m_maxSpeed
+ std::cout << "Hi, I'm " << m_name
+ << ", I weight " << m_weight
+ << " and my speed limit is " << m_maxSpeed
<< std::endl;
}
void Pony::run()
{
for (int i = 0; i <= m_maxSpeed; i += m_maxSpeed / 10)
- std::cout << "I'm running really fast at " << i
- << ", look at me!" << std::endl;
+ std::cout << m_name << " is running really fast at " << i
+ << ", look at him!" << std::endl;
}
diff --git a/cpp01/ex00/Pony.hpp b/cpp01/ex00/Pony.hpp
index 571414c..5c42a60 100644
--- a/cpp01/ex00/Pony.hpp
+++ b/cpp01/ex00/Pony.hpp
@@ -6,20 +6,26 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:26:16 by charles #+# #+# */
-/* Updated: 2020/04/13 09:27:49 by charles ### ########.fr */
+/* Updated: 2020/11/09 09:54:25 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PONY_HPP
# define PONY_HPP
+# include <iostream>
+# include <string>
+
class Pony
{
public:
- Pony(int weight, int maxSpeed);
+ Pony(std::string const& name, int weight, int maxSpeed);
+ ~Pony();
void sayHello();
void run();
+
private:
+ std::string m_name;
int m_weight;
int m_maxSpeed;
};
diff --git a/cpp01/ex00/main.cpp b/cpp01/ex00/main.cpp
index 689f7f1..62a9e67 100644
--- a/cpp01/ex00/main.cpp
+++ b/cpp01/ex00/main.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:26:11 by charles #+# #+# */
-/* Updated: 2020/04/13 09:29:58 by charles ### ########.fr */
+/* Updated: 2020/11/09 09:58:46 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,7 +15,8 @@
void ponyOnTheHeap()
{
- Pony *p = new Pony(200, 100);
+ std::cout << "=== ponyOnTheHeap ===" << std::endl;
+ Pony *p = new Pony("ChunkyBoy", 200, 100);
p->sayHello();
p->run();
delete p;
@@ -23,7 +24,8 @@ void ponyOnTheHeap()
void ponyOnTheStack()
{
- Pony p(200, 100);
+ std::cout << "=== ponyOnTheStack ===" << std::endl;
+ Pony p("Jean", 200, 100);
p.sayHello();
p.run();
}
@@ -31,6 +33,7 @@ void ponyOnTheStack()
int main()
{
ponyOnTheHeap();
+ std::cout << std::endl;
ponyOnTheStack();
return 0;
}
diff --git a/cpp01/ex01/ex01.cpp b/cpp01/ex01/ex01.cpp
index c3f416f..00b2b2e 100644
--- a/cpp01/ex01/ex01.cpp
+++ b/cpp01/ex01/ex01.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:35:26 by charles #+# #+# */
-/* Updated: 2020/04/13 09:36:03 by charles ### ########.fr */
+/* Updated: 2020/11/09 10:02:10 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
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;
}
diff --git a/cpp01/ex03/Zombie.cpp b/cpp01/ex03/Zombie.cpp
index 40fb849..79f6ad2 100644
--- a/cpp01/ex03/Zombie.cpp
+++ b/cpp01/ex03/Zombie.cpp
@@ -6,19 +6,24 @@
/* 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:38:44 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();
}
+Zombie::~Zombie()
+{
+ std::cout << "<" << m_name << " (" << m_type << ")> AAAAARG... ME DYING" << std::endl;
+}
+
void Zombie::announce()
{
std::cout << "<" << m_name << " (" << m_type << ")> Braiiiiiiinnnssss..." << std::endl;
diff --git a/cpp01/ex03/Zombie.hpp b/cpp01/ex03/Zombie.hpp
index 5106c8f..e87200e 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/04/13 09:40:49 by charles ### ########.fr */
+/* Updated: 2020/11/09 10:38:52 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,7 +18,8 @@
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/ex03/ZombieHorde.cpp b/cpp01/ex03/ZombieHorde.cpp
index 955355b..0492fb3 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/04/13 10:02:01 by charles ### ########.fr */
+/* Updated: 2020/11/09 10:57:08 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,6 +15,12 @@
ZombieHorde::ZombieHorde(int n)
: m_size(n)
{
+ if (n < 0)
+ {
+ std::cerr << "Error: n should be > 0" << std::endl;
+ m_horde = NULL;
+ return;
+ }
std::string name_pool[10] = {
"Jordan",
"Mr.poopybutthole",
@@ -40,6 +46,8 @@ ZombieHorde::ZombieHorde(int n)
ZombieHorde::~ZombieHorde()
{
+ if (m_horde == NULL)
+ return;
for (size_t i = 0; i < m_size; i++)
delete m_horde[i];
delete [] m_horde;
@@ -47,6 +55,8 @@ ZombieHorde::~ZombieHorde()
void ZombieHorde::announce()
{
+ if (m_horde == NULL)
+ return;
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 991c2ec..bb6bbde 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/04/13 09:59:53 by charles ### ########.fr */
+/* Updated: 2020/11/09 10:53:45 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,17 +15,18 @@
# include <cstdlib>
# include <string>
+# include <iostream>
# include "Zombie.hpp"
class ZombieHorde
{
public:
- ZombieHorde(int n);
+ ZombieHorde(int n); // subject wants int
~ZombieHorde();
void announce();
private:
- size_t m_size;
+ size_t m_size;
Zombie** m_horde;
};
diff --git a/cpp01/ex03/main.cpp b/cpp01/ex03/main.cpp
index 20db57c..cef8577 100644
--- a/cpp01/ex03/main.cpp
+++ b/cpp01/ex03/main.cpp
@@ -6,25 +6,47 @@
/* 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 */
+/* Updated: 2020/11/09 10:57:25 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include <cstdlib>
#include <iostream>
+#include <fstream>
#include "Zombie.hpp"
#include "ZombieHorde.hpp"
int main()
{
- srand(time(NULL));
+ 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);
- std::cout << "Stack horde" << std::endl;
+ std::cout << "=== Stack horde ===" << std::endl;
ZombieHorde horde(5);
horde.announce();
- std::cout << std::endl << "Heap horde" << std::endl;
+ std::cout << std::endl << "=== Heap horde ===" << std::endl;
ZombieHorde *heap_horde = new ZombieHorde(7);
heap_horde->announce();
delete heap_horde;
+
+ std::cout << std::endl << "=== Empty horde ===" << std::endl;
+ ZombieHorde *empty_horde = new ZombieHorde(0);
+ empty_horde->announce();
+ delete empty_horde;
+
+ std::cout << std::endl << "=== Error horde ===" << std::endl;
+ ZombieHorde *negative_horde = new ZombieHorde(-13);
+ negative_horde->announce();
+ delete negative_horde;
+
+ return 0;
}
diff --git a/cpp01/ex04/ex04.cpp b/cpp01/ex04/ex04.cpp
index 7eed286..bdc60e9 100644
--- a/cpp01/ex04/ex04.cpp
+++ b/cpp01/ex04/ex04.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 12:43:03 by cacharle #+# #+# */
-/* Updated: 2020/04/13 10:01:19 by charles ### ########.fr */<