cpp01 ex03
This commit is contained in:
parent
4c13dc84cb
commit
87e67b4e79
@ -6,7 +6,24 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/10 21:20:34 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;
|
||||||
|
}
|
||||||
@ -6,21 +6,29 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/10 21:20:32 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 {
|
class HumanA {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
HumanA(void);
|
HumanA(const std::string name, Weapon Weapon);
|
||||||
~HumanA(void);
|
~HumanA(void);
|
||||||
|
void attack(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void attack(void) const;
|
|
||||||
std::string _name;
|
std::string _name;
|
||||||
std::string *_Weapon;
|
std::string *_Weapon;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -6,7 +6,36 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/10 21:25:58 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;
|
||||||
|
}
|
||||||
@ -6,20 +6,30 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/10 21:23:58 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 {
|
class HumanB {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
HumanB(void);
|
HumanB(const std::string name, Weapon Weapon);
|
||||||
|
HumanB (const std::string name);
|
||||||
~HumanB(void);
|
~HumanB(void);
|
||||||
|
void attack(void) const;
|
||||||
|
void setWeapon(Weapon Weapon);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string _name;
|
std::string _name;
|
||||||
std::string &_Weapon;
|
std::string &_Weapon;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# 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
|
||||||
@ -6,26 +6,27 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/10 21:13:13 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"
|
#include "Weapon.hpp"
|
||||||
|
|
||||||
Weapon::Weapon(std::string name): _type(name) {
|
|
||||||
|
|
||||||
|
Weapon::Weapon(std::string name): _type(name) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Weapon::~Weapon() {
|
Weapon::~Weapon() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const getType(void)
|
const std::string &getType(void)
|
||||||
{
|
{
|
||||||
return (this->_type);
|
return (this->_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setType(std::string type)
|
void setType(const std::string &type)
|
||||||
{
|
{
|
||||||
this->_type = type;
|
this->_type = type;
|
||||||
}
|
}
|
||||||
@ -6,21 +6,30 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/10 19:43:13 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 <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
class Weapon {
|
class Weapon {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Weapon(void);
|
Weapon(std::string str);
|
||||||
~Weapon(void);
|
~Weapon(void);
|
||||||
std::string const getType(void);
|
std::string& getType(void);
|
||||||
void setType(void);
|
void setType(const std::string type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string _type;
|
std::string _type;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -6,10 +6,13 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/10 20:12:10 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()
|
int main()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user