aboutsummaryrefslogtreecommitdiff
path: root/cpp01/ex06
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-02 18:05:01 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-02 18:05:01 +0100
commita5a197590e45494dc31f0d2fc8fb13194b3975c9 (patch)
treef3350feda6ac6549a2b5fc4b45d9ca19f86345d0 /cpp01/ex06
parent7d6a4c877de8048ec5fbea4a563b3d09c8976105 (diff)
downloadpiscine_cpp-a5a197590e45494dc31f0d2fc8fb13194b3975c9.tar.gz
piscine_cpp-a5a197590e45494dc31f0d2fc8fb13194b3975c9.tar.bz2
piscine_cpp-a5a197590e45494dc31f0d2fc8fb13194b3975c9.zip
cpp01 ex05 wip, ex06
Diffstat (limited to 'cpp01/ex06')
-rw-r--r--cpp01/ex06/HumanA.cpp24
-rw-r--r--cpp01/ex06/HumanA.hpp29
-rw-r--r--cpp01/ex06/HumanB.cpp28
-rw-r--r--cpp01/ex06/HumanB.hpp30
-rw-r--r--cpp01/ex06/Weapon.cpp28
-rw-r--r--cpp01/ex06/Weapon.hpp29
-rw-r--r--cpp01/ex06/main.cpp34
7 files changed, 202 insertions, 0 deletions
diff --git a/cpp01/ex06/HumanA.cpp b/cpp01/ex06/HumanA.cpp
new file mode 100644
index 0000000..8d9b449
--- /dev/null
+++ b/cpp01/ex06/HumanA.cpp
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* HumanA.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:44:03 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:54:07 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "HumanA.hpp"
+
+HumanA::HumanA(std::string name, Weapon weapon)
+{
+ this->name = name;
+ this->weapon = weapon;
+}
+
+void HumanA::attack()
+{
+ std::cout << name << " attack with his " << weapon.getType();
+}
diff --git a/cpp01/ex06/HumanA.hpp b/cpp01/ex06/HumanA.hpp
new file mode 100644
index 0000000..1c3ccf9
--- /dev/null
+++ b/cpp01/ex06/HumanA.hpp
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* HumanA.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:37:23 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:54:48 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef HUMANA_HPP
+# define HUMANA_HPP
+
+# include <iostream>
+# include "Weapon.hpp"
+
+class HumanA
+{
+ private:
+ std::string name;
+ Weapon weapon;
+ public:
+ HumanA(std::string(name), Weapon(weapon));
+ void attack();
+};
+
+#endif
diff --git a/cpp01/ex06/HumanB.cpp b/cpp01/ex06/HumanB.cpp
new file mode 100644
index 0000000..e08363c
--- /dev/null
+++ b/cpp01/ex06/HumanB.cpp
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* HumanB.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:46:02 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:54:33 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "HumanB.hpp"
+
+HumanB::HumanB(std::string name)
+{
+ this->name = name;
+}
+
+void HumanB::attack()
+{
+ std::cout << name << " attack with his " << weapon.getType();
+}
+
+void HumanB::setWeapon(Weapon weapon)
+{
+ this->weapon = weapon;
+}
diff --git a/cpp01/ex06/HumanB.hpp b/cpp01/ex06/HumanB.hpp
new file mode 100644
index 0000000..a01c881
--- /dev/null
+++ b/cpp01/ex06/HumanB.hpp
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* HumanB.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:42:54 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:54:18 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef HUMANB_HPP
+# define HUMANB_HPP
+
+# include <iostream>
+# include "Weapon.hpp"
+
+class HumanB
+{
+ private:
+ std::string name;
+ Weapon weapon;
+ public:
+ HumanB(std::string name);
+ void attack();
+ void setWeapon(Weapon weapon);
+};
+
+#endif
diff --git a/cpp01/ex06/Weapon.cpp b/cpp01/ex06/Weapon.cpp
new file mode 100644
index 0000000..86738a8
--- /dev/null
+++ b/cpp01/ex06/Weapon.cpp
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Weapon.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:36:23 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:56:48 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Weapon.hpp"
+
+Weapon::Weapon(std::string type)
+{
+ this->type = type;
+}
+
+const std::string& Weapon::getType()
+{
+ return &type;
+}
+
+void Weapon::setType(const std::string& type)
+{
+ this->type = type;
+}
diff --git a/cpp01/ex06/Weapon.hpp b/cpp01/ex06/Weapon.hpp
new file mode 100644
index 0000000..ea9b738
--- /dev/null
+++ b/cpp01/ex06/Weapon.hpp
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Weapon.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:34:31 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:56:40 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef WEAPON_HPP
+# define WEAPON_HPP
+
+# include <string>
+
+class Weapon
+{
+ private:
+ std::string type;
+
+ public:
+ Weapon(std::string type);
+ const std::string& getType();
+ void setType(const std::string& type);
+};
+
+#endif
diff --git a/cpp01/ex06/main.cpp b/cpp01/ex06/main.cpp
new file mode 100644
index 0000000..dfc03a0
--- /dev/null
+++ b/cpp01/ex06/main.cpp
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:40:20 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:40:51 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Weapon.hpp"
+#include "HumanA.hpp"
+#include "HumanB.hpp"
+
+int main()
+{
+ {
+ Weapon club = Weapon("crude spiked club");
+ HumanA bob("Bob", club);
+ bob.attack();
+ club.setType("some other type of club");
+ bob.attack();
+ }
+ {
+ Weapon club = Weapon("crude spiked club");
+ HumanB jim("Jim");
+ jim.setWeapon(club);
+ jim.attack();
+ club.setType("some other type of club");
+ jim.attack();
+ }
+}