diff options
Diffstat (limited to 'cpp01')
| -rw-r--r-- | cpp01/ex00/Pony.cpp | 22 | ||||
| -rw-r--r-- | cpp01/ex00/Pony.hpp | 10 | ||||
| -rw-r--r-- | cpp01/ex00/main.cpp | 9 | ||||
| -rw-r--r-- | cpp01/ex01/ex01.cpp | 2 | ||||
| -rw-r--r-- | cpp01/ex02/Zombie.cpp | 12 | ||||
| -rw-r--r-- | cpp01/ex02/Zombie.hpp | 6 | ||||
| -rw-r--r-- | cpp01/ex02/ZombieEvent.cpp | 8 | ||||
| -rw-r--r-- | cpp01/ex02/ZombieEvent.hpp | 6 | ||||
| -rw-r--r-- | cpp01/ex02/main.cpp | 23 | ||||
| -rw-r--r-- | cpp01/ex03/Zombie.cpp | 9 | ||||
| -rw-r--r-- | cpp01/ex03/Zombie.hpp | 5 | ||||
| -rw-r--r-- | cpp01/ex03/ZombieHorde.cpp | 12 | ||||
| -rw-r--r-- | cpp01/ex03/ZombieHorde.hpp | 7 | ||||
| -rw-r--r-- | cpp01/ex03/main.cpp | 30 | ||||
| -rw-r--r-- | cpp01/ex04/ex04.cpp | 4 | ||||
| -rw-r--r-- | cpp01/ex05/Human.cpp | 11 | ||||
| -rw-r--r-- | cpp01/ex05/Human.hpp | 6 | ||||
| -rw-r--r-- | cpp01/ex05/main.cpp | 6 | ||||
| -rw-r--r-- | cpp01/ex06/HumanA.cpp | 7 | ||||
| -rw-r--r-- | cpp01/ex06/HumanA.hpp | 6 | ||||
| -rw-r--r-- | cpp01/ex06/HumanB.cpp | 12 | ||||
| -rw-r--r-- | cpp01/ex06/HumanB.hpp | 6 | ||||
| -rw-r--r-- | cpp01/ex06/Weapon.cpp | 11 | ||||
| -rw-r--r-- | cpp01/ex06/Weapon.hpp | 8 | ||||
| -rw-r--r-- | cpp01/ex06/main.cpp | 2 | ||||
| -rw-r--r-- | cpp01/ex07/Makefile | 4 | ||||
| -rw-r--r-- | cpp01/ex07/main.cpp | 13 |
27 files changed, 161 insertions, 96 deletions
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 */ +/* Updated: 2020/11/09 10:59:22 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,6 @@ int main() std::string& ref_s = s; std::cout << *ptr_s << std::endl; - std::cout << ref_s << std::endl; + std::cout << ref_s << std::endl; return 0; } diff --git a/cpp01/ex05/Human.cpp b/cpp01/ex05/Human.cpp index f4c0066..e7f55bd 100644 --- a/cpp01/ex05/Human.cpp +++ b/cpp01/ex05/Human.cpp @@ -6,23 +6,20 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 12:52:38 by cacharle #+# #+# */ -/* Updated: 2020/04/13 10:09:03 by charles ### ########.fr */ +/* Updated: 2020/11/09 11:04:09 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "Human.hpp" -Human::Human() - : m_brain() -{ -} +Human::Human() : m_brain() {} -std::string Human::identify() +std::string Human::identify() const { return m_brain.identify(); } -const Brain& Human::getBrain() +const Brain& Human::getBrain() const { return m_brain; } diff --git a/cpp01/ex05/Human.hpp b/cpp01/ex05/Human.hpp index d7a4611..fc89d03 100644 --- a/cpp01/ex05/Human.hpp +++ b/cpp01/ex05/Human.hpp @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 12:52:39 by cacharle #+# #+# */ -/* Updated: 2020/04/13 10:08:07 by charles ### ########.fr */ +/* Updated: 2020/11/09 11:03:44 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,8 @@ class Human { public: Human(); - std::string identify(); - const Brain& getBrain() ; + std::string identify() const; + const Brain& getBrain() const; private: const Brain m_brain; diff --git a/cpp01/ex05/main.cpp b/cpp01/ex05/main.cpp index 584320a..8ad1493 100644 --- a/cpp01/ex05/main.cpp +++ b/cpp01/ex05/main.cpp @@ -6,12 +6,12 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 12:57:25 by cacharle #+# #+# */ -/* Updated: 2020/02/02 16:27:47 by cacharle ### ########.fr */ +/* Updated: 2020/11/09 10:59:52 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ -# include "Brain.hpp" -# include "Human.hpp" +#include "Brain.hpp" +#include "Human.hpp" int main() { diff --git a/cpp01/ex06/HumanA.cpp b/cpp01/ex06/HumanA.cpp index 7e52494..ab4e5f3 100644 --- a/cpp01/ex06/HumanA.cpp +++ b/cpp01/ex06/HumanA.cpp @@ -6,16 +6,15 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 16:44:03 by cacharle #+# #+# */ -/* Updated: 2020/04/13 10:26:03 by charles ### ########.fr */ +/* Updated: 2020/11/09 11:09:22 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "HumanA.hpp" -HumanA::HumanA(std::string name, Weapon& weapon) +HumanA::HumanA(std::string const& name, Weapon& weapon) : m_name(name), m_weapon(weapon) -{ -} +{} void HumanA::attack() { diff --git a/cpp01/ex06/HumanA.hpp b/cpp01/ex06/HumanA.hpp index f1691b3..d05d2fd 100644 --- a/cpp01/ex06/HumanA.hpp +++ b/cpp01/ex06/HumanA.hpp @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 16:37:23 by cacharle #+# #+# */ -/* Updated: 2020/04/13 10:24:13 by charles ### ########.fr */ +/* Updated: 2020/11/09 11:08:55 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,11 +19,11 @@ class HumanA { public: - HumanA(std::string name, Weapon& weapon); + HumanA(std::string const& name, Weapon& weapon); void attack(); private: std::string m_name; - Weapon& m_weapon; + Weapon& m_weapon; }; #endif diff --git a/cpp01/ex06/HumanB.cpp b/cpp01/ex06/HumanB.cpp index 98774aa..e6adb22 100644 --- a/cpp01/ex06/HumanB.cpp +++ b/cpp01/ex06/HumanB.cpp @@ -6,20 +6,22 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 16:46:02 by cacharle #+# #+# */ -/* Updated: 2020/04/13 10:25:54 by charles ### ########.fr */ +/* Updated: 2020/11/09 11:13:34 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "HumanB.hpp" -HumanB::HumanB(std::string name) +HumanB::HumanB(std::string const& name) : m_name(name), m_weapon(NULL) -{ -} +{} void HumanB::attack() { - std::cout << m_name << " attack with his " << m_weapon->getType() << std::endl; + if (m_weapon == NULL) + std::cout << m_name << " doesn't have any weapon " << std::endl; + else + std::cout << m_name << " attack with his " << m_weapon->getType() << std::endl; } void HumanB::setWeapon(Weapon& weapon) diff --git a/cpp01/ex06/HumanB.hpp b/cpp01/ex06/HumanB.hpp index 269f4fc..fc9236c 100644 --- a/cpp01/ex06/HumanB.hpp +++ b/cpp01/ex06/HumanB.hpp @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 16:42:54 by cacharle #+# #+# */ -/* Updated: 2020/04/13 10:23:31 by charles ### ########.fr */ +/* Updated: 2020/11/09 11:09:56 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,12 +19,12 @@ class HumanB { public: - HumanB(std::string name); + HumanB(std::string const& name); void attack(); void setWeapon(Weapon& weapon); private: std::string m_name; - Weapon* m_weapon; + Weapon* m_weapon; }; #endif diff --git a/cpp01/ex06/Weapon.cpp b/cpp01/ex06/Weapon.cpp index e517947..88b4357 100644 --- a/cpp01/ex06/Weapon.cpp +++ b/cpp01/ex06/Weapon.cpp @@ -6,23 +6,20 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 16:36:23 by cacharle #+# #+# */ -/* Updated: 2020/04/13 10:25:35 by charles ### ########.fr */ +/* Updated: 2020/11/09 11:08:23 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "Weapon.hpp" -Weapon::Weapon(std::string t) - : type(t) -{ -} +Weapon::Weapon(std::string t) : type(t) {} -const std::string& Weapon::getType() const +std::string const& Weapon::getType() const { return type; } -void Weapon::setType(const std::string& t) +void Weapon::setType(std::string const& t) { type = t; } diff --git a/cpp01/ex06/Weapon.hpp b/cpp01/ex06/Weapon.hpp index d9ad476..08fef0c 100644 --- a/cpp01/ex06/Weapon.hpp +++ b/cpp01/ex06/Weapon.hpp @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 16:34:31 by cacharle #+# #+# */ -/* Updated: 2020/04/13 10:16:46 by charles ### ########.fr */ +/* Updated: 2020/11/09 11:08:36 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,11 +19,11 @@ class Weapon { public: Weapon(std::string t); - const std::string& getType() const; - void setType(const std::string& t); + std::string const& getType() const; + void setType(std::string const& t); private: - std::string type; // subject want litteraly `type` + std::string type; // subject wants litteraly `type` }; #endif diff --git a/cpp01/ex06/main.cpp b/cpp01/ex06/main.cpp index dfc03a0..5c92b43 100644 --- a/cpp01/ex06/main.cpp +++ b/cpp01/ex06/main.cpp @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/02 16:40:20 by cacharle #+# #+# */ -/* Updated: 2020/02/02 16:40:51 by cacharle ### ########.fr */ +/* Updated: 2020/11/09 11:13:54 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/cpp01/ex07/Makefile b/cpp01/ex07/Makefile index 1617d62..15c5518 100644 --- a/cpp01/ex07/Makefile +++ b/ |
