half part of cpp01

This commit is contained in:
kinou-p 2022-06-10 23:03:30 +02:00
parent 5b4d263d7f
commit 4c13dc84cb
11 changed files with 227 additions and 0 deletions

Binary file not shown.

33
cpp01/ex02/Makefile Normal file
View File

@ -0,0 +1,33 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/06/10 14:10:33 by apommier #+# #+# #
# Updated: 2022/06/10 14:11:06 by apommier ### ########.fr #
# #
# **************************************************************************** #
NAME = a.out
SRCS = main.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

31
cpp01/ex02/main.cpp Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 14:10:35 by apommier #+# #+# */
/* Updated: 2022/06/10 17:59:29 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include <string>
#include <iostream>
#include <cstdio>
int main()
{
std::string str = "HI THIS IS BRAIN";
std::string* stringPTR = &str;
std::string& stringREF = str;
std::cout << "The memory address of the string variable is | " << &str << std::endl;
std::cout << "The memory address held by stringPTR is | " << stringPTR << std::endl;
std::cout << "The memory address held by stringREF is | " << &stringREF << std::endl;
std::cout << "The value of the string variable is | " << str << std::endl;
std::cout << "The value pointed to by stringPTR is | " << *stringPTR << std::endl;
std::cout << "The value pointed to by stringREF is | " << stringREF << std::endl;
}

12
cpp01/ex03/HumanA.cpp Normal file
View File

@ -0,0 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanA.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 21:20:34 by apommier #+# #+# */
/* Updated: 2022/06/10 21:23:56 by apommier ### ########.fr */
/* */
/* ************************************************************************** */

26
cpp01/ex03/HumanA.hpp Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanA.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 21:20:32 by apommier #+# #+# */
/* Updated: 2022/06/10 23:01:02 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
class HumanA {
public:
HumanA(void);
~HumanA(void);
private:
void attack(void) const;
std::string _name;
std::string *_Weapon;
};

12
cpp01/ex03/HumanB.cpp Normal file
View File

@ -0,0 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanB.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 21:25:58 by apommier #+# #+# */
/* Updated: 2022/06/10 21:25:59 by apommier ### ########.fr */
/* */
/* ************************************************************************** */

25
cpp01/ex03/HumanB.hpp Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanB.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 21:23:58 by apommier #+# #+# */
/* Updated: 2022/06/10 23:01:08 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
class HumanB {
public:
HumanB(void);
~HumanB(void);
private:
std::string _name;
std::string &_Weapon;
};

0
cpp01/ex03/Makefile Normal file
View File

31
cpp01/ex03/Weapon.cpp Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Weapon.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 21:13:13 by apommier #+# #+# */
/* Updated: 2022/06/10 21:18:19 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon.hpp"
Weapon::Weapon(std::string name): _type(name) {
}
Weapon::~Weapon() {
}
std::string const getType(void)
{
return (this->_type);
}
void setType(std::string type)
{
this->_type = type;
}

26
cpp01/ex03/Weapon.hpp Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Weapon.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 19:43:13 by apommier #+# #+# */
/* Updated: 2022/06/10 21:13:47 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
class Weapon {
public:
Weapon(void);
~Weapon(void);
std::string const getType(void);
void setType(void);
private:
std::string _type;
};

31
cpp01/ex03/main.cpp Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/10 20:12:10 by apommier #+# #+# */
/* Updated: 2022/06/10 20:12:47 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
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();
}
return 0;
}