From a5a197590e45494dc31f0d2fc8fb13194b3975c9 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 2 Feb 2020 18:05:01 +0100 Subject: cpp01 ex05 wip, ex06 --- cpp01/ex06/HumanA.cpp | 24 ++++++++++++++++++++++++ cpp01/ex06/HumanA.hpp | 29 +++++++++++++++++++++++++++++ cpp01/ex06/HumanB.cpp | 28 ++++++++++++++++++++++++++++ cpp01/ex06/HumanB.hpp | 30 ++++++++++++++++++++++++++++++ cpp01/ex06/Weapon.cpp | 28 ++++++++++++++++++++++++++++ cpp01/ex06/Weapon.hpp | 29 +++++++++++++++++++++++++++++ cpp01/ex06/main.cpp | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 202 insertions(+) create mode 100644 cpp01/ex06/HumanA.cpp create mode 100644 cpp01/ex06/HumanA.hpp create mode 100644 cpp01/ex06/HumanB.cpp create mode 100644 cpp01/ex06/HumanB.hpp create mode 100644 cpp01/ex06/Weapon.cpp create mode 100644 cpp01/ex06/Weapon.hpp create mode 100644 cpp01/ex06/main.cpp (limited to 'cpp01/ex06') 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +# 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +# 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +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 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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(); + } +} -- cgit