aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp01/ex00/Pony.cpp19
-rw-r--r--cpp01/ex00/Pony.hpp26
-rw-r--r--cpp01/ex00/main.cpp16
-rw-r--r--cpp01/ex01/ex01.cpp12
-rw-r--r--cpp01/ex02/Zombie.cpp19
-rw-r--r--cpp01/ex02/Zombie.hpp26
-rw-r--r--cpp01/ex02/ZombieEvent.cpp25
-rw-r--r--cpp01/ex02/ZombieEvent.hpp29
-rw-r--r--cpp01/ex02/main.cpp16
-rw-r--r--cpp01/ex03/Zombie.cpp19
-rw-r--r--cpp01/ex03/Zombie.hpp26
-rw-r--r--cpp01/ex03/ZombieHorde.cpp33
-rw-r--r--cpp01/ex03/ZombieHorde.hpp28
-rw-r--r--cpp01/ex03/main.cpp19
-rw-r--r--cpp01/ex04/ex04.cpp8
-rw-r--r--cpp01/ex05/Brain.hpp4
-rw-r--r--cpp01/ex05/Human.cpp11
-rw-r--r--cpp01/ex05/Human.hpp13
-rw-r--r--cpp01/ex06/HumanA.cpp9
-rw-r--r--cpp01/ex06/HumanA.hpp14
-rw-r--r--cpp01/ex06/HumanB.cpp10
-rw-r--r--cpp01/ex06/HumanB.hpp16
-rw-r--r--cpp01/ex06/Weapon.cpp14
-rw-r--r--cpp01/ex06/Weapon.hpp14
-rw-r--r--cpp01/ex07/Makefile4
-rw-r--r--cpp01/ex07/main.cpp19
26 files changed, 311 insertions, 138 deletions
diff --git a/cpp01/ex00/Pony.cpp b/cpp01/ex00/Pony.cpp
index 61f3b47..b45f0e1 100644
--- a/cpp01/ex00/Pony.cpp
+++ b/cpp01/ex00/Pony.cpp
@@ -6,27 +6,28 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:06:06 by charles #+# #+# */
-/* Updated: 2020/04/13 09:06:11 by charles ### ########.fr */
+/* Updated: 2020/04/13 09:33:59 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include "Pony.hpp"
-Pony::Pony(int w, int s)
+Pony::Pony(int weight, int maxSpeed)
+ : m_weight(weight), m_maxSpeed(maxSpeed)
{
- weight = w;
- max_speed = s;
}
-void Pony::say_hello()
+void Pony::sayHello()
{
- std::cout << "Hi, I'm a pony, I weight " << weight
- << " and my speed limit is " << max_speed << std::endl;
+ std::cout << "Hi, I'm a pony, I weight " << m_weight
+ << " and my speed limit is " << m_maxSpeed
+ << std::endl;
}
void Pony::run()
{
- for (int i = 0; i < max_speed; i++)
- std::cout << "I'm running really fast at " << i << ", look at me!" << std::endl;
+ 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;
}
diff --git a/cpp01/ex00/Pony.hpp b/cpp01/ex00/Pony.hpp
index 31a69f4..571414c 100644
--- a/cpp01/ex00/Pony.hpp
+++ b/cpp01/ex00/Pony.hpp
@@ -1,15 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Pony.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#ifndef PONY_HPP
# define PONY_HPP
class Pony
{
- public:
- Pony(int w, int s);
- void say_hello();
- void run();
- private:
- int weight;
- int max_speed;
+public:
+ Pony(int weight, int maxSpeed);
+ void sayHello();
+ void run();
+private:
+ int m_weight;
+ int m_maxSpeed;
};
#endif
diff --git a/cpp01/ex00/main.cpp b/cpp01/ex00/main.cpp
index c8aa0b8..689f7f1 100644
--- a/cpp01/ex00/main.cpp
+++ b/cpp01/ex00/main.cpp
@@ -1,10 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#include <iostream>
#include "Pony.hpp"
void ponyOnTheHeap()
{
Pony *p = new Pony(200, 100);
- p->say_hello();
+ p->sayHello();
p->run();
delete p;
}
@@ -12,7 +24,7 @@ void ponyOnTheHeap()
void ponyOnTheStack()
{
Pony p(200, 100);
- p.say_hello();
+ p.sayHello();
p.run();
}
diff --git a/cpp01/ex01/ex01.cpp b/cpp01/ex01/ex01.cpp
index c08e1d2..c3f416f 100644
--- a/cpp01/ex01/ex01.cpp
+++ b/cpp01/ex01/ex01.cpp
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ex01.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#include <iostream>
void memoryLeak()
diff --git a/cpp01/ex02/Zombie.cpp b/cpp01/ex02/Zombie.cpp
index 2ea23b6..40fb849 100644
--- a/cpp01/ex02/Zombie.cpp
+++ b/cpp01/ex02/Zombie.cpp
@@ -1,14 +1,25 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Zombie.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#include <iostream>
#include "Zombie.hpp"
-Zombie::Zombie(std::string n, std::string t)
+Zombie::Zombie(std::string name, std::string type)
+ : m_name(name), m_type(type)
{
- name = n;
- type = t;
announce();
}
void Zombie::announce()
{
- std::cout << "<" << name << " (" << type << ")> Braiiiiiiinnnssss..." << std::endl;
+ std::cout << "<" << m_name << " (" << m_type << ")> Braiiiiiiinnnssss..." << std::endl;
}
diff --git a/cpp01/ex02/Zombie.hpp b/cpp01/ex02/Zombie.hpp
index 980ea49..5106c8f 100644
--- a/cpp01/ex02/Zombie.hpp
+++ b/cpp01/ex02/Zombie.hpp
@@ -1,17 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Zombie.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
-#include <string>
+# include <string>
class Zombie
{
- public:
- Zombie(std::string n, std::string t);
- void announce();
+public:
+ Zombie(std::string name, std::string type);
+ void announce();
- private:
- std::string name;
- std::string type;
+private:
+ std::string m_name;
+ std::string m_type;
};
#endif
diff --git a/cpp01/ex02/ZombieEvent.cpp b/cpp01/ex02/ZombieEvent.cpp
index 6775138..acb8dd0 100644
--- a/cpp01/ex02/ZombieEvent.cpp
+++ b/cpp01/ex02/ZombieEvent.cpp
@@ -1,17 +1,28 @@
-#include <cstdlib>
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ZombieEvent.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#include "ZombieEvent.hpp"
-void ZombieEvent::setZombieType(std::string type)
+void ZombieEvent::setZombieType(std::string storedType)
{
- stored_type = type;
+ m_storedType = storedType;
}
-Zombie *ZombieEvent::newZombie(std::string name)
+Zombie* ZombieEvent::newZombie(std::string name)
{
- return new Zombie(name, stored_type);
+ return new Zombie(name, m_storedType);
}
-Zombie *ZombieEvent::randomChump()
+Zombie* ZombieEvent::randomChump()
{
std::string pool[10] = {
"Jordan",
@@ -25,5 +36,5 @@ Zombie *ZombieEvent::randomChump()
"yo",
"rideaux"
};
- return new Zombie(pool[rand() % 10], stored_type);
+ return new Zombie(pool[rand() % 10], m_storedType);
}
diff --git a/cpp01/ex02/ZombieEvent.hpp b/cpp01/ex02/ZombieEvent.hpp
index 869207e..7b2fe79 100644
--- a/cpp01/ex02/ZombieEvent.hpp
+++ b/cpp01/ex02/ZombieEvent.hpp
@@ -1,18 +1,31 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ZombieEvent.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#ifndef ZOMBIE_EVENT_HPP
# define ZOMBIE_EVENT_HPP
-#include <string>
-#include "Zombie.hpp"
+# include <string>
+# include <cstdlib>
+# include "Zombie.hpp"
class ZombieEvent
{
- public:
- void setZombieType(std::string type);
- Zombie *newZombie(std::string name);
- Zombie *randomChump();
+public:
+ void setZombieType(std::string type);
+ Zombie* newZombie(std::string name);
+ Zombie* randomChump();
- private:
- std::string stored_type;
+private:
+ std::string m_storedType;
};
#endif
diff --git a/cpp01/ex02/main.cpp b/cpp01/ex02/main.cpp
index 1df20d2..291fddb 100644
--- a/cpp01/ex02/main.cpp
+++ b/cpp01/ex02/main.cpp
@@ -1,11 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#include <cstdlib>
#include "Zombie.hpp"
#include "ZombieEvent.hpp"
int main()
{
- Zombie *z;
+ Zombie* z;
ZombieEvent zevent;
+ Zombie zStack("onTheStack", "IdontLikeHeap");
srand(time(NULL));
zevent.setZombieType("standard");
@@ -16,5 +29,6 @@ int main()
z = zevent.randomChump();
delete z;
}
+
return 0;
}
diff --git a/cpp01/ex03/Zombie.cpp b/cpp01/ex03/Zombie.cpp
index 2ea23b6..40fb849 100644
--- a/cpp01/ex03/Zombie.cpp
+++ b/cpp01/ex03/Zombie.cpp
@@ -1,14 +1,25 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Zombie.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#include <iostream>
#include "Zombie.hpp"
-Zombie::Zombie(std::string n, std::string t)
+Zombie::Zombie(std::string name, std::string type)
+ : m_name(name), m_type(type)
{
- name = n;
- type = t;
announce();
}
void Zombie::announce()
{
- std::cout << "<" << name << " (" << type << ")> Braiiiiiiinnnssss..." << std::endl;
+ std::cout << "<" << m_name << " (" << m_type << ")> Braiiiiiiinnnssss..." << std::endl;
}
diff --git a/cpp01/ex03/Zombie.hpp b/cpp01/ex03/Zombie.hpp
index 980ea49..5106c8f 100644
--- a/cpp01/ex03/Zombie.hpp
+++ b/cpp01/ex03/Zombie.hpp
@@ -1,17 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Zombie.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
-#include <string>
+# include <string>
class Zombie
{
- public:
- Zombie(std::string n, std::string t);
- void announce();
+public:
+ Zombie(std::string name, std::string type);
+ void announce();
- private:
- std::string name;
- std::string type;
+private:
+ std::string m_name;
+ std::string m_type;
};
#endif
diff --git a/cpp01/ex03/ZombieHorde.cpp b/cpp01/ex03/ZombieHorde.cpp
index e8218b4..955355b 100644
--- a/cpp01/ex03/ZombieHorde.cpp
+++ b/cpp01/ex03/ZombieHorde.cpp
@@ -1,7 +1,19 @@
-#include <cstdlib>
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ZombieHorde.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#include "ZombieHorde.hpp"
-ZombieHorde::ZombieHorde(int size)
+ZombieHorde::ZombieHorde(int n)
+ : m_size(n)
{
std::string name_pool[10] = {
"Jordan",
@@ -21,21 +33,20 @@ ZombieHorde::ZombieHorde(int size)
"earth",
"wind"
};
- horde = new Zombie*[size];
- horde_size = size;
- for (int i = 0; i < size; i++)
- horde[i] = new Zombie(name_pool[rand() % 10], type_pool[rand() % 4]);
+ 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]);
}
ZombieHorde::~ZombieHorde()
{
- for (int i = 0; i < horde_size; i++)
- delete horde[i];
- delete [] horde;
+ for (size_t i = 0; i < m_size; i++)
+ delete m_horde[i];
+ delete [] m_horde;
}
void ZombieHorde::announce()
{
- for (int i = 0; i < horde_size; i++)
- horde[i]->announce();
+ 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 772bcc0..991c2ec 100644
--- a/cpp01/ex03/ZombieHorde.hpp
+++ b/cpp01/ex03/ZombieHorde.hpp
@@ -1,18 +1,32 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ZombieHorde.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#ifndef ZOMBIE_HORDE_HPP
# define ZOMBIE_HORDE_HPP
+# include <cstdlib>
+# include <string>
# include "Zombie.hpp"
class ZombieHorde
{
- public:
- ZombieHorde(int size);
- void announce();
- ~ZombieHorde();
+public:
+ ZombieHorde(int n);
+ ~ZombieHorde();
+ void announce();
- private:
- int horde_size;
- Zombie **horde;
+private:
+ size_t m_size;
+ Zombie** m_horde;
};
#endif
diff --git a/cpp01/ex03/main.cpp b/cpp01/ex03/main.cpp
index 896b05e..20db57c 100644
--- a/cpp01/ex03/main.cpp
+++ b/cpp01/ex03/main.cpp
@@ -1,4 +1,17 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* 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 */
+/* */
+/* ************************************************************************** */
+
#include <cstdlib>
+#include <iostream>
#include "Zombie.hpp"
#include "ZombieHorde.hpp"
@@ -6,10 +19,12 @@ int main()
{
srand(time(NULL));
- ZombieHorde horde = ZombieHorde(10);
+ std::cout << "Stack horde" << std::endl;
+ ZombieHorde horde(5);
horde.announce();
- ZombieHorde *heap_horde = new ZombieHorde(10);
+ std::cout << std::endl << "Heap horde" << std::endl;
+ ZombieHorde *heap_horde = new ZombieHorde(7);
heap_horde->announce();
delete heap_horde;
}
diff --git a/cpp01/ex04/ex04.cpp b/cpp01/ex04/ex04.cpp
index 9c34b51..7eed286 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/02/02 12:43:06 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:01:19 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,10 +16,10 @@
int main()
{
std::string s = "HI THIS IS BRAIN";
- std::string &ref_s = s;
- std::string *ptr_s = &s;
+ std::string* ptr_s = &s;
+ std::string& ref_s = s;
- std::cout << ref_s << std::endl;
std::cout << *ptr_s << std::endl;
+ std::cout << ref_s << std::endl;
return 0;
}
diff --git a/cpp01/ex05/Brain.hpp b/cpp01/ex05/Brain.hpp
index 6c1f28b..81b5a07 100644
--- a/cpp01/ex05/Brain.hpp
+++ b/cpp01/ex05/Brain.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 12:47:22 by cacharle #+# #+# */
-/* Updated: 2020/02/02 16:28:27 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:04:01 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,7 +19,7 @@
class Brain
{
- public:
+public:
std::string identify() const;
};
diff --git a/cpp01/ex05/Human.cpp b/cpp01/ex05/Human.cpp
index 4db0568..f4c0066 100644
--- a/cpp01/ex05/Human.cpp
+++ b/cpp01/ex05/Human.cpp
@@ -6,18 +6,23 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 12:52:38 by cacharle #+# #+# */
-/* Updated: 2020/02/02 13:08:39 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:09:03 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "Human.hpp"
+Human::Human()
+ : m_brain()
+{
+}
+
std::string Human::identify()
{
- return brain.identify();
+ return m_brain.identify();
}
const Brain& Human::getBrain()
{
- return brain;
+ return m_brain;
}
diff --git a/cpp01/ex05/Human.hpp b/cpp01/ex05/Human.hpp
index 6c38ee0..d7a4611 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/02/02 13:08:46 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:08:07 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,12 +17,13 @@
class Human
{
- private:
- const Brain brain;
+public:
+ Human();
+ std::string identify();
+ const Brain& getBrain() ;
- public:
- std::string identify();
- const Brain& getBrain() ;
+private:
+ const Brain m_brain;
};
#endif
diff --git a/cpp01/ex06/HumanA.cpp b/cpp01/ex06/HumanA.cpp
index 8d9b449..7e52494 100644
--- a/cpp01/ex06/HumanA.cpp
+++ b/cpp01/ex06/HumanA.cpp
@@ -6,19 +6,18 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:44:03 by cacharle #+# #+# */
-/* Updated: 2020/02/02 16:54:07 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:26:03 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanA.hpp"
-HumanA::HumanA(std::string name, Weapon weapon)
+HumanA::HumanA(std::string name, Weapon& weapon)
+ : m_name(name), m_weapon(weapon)
{
- this->name = name;
- this->weapon = weapon;
}
void HumanA::attack()
{
- std::cout << name << " attack with his " << weapon.getType();
+ std::cout << m_name << " attack with his " << m_weapon.getType() << std::endl;
}
diff --git a/cpp01/ex06/HumanA.hpp b/cpp01/ex06/HumanA.hpp
index 1c3ccf9..f1691b3 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/02/02 16:54:48 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:24:13 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,12 +18,12 @@
class HumanA
{
- private:
- std::string name;
- Weapon weapon;
- public:
- HumanA(std::string(name), Weapon(weapon));
- void attack();
+public:
+ HumanA(std::string name, Weapon& weapon);
+ void attack();
+private:
+ std::string m_name;
+ Weapon& m_weapon;
};
#endif
diff --git a/cpp01/ex06/HumanB.cpp b/cpp01/ex06/HumanB.cpp
index e08363c..98774aa 100644
--- a/cpp01/ex06/HumanB.cpp
+++ b/cpp01/ex06/HumanB.cpp
@@ -6,23 +6,23 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:46:02 by cacharle #+# #+# */
-/* Updated: 2020/02/02 16:54:33 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:25:54 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanB.hpp"
HumanB::HumanB(std::string name)
+ : m_name(name), m_weapon(NULL)
{
- this->name = name;
}
void HumanB::attack()
{
- std::cout << name << " attack with his " << weapon.getType();
+ std::cout << m_name << " attack with his " << m_weapon->getType() << std::endl;
}
-void HumanB::setWeapon(Weapon weapon)
+void HumanB::setWeapon(Weapon& weapon)
{
- this->weapon = weapon;
+ m_weapon = &weapon;
}
diff --git a/cpp01/ex06/HumanB.hpp b/cpp01/ex06/HumanB.hpp
index a01c881..269f4fc 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/02/02 16:54:18 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:23:31 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,13 +18,13 @@
class HumanB
{
- private:
- std::string name;
- Weapon weapon;
- public:
- HumanB(std::string name);
- void attack();
- void setWeapon(Weapon weapon);
+public:
+ HumanB(std::string name);
+ void attack();
+ void setWeapon(Weapon& weapon);
+private:
+ std::string m_name;
+ Weapon* m_weapon;
};
#endif
diff --git a/cpp01/ex06/Weapon.cpp b/cpp01/ex06/Weapon.cpp
index 86738a8..e517947 100644
--- a/cpp01/ex06/Weapon.cpp
+++ b/cpp01/ex06/Weapon.cpp
@@ -6,23 +6,23 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:36:23 by cacharle #+# #+# */
-/* Updated: 2020/02/02 16:56:48 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:25:35 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon.hpp"
-Weapon::Weapon(std::string type)
+Weapon::Weapon(std::string t)
+ : type(t)
{
- this->type = type;
}
-const std::string& Weapon::getType()
+const std::string& Weapon::getType() const
{
- return &type;
+ return type;
}
-void Weapon::setType(const std::string& type)
+void Weapon::setType(const std::string& t)
{
- this->type = type;
+ type = t;
}
diff --git a/cpp01/ex06/Weapon.hpp b/cpp01/ex06/Weapon.hpp
index ea9b738..d9ad476 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/02/02 16:56:40 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:16:46 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,13 +17,13 @@
class Weapon
{
- private:
- std::string type;
+public:
+ Weapon(std::string t);
+ const std::string& getType() const;
+ void setType(const std::string& t);
- public:
- Weapon(std::string type);
- const std::string& getType();
- void setType(const std::string& type);
+private:
+ std::string type; // subject want litteraly `type`
};
#endif
diff --git a/cpp01/ex07/Makefile b/cpp01/ex07/Makefile
index 7a649fc..1617d62 100644
--- a/cpp01/ex07/Makefile
+++ b/cpp01/ex07/Makefile
@@ -6,12 +6,12 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/02/02 17:05:31 by cacharle #+# #+# #
-# Updated: 2020/02/02 17:58:08 by cacharle ### ########.fr #
+# Updated: 2020/04/13 10:32:03 by charles ### ########.fr #
# #
# **************************************************************************** #
CXX = clang++
-CXXFLAGS= -Wall -Wextra #-Werror
+CXXFLAGS= -Wall -Wextra -Werror
SRC = $(shell find . -type f -name "*.cpp")
OBJ = $(SRC:.cpp=.o)
diff --git a/cpp01/ex07/main.cpp b/cpp01/ex07/main.cpp
index fbef95f..64e5ce8 100644
--- a/cpp01/ex07/main.cpp
+++ b/cpp01/ex07/main.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 17:08:28 by cacharle #+# #+# */
-/* Updated: 2020/02/02 18:00:25 by cacharle ### ########.fr */
+/* Updated: 2020/04/13 10:31:55 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,12 +18,17 @@ int main(int argc, char **argv)
{
if (argc != 4)
{
- std::cerr << "Usage: " << argv[0] << " filename s1 s2";
+ std::cerr << "Usage: " << argv[0] << " filename s1 s2" << std::endl;
return 1;
}
std::string filename(argv[1]);
- std::string find_str(argv[2]);
- std::string replace_str(argv[3]);
+ std::string s1(argv[2]);
+ std::string s2(argv[3]);
+ if (s1 == "" || s2 == "")
+ {
+ std::cerr << "Error: s1 and s2 should not be empty" << std::endl;
+ return 1;
+ }
std::ifstream file(filename);
std::ofstream outfile(filename + ".replace");
@@ -39,18 +44,20 @@ int main(int argc, char **argv)
file.close();
return 1;
}
+
std::string line;
while (std::getline(file, line))
{
while (true)
{
- size_t i = line.find(find_str);
+ size_t i = line.find(s1);
if (i == std::string::npos)
break;
- line.replace(i, find_str.length(), replace_str);
+ line.replace(i, s1.length(), s2);
}
outfile << line << std::endl;
}
file.close();
outfile.close();
+ return 0;
}