add a lot of things
This commit is contained in:
parent
1a86607d24
commit
3a2ef3d69d
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/04/15 01:47:51 by apommier #+# #+# #
|
||||
# Updated: 2022/04/15 05:00:14 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -18,6 +18,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/04/15 01:47:51 by apommier #+# #+# #
|
||||
# Updated: 2022/04/20 05:40:02 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -20,6 +20,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror -g
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/04/15 01:47:51 by apommier #+# #+# #
|
||||
# Updated: 2022/04/15 05:00:14 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -18,6 +18,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/06/08 16:30:13 by apommier #+# #+# #
|
||||
# Updated: 2022/06/08 16:32:48 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -21,6 +21,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/06/08 16:30:13 by apommier #+# #+# #
|
||||
# Updated: 2022/06/10 13:49:47 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -20,6 +20,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# 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 #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -17,6 +17,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# 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 #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -20,6 +20,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,19 +6,21 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/06/19 16:15:23 by apommier #+# #+# #
|
||||
# Updated: 2022/06/19 16:15:32 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = a.out
|
||||
SRCS = main.cpp\
|
||||
|
||||
|
||||
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/06/19 16:15:21 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/21 22:02:37 by apommier ### ########.fr */
|
||||
/* Updated: 2022/07/18 16:45:54 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -47,7 +47,7 @@ int main(int ac, char **av)
|
||||
std::string allFile;
|
||||
std::string buffer;
|
||||
std::ofstream outfile((std::string)av[1] + ".replace");
|
||||
|
||||
|
||||
if (ac != 4 || !verifyPathname(av[1], av[2], av[3]) || !fileOne)
|
||||
{
|
||||
std::cout << "Bad argument\n";
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/06/21 22:07:00 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/21 23:23:28 by apommier ### ########.fr */
|
||||
/* Updated: 2022/07/19 10:42:46 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -24,7 +24,7 @@ Harl::~Harl()
|
||||
|
||||
void Harl::complain(std::string level)
|
||||
{
|
||||
void (Harl::*complaint[])(void) = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
|
||||
void (Harl::*complaint[])(void) = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
|
||||
std::string levelTab[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
|
||||
for (int i = 0; i < 4 ; i++)
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/06/21 22:05:40 by apommier #+# #+# #
|
||||
# Updated: 2022/06/21 23:10:46 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -20,6 +20,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/06/21 23:38:45 by apommier #+# #+# #
|
||||
# Updated: 2022/06/21 23:46:38 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -19,6 +19,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/06/22 00:57:33 by apommier #+# #+# #
|
||||
# Updated: 2022/06/22 01:25:33 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -19,6 +19,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/06/22 15:30:34 by apommier #+# #+# #
|
||||
# Updated: 2022/06/22 15:30:36 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -19,6 +19,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/06/22 15:31:03 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/13 03:36:07 by apommier ### ########.fr */
|
||||
/* Updated: 2022/07/18 14:44:52 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/06/22 15:30:34 by apommier #+# #+# #
|
||||
# Updated: 2022/06/22 15:30:36 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:44 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -19,6 +19,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/07/13 05:22:57 by apommier #+# #+# #
|
||||
# Updated: 2022/07/13 05:23:09 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -19,6 +19,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/07/13 05:22:57 by apommier #+# #+# #
|
||||
# Updated: 2022/07/13 09:43:08 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -20,6 +20,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/13 05:22:53 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/13 13:13:24 by apommier ### ########.fr */
|
||||
/* Updated: 2022/07/18 22:57:33 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
class ClapTrap {
|
||||
public:
|
||||
|
||||
|
||||
ClapTrap(std::string name);
|
||||
ClapTrap(const ClapTrap& copy);
|
||||
~ClapTrap();
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/07/13 05:22:57 by apommier #+# #+# #
|
||||
# Updated: 2022/07/14 01:54:37 by apommier ### ########.fr #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -21,6 +21,9 @@ CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
|
||||
47
cpp04/ex00/Animal.cpp
Normal file
47
cpp04/ex00/Animal.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:05:22 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:13:43 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
Animal::Animal()
|
||||
{
|
||||
std::cout << "Animal Default constructor called" << std::endl;
|
||||
this->type = "Animal";
|
||||
}
|
||||
|
||||
Animal::Animal(const Animal& copy)
|
||||
{
|
||||
std::cout << "Animal Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
Animal::~Animal()
|
||||
{
|
||||
std::cout << "Animal Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
std::string Animal::getType(void) const
|
||||
{
|
||||
return (this->type);
|
||||
}
|
||||
|
||||
void Animal::makeSound(void) const
|
||||
{
|
||||
std::cout << "Groar im an animal\n";
|
||||
}
|
||||
|
||||
Animal &Animal::operator=(const Animal& rhs)
|
||||
{
|
||||
std::cout << "Animal assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return (*this);
|
||||
}
|
||||
35
cpp04/ex00/Animal.hpp
Normal file
35
cpp04/ex00/Animal.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:05:20 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:27:22 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ANIMAL_HPP
|
||||
# define ANIMAL_HPP
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Animal {
|
||||
|
||||
public:
|
||||
|
||||
Animal();
|
||||
Animal(const Animal& copy);
|
||||
virtual ~Animal();
|
||||
Animal &operator=(const Animal& rhs);
|
||||
|
||||
virtual void makeSound(void) const;
|
||||
std::string getType(void) const;
|
||||
|
||||
protected:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
42
cpp04/ex00/Cat.cpp
Normal file
42
cpp04/ex00/Cat.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:37 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:24:25 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Cat.hpp"
|
||||
|
||||
Cat::Cat() : Animal()
|
||||
{
|
||||
std::cout << "Cat Default constructor called" << std::endl;
|
||||
this->type = "Cat";
|
||||
}
|
||||
|
||||
Cat::Cat(const Cat& copy) : Animal(copy)
|
||||
{
|
||||
std::cout << "Cat Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
Cat::~Cat()
|
||||
{
|
||||
std::cout << "Cat Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
void Cat::makeSound(void) const
|
||||
{
|
||||
std::cout << "Meow\n";
|
||||
}
|
||||
|
||||
Cat &Cat::operator=(const Cat& rhs)
|
||||
{
|
||||
std::cout << "Cat assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return (*this);
|
||||
}
|
||||
30
cpp04/ex00/Cat.hpp
Normal file
30
cpp04/ex00/Cat.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:39 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:47:44 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CAT_HPP
|
||||
# define CAT_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Cat : public Animal {
|
||||
public :
|
||||
|
||||
Cat();
|
||||
Cat(const Cat& copy);
|
||||
~Cat();
|
||||
Cat &operator=(const Cat& rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
42
cpp04/ex00/Dog.cpp
Normal file
42
cpp04/ex00/Dog.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:41 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:14:01 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Dog.hpp"
|
||||
|
||||
Dog::Dog() : Animal()
|
||||
{
|
||||
std::cout << "Dog Default constructor called" << std::endl;
|
||||
this->type = "Dog";
|
||||
}
|
||||
|
||||
Dog::Dog(const Dog& copy) : Animal(copy)
|
||||
{
|
||||
std::cout << "Dog Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
Dog::~Dog()
|
||||
{
|
||||
std::cout << "Dog Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
void Dog::makeSound(void) const
|
||||
{
|
||||
std::cout << "Ouaf\n";
|
||||
}
|
||||
|
||||
Dog &Dog::operator=(const Dog& rhs)
|
||||
{
|
||||
std::cout << "Dog assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return (*this);
|
||||
}
|
||||
30
cpp04/ex00/Dog.hpp
Normal file
30
cpp04/ex00/Dog.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:42 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/15 04:27:19 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DOG_HPP
|
||||
# define DOG_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Dog : public Animal {
|
||||
public:
|
||||
|
||||
Dog();
|
||||
Dog(const Dog& copy);
|
||||
~Dog();
|
||||
Dog &operator=(const Dog& rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
42
cpp04/ex00/Makefile
Normal file
42
cpp04/ex00/Makefile
Normal file
@ -0,0 +1,42 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/07/14 02:04:13 by apommier #+# #+# #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = a.out
|
||||
SRCS = main.cpp\
|
||||
Cat.cpp\
|
||||
Dog.cpp\
|
||||
Animal.cpp\
|
||||
WrongAnimal.cpp\
|
||||
WrongCat.cpp
|
||||
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
clean:
|
||||
@${RM} ${OBJS}
|
||||
|
||||
fclean: clean
|
||||
@${RM} ${NAME}
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
47
cpp04/ex00/WrongAnimal.cpp
Normal file
47
cpp04/ex00/WrongAnimal.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongAnimal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:53:56 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:16:20 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
WrongAnimal::WrongAnimal()
|
||||
{
|
||||
std::cout << "WrongAnimal Default constructor called" << std::endl;
|
||||
this->type = "WrongAnimal";
|
||||
}
|
||||
|
||||
WrongAnimal::WrongAnimal(const WrongAnimal& copy)
|
||||
{
|
||||
std::cout << "WrongAnimal Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
WrongAnimal::~WrongAnimal()
|
||||
{
|
||||
std::cout << "WrongAnimal Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
std::string WrongAnimal::getType(void) const
|
||||
{
|
||||
return (this->type);
|
||||
}
|
||||
|
||||
void WrongAnimal::makeSound(void) const
|
||||
{
|
||||
std::cout << "Gruuu im an WrongAnimal\n";
|
||||
}
|
||||
|
||||
WrongAnimal &WrongAnimal::operator=(const WrongAnimal& rhs)
|
||||
{
|
||||
std::cout << "WrongAnimal assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return (*this);
|
||||
}
|
||||
36
cpp04/ex00/WrongAnimal.hpp
Normal file
36
cpp04/ex00/WrongAnimal.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongAnimal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:53:59 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:27:27 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRONGANIMAL_HPP
|
||||
# define WRONGANIMAL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class WrongAnimal {
|
||||
|
||||
public:
|
||||
|
||||
WrongAnimal();
|
||||
WrongAnimal(const WrongAnimal& copy);
|
||||
virtual ~WrongAnimal();
|
||||
WrongAnimal &operator=(const WrongAnimal& rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
std::string getType(void) const;
|
||||
|
||||
protected:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
42
cpp04/ex00/WrongCat.cpp
Normal file
42
cpp04/ex00/WrongCat.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongCat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:54:01 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:14:14 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
WrongCat::WrongCat() : WrongAnimal()
|
||||
{
|
||||
std::cout << "WrongCat Default constructor called" << std::endl;
|
||||
this->type = "WrongCat";
|
||||
}
|
||||
|
||||
WrongCat::WrongCat(const WrongCat& copy) : WrongAnimal(copy)
|
||||
{
|
||||
std::cout << "WrongCat Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
WrongCat::~WrongCat()
|
||||
{
|
||||
std::cout << "WrongCat Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
void WrongCat::makeSound(void) const
|
||||
{
|
||||
std::cout << "Meow\n";
|
||||
}
|
||||
|
||||
WrongCat &WrongCat::operator=(const WrongCat& rhs)
|
||||
{
|
||||
std::cout << "WrongCat assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return (*this);
|
||||
}
|
||||
31
cpp04/ex00/WrongCat.hpp
Normal file
31
cpp04/ex00/WrongCat.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongCat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:54:02 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:15:05 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRONGCAT_HPP
|
||||
# define WRONGCAT_HPP
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
class WrongCat : public WrongAnimal {
|
||||
public :
|
||||
|
||||
WrongCat();
|
||||
WrongCat(const WrongCat& copy);
|
||||
~WrongCat();
|
||||
WrongCat &operator=(const WrongCat& rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
|
||||
private :
|
||||
};
|
||||
|
||||
#endif
|
||||
46
cpp04/ex00/main.cpp
Normal file
46
cpp04/ex00/main.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:04:10 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:29:39 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "Dog.hpp"
|
||||
#include "Cat.hpp"
|
||||
#include "WrongAnimal.hpp"
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
const Animal* meta = new Animal();
|
||||
const Animal* j = new Dog();
|
||||
const Animal* i = new Cat();
|
||||
std::cout << j->getType() << " " << std::endl;
|
||||
std::cout << i->getType() << " " << std::endl;
|
||||
i->makeSound(); //will output the cat sound!
|
||||
j->makeSound();
|
||||
meta->makeSound();
|
||||
|
||||
delete meta;
|
||||
delete j;
|
||||
delete i;
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
const WrongAnimal* meta2 = new WrongAnimal();
|
||||
const WrongAnimal* i2 = new WrongCat();
|
||||
std::cout << i2->getType() << " " << std::endl;
|
||||
i2->makeSound(); //will output the WrongAnimal sound!
|
||||
meta2->makeSound(); //same
|
||||
|
||||
delete meta2;
|
||||
delete i2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
47
cpp04/ex01/Animal.cpp
Normal file
47
cpp04/ex01/Animal.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:05:22 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 18:36:09 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
Animal::Animal()
|
||||
{
|
||||
std::cout << "Animal Default constructor called" << std::endl;
|
||||
this->type = "Animal";
|
||||
}
|
||||
|
||||
Animal::Animal(const Animal& copy)
|
||||
{
|
||||
std::cout << "Animal Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
Animal::~Animal()
|
||||
{
|
||||
std::cout << "Animal Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
std::string Animal::getType(void) const
|
||||
{
|
||||
return (this->type);
|
||||
}
|
||||
|
||||
void Animal::makeSound(void) const
|
||||
{
|
||||
std::cout << "Groar im an animal\n";
|
||||
}
|
||||
|
||||
Animal &Animal::operator=(const Animal& rhs)
|
||||
{
|
||||
std::cout << "Animal assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return *this;
|
||||
}
|
||||
37
cpp04/ex01/Animal.hpp
Normal file
37
cpp04/ex01/Animal.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:05:20 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 19:02:35 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ANIMAL_HPP
|
||||
# define ANIMAL_HPP
|
||||
|
||||
#include "Brain.hpp"
|
||||
#include <iostream>
|
||||
|
||||
class Animal {
|
||||
|
||||
public:
|
||||
|
||||
Animal();
|
||||
Animal(const Animal& copy);
|
||||
virtual ~Animal();
|
||||
virtual Animal &operator=(const Animal& rhs);
|
||||
|
||||
virtual void makeSound(void) const;
|
||||
virtual Brain *getBrain( void ) const = 0;
|
||||
std::string getType(void) const;
|
||||
|
||||
protected:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
51
cpp04/ex01/Brain.cpp
Normal file
51
cpp04/ex01/Brain.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Brain.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/15 04:37:19 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/18 09:17:44 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Brain.hpp"
|
||||
|
||||
Brain::Brain()
|
||||
{
|
||||
std::cout << "Brain Default constructor called" << std::endl;
|
||||
}
|
||||
|
||||
Brain::Brain(const Brain& copy)
|
||||
{
|
||||
std::cout << "Brain Copy constructor called" << std::endl;
|
||||
*this = copy;
|
||||
}
|
||||
|
||||
Brain::~Brain()
|
||||
{
|
||||
std::cout << "Brain Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
Brain &Brain::operator=(const Brain& rhs)
|
||||
{
|
||||
std::cout << "Brain assignement operator called" << std::endl;
|
||||
if (this != &rhs)
|
||||
{
|
||||
for (int i = 0; i < 100; i++) {
|
||||
this->_ideas[i] = rhs._ideas[i];
|
||||
}
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
std::string *Brain::getIdeas()
|
||||
{
|
||||
return (this->_ideas);
|
||||
}
|
||||
|
||||
void Brain::setIdeas(int i, std::string str)
|
||||
{
|
||||
this->_ideas[i] = str;
|
||||
}
|
||||
34
cpp04/ex01/Brain.hpp
Normal file
34
cpp04/ex01/Brain.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Brain.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 12:22:17 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/18 09:17:40 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BRAIN_HPP
|
||||
# define BRAIN_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
class Brain{
|
||||
public :
|
||||
Brain();
|
||||
Brain(const Brain& copy);
|
||||
~Brain();
|
||||
Brain &operator=(const Brain& rhs);
|
||||
std::string *getIdeas();
|
||||
void setIdeas(int i, std::string str);
|
||||
|
||||
private:
|
||||
|
||||
std::string _ideas[100];
|
||||
};
|
||||
|
||||
#endif
|
||||
67
cpp04/ex01/Cat.cpp
Normal file
67
cpp04/ex01/Cat.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:37 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 19:03:24 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Cat.hpp"
|
||||
|
||||
Cat::Cat() : Animal()
|
||||
{
|
||||
std::cout << "Cat Default constructor called" << std::endl;
|
||||
this->type = "Cat";
|
||||
this->_Brain = new Brain;
|
||||
}
|
||||
|
||||
Cat::Cat(const Cat& copy) : Animal(copy)
|
||||
{
|
||||
std::cout << "Cat Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
//this->_Brain = copy.getType();
|
||||
}
|
||||
|
||||
Cat::~Cat()
|
||||
{
|
||||
std::cout << "Cat Destructor called" << std::endl;
|
||||
delete this->_Brain;
|
||||
}
|
||||
|
||||
void Cat::makeSound(void) const
|
||||
{
|
||||
std::cout << "Meow\n";
|
||||
}
|
||||
|
||||
Cat &Cat::operator=(const Cat& rhs)
|
||||
{
|
||||
std::cout << "Cat assignement operator called" << std::endl;
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->type = rhs.getType();
|
||||
delete this->_Brain;
|
||||
this->_Brain = new Brain(*rhs._Brain);
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Animal &Cat::operator=( const Animal &rhs)
|
||||
{
|
||||
std::cout << "Cat assignement operator called" << std::endl;
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->type = rhs.getType();
|
||||
delete this->_Brain;
|
||||
this->_Brain = new Brain(*rhs.getBrain());
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Brain *Cat::getBrain() const
|
||||
{
|
||||
return (this->_Brain);
|
||||
}
|
||||
33
cpp04/ex01/Cat.hpp
Normal file
33
cpp04/ex01/Cat.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:39 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 18:39:59 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CAT_HPP
|
||||
# define CAT_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Cat : public Animal {
|
||||
public :
|
||||
Cat();
|
||||
Cat(const Cat& copy);
|
||||
~Cat();
|
||||
Cat &operator=(const Cat& rhs);
|
||||
Animal &operator=( const Animal &rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
Brain *getBrain() const;
|
||||
|
||||
private :
|
||||
Brain *_Brain;
|
||||
};
|
||||
|
||||
#endif
|
||||
66
cpp04/ex01/Dog.cpp
Normal file
66
cpp04/ex01/Dog.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:41 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 19:03:52 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Dog.hpp"
|
||||
|
||||
Dog::Dog() : Animal()
|
||||
{
|
||||
std::cout << "Dog Default constructor called" << std::endl;
|
||||
this->type = "Dog";
|
||||
this->_Brain = new Brain;
|
||||
}
|
||||
|
||||
Dog::Dog(const Dog& copy) : Animal(copy)
|
||||
{
|
||||
std::cout << "Dog Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
Dog::~Dog()
|
||||
{
|
||||
std::cout << "Dog Destructor called" << std::endl;
|
||||
delete this->_Brain;
|
||||
}
|
||||
|
||||
void Dog::makeSound(void) const
|
||||
{
|
||||
std::cout << "Ouaf\n";
|
||||
}
|
||||
|
||||
Dog &Dog::operator=(const Dog& rhs)
|
||||
{
|
||||
std::cout << "Dog assignement operator called" << std::endl;
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->type = rhs.getType();
|
||||
delete this->_Brain;
|
||||
this->_Brain = new Brain(*rhs._Brain);
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Animal &Dog::operator=( const Animal &rhs)
|
||||
{
|
||||
std::cout << "Cat assignement operator called" << std::endl;
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->type = rhs.getType();
|
||||
delete this->_Brain;
|
||||
this->_Brain = new Brain(*rhs.getBrain());
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Brain *Dog::getBrain() const
|
||||
{
|
||||
return (this->_Brain);
|
||||
}
|
||||
35
cpp04/ex01/Dog.hpp
Normal file
35
cpp04/ex01/Dog.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:42 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 19:04:03 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DOG_HPP
|
||||
# define DOG_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Dog : public Animal {
|
||||
public:
|
||||
|
||||
Dog();
|
||||
Dog(const Dog& copy);
|
||||
~Dog();
|
||||
Dog &operator=(const Dog& rhs);
|
||||
Animal &operator=( const Animal &rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
Brain *getBrain() const;
|
||||
|
||||
private:
|
||||
|
||||
Brain *_Brain;
|
||||
};
|
||||
|
||||
#endif
|
||||
43
cpp04/ex01/Makefile
Normal file
43
cpp04/ex01/Makefile
Normal file
@ -0,0 +1,43 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/07/14 02:04:13 by apommier #+# #+# #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = a.out
|
||||
SRCS = main.cpp\
|
||||
Cat.cpp\
|
||||
Dog.cpp\
|
||||
Animal.cpp\
|
||||
WrongAnimal.cpp\
|
||||
WrongCat.cpp\
|
||||
Brain.cpp\
|
||||
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
clean:
|
||||
@${RM} ${OBJS}
|
||||
|
||||
fclean: clean
|
||||
@${RM} ${NAME}
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
47
cpp04/ex01/WrongAnimal.cpp
Normal file
47
cpp04/ex01/WrongAnimal.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongAnimal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:53:56 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:16:20 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
WrongAnimal::WrongAnimal()
|
||||
{
|
||||
std::cout << "WrongAnimal Default constructor called" << std::endl;
|
||||
this->type = "WrongAnimal";
|
||||
}
|
||||
|
||||
WrongAnimal::WrongAnimal(const WrongAnimal& copy)
|
||||
{
|
||||
std::cout << "WrongAnimal Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
WrongAnimal::~WrongAnimal()
|
||||
{
|
||||
std::cout << "WrongAnimal Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
std::string WrongAnimal::getType(void) const
|
||||
{
|
||||
return (this->type);
|
||||
}
|
||||
|
||||
void WrongAnimal::makeSound(void) const
|
||||
{
|
||||
std::cout << "Gruuu im an WrongAnimal\n";
|
||||
}
|
||||
|
||||
WrongAnimal &WrongAnimal::operator=(const WrongAnimal& rhs)
|
||||
{
|
||||
std::cout << "WrongAnimal assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return (*this);
|
||||
}
|
||||
36
cpp04/ex01/WrongAnimal.hpp
Normal file
36
cpp04/ex01/WrongAnimal.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongAnimal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:53:59 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:27:27 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRONGANIMAL_HPP
|
||||
# define WRONGANIMAL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class WrongAnimal {
|
||||
|
||||
public:
|
||||
|
||||
WrongAnimal();
|
||||
WrongAnimal(const WrongAnimal& copy);
|
||||
virtual ~WrongAnimal();
|
||||
WrongAnimal &operator=(const WrongAnimal& rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
std::string getType(void) const;
|
||||
|
||||
protected:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
42
cpp04/ex01/WrongCat.cpp
Normal file
42
cpp04/ex01/WrongCat.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongCat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:54:01 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:14:14 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
WrongCat::WrongCat() : WrongAnimal()
|
||||
{
|
||||
std::cout << "WrongCat Default constructor called" << std::endl;
|
||||
this->type = "WrongCat";
|
||||
}
|
||||
|
||||
WrongCat::WrongCat(const WrongCat& copy) : WrongAnimal(copy)
|
||||
{
|
||||
std::cout << "WrongCat Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
WrongCat::~WrongCat()
|
||||
{
|
||||
std::cout << "WrongCat Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
void WrongCat::makeSound(void) const
|
||||
{
|
||||
std::cout << "Meow\n";
|
||||
}
|
||||
|
||||
WrongCat &WrongCat::operator=(const WrongCat& rhs)
|
||||
{
|
||||
std::cout << "WrongCat assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return (*this);
|
||||
}
|
||||
31
cpp04/ex01/WrongCat.hpp
Normal file
31
cpp04/ex01/WrongCat.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongCat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:54:02 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:15:05 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRONGCAT_HPP
|
||||
# define WRONGCAT_HPP
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
class WrongCat : public WrongAnimal {
|
||||
public :
|
||||
|
||||
WrongCat();
|
||||
WrongCat(const WrongCat& copy);
|
||||
~WrongCat();
|
||||
WrongCat &operator=(const WrongCat& rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
|
||||
private :
|
||||
};
|
||||
|
||||
#endif
|
||||
79
cpp04/ex01/main.cpp
Normal file
79
cpp04/ex01/main.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:04:10 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/18 10:28:22 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "Dog.hpp"
|
||||
#include "Cat.hpp"
|
||||
#include "WrongAnimal.hpp"
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
/*int main()
|
||||
{
|
||||
Animal *Animals[10];
|
||||
Brain *OneBrain;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (i < 5)
|
||||
{
|
||||
Animals[i] = new Cat;
|
||||
Animals[i]->getBrain()->setgetIdeas(0) "Sleep");
|
||||
Animals[i]->getBrain()->setgetIdeas(1) "Hate");
|
||||
Animals[i]->getBrain()->setgetIdeas(2) "Sleep");
|
||||
}
|
||||
else
|
||||
{
|
||||
Animals[i] = new Dog;
|
||||
Animals[i]->getBrain()->setgetIdeas(0) "Sleep");
|
||||
Animals[i]->getBrain()->setgetIdeas(1) "Play");
|
||||
Animals[i]->getBrain()->setgetIdeas(2) "Ate");
|
||||
}
|
||||
std::cout << Animals[i]->getType() << std::endl;
|
||||
}
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
std::cout << Animals[i]->getBrain() << std::endl;
|
||||
}
|
||||
for (int i = 0; i < 10; i++)
|
||||
delete Animals[i];
|
||||
}*/
|
||||
|
||||
int main( void )
|
||||
{
|
||||
Animal *animals[10];
|
||||
Brain *brain;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (i < 5)
|
||||
animals[i] = new Dog();
|
||||
else
|
||||
animals[i] = new Cat();
|
||||
std::cout << animals[i]->getType() << std::endl;
|
||||
}
|
||||
|
||||
brain = animals[7]->getBrain();
|
||||
brain->setIdeas(0, "I'm hungry");
|
||||
brain->setIdeas(1, "That's a strange idea I'm having");
|
||||
brain->setIdeas(2, "Ball!!!!!");
|
||||
brain->setIdeas(3, "Squirrel!!!!!");
|
||||
std::cout << std::endl << animals[7]->getBrain()->getIdeas()[0] << std::endl;
|
||||
std::cout << animals[7]->getBrain()->getIdeas()[2] << std::endl;
|
||||
|
||||
*(animals[5]) = *(animals[7]);
|
||||
std::cout << animals[5]->getBrain()->getIdeas()[2] << std::endl;
|
||||
std::cout << "Test of copy\n";
|
||||
animals[7]->getBrain()->setIdeas(2, "Squirrel!!!!!");
|
||||
std::cout << animals[5]->getBrain()->getIdeas()[2] << std::endl << std::endl;
|
||||
for (int i = 0; i < 10; i++)
|
||||
delete animals[i];
|
||||
}
|
||||
47
cpp04/ex02/Animal.cpp
Normal file
47
cpp04/ex02/Animal.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:05:22 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 18:36:09 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
Animal::Animal()
|
||||
{
|
||||
std::cout << "Animal Default constructor called" << std::endl;
|
||||
this->type = "Animal";
|
||||
}
|
||||
|
||||
Animal::Animal(const Animal& copy)
|
||||
{
|
||||
std::cout << "Animal Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
Animal::~Animal()
|
||||
{
|
||||
std::cout << "Animal Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
std::string Animal::getType(void) const
|
||||
{
|
||||
return (this->type);
|
||||
}
|
||||
|
||||
void Animal::makeSound(void) const
|
||||
{
|
||||
std::cout << "Groar im an animal\n";
|
||||
}
|
||||
|
||||
Animal &Animal::operator=(const Animal& rhs)
|
||||
{
|
||||
std::cout << "Animal assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return *this;
|
||||
}
|
||||
37
cpp04/ex02/Animal.hpp
Normal file
37
cpp04/ex02/Animal.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:05:20 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/18 18:07:34 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ANIMAL_HPP
|
||||
# define ANIMAL_HPP
|
||||
|
||||
#include "Brain.hpp"
|
||||
#include <iostream>
|
||||
|
||||
class Animal {
|
||||
|
||||
public:
|
||||
|
||||
Animal();
|
||||
Animal(const Animal& copy);
|
||||
virtual ~Animal();
|
||||
virtual Animal &operator=(const Animal& rhs);
|
||||
|
||||
virtual void makeSound(void) const = 0;
|
||||
virtual Brain *getBrain( void ) const = 0;
|
||||
std::string getType(void) const;
|
||||
|
||||
protected:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
51
cpp04/ex02/Brain.cpp
Normal file
51
cpp04/ex02/Brain.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Brain.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/15 04:37:19 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/18 09:17:44 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Brain.hpp"
|
||||
|
||||
Brain::Brain()
|
||||
{
|
||||
std::cout << "Brain Default constructor called" << std::endl;
|
||||
}
|
||||
|
||||
Brain::Brain(const Brain& copy)
|
||||
{
|
||||
std::cout << "Brain Copy constructor called" << std::endl;
|
||||
*this = copy;
|
||||
}
|
||||
|
||||
Brain::~Brain()
|
||||
{
|
||||
std::cout << "Brain Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
Brain &Brain::operator=(const Brain& rhs)
|
||||
{
|
||||
std::cout << "Brain assignement operator called" << std::endl;
|
||||
if (this != &rhs)
|
||||
{
|
||||
for (int i = 0; i < 100; i++) {
|
||||
this->_ideas[i] = rhs._ideas[i];
|
||||
}
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
std::string *Brain::getIdeas()
|
||||
{
|
||||
return (this->_ideas);
|
||||
}
|
||||
|
||||
void Brain::setIdeas(int i, std::string str)
|
||||
{
|
||||
this->_ideas[i] = str;
|
||||
}
|
||||
34
cpp04/ex02/Brain.hpp
Normal file
34
cpp04/ex02/Brain.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Brain.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 12:22:17 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/18 09:17:40 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BRAIN_HPP
|
||||
# define BRAIN_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
class Brain{
|
||||
public :
|
||||
Brain();
|
||||
Brain(const Brain& copy);
|
||||
~Brain();
|
||||
Brain &operator=(const Brain& rhs);
|
||||
std::string *getIdeas();
|
||||
void setIdeas(int i, std::string str);
|
||||
|
||||
private:
|
||||
|
||||
std::string _ideas[100];
|
||||
};
|
||||
|
||||
#endif
|
||||
67
cpp04/ex02/Cat.cpp
Normal file
67
cpp04/ex02/Cat.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:37 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 19:03:24 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Cat.hpp"
|
||||
|
||||
Cat::Cat() : Animal()
|
||||
{
|
||||
std::cout << "Cat Default constructor called" << std::endl;
|
||||
this->type = "Cat";
|
||||
this->_Brain = new Brain;
|
||||
}
|
||||
|
||||
Cat::Cat(const Cat& copy) : Animal(copy)
|
||||
{
|
||||
std::cout << "Cat Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
//this->_Brain = copy.getType();
|
||||
}
|
||||
|
||||
Cat::~Cat()
|
||||
{
|
||||
std::cout << "Cat Destructor called" << std::endl;
|
||||
delete this->_Brain;
|
||||
}
|
||||
|
||||
void Cat::makeSound(void) const
|
||||
{
|
||||
std::cout << "Meow\n";
|
||||
}
|
||||
|
||||
Cat &Cat::operator=(const Cat& rhs)
|
||||
{
|
||||
std::cout << "Cat assignement operator called" << std::endl;
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->type = rhs.getType();
|
||||
delete this->_Brain;
|
||||
this->_Brain = new Brain(*rhs._Brain);
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Animal &Cat::operator=( const Animal &rhs)
|
||||
{
|
||||
std::cout << "Cat assignement operator called" << std::endl;
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->type = rhs.getType();
|
||||
delete this->_Brain;
|
||||
this->_Brain = new Brain(*rhs.getBrain());
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Brain *Cat::getBrain() const
|
||||
{
|
||||
return (this->_Brain);
|
||||
}
|
||||
33
cpp04/ex02/Cat.hpp
Normal file
33
cpp04/ex02/Cat.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:39 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 18:39:59 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CAT_HPP
|
||||
# define CAT_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Cat : public Animal {
|
||||
public :
|
||||
Cat();
|
||||
Cat(const Cat& copy);
|
||||
~Cat();
|
||||
Cat &operator=(const Cat& rhs);
|
||||
Animal &operator=( const Animal &rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
Brain *getBrain() const;
|
||||
|
||||
private :
|
||||
Brain *_Brain;
|
||||
};
|
||||
|
||||
#endif
|
||||
66
cpp04/ex02/Dog.cpp
Normal file
66
cpp04/ex02/Dog.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:41 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 19:03:52 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Dog.hpp"
|
||||
|
||||
Dog::Dog() : Animal()
|
||||
{
|
||||
std::cout << "Dog Default constructor called" << std::endl;
|
||||
this->type = "Dog";
|
||||
this->_Brain = new Brain;
|
||||
}
|
||||
|
||||
Dog::Dog(const Dog& copy) : Animal(copy)
|
||||
{
|
||||
std::cout << "Dog Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
Dog::~Dog()
|
||||
{
|
||||
std::cout << "Dog Destructor called" << std::endl;
|
||||
delete this->_Brain;
|
||||
}
|
||||
|
||||
void Dog::makeSound(void) const
|
||||
{
|
||||
std::cout << "Ouaf\n";
|
||||
}
|
||||
|
||||
Dog &Dog::operator=(const Dog& rhs)
|
||||
{
|
||||
std::cout << "Dog assignement operator called" << std::endl;
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->type = rhs.getType();
|
||||
delete this->_Brain;
|
||||
this->_Brain = new Brain(*rhs._Brain);
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Animal &Dog::operator=( const Animal &rhs)
|
||||
{
|
||||
std::cout << "Cat assignement operator called" << std::endl;
|
||||
if (&rhs != this)
|
||||
{
|
||||
this->type = rhs.getType();
|
||||
delete this->_Brain;
|
||||
this->_Brain = new Brain(*rhs.getBrain());
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Brain *Dog::getBrain() const
|
||||
{
|
||||
return (this->_Brain);
|
||||
}
|
||||
35
cpp04/ex02/Dog.hpp
Normal file
35
cpp04/ex02/Dog.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:11:42 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 19:04:03 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DOG_HPP
|
||||
# define DOG_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Dog : public Animal {
|
||||
public:
|
||||
|
||||
Dog();
|
||||
Dog(const Dog& copy);
|
||||
~Dog();
|
||||
Dog &operator=(const Dog& rhs);
|
||||
Animal &operator=( const Animal &rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
Brain *getBrain() const;
|
||||
|
||||
private:
|
||||
|
||||
Brain *_Brain;
|
||||
};
|
||||
|
||||
#endif
|
||||
43
cpp04/ex02/Makefile
Normal file
43
cpp04/ex02/Makefile
Normal file
@ -0,0 +1,43 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/07/14 02:04:13 by apommier #+# #+# #
|
||||
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = a.out
|
||||
SRCS = main.cpp\
|
||||
Cat.cpp\
|
||||
Dog.cpp\
|
||||
Animal.cpp\
|
||||
WrongAnimal.cpp\
|
||||
WrongCat.cpp\
|
||||
Brain.cpp\
|
||||
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
clean:
|
||||
@${RM} ${OBJS}
|
||||
|
||||
fclean: clean
|
||||
@${RM} ${NAME}
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
47
cpp04/ex02/WrongAnimal.cpp
Normal file
47
cpp04/ex02/WrongAnimal.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongAnimal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:53:56 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:16:20 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
WrongAnimal::WrongAnimal()
|
||||
{
|
||||
std::cout << "WrongAnimal Default constructor called" << std::endl;
|
||||
this->type = "WrongAnimal";
|
||||
}
|
||||
|
||||
WrongAnimal::WrongAnimal(const WrongAnimal& copy)
|
||||
{
|
||||
std::cout << "WrongAnimal Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
WrongAnimal::~WrongAnimal()
|
||||
{
|
||||
std::cout << "WrongAnimal Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
std::string WrongAnimal::getType(void) const
|
||||
{
|
||||
return (this->type);
|
||||
}
|
||||
|
||||
void WrongAnimal::makeSound(void) const
|
||||
{
|
||||
std::cout << "Gruuu im an WrongAnimal\n";
|
||||
}
|
||||
|
||||
WrongAnimal &WrongAnimal::operator=(const WrongAnimal& rhs)
|
||||
{
|
||||
std::cout << "WrongAnimal assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return (*this);
|
||||
}
|
||||
36
cpp04/ex02/WrongAnimal.hpp
Normal file
36
cpp04/ex02/WrongAnimal.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongAnimal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:53:59 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:27:27 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRONGANIMAL_HPP
|
||||
# define WRONGANIMAL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class WrongAnimal {
|
||||
|
||||
public:
|
||||
|
||||
WrongAnimal();
|
||||
WrongAnimal(const WrongAnimal& copy);
|
||||
virtual ~WrongAnimal();
|
||||
WrongAnimal &operator=(const WrongAnimal& rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
std::string getType(void) const;
|
||||
|
||||
protected:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
42
cpp04/ex02/WrongCat.cpp
Normal file
42
cpp04/ex02/WrongCat.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongCat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:54:01 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:14:14 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
WrongCat::WrongCat() : WrongAnimal()
|
||||
{
|
||||
std::cout << "WrongCat Default constructor called" << std::endl;
|
||||
this->type = "WrongCat";
|
||||
}
|
||||
|
||||
WrongCat::WrongCat(const WrongCat& copy) : WrongAnimal(copy)
|
||||
{
|
||||
std::cout << "WrongCat Copy constructor called" << std::endl;
|
||||
this->type = copy.getType();
|
||||
}
|
||||
|
||||
WrongCat::~WrongCat()
|
||||
{
|
||||
std::cout << "WrongCat Destructor called" << std::endl;
|
||||
}
|
||||
|
||||
void WrongCat::makeSound(void) const
|
||||
{
|
||||
std::cout << "Meow\n";
|
||||
}
|
||||
|
||||
WrongCat &WrongCat::operator=(const WrongCat& rhs)
|
||||
{
|
||||
std::cout << "WrongCat assignement operator called" << std::endl;
|
||||
this->type = rhs.getType();
|
||||
return (*this);
|
||||
}
|
||||
31
cpp04/ex02/WrongCat.hpp
Normal file
31
cpp04/ex02/WrongCat.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongCat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/17 10:54:02 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/17 11:15:05 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRONGCAT_HPP
|
||||
# define WRONGCAT_HPP
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
class WrongCat : public WrongAnimal {
|
||||
public :
|
||||
|
||||
WrongCat();
|
||||
WrongCat(const WrongCat& copy);
|
||||
~WrongCat();
|
||||
WrongCat &operator=(const WrongCat& rhs);
|
||||
|
||||
void makeSound(void) const;
|
||||
|
||||
private :
|
||||
};
|
||||
|
||||
#endif
|
||||
79
cpp04/ex02/main.cpp
Normal file
79
cpp04/ex02/main.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/14 02:04:10 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/18 20:29:04 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "Dog.hpp"
|
||||
#include "Cat.hpp"
|
||||
#include "WrongAnimal.hpp"
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
/*int main()
|
||||
{
|
||||
Animal *Animals[10];
|
||||
Brain *OneBrain;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (i < 5)
|
||||
{
|
||||
Animals[i] = new Cat;
|
||||
Animals[i]->getBrain()->setgetIdeas(0) "Sleep");
|
||||
Animals[i]->getBrain()->setgetIdeas(1) "Hate");
|
||||
Animals[i]->getBrain()->setgetIdeas(2) "Sleep");
|
||||
}
|
||||
else
|
||||
{
|
||||
Animals[i] = new Dog;
|
||||
Animals[i]->getBrain()->setgetIdeas(0) "Sleep");
|
||||
Animals[i]->getBrain()->setgetIdeas(1) "Play");
|
||||
Animals[i]->getBrain()->setgetIdeas(2) "Ate");
|
||||
}
|
||||
std::cout << Animals[i]->getType() << std::endl;
|
||||
}
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
std::cout << Animals[i]->getBrain() << std::endl;
|
||||
}
|
||||
for (int i = 0; i < 10; i++)
|
||||
delete Animals[i];
|
||||
}*/
|
||||
|
||||
int main( void )
|
||||
{
|
||||
Animal *animals[10];
|
||||
Brain *brain;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (i < 5)
|
||||
animals[i] = new Dog();
|
||||
else
|
||||
animals[i] = new Cat();
|
||||
std::cout << animals[i]->getType() << std::endl;
|
||||
}
|
||||
|
||||
brain = animals[7]->getBrain();
|
||||
brain->setIdeas(0, "I'm hungry");
|
||||
brain->setIdeas(1, "That's a strange idea I'm having");
|
||||
brain->setIdeas(2, "Ball!!!!!");
|
||||
brain->setIdeas(3, "Squirrel!!!!!");
|
||||
std::cout << std::endl << animals[7]->getBrain()->getIdeas()[0] << std::endl;
|
||||
std::cout << animals[7]->getBrain()->getIdeas()[2] << std::endl;
|
||||
|
||||
*(animals[5]) = *(animals[7]);
|
||||
std::cout << animals[5]->getBrain()->getIdeas()[2] << std::endl;
|
||||
std::cout << "Test of copy\n";
|
||||
animals[7]->getBrain()->setIdeas(2, "Squirrel!!!!!");
|
||||
std::cout << animals[5]->getBrain()->getIdeas()[2] << std::endl << std::endl;
|
||||
for (int i = 0; i < 10; i++)
|
||||
delete animals[i];
|
||||
}
|
||||
76
cpp05/ex00/Bureaucrat.cpp
Normal file
76
cpp05/ex00/Bureaucrat.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Bureaucrat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 21:34:42 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 11:59:12 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Bureaucrat.hpp"
|
||||
|
||||
Bureaucrat::Bureaucrat(int grade, std::string name) : _name(name)
|
||||
{
|
||||
this->_grade = grade;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
Bureaucrat::Bureaucrat(const Bureaucrat& copy)
|
||||
{
|
||||
*this = copy;
|
||||
}
|
||||
|
||||
Bureaucrat::~Bureaucrat()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Bureaucrat &Bureaucrat::operator=(const Bureaucrat& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
std::cout << "Only grade can be copied, name is const\n";
|
||||
this->_grade = rhs.getGrade();
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat)
|
||||
{
|
||||
out << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade();
|
||||
return (out);
|
||||
}
|
||||
|
||||
const std::string Bureaucrat::getName() const
|
||||
{
|
||||
return (this->_name);
|
||||
}
|
||||
|
||||
int Bureaucrat::getGrade() const
|
||||
{
|
||||
return (this->_grade);
|
||||
}
|
||||
|
||||
void Bureaucrat::upGrade()
|
||||
{
|
||||
this->_grade--;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
void Bureaucrat::downGrade()
|
||||
{
|
||||
this->_grade++;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
void Bureaucrat::checkGrade() const
|
||||
{
|
||||
if (this->_grade > 150)
|
||||
throw Bureaucrat::GradeTooLowException();
|
||||
else if (this->_grade < 1)
|
||||
throw Bureaucrat::GradeTooHighException();
|
||||
}
|
||||
|
||||
60
cpp05/ex00/Bureaucrat.hpp
Normal file
60
cpp05/ex00/Bureaucrat.hpp
Normal file
@ -0,0 +1,60 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Bureaucrat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 21:34:43 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 11:23:31 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BUREAUCRAT_HPP
|
||||
# define BUREAUCRAT_HPP
|
||||
|
||||
# include <ostream>
|
||||
# include <string>
|
||||
# include <iostream>
|
||||
|
||||
class Bureaucrat{
|
||||
public:
|
||||
|
||||
Bureaucrat(int grade, std::string name);
|
||||
Bureaucrat(const Bureaucrat& copy);
|
||||
~Bureaucrat();
|
||||
Bureaucrat &operator=(const Bureaucrat& rhs);
|
||||
|
||||
const std::string getName() const;
|
||||
int getGrade() const;
|
||||
void upGrade();
|
||||
void downGrade();
|
||||
void checkGrade() const;
|
||||
|
||||
class GradeTooLowException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Bureaucrat grade is too low\n");
|
||||
}
|
||||
};
|
||||
|
||||
class GradeTooHighException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Bureaucrat grade is too high\n");
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
std::string const _name;
|
||||
int _grade;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat);
|
||||
|
||||
#endif
|
||||
38
cpp05/ex00/Makefile
Normal file
38
cpp05/ex00/Makefile
Normal file
@ -0,0 +1,38 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/07/18 21:34:54 by apommier #+# #+# #
|
||||
# Updated: 2022/07/19 10:52:12 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = a.out
|
||||
SRCS = main.cpp\
|
||||
Bureaucrat.cpp
|
||||
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
clean:
|
||||
@${RM} ${OBJS}
|
||||
|
||||
fclean: clean
|
||||
@${RM} ${NAME}
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
27
cpp05/ex00/main.cpp
Normal file
27
cpp05/ex00/main.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 21:34:45 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 11:32:05 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Bureaucrat.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
Bureaucrat First(151, "john");
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
std::cout << e.what();
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
87
cpp05/ex01/Bureaucrat.cpp
Normal file
87
cpp05/ex01/Bureaucrat.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Bureaucrat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 21:34:42 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 12:55:48 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Bureaucrat.hpp"
|
||||
|
||||
Bureaucrat::Bureaucrat(int grade, std::string name) : _name(name)
|
||||
{
|
||||
this->_grade = grade;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
Bureaucrat::Bureaucrat(const Bureaucrat& copy)
|
||||
{
|
||||
*this = copy;
|
||||
}
|
||||
|
||||
Bureaucrat::~Bureaucrat()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Bureaucrat &Bureaucrat::operator=(const Bureaucrat& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
std::cout << "Only grade can be copied, name is const\n";
|
||||
this->_grade = rhs.getGrade();
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat)
|
||||
{
|
||||
out << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade();
|
||||
return (out);
|
||||
}
|
||||
|
||||
const std::string Bureaucrat::getName() const
|
||||
{
|
||||
return (this->_name);
|
||||
}
|
||||
|
||||
int Bureaucrat::getGrade() const
|
||||
{
|
||||
return (this->_grade);
|
||||
}
|
||||
|
||||
void Bureaucrat::upGrade()
|
||||
{
|
||||
this->_grade--;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
void Bureaucrat::downGrade()
|
||||
{
|
||||
this->_grade++;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
void Bureaucrat::checkGrade() const
|
||||
{
|
||||
if (this->_grade > 150)
|
||||
throw Bureaucrat::GradeTooLowException();
|
||||
else if (this->_grade < 1)
|
||||
throw Bureaucrat::GradeTooHighException();
|
||||
}
|
||||
|
||||
void Bureaucrat::signForm(Form form)
|
||||
{
|
||||
try
|
||||
{
|
||||
form.beSigned(*this);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
std::cout << this->_name << " couldn’t sign " << form.getName() << " form because "<< e.what();
|
||||
}
|
||||
}
|
||||
65
cpp05/ex01/Bureaucrat.hpp
Normal file
65
cpp05/ex01/Bureaucrat.hpp
Normal file
@ -0,0 +1,65 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Bureaucrat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 21:34:43 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 12:52:52 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BUREAUCRAT_HPP
|
||||
# define BUREAUCRAT_HPP
|
||||
|
||||
# include <ostream>
|
||||
# include <string>
|
||||
# include <iostream>
|
||||
# include "Form.hpp"
|
||||
|
||||
class Form;
|
||||
|
||||
class Bureaucrat{
|
||||
public:
|
||||
|
||||
Bureaucrat(int grade, std::string name);
|
||||
Bureaucrat(const Bureaucrat& copy);
|
||||
~Bureaucrat();
|
||||
Bureaucrat &operator=(const Bureaucrat& rhs);
|
||||
|
||||
const std::string getName() const;
|
||||
int getGrade() const;
|
||||
void upGrade();
|
||||
void downGrade();
|
||||
void checkGrade() const;
|
||||
|
||||
void signForm(Form form);
|
||||
|
||||
class GradeTooLowException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Bureaucrat grade is too low\n");
|
||||
}
|
||||
};
|
||||
|
||||
class GradeTooHighException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Bureaucrat grade is too high\n");
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
std::string const _name;
|
||||
int _grade;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat);
|
||||
|
||||
#endif
|
||||
94
cpp05/ex01/Form.cpp
Normal file
94
cpp05/ex01/Form.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Form.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 11:54:01 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 12:54:48 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Form.hpp"
|
||||
|
||||
Form::Form(int signedGrade, int executionGrade, std::string name) : _name(name)
|
||||
{
|
||||
this->_signedGrade = signedGrade;
|
||||
this->_executionGrade = executionGrade;
|
||||
this->_isSigned = 0;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
Form::Form(const Form& copy)
|
||||
{
|
||||
*this = copy;
|
||||
}
|
||||
|
||||
Form::~Form()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Form &Form::operator=(const Form& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
std::cout << "Only grade can be copied, name is const\n";
|
||||
this->_signedGrade = rhs.getSignedGrade();
|
||||
this->_executionGrade = rhs.getExecutionGrade();
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Form &form)
|
||||
{
|
||||
out << form.getName() << "form need at least " << form.getSignedGrade() << " grade to be signed and ";
|
||||
out << form.getExecutionGrade() << " grade to be executed, ";
|
||||
if (form.getIsSigned())
|
||||
out << form.getName() << " form is signed\n";
|
||||
else
|
||||
out << form.getName() << " form isn't signed\n";
|
||||
return (out);
|
||||
}
|
||||
|
||||
int Form::getSignedGrade() const
|
||||
{
|
||||
return (this->_signedGrade);
|
||||
}
|
||||
|
||||
int Form::getExecutionGrade() const
|
||||
{
|
||||
return (this->_executionGrade);
|
||||
}
|
||||
|
||||
int Form::getIsSigned() const
|
||||
{
|
||||
return (this->_isSigned);
|
||||
}
|
||||
|
||||
const std::string Form::getName() const
|
||||
{
|
||||
return (this->_name);
|
||||
}
|
||||
|
||||
void Form::beSigned(Bureaucrat &bureaucrat)
|
||||
{
|
||||
if (bureaucrat.getGrade() > this->_signedGrade)
|
||||
throw Form::signedGradeTooLowException();
|
||||
else
|
||||
{
|
||||
this->_isSigned = 1;
|
||||
std::cout << bureaucrat.getName() << " signed " << this->_name << " form\n";
|
||||
}
|
||||
}
|
||||
|
||||
void Form::checkGrade() const
|
||||
{
|
||||
if (this->_signedGrade > 150 || this->_executionGrade > 150)
|
||||
throw Form::GradeTooLowException();
|
||||
else if (this->_signedGrade < 1 || this->_executionGrade < 1)
|
||||
throw Form::GradeTooHighException();
|
||||
}
|
||||
|
||||
|
||||
77
cpp05/ex01/Form.hpp
Normal file
77
cpp05/ex01/Form.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Form.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 11:54:09 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 12:52:43 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FORM_HPP
|
||||
# define FORM_HPP
|
||||
|
||||
# include <ostream>
|
||||
# include <string>
|
||||
# include <iostream>
|
||||
# include "Bureaucrat.hpp"
|
||||
|
||||
class Bureaucrat;
|
||||
|
||||
class Form{
|
||||
public :
|
||||
|
||||
Form(int signedGrade, int executionGrade, std::string name);
|
||||
Form(const Form& copy);
|
||||
~Form();
|
||||
Form &operator=(const Form& rhs);
|
||||
|
||||
const std::string getName() const;
|
||||
int getSignedGrade() const;
|
||||
int getExecutionGrade() const;
|
||||
int getIsSigned() const;
|
||||
|
||||
void checkGrade() const;
|
||||
|
||||
void beSigned(Bureaucrat &bureaucrat);
|
||||
|
||||
class GradeTooLowException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Signed or Execution grade is too low\n");
|
||||
}
|
||||
};
|
||||
|
||||
class GradeTooHighException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Signed or Execution grade is too high\n");
|
||||
}
|
||||
};
|
||||
|
||||
class signedGradeTooLowException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Signed grade is too low\n");
|
||||
}
|
||||
};
|
||||
|
||||
private :
|
||||
|
||||
std::string const _name;
|
||||
bool _isSigned;
|
||||
int _signedGrade;
|
||||
int _executionGrade;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Form &form);
|
||||
|
||||
#endif
|
||||
39
cpp05/ex01/Makefile
Normal file
39
cpp05/ex01/Makefile
Normal file
@ -0,0 +1,39 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/07/18 21:34:54 by apommier #+# #+# #
|
||||
# Updated: 2022/07/19 12:02:15 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = a.out
|
||||
SRCS = main.cpp\
|
||||
Bureaucrat.cpp\
|
||||
Form.cpp
|
||||
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
clean:
|
||||
@${RM} ${OBJS}
|
||||
|
||||
fclean: clean
|
||||
@${RM} ${NAME}
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
28
cpp05/ex01/main.cpp
Normal file
28
cpp05/ex01/main.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 21:34:45 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 12:42:13 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Form.hpp"
|
||||
#include "Bureaucrat.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
Bureaucrat First(151, "john");
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
std::cout << e.what();
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
87
cpp05/ex02/Bureaucrat.cpp
Normal file
87
cpp05/ex02/Bureaucrat.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Bureaucrat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 21:34:42 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 12:55:48 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Bureaucrat.hpp"
|
||||
|
||||
Bureaucrat::Bureaucrat(int grade, std::string name) : _name(name)
|
||||
{
|
||||
this->_grade = grade;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
Bureaucrat::Bureaucrat(const Bureaucrat& copy)
|
||||
{
|
||||
*this = copy;
|
||||
}
|
||||
|
||||
Bureaucrat::~Bureaucrat()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Bureaucrat &Bureaucrat::operator=(const Bureaucrat& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
std::cout << "Only grade can be copied, name is const\n";
|
||||
this->_grade = rhs.getGrade();
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat)
|
||||
{
|
||||
out << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade();
|
||||
return (out);
|
||||
}
|
||||
|
||||
const std::string Bureaucrat::getName() const
|
||||
{
|
||||
return (this->_name);
|
||||
}
|
||||
|
||||
int Bureaucrat::getGrade() const
|
||||
{
|
||||
return (this->_grade);
|
||||
}
|
||||
|
||||
void Bureaucrat::upGrade()
|
||||
{
|
||||
this->_grade--;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
void Bureaucrat::downGrade()
|
||||
{
|
||||
this->_grade++;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
void Bureaucrat::checkGrade() const
|
||||
{
|
||||
if (this->_grade > 150)
|
||||
throw Bureaucrat::GradeTooLowException();
|
||||
else if (this->_grade < 1)
|
||||
throw Bureaucrat::GradeTooHighException();
|
||||
}
|
||||
|
||||
void Bureaucrat::signForm(Form form)
|
||||
{
|
||||
try
|
||||
{
|
||||
form.beSigned(*this);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
std::cout << this->_name << " couldn’t sign " << form.getName() << " form because "<< e.what();
|
||||
}
|
||||
}
|
||||
65
cpp05/ex02/Bureaucrat.hpp
Normal file
65
cpp05/ex02/Bureaucrat.hpp
Normal file
@ -0,0 +1,65 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Bureaucrat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 21:34:43 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 12:52:52 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BUREAUCRAT_HPP
|
||||
# define BUREAUCRAT_HPP
|
||||
|
||||
# include <ostream>
|
||||
# include <string>
|
||||
# include <iostream>
|
||||
# include "Form.hpp"
|
||||
|
||||
class Form;
|
||||
|
||||
class Bureaucrat{
|
||||
public:
|
||||
|
||||
Bureaucrat(int grade, std::string name);
|
||||
Bureaucrat(const Bureaucrat& copy);
|
||||
~Bureaucrat();
|
||||
Bureaucrat &operator=(const Bureaucrat& rhs);
|
||||
|
||||
const std::string getName() const;
|
||||
int getGrade() const;
|
||||
void upGrade();
|
||||
void downGrade();
|
||||
void checkGrade() const;
|
||||
|
||||
void signForm(Form form);
|
||||
|
||||
class GradeTooLowException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Bureaucrat grade is too low\n");
|
||||
}
|
||||
};
|
||||
|
||||
class GradeTooHighException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Bureaucrat grade is too high\n");
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
std::string const _name;
|
||||
int _grade;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat);
|
||||
|
||||
#endif
|
||||
94
cpp05/ex02/Form.cpp
Normal file
94
cpp05/ex02/Form.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Form.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 11:54:01 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 12:54:48 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Form.hpp"
|
||||
|
||||
Form::Form(int signedGrade, int executionGrade, std::string name) : _name(name)
|
||||
{
|
||||
this->_signedGrade = signedGrade;
|
||||
this->_executionGrade = executionGrade;
|
||||
this->_isSigned = 0;
|
||||
this->checkGrade();
|
||||
}
|
||||
|
||||
Form::Form(const Form& copy)
|
||||
{
|
||||
*this = copy;
|
||||
}
|
||||
|
||||
Form::~Form()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Form &Form::operator=(const Form& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
std::cout << "Only grade can be copied, name is const\n";
|
||||
this->_signedGrade = rhs.getSignedGrade();
|
||||
this->_executionGrade = rhs.getExecutionGrade();
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Form &form)
|
||||
{
|
||||
out << form.getName() << "form need at least " << form.getSignedGrade() << " grade to be signed and ";
|
||||
out << form.getExecutionGrade() << " grade to be executed, ";
|
||||
if (form.getIsSigned())
|
||||
out << form.getName() << " form is signed\n";
|
||||
else
|
||||
out << form.getName() << " form isn't signed\n";
|
||||
return (out);
|
||||
}
|
||||
|
||||
int Form::getSignedGrade() const
|
||||
{
|
||||
return (this->_signedGrade);
|
||||
}
|
||||
|
||||
int Form::getExecutionGrade() const
|
||||
{
|
||||
return (this->_executionGrade);
|
||||
}
|
||||
|
||||
int Form::getIsSigned() const
|
||||
{
|
||||
return (this->_isSigned);
|
||||
}
|
||||
|
||||
const std::string Form::getName() const
|
||||
{
|
||||
return (this->_name);
|
||||
}
|
||||
|
||||
void Form::beSigned(Bureaucrat &bureaucrat)
|
||||
{
|
||||
if (bureaucrat.getGrade() > this->_signedGrade)
|
||||
throw Form::signedGradeTooLowException();
|
||||
else
|
||||
{
|
||||
this->_isSigned = 1;
|
||||
std::cout << bureaucrat.getName() << " signed " << this->_name << " form\n";
|
||||
}
|
||||
}
|
||||
|
||||
void Form::checkGrade() const
|
||||
{
|
||||
if (this->_signedGrade > 150 || this->_executionGrade > 150)
|
||||
throw Form::GradeTooLowException();
|
||||
else if (this->_signedGrade < 1 || this->_executionGrade < 1)
|
||||
throw Form::GradeTooHighException();
|
||||
}
|
||||
|
||||
|
||||
77
cpp05/ex02/Form.hpp
Normal file
77
cpp05/ex02/Form.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Form.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 11:54:09 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 12:52:43 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FORM_HPP
|
||||
# define FORM_HPP
|
||||
|
||||
# include <ostream>
|
||||
# include <string>
|
||||
# include <iostream>
|
||||
# include "Bureaucrat.hpp"
|
||||
|
||||
class Bureaucrat;
|
||||
|
||||
class Form{
|
||||
public :
|
||||
|
||||
Form(int signedGrade, int executionGrade, std::string name);
|
||||
Form(const Form& copy);
|
||||
~Form();
|
||||
Form &operator=(const Form& rhs);
|
||||
|
||||
const std::string getName() const;
|
||||
int getSignedGrade() const;
|
||||
int getExecutionGrade() const;
|
||||
int getIsSigned() const;
|
||||
|
||||
void checkGrade() const;
|
||||
|
||||
void beSigned(Bureaucrat &bureaucrat);
|
||||
|
||||
class GradeTooLowException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Signed or Execution grade is too low\n");
|
||||
}
|
||||
};
|
||||
|
||||
class GradeTooHighException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Signed or Execution grade is too high\n");
|
||||
}
|
||||
};
|
||||
|
||||
class signedGradeTooLowException : public std::exception
|
||||
{
|
||||
public :
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return ("Signed grade is too low\n");
|
||||
}
|
||||
};
|
||||
|
||||
private :
|
||||
|
||||
std::string const _name;
|
||||
bool _isSigned;
|
||||
int _signedGrade;
|
||||
int _executionGrade;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Form &form);
|
||||
|
||||
#endif
|
||||
39
cpp05/ex02/Makefile
Normal file
39
cpp05/ex02/Makefile
Normal file
@ -0,0 +1,39 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/07/18 21:34:54 by apommier #+# #+# #
|
||||
# Updated: 2022/07/19 12:02:15 by apommier ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = a.out
|
||||
SRCS = main.cpp\
|
||||
Bureaucrat.cpp\
|
||||
Form.cpp
|
||||
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
$(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o)
|
||||
|
||||
${NAME}: ${OBJS}
|
||||
${CC} ${LIB} ${OBJS} -o ${NAME}
|
||||
|
||||
all: ${NAME}
|
||||
|
||||
clean:
|
||||
@${RM} ${OBJS}
|
||||
|
||||
fclean: clean
|
||||
@${RM} ${NAME}
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
28
cpp05/ex02/main.cpp
Normal file
28
cpp05/ex02/main.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 21:34:45 by apommier #+# #+# */
|
||||
/* Updated: 2022/07/19 12:42:13 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Form.hpp"
|
||||
#include "Bureaucrat.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
Bureaucrat First(151, "john");
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
std::cout << e.what();
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user