diff --git a/cpp00/ex00/Makefile b/cpp00/ex00/Makefile index eca33fe..72b2288 100644 --- a/cpp00/ex00/Makefile +++ b/cpp00/ex00/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp00/ex01/Makefile b/cpp00/ex01/Makefile index f454103..ca0aefa 100644 --- a/cpp00/ex01/Makefile +++ b/cpp00/ex01/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp00/ex02/Makefile b/cpp00/ex02/Makefile index eca33fe..72b2288 100644 --- a/cpp00/ex02/Makefile +++ b/cpp00/ex02/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp01/ex00/Makefile b/cpp01/ex00/Makefile index ac3b762..e6c3e08 100644 --- a/cpp01/ex00/Makefile +++ b/cpp01/ex00/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp01/ex01/Makefile b/cpp01/ex01/Makefile index 3805900..c11fc69 100644 --- a/cpp01/ex01/Makefile +++ b/cpp01/ex01/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp01/ex02/Makefile b/cpp01/ex02/Makefile index f5a90ab..34dabfa 100644 --- a/cpp01/ex02/Makefile +++ b/cpp01/ex02/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp01/ex03/Makefile b/cpp01/ex03/Makefile index 1ea0008..d1c5938 100644 --- a/cpp01/ex03/Makefile +++ b/cpp01/ex03/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp01/ex04/Makefile b/cpp01/ex04/Makefile index 784caf7..a2f0004 100644 --- a/cpp01/ex04/Makefile +++ b/cpp01/ex04/Makefile @@ -6,19 +6,21 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp01/ex04/main.cpp b/cpp01/ex04/main.cpp index 9aa18a0..b7551d6 100644 --- a/cpp01/ex04/main.cpp +++ b/cpp01/ex04/main.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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"; diff --git a/cpp01/ex05/Harl.cpp b/cpp01/ex05/Harl.cpp index ec995d1..70ec64e 100644 --- a/cpp01/ex05/Harl.cpp +++ b/cpp01/ex05/Harl.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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++) { diff --git a/cpp01/ex05/Makefile b/cpp01/ex05/Makefile index b8710e1..8232634 100644 --- a/cpp01/ex05/Makefile +++ b/cpp01/ex05/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp01/ex06/Makefile b/cpp01/ex06/Makefile index 275de67..20a5614 100644 --- a/cpp01/ex06/Makefile +++ b/cpp01/ex06/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp02/ex00/Makefile b/cpp02/ex00/Makefile index 02ca3e9..8f7c7eb 100644 --- a/cpp02/ex00/Makefile +++ b/cpp02/ex00/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp02/ex01/Makefile b/cpp02/ex01/Makefile index 987f17b..fc8ee60 100644 --- a/cpp02/ex01/Makefile +++ b/cpp02/ex01/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp02/ex02/Fixed.cpp b/cpp02/ex02/Fixed.cpp index 7b6f597..2076e95 100644 --- a/cpp02/ex02/Fixed.cpp +++ b/cpp02/ex02/Fixed.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/cpp02/ex02/Makefile b/cpp02/ex02/Makefile index 987f17b..dc327d9 100644 --- a/cpp02/ex02/Makefile +++ b/cpp02/ex02/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp03/ex00/Makefile b/cpp03/ex00/Makefile index 62c477e..e57ce3e 100644 --- a/cpp03/ex00/Makefile +++ b/cpp03/ex00/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp03/ex01/Makefile b/cpp03/ex01/Makefile index 71af1ed..403fc25 100644 --- a/cpp03/ex01/Makefile +++ b/cpp03/ex01/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp03/ex02/ClapTrap.hpp b/cpp03/ex02/ClapTrap.hpp index 4e19760..6af74c9 100644 --- a/cpp03/ex02/ClapTrap.hpp +++ b/cpp03/ex02/ClapTrap.hpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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(); diff --git a/cpp03/ex02/Makefile b/cpp03/ex02/Makefile index be3bfe9..a81e65e 100644 --- a/cpp03/ex02/Makefile +++ b/cpp03/ex02/Makefile @@ -6,7 +6,7 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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} diff --git a/cpp04/ex00/Animal.cpp b/cpp04/ex00/Animal.cpp new file mode 100644 index 0000000..fa26286 --- /dev/null +++ b/cpp04/ex00/Animal.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/cpp04/ex00/Animal.hpp b/cpp04/ex00/Animal.hpp new file mode 100644 index 0000000..c9b45a2 --- /dev/null +++ b/cpp04/ex00/Animal.hpp @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +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 \ No newline at end of file diff --git a/cpp04/ex00/Cat.cpp b/cpp04/ex00/Cat.cpp new file mode 100644 index 0000000..df57bd8 --- /dev/null +++ b/cpp04/ex00/Cat.cpp @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/cpp04/ex00/Cat.hpp b/cpp04/ex00/Cat.hpp new file mode 100644 index 0000000..7341da5 --- /dev/null +++ b/cpp04/ex00/Cat.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 \ No newline at end of file diff --git a/cpp04/ex00/Dog.cpp b/cpp04/ex00/Dog.cpp new file mode 100644 index 0000000..494c78c --- /dev/null +++ b/cpp04/ex00/Dog.cpp @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/cpp04/ex00/Dog.hpp b/cpp04/ex00/Dog.hpp new file mode 100644 index 0000000..ab40463 --- /dev/null +++ b/cpp04/ex00/Dog.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 \ No newline at end of file diff --git a/cpp04/ex00/Makefile b/cpp04/ex00/Makefile new file mode 100644 index 0000000..c62d3a8 --- /dev/null +++ b/cpp04/ex00/Makefile @@ -0,0 +1,42 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/cpp04/ex00/WrongAnimal.cpp b/cpp04/ex00/WrongAnimal.cpp new file mode 100644 index 0000000..093a07a --- /dev/null +++ b/cpp04/ex00/WrongAnimal.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/cpp04/ex00/WrongAnimal.hpp b/cpp04/ex00/WrongAnimal.hpp new file mode 100644 index 0000000..a8b8cd1 --- /dev/null +++ b/cpp04/ex00/WrongAnimal.hpp @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#include + +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 \ No newline at end of file diff --git a/cpp04/ex00/WrongCat.cpp b/cpp04/ex00/WrongCat.cpp new file mode 100644 index 0000000..cf8faed --- /dev/null +++ b/cpp04/ex00/WrongCat.cpp @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/cpp04/ex00/WrongCat.hpp b/cpp04/ex00/WrongCat.hpp new file mode 100644 index 0000000..4026b11 --- /dev/null +++ b/cpp04/ex00/WrongCat.hpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 \ No newline at end of file diff --git a/cpp04/ex00/main.cpp b/cpp04/ex00/main.cpp new file mode 100644 index 0000000..33a9f44 --- /dev/null +++ b/cpp04/ex00/main.cpp @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} \ No newline at end of file diff --git a/cpp04/ex01/Animal.cpp b/cpp04/ex01/Animal.cpp new file mode 100644 index 0000000..fc947b4 --- /dev/null +++ b/cpp04/ex01/Animal.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} \ No newline at end of file diff --git a/cpp04/ex01/Animal.hpp b/cpp04/ex01/Animal.hpp new file mode 100644 index 0000000..a2f9dbe --- /dev/null +++ b/cpp04/ex01/Animal.hpp @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +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 \ No newline at end of file diff --git a/cpp04/ex01/Brain.cpp b/cpp04/ex01/Brain.cpp new file mode 100644 index 0000000..8607f7f --- /dev/null +++ b/cpp04/ex01/Brain.cpp @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/cpp04/ex01/Brain.hpp b/cpp04/ex01/Brain.hpp new file mode 100644 index 0000000..f77458a --- /dev/null +++ b/cpp04/ex01/Brain.hpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#include + + +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 \ No newline at end of file diff --git a/cpp04/ex01/Cat.cpp b/cpp04/ex01/Cat.cpp new file mode 100644 index 0000000..894bfb0 --- /dev/null +++ b/cpp04/ex01/Cat.cpp @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/cpp04/ex01/Cat.hpp b/cpp04/ex01/Cat.hpp new file mode 100644 index 0000000..332984c --- /dev/null +++ b/cpp04/ex01/Cat.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 \ No newline at end of file diff --git a/cpp04/ex01/Dog.cpp b/cpp04/ex01/Dog.cpp new file mode 100644 index 0000000..a0ec1d2 --- /dev/null +++ b/cpp04/ex01/Dog.cpp @@ -0,0 +1,66 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/cpp04/ex01/Dog.hpp b/cpp04/ex01/Dog.hpp new file mode 100644 index 0000000..7cc6705 --- /dev/null +++ b/cpp04/ex01/Dog.hpp @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 \ No newline at end of file diff --git a/cpp04/ex01/Makefile b/cpp04/ex01/Makefile new file mode 100644 index 0000000..c9a8ac1 --- /dev/null +++ b/cpp04/ex01/Makefile @@ -0,0 +1,43 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/cpp04/ex01/WrongAnimal.cpp b/cpp04/ex01/WrongAnimal.cpp new file mode 100644 index 0000000..093a07a --- /dev/null +++ b/cpp04/ex01/WrongAnimal.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/cpp04/ex01/WrongAnimal.hpp b/cpp04/ex01/WrongAnimal.hpp new file mode 100644 index 0000000..a8b8cd1 --- /dev/null +++ b/cpp04/ex01/WrongAnimal.hpp @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#include + +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 \ No newline at end of file diff --git a/cpp04/ex01/WrongCat.cpp b/cpp04/ex01/WrongCat.cpp new file mode 100644 index 0000000..cf8faed --- /dev/null +++ b/cpp04/ex01/WrongCat.cpp @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/cpp04/ex01/WrongCat.hpp b/cpp04/ex01/WrongCat.hpp new file mode 100644 index 0000000..4026b11 --- /dev/null +++ b/cpp04/ex01/WrongCat.hpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 \ No newline at end of file diff --git a/cpp04/ex01/main.cpp b/cpp04/ex01/main.cpp new file mode 100644 index 0000000..d428e4b --- /dev/null +++ b/cpp04/ex01/main.cpp @@ -0,0 +1,79 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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]; +} \ No newline at end of file diff --git a/cpp04/ex02/Animal.cpp b/cpp04/ex02/Animal.cpp new file mode 100644 index 0000000..fc947b4 --- /dev/null +++ b/cpp04/ex02/Animal.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} \ No newline at end of file diff --git a/cpp04/ex02/Animal.hpp b/cpp04/ex02/Animal.hpp new file mode 100644 index 0000000..8010e3c --- /dev/null +++ b/cpp04/ex02/Animal.hpp @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +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 \ No newline at end of file diff --git a/cpp04/ex02/Brain.cpp b/cpp04/ex02/Brain.cpp new file mode 100644 index 0000000..8607f7f --- /dev/null +++ b/cpp04/ex02/Brain.cpp @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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; +} diff --git a/cpp04/ex02/Brain.hpp b/cpp04/ex02/Brain.hpp new file mode 100644 index 0000000..f77458a --- /dev/null +++ b/cpp04/ex02/Brain.hpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#include + + +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 \ No newline at end of file diff --git a/cpp04/ex02/Cat.cpp b/cpp04/ex02/Cat.cpp new file mode 100644 index 0000000..894bfb0 --- /dev/null +++ b/cpp04/ex02/Cat.cpp @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/cpp04/ex02/Cat.hpp b/cpp04/ex02/Cat.hpp new file mode 100644 index 0000000..332984c --- /dev/null +++ b/cpp04/ex02/Cat.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 \ No newline at end of file diff --git a/cpp04/ex02/Dog.cpp b/cpp04/ex02/Dog.cpp new file mode 100644 index 0000000..a0ec1d2 --- /dev/null +++ b/cpp04/ex02/Dog.cpp @@ -0,0 +1,66 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/cpp04/ex02/Dog.hpp b/cpp04/ex02/Dog.hpp new file mode 100644 index 0000000..7cc6705 --- /dev/null +++ b/cpp04/ex02/Dog.hpp @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 \ No newline at end of file diff --git a/cpp04/ex02/Makefile b/cpp04/ex02/Makefile new file mode 100644 index 0000000..c9a8ac1 --- /dev/null +++ b/cpp04/ex02/Makefile @@ -0,0 +1,43 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/cpp04/ex02/WrongAnimal.cpp b/cpp04/ex02/WrongAnimal.cpp new file mode 100644 index 0000000..093a07a --- /dev/null +++ b/cpp04/ex02/WrongAnimal.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/cpp04/ex02/WrongAnimal.hpp b/cpp04/ex02/WrongAnimal.hpp new file mode 100644 index 0000000..a8b8cd1 --- /dev/null +++ b/cpp04/ex02/WrongAnimal.hpp @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#include + +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 \ No newline at end of file diff --git a/cpp04/ex02/WrongCat.cpp b/cpp04/ex02/WrongCat.cpp new file mode 100644 index 0000000..cf8faed --- /dev/null +++ b/cpp04/ex02/WrongCat.cpp @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/cpp04/ex02/WrongCat.hpp b/cpp04/ex02/WrongCat.hpp new file mode 100644 index 0000000..4026b11 --- /dev/null +++ b/cpp04/ex02/WrongCat.hpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 \ No newline at end of file diff --git a/cpp04/ex02/main.cpp b/cpp04/ex02/main.cpp new file mode 100644 index 0000000..0a3094b --- /dev/null +++ b/cpp04/ex02/main.cpp @@ -0,0 +1,79 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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]; +} \ No newline at end of file diff --git a/cpp05/ex00/Bureaucrat.cpp b/cpp05/ex00/Bureaucrat.cpp new file mode 100644 index 0000000..54c0a61 --- /dev/null +++ b/cpp05/ex00/Bureaucrat.cpp @@ -0,0 +1,76 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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(); +} + diff --git a/cpp05/ex00/Bureaucrat.hpp b/cpp05/ex00/Bureaucrat.hpp new file mode 100644 index 0000000..fd244b0 --- /dev/null +++ b/cpp05/ex00/Bureaucrat.hpp @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +# include +# include + +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 \ No newline at end of file diff --git a/cpp05/ex00/Makefile b/cpp05/ex00/Makefile new file mode 100644 index 0000000..960a5d3 --- /dev/null +++ b/cpp05/ex00/Makefile @@ -0,0 +1,38 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/cpp05/ex00/main.cpp b/cpp05/ex00/main.cpp new file mode 100644 index 0000000..92e1bee --- /dev/null +++ b/cpp05/ex00/main.cpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/cpp05/ex01/Bureaucrat.cpp b/cpp05/ex01/Bureaucrat.cpp new file mode 100644 index 0000000..daef1f9 --- /dev/null +++ b/cpp05/ex01/Bureaucrat.cpp @@ -0,0 +1,87 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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(); + } +} diff --git a/cpp05/ex01/Bureaucrat.hpp b/cpp05/ex01/Bureaucrat.hpp new file mode 100644 index 0000000..c691d87 --- /dev/null +++ b/cpp05/ex01/Bureaucrat.hpp @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +# include +# include +# 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 \ No newline at end of file diff --git a/cpp05/ex01/Form.cpp b/cpp05/ex01/Form.cpp new file mode 100644 index 0000000..63c8b19 --- /dev/null +++ b/cpp05/ex01/Form.cpp @@ -0,0 +1,94 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Form.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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(); +} + + diff --git a/cpp05/ex01/Form.hpp b/cpp05/ex01/Form.hpp new file mode 100644 index 0000000..e834d4a --- /dev/null +++ b/cpp05/ex01/Form.hpp @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Form.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +# include +# include +# 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 \ No newline at end of file diff --git a/cpp05/ex01/Makefile b/cpp05/ex01/Makefile new file mode 100644 index 0000000..709b26e --- /dev/null +++ b/cpp05/ex01/Makefile @@ -0,0 +1,39 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/cpp05/ex01/main.cpp b/cpp05/ex01/main.cpp new file mode 100644 index 0000000..3f14eb3 --- /dev/null +++ b/cpp05/ex01/main.cpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file diff --git a/cpp05/ex02/Bureaucrat.cpp b/cpp05/ex02/Bureaucrat.cpp new file mode 100644 index 0000000..daef1f9 --- /dev/null +++ b/cpp05/ex02/Bureaucrat.cpp @@ -0,0 +1,87 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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(); + } +} diff --git a/cpp05/ex02/Bureaucrat.hpp b/cpp05/ex02/Bureaucrat.hpp new file mode 100644 index 0000000..c691d87 --- /dev/null +++ b/cpp05/ex02/Bureaucrat.hpp @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +# include +# include +# 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 \ No newline at end of file diff --git a/cpp05/ex02/Form.cpp b/cpp05/ex02/Form.cpp new file mode 100644 index 0000000..63c8b19 --- /dev/null +++ b/cpp05/ex02/Form.cpp @@ -0,0 +1,94 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Form.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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(); +} + + diff --git a/cpp05/ex02/Form.hpp b/cpp05/ex02/Form.hpp new file mode 100644 index 0000000..e834d4a --- /dev/null +++ b/cpp05/ex02/Form.hpp @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Form.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +# include +# include +# 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 \ No newline at end of file diff --git a/cpp05/ex02/Makefile b/cpp05/ex02/Makefile new file mode 100644 index 0000000..709b26e --- /dev/null +++ b/cpp05/ex02/Makefile @@ -0,0 +1,39 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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 \ No newline at end of file diff --git a/cpp05/ex02/main.cpp b/cpp05/ex02/main.cpp new file mode 100644 index 0000000..3f14eb3 --- /dev/null +++ b/cpp05/ex02/main.cpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} \ No newline at end of file