From 87e67b4e790d5bf3a071184b9820e10c088afcc0 Mon Sep 17 00:00:00 2001 From: kinou-p Date: Thu, 16 Jun 2022 23:45:33 +0200 Subject: [PATCH] cpp01 ex03 --- cpp01/ex03/HumanA.cpp | 19 ++++++++++++++++++- cpp01/ex03/HumanA.hpp | 16 ++++++++++++---- cpp01/ex03/HumanB.cpp | 31 ++++++++++++++++++++++++++++++- cpp01/ex03/HumanB.hpp | 18 ++++++++++++++---- cpp01/ex03/Makefile | 36 ++++++++++++++++++++++++++++++++++++ cpp01/ex03/Weapon.cpp | 9 +++++---- cpp01/ex03/Weapon.hpp | 19 ++++++++++++++----- cpp01/ex03/main.cpp | 5 ++++- 8 files changed, 133 insertions(+), 20 deletions(-) diff --git a/cpp01/ex03/HumanA.cpp b/cpp01/ex03/HumanA.cpp index b5c87af..644cb1a 100644 --- a/cpp01/ex03/HumanA.cpp +++ b/cpp01/ex03/HumanA.cpp @@ -6,7 +6,24 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 21:20:34 by apommier #+# #+# */ -/* Updated: 2022/06/10 21:23:56 by apommier ### ########.fr */ +/* Updated: 2022/06/16 23:41:51 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ +#include "HumanA.hpp" + +HumanA::HumanA(const std::string name, Weapon Weapon) +{ + this->_name = name; + this->_Weapon = &Weapon.getType(); +} + +HumanA::~HumanA(void) +{ + +} + +void HumanA::attack(void) +{ + std::cout << this->_name << " attacks with their " << this->_Weapon << std::endl; +} \ No newline at end of file diff --git a/cpp01/ex03/HumanA.hpp b/cpp01/ex03/HumanA.hpp index 356a1c9..b6e4b63 100644 --- a/cpp01/ex03/HumanA.hpp +++ b/cpp01/ex03/HumanA.hpp @@ -6,21 +6,29 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 21:20:32 by apommier #+# #+# */ -/* Updated: 2022/06/10 23:01:02 by apommier ### ########.fr */ +/* Updated: 2022/06/16 23:39:42 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ +#ifndef HUMANA_HPP +# define HUMANA_HPP + +#include "Weapon.hpp" + + class HumanA { public: - HumanA(void); + HumanA(const std::string name, Weapon Weapon); ~HumanA(void); + void attack(void); private: - void attack(void) const; std::string _name; std::string *_Weapon; -}; \ No newline at end of file +}; + +#endif \ No newline at end of file diff --git a/cpp01/ex03/HumanB.cpp b/cpp01/ex03/HumanB.cpp index 0b73f02..7ada8eb 100644 --- a/cpp01/ex03/HumanB.cpp +++ b/cpp01/ex03/HumanB.cpp @@ -6,7 +6,36 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 21:25:58 by apommier #+# #+# */ -/* Updated: 2022/06/10 21:25:59 by apommier ### ########.fr */ +/* Updated: 2022/06/16 23:42:41 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ +#include "HumanB.hpp" + + +HumanB::HumanB(const std::string name) +{ + this->_name = name; + //this->_Weapon = NULL; +} + +HumanB::HumanB(const std::string name, Weapon Weapon) +{ + this->_name = name; + this->_Weapon = Weapon.getType(); +} + +HumanB::~HumanB(void) +{ + +} + +void HumanB::setWeapon(Weapon Weapon) +{ + this->_Weapon = Weapon.getType(); +} + +void HumanB::attack(void) const +{ + std::cout << this->_name << " attacks with their " << this->_Weapon << std::endl; +} \ No newline at end of file diff --git a/cpp01/ex03/HumanB.hpp b/cpp01/ex03/HumanB.hpp index 3c1fbef..ecb59e0 100644 --- a/cpp01/ex03/HumanB.hpp +++ b/cpp01/ex03/HumanB.hpp @@ -6,20 +6,30 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 21:23:58 by apommier #+# #+# */ -/* Updated: 2022/06/10 23:01:08 by apommier ### ########.fr */ +/* Updated: 2022/06/16 23:32:27 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ +#ifndef HUMANB_HPP +# define HUMANB_HPP + +#include "Weapon.hpp" + class HumanB { public: - HumanB(void); + HumanB(const std::string name, Weapon Weapon); + HumanB (const std::string name); ~HumanB(void); + void attack(void) const; + void setWeapon(Weapon Weapon); private: - + std::string _name; std::string &_Weapon; -}; \ No newline at end of file +}; + +#endif \ No newline at end of file diff --git a/cpp01/ex03/Makefile b/cpp01/ex03/Makefile index e69de29..1ea0008 100644 --- a/cpp01/ex03/Makefile +++ b/cpp01/ex03/Makefile @@ -0,0 +1,36 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2022/06/16 21:39:06 by apommier #+# #+# # +# Updated: 2022/06/16 21:39:45 by apommier ### ########.fr # +# # +# **************************************************************************** # + +NAME = a.out +SRCS = main.cpp\ + HumanA.cpp\ + HumanB.cpp\ + Weapon.cpp +OBJS = ${SRCS:.cpp=.o} +CC = c++ +CFLAGS = -Wall -Wextra -Werror +RM = rm -rf + +${NAME}: ${OBJS} + ${CC} ${LIB} ${OBJS} -o ${NAME} + +all: ${NAME} + +clean: + @${RM} ${OBJS} + +fclean: clean + @${RM} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re \ No newline at end of file diff --git a/cpp01/ex03/Weapon.cpp b/cpp01/ex03/Weapon.cpp index 5b42d11..ca169dc 100644 --- a/cpp01/ex03/Weapon.cpp +++ b/cpp01/ex03/Weapon.cpp @@ -6,26 +6,27 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 21:13:13 by apommier #+# #+# */ -/* Updated: 2022/06/10 21:18:19 by apommier ### ########.fr */ +/* Updated: 2022/06/16 22:25:56 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "Weapon.hpp" -Weapon::Weapon(std::string name): _type(name) { +Weapon::Weapon(std::string name): _type(name) { + } Weapon::~Weapon() { } -std::string const getType(void) +const std::string &getType(void) { return (this->_type); } -void setType(std::string type) +void setType(const std::string &type) { this->_type = type; } \ No newline at end of file diff --git a/cpp01/ex03/Weapon.hpp b/cpp01/ex03/Weapon.hpp index 782a49f..0b3a888 100644 --- a/cpp01/ex03/Weapon.hpp +++ b/cpp01/ex03/Weapon.hpp @@ -6,21 +6,30 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 19:43:13 by apommier #+# #+# */ -/* Updated: 2022/06/10 21:13:47 by apommier ### ########.fr */ +/* Updated: 2022/06/16 23:39:20 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ +#ifndef WEAPON_HPP +# define WEAPON_HPP + +#include +#include + + class Weapon { public: - Weapon(void); + Weapon(std::string str); ~Weapon(void); - std::string const getType(void); - void setType(void); + std::string& getType(void); + void setType(const std::string type); private: std::string _type; -}; \ No newline at end of file +}; + +#endif \ No newline at end of file diff --git a/cpp01/ex03/main.cpp b/cpp01/ex03/main.cpp index 57be118..0790270 100644 --- a/cpp01/ex03/main.cpp +++ b/cpp01/ex03/main.cpp @@ -6,10 +6,13 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/10 20:12:10 by apommier #+# #+# */ -/* Updated: 2022/06/10 20:12:47 by apommier ### ########.fr */ +/* Updated: 2022/06/16 22:57:13 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ +#include "HumanA.hpp" +#include "HumanB.hpp" + int main() { {