diff --git a/cpp04/ex00/Animal.cpp b/cpp04/ex00/Animal.cpp index b80a082..01f7034 100644 --- a/cpp04/ex00/Animal.cpp +++ b/cpp04/ex00/Animal.cpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:53:47 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:51:30 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,25 @@ #include Animal::Animal() { - std::cout << "[Animal]\tCreating the class" << std::endl; - type = ""; + std::cout << "[Animal]\tCreating Animal class" << std::endl; + type = "Animal"; +} + +Animal::Animal(Animal const & copy) { + std::cout << "[Animal]\tCreating Animal class (copy)" << std::endl; + this->type = copy.type; +} + +Animal & Animal::operator=(Animal const & assign) { + std::cout << "[Animal]\tCreating Animal class (assign)" << std::endl; + this->type = assign.type; + return *this; } Animal::~Animal() { - std::cout << "[Animal]\tDeleting the class" << std::endl; -} - -std::string Animal::getType() const { - return (type); + std::cout << "[Animal]\tDeleting animal class" << std::endl; } void Animal::makeSound() const { - std::cout << "šŸ¤” | thinking how to make a sound" << std::endl; + std::cout << "[Animal]\t🦊 | What does the fox say ?" << std::endl; } diff --git a/cpp04/ex00/Animal.hpp b/cpp04/ex00/Animal.hpp index bfb8474..99d9d0c 100644 --- a/cpp04/ex00/Animal.hpp +++ b/cpp04/ex00/Animal.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:23:05 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:24:40 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,17 +14,17 @@ #define ANIMAL_HPP #include -#include class Animal { public: Animal(); virtual ~Animal(); + Animal(Animal const & copy); + Animal & operator=(Animal const & assign); virtual void makeSound() const; - std::string getType() const; + protected: std::string type; - private: }; #endif diff --git a/cpp04/ex00/Cat.cpp b/cpp04/ex00/Cat.cpp index 5e2ef4c..9c8a160 100644 --- a/cpp04/ex00/Cat.cpp +++ b/cpp04/ex00/Cat.cpp @@ -5,22 +5,34 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:54:03 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:41:28 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Cat.hpp" +#include Cat::Cat() { - std::cout << "[Cat]\t\tCreating the class" << std::endl; + std::cout << "[Cat]\t\tCreating cat class" << std::endl; type = "Cat"; } +Cat::Cat(Cat const & copy) { + std::cout << "[Cat]\t\tCreating cat class (copy)" << std::endl; + this->type = copy.type; +} + +Cat & Cat::operator=(Cat const & assign) { + std::cout << "[Cat]\t\tCreating cat class (assign)" << std::endl; + this->type = assign.type; + return *this; +} + Cat::~Cat() { - std::cout << "[Cat]\t\tDeleting the class" << std::endl; + std::cout << "[Cat]\t\tDeleting cat class" << std::endl; } void Cat::makeSound() const { - std::cout << "🐱 | Meow Meow" << std::endl; + std::cout << "[Cat]\t\t🐱 | Meow meow" << std::endl; } diff --git a/cpp04/ex00/Cat.hpp b/cpp04/ex00/Cat.hpp index f770266..afb4d1f 100644 --- a/cpp04/ex00/Cat.hpp +++ b/cpp04/ex00/Cat.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */ -/* Updated: 2025/01/31 18:24:18 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:26:01 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,17 +14,16 @@ #define CAT_HPP #include "Animal.hpp" -#include class Cat : public Animal { public: Cat(); ~Cat(); + Cat(Cat const & copy); + Cat & operator=(Cat const & assign); virtual void makeSound() const; protected: - - private: - + std::string type; }; #endif diff --git a/cpp04/ex00/Dog.cpp b/cpp04/ex00/Dog.cpp index 7b8c767..cc35c60 100644 --- a/cpp04/ex00/Dog.cpp +++ b/cpp04/ex00/Dog.cpp @@ -5,22 +5,34 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:53:02 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:02 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:51:41 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Dog.hpp" +#include Dog::Dog() { - std::cout << "[Dog]\t\tCreating the class" << std::endl; + std::cout << "[Dog]\t\tCreating Dog class" << std::endl; type = "Dog"; } +Dog::Dog(Dog const & copy) { + std::cout << "[Dog]\t\tCreating Dog class (copy)" << std::endl; + this->type = copy.type; +} + +Dog & Dog::operator=(Dog const & assign) { + std::cout << "[Dog]\t\tCreating Dog class (assign)" << std::endl; + this->type = assign.type; + return *this; +} + Dog::~Dog() { - std::cout << "[Dog]\t\tDeleting the class" << std::endl; + std::cout << "[Dog]\t\tDeleting dog class" << std::endl; } void Dog::makeSound() const { - std::cout << "🐶 | Wouf Wouf" << std::endl; + std::cout << "[Dog]\t\t🐶 | Wouf wouf" << std::endl; } diff --git a/cpp04/ex00/Dog.hpp b/cpp04/ex00/Dog.hpp index 9d67241..2848338 100644 --- a/cpp04/ex00/Dog.hpp +++ b/cpp04/ex00/Dog.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */ -/* Updated: 2025/01/31 18:24:07 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:26:17 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:27:11 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,17 +14,16 @@ #define DOG_HPP #include "Animal.hpp" -#include class Dog : public Animal { public: Dog(); ~Dog(); + Dog(Dog const & copy); + Dog & operator=(Dog const & assign); virtual void makeSound() const; protected: - - private: - + std::string type; }; #endif diff --git a/cpp04/ex00/Makefile b/cpp04/ex00/Makefile index cba237f..b206e0b 100644 --- a/cpp04/ex00/Makefile +++ b/cpp04/ex00/Makefile @@ -1,36 +1,38 @@ # **************************************************************************** # + # ::: :::::::: # # Makefile :+: :+: :+: # # +:+ +:+ +:+ # # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/12/21 19:50:58 by rparodi ### ########.fr # +# Updated: 2025/02/18 16:50:42 by rparodi ### ########.fr # # # # **************************************************************************** # # Variables # Name -NAME = polymorphism +NAME = open # Commands CXX = c++ RM = rm -rf # Flags -# Mandatory flags for 42 +# Mandatory flags for 42 cpp CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/ # Flags to debug and have the dependences (can be removed for correction) CXXFLAGS += -MMD -g3 - +# Flag to debug (TO REMOVE) +# CXXFLAGS += -D DEBUG=1 # Sources -SRC = Animal.cpp \ - Cat.cpp \ - Dog.cpp \ - WrongAnimal.cpp \ +SRC = main.cpp \ WrongCat.cpp \ - main.cpp + WrongAnimal.cpp \ + Dog.cpp \ + Animal.cpp \ + Cat.cpp # Objects OBJDIRNAME = ./build diff --git a/cpp04/ex00/WrongAnimal.cpp b/cpp04/ex00/WrongAnimal.cpp index 0afff32..2e0292c 100644 --- a/cpp04/ex00/WrongAnimal.cpp +++ b/cpp04/ex00/WrongAnimal.cpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:54:23 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:50:06 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,25 @@ #include WrongAnimal::WrongAnimal() { - std::cout << "[WrongAnimal]\tCreating the class" << std::endl; - type = ""; + std::cout << "[WrongAnimal]\tCreating WrongAnimal class" << std::endl; + type = "WrongAnimal"; +} + +WrongAnimal::WrongAnimal(WrongAnimal const & copy) { + std::cout << "[WrongAnimal]\tCreating WrongAnimal class (copy)" << std::endl; + this->type = copy.type; +} + +WrongAnimal & WrongAnimal::operator=(WrongAnimal const & assign) { + std::cout << "[WrongAnimal]\tCreating WrongAnimal class (assign)" << std::endl; + this->type = assign.type; + return *this; } WrongAnimal::~WrongAnimal() { - std::cout << "[WrongAnimal]\tDeleting the class" << std::endl; -} - -std::string WrongAnimal::getType() const { - return (type); + std::cout << "[WrongAnimal]\tDeleting cat class" << std::endl; } void WrongAnimal::makeSound() const { - std::cout << "🦊 | What does the fox say ?" << std::endl; + std::cout << "[WrongAnimal]\t🦊 | What does the fox say ?" << std::endl; } diff --git a/cpp04/ex00/WrongAnimal.hpp b/cpp04/ex00/WrongAnimal.hpp index 3e13252..f937c40 100644 --- a/cpp04/ex00/WrongAnimal.hpp +++ b/cpp04/ex00/WrongAnimal.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:34:06 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:30:56 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,17 +14,17 @@ #define WRONGANIMAL_HPP #include -#include class WrongAnimal { public: WrongAnimal(); virtual ~WrongAnimal(); - virtual void makeSound() const; - std::string getType() const; + WrongAnimal(WrongAnimal const & copy); + WrongAnimal & operator=(WrongAnimal const & assign); + void makeSound() const; + protected: std::string type; - private: }; #endif diff --git a/cpp04/ex00/WrongCat.cpp b/cpp04/ex00/WrongCat.cpp index 3fa7a60..47bc993 100644 --- a/cpp04/ex00/WrongCat.cpp +++ b/cpp04/ex00/WrongCat.cpp @@ -5,18 +5,34 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ -/* Updated: 2025/02/10 12:48:59 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:53:06 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "WrongCat.hpp" +#include WrongCat::WrongCat() { - std::cout << "[WrongCat]\tCreating the class" << std::endl; + std::cout << "[WrongCat]\t\tCreating WrongCat class" << std::endl; type = "WrongCat"; } -WrongCat::~WrongCat() { - std::cout << "[WrongCat]\tDeleting the class" << std::endl; +WrongCat::WrongCat(WrongCat const & copy) { + std::cout << "[WrongCat]\t\tCreating WrongCat class (copy)" << std::endl; + this->type = copy.type; +} + +WrongCat & WrongCat::operator=(WrongCat const & assign) { + std::cout << "[WrongCat]\t\tCreating WrongCat class (assign)" << std::endl; + this->type = assign.type; + return *this; +} + +WrongCat::~WrongCat() { + std::cout << "[WrongCat]\t\tDeleting WrongCat class" << std::endl; +} + +void WrongCat::makeSound() const { + std::cout << "[WrongCat]\t\t🐱 | Wouf wouf" << std::endl; } diff --git a/cpp04/ex00/WrongCat.hpp b/cpp04/ex00/WrongCat.hpp index 76f621a..c228107 100644 --- a/cpp04/ex00/WrongCat.hpp +++ b/cpp04/ex00/WrongCat.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */ -/* Updated: 2025/02/10 12:49:13 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:48:00 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,16 +14,16 @@ #define WRONGCAT_HPP #include "WrongAnimal.hpp" -#include class WrongCat : public WrongAnimal { public: WrongCat(); ~WrongCat(); + WrongCat(WrongCat const & copy); + WrongCat & operator=(WrongCat const & assign); + virtual void makeSound() const; protected: - - private: - + std::string type; }; #endif diff --git a/cpp04/ex00/color.hpp b/cpp04/ex00/color.hpp new file mode 100644 index 0000000..e1c3f79 --- /dev/null +++ b/cpp04/ex00/color.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* color.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/17 15:27:54 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:43:18 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef COLOR_HPP + #define COLOR_HPP + + #define RESET "\033[0m" + + #define BLACK "\033[0;30m" + #define RED "\033[0;31m" + #define GREEN "\033[0;32m" + #define YELLOW "\033[0;33m" + #define BLUE "\033[0;34m" + #define MAGENTA "\033[0;35m" + #define CYAN "\033[0;36m" + #define WHITE "\033[0;37m" + #define GOLD "\033[38;5;220m" + #define GREY "\033[38;5;240m" + + #define L_BLACK "\033[0;90m" + #define L_RED "\033[0;91m" + #define L_GREEN "\033[0;92m" + #define L_YELLOW "\033[0;93m" + #define L_BLUE "\033[0;94m" + #define L_MAGENTA "\033[0;95m" + #define L_CYAN "\033[0;96m" + #define L_WHITE "\033[0;97m" + + #define B_BLACK "\033[1;30m" + #define B_RED "\033[1;31m" + #define B_GREEN "\033[1;32m" + #define B_YELLOW "\033[1;33m" + #define B_BLUE "\033[1;34m" + #define B_MAGENTA "\033[1;35m" + #define B_CYAN "\033[1;36m" + #define B_WHITE "\033[1;37m" + +#endif diff --git a/cpp04/ex00/main.cpp b/cpp04/ex00/main.cpp index 3d8220d..188b0ba 100644 --- a/cpp04/ex00/main.cpp +++ b/cpp04/ex00/main.cpp @@ -5,46 +5,40 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:52:09 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:11 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:48:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Animal.hpp" -#include "Dog.hpp" #include "Cat.hpp" +#include "Dog.hpp" #include "WrongAnimal.hpp" #include "WrongCat.hpp" +#include "color.hpp" +#include +#include int main() { - std::cout << "\033[0;33m[ Building classes ]\033[0m" << std::endl; - const Animal* meta = new Animal(); - const Animal* j = new Dog(); - const Animal* i = new Cat(); - const WrongAnimal* k = new WrongAnimal(); - const WrongAnimal* l = new WrongCat(); + std::cout << YELLOW << "\t\t[ Constructor ]" << RESET << std::endl; + const Animal* theClassic = new Animal(); + const Animal* theDog = new Dog(); + const Animal* theCat = new Cat(); + const WrongAnimal* theBadAnimal = new WrongAnimal(); + const WrongAnimal* theBadCat = new WrongCat(); - std::cout << std::endl << "\033[0;33m[ Testing the getType method ]\033[0m" << std::endl; - std::cout << "Type of j:\t" << j->getType() << std::endl; - std::cout << "Type of i:\t" << i->getType() << std::endl; - std::cout << "Type of l:\t" << l->getType() << std::endl; + std::cout << std::endl << YELLOW << "\t\t[ Make Sound ]" << RESET << std::endl; + theClassic->makeSound(); + theDog->makeSound(); + theCat->makeSound(); + theBadAnimal->makeSound(); + theBadCat->makeSound(); - std::cout << std::endl << "\033[0;33m[ Testing the makeSound method ]\033[0m" << std::endl; - std::cout << "Sound of meta:\t"; - meta->makeSound(); - std::cout << std::endl << "Sound of i:\t"; - i->makeSound(); - std::cout << std::endl << "Sound of j:\t"; - j->makeSound(); - std::cout << std::endl << "Sound of k:\t"; - k->makeSound(); - std::cout << std::endl << "Sound of l:\t"; - l->makeSound(); - std::cout << std::endl << "\033[0;33m[ Deleting classes ]\033[0m" << std::endl; - delete meta; - delete j; - delete i; - delete k; - delete l; + std::cout << std::endl << YELLOW << "\t\t[ Destructor ]" << RESET << std::endl; + delete theClassic; + delete theDog; + delete theCat; + delete theBadAnimal; + delete theBadCat; return 0; } diff --git a/cpp04/ex01/Animal.cpp b/cpp04/ex01/Animal.cpp index b80a082..b99e8b0 100644 --- a/cpp04/ex01/Animal.cpp +++ b/cpp04/ex01/Animal.cpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:53:47 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */ +/* Updated: 2025/02/18 17:19:20 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,25 @@ #include Animal::Animal() { - std::cout << "[Animal]\tCreating the class" << std::endl; - type = ""; + std::cout << "[Animal]\tCreating Animal class" << std::endl; + type = "Animal"; +} + +Animal::Animal(Animal const & copy) { + std::cout << "[Animal]\tCreating Animal class (copy)" << std::endl; + this->type = copy.type; +} + +Animal & Animal::operator=(Animal const & assign) { + std::cout << "[Animal]\tCreating Animal class (assign)" << std::endl; + this->type = assign.type; + return *this; } Animal::~Animal() { - std::cout << "[Animal]\tDeleting the class" << std::endl; -} - -std::string Animal::getType() const { - return (type); + std::cout << "[Animal]\tDeleting Animal class" << std::endl; } void Animal::makeSound() const { - std::cout << "šŸ¤” | thinking how to make a sound" << std::endl; + std::cout << "[Animal]\t🦊 | What does the fox say ?" << std::endl; } diff --git a/cpp04/ex01/Animal.hpp b/cpp04/ex01/Animal.hpp index bfb8474..f64e2e9 100644 --- a/cpp04/ex01/Animal.hpp +++ b/cpp04/ex01/Animal.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:23:05 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:03:00 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,17 +14,20 @@ #define ANIMAL_HPP #include -#include class Animal { public: Animal(); virtual ~Animal(); + Animal(Animal const & copy); + Animal & operator=(Animal const & assign); virtual void makeSound() const; - std::string getType() const; + virtual Animal* clone() const = 0; + virtual std::string getIdea(int const index) const = 0; + virtual void setIdea(int const index, std::string const idea) const = 0; + protected: std::string type; - private: }; #endif diff --git a/cpp04/ex01/Brain.cpp b/cpp04/ex01/Brain.cpp index 3ed559c..38e9838 100644 --- a/cpp04/ex01/Brain.cpp +++ b/cpp04/ex01/Brain.cpp @@ -5,27 +5,49 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/06 15:17:41 by rparodi #+# #+# */ -/* Updated: 2025/02/07 17:51:50 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:57:51 by rparodi #+# #+# */ +/* Updated: 2025/02/18 18:45:33 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Brain.hpp" +#include #include -#include Brain::Brain() { + std::cout << "[Brain]\t\tCreating Brain class" << std::endl; for (int i = 0; i < 100; i++) { - std::ostringstream oss; - oss << "I'm thinking about the number " << (i + 1); - idea[i] = oss.str(); + std::stringstream oss; + oss << "🧠 | Idea " << (i + 1); + ideas[i] = oss.str(); } } +Brain::Brain(Brain const & copy) { + std::cout << "[Brain]\t\tCreating Brain class (copy)" << std::endl; + for (int i = 0; i < 100; i++) { + this->ideas[i] = std::string(copy.ideas[i]); + } +} + +Brain& Brain::operator=(Brain const & assign) { + if (this != &assign) { + std::cout << "[Brain]\t\tCreating Brain class (assign)" << std::endl; + for (int i = 0; i < 100; i++) { + this->ideas[i] = std::string(assign.ideas[i]); + } + } + return *this; +} + Brain::~Brain() { - + std::cout << "[Brain]\t\tDeleting Brain class" << std::endl; } -Brain& Brain::operator=(Brain &value) { - return (value); +std::string Brain::getIdea(int index) const { + return ideas[index % 100]; +} + +void Brain::setIdea(int index, std::string idea) { + this->ideas[index % 100] = idea; } diff --git a/cpp04/ex01/Brain.hpp b/cpp04/ex01/Brain.hpp index 3e7e09a..c3534f4 100644 --- a/cpp04/ex01/Brain.hpp +++ b/cpp04/ex01/Brain.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/06 15:17:49 by rparodi #+# #+# */ -/* Updated: 2025/02/07 17:51:43 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:58:06 by rparodi #+# #+# */ +/* Updated: 2025/02/18 18:51:23 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,17 +15,16 @@ #include -class Brain { +class Brain { public: Brain(); + Brain(const Brain ©); + Brain& operator=(const Brain &assign); ~Brain(); - std::string idea[100]; - Brain& operator=(Brain &value); - - protected: - + std::string getIdea(int index) const; + void setIdea(int const index, std::string const idea); private: - + std::string ideas[100]; }; #endif diff --git a/cpp04/ex01/Cat.cpp b/cpp04/ex01/Cat.cpp index c045f91..8b477b0 100644 --- a/cpp04/ex01/Cat.cpp +++ b/cpp04/ex01/Cat.cpp @@ -5,24 +5,53 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ -/* Updated: 2025/02/10 12:22:32 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:06:18 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Cat.hpp" +#include Cat::Cat() { - std::cout << "[Cat]\t\tCreating the class" << std::endl; + std::cout << "[Cat]\t\tCreating Cat class" << std::endl; type = "Cat"; brain = new Brain(); } +Cat::Cat(Cat const & copy) { + std::cout << "[Cat]\t\tCreating Cat class (copy)" << std::endl; + this->type = copy.type; + this->brain = new Brain(*copy.brain); +} + +Cat & Cat::operator=(Cat const & assign) { + if (this != &assign) { + std::cout << "[Cat]\t\tCreating Cat class (assign)" << std::endl; + this->type = assign.type; + for (int i = 0; i < 100; i++) + this->brain[i] = assign.brain[i]; + } + return *this; +} + +Cat* Cat::clone() const { + return new Cat(*this); +} + Cat::~Cat() { delete brain; - std::cout << "[Cat]\t\tDeleting the class" << std::endl; + std::cout << "[Cat]\t\tDeleting Cat class" << std::endl; +} + +void Cat::setIdea(int const index, std::string const idea) const { + brain->setIdea(index, idea); +} + +std::string Cat::getIdea(int const index) const { + return brain->getIdea(index); } void Cat::makeSound() const { - std::cout << "🐱 | Meow Meow" << std::endl; + std::cout << "[Cat]\t\t🐱 | Meow meow" << std::endl; } diff --git a/cpp04/ex01/Cat.hpp b/cpp04/ex01/Cat.hpp index 78e9530..7674b37 100644 --- a/cpp04/ex01/Cat.hpp +++ b/cpp04/ex01/Cat.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */ -/* Updated: 2025/02/10 12:20:07 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:05:29 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,17 +15,20 @@ #include "Animal.hpp" #include "Brain.hpp" -#include class Cat : public Animal { public: Cat(); ~Cat(); + Cat(Cat const & copy); + Cat & operator=(Cat const & assign); virtual void makeSound() const; + virtual Cat* clone() const; + std::string getIdea(int const index) const; + void setIdea(int const index, std::string const idea) const; protected: - - private: Brain *brain; + std::string type; }; #endif diff --git a/cpp04/ex01/Dog.cpp b/cpp04/ex01/Dog.cpp index 1eb69f7..33591e8 100644 --- a/cpp04/ex01/Dog.cpp +++ b/cpp04/ex01/Dog.cpp @@ -5,25 +5,50 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */ -/* Updated: 2025/02/10 12:19:22 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:02 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:07:55 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Dog.hpp" -#include "Brain.hpp" +#include Dog::Dog() { - std::cout << "[Dog]\t\tCreating the class" << std::endl; + std::cout << "[Dog]\t\tCreating Dog class" << std::endl; type = "Dog"; brain = new Brain(); } +Dog::Dog(Dog const & copy) { + std::cout << "[Dog]\t\tCreating Dog class (copy)" << std::endl; + this->type = copy.type; + this->brain = new Brain(); +} + +Dog & Dog::operator=(Dog const & assign) { + std::cout << "[Dog]\t\tCreating Dog class (assign)" << std::endl; + (void)assign; + this->brain = new Brain(); + return *this; +} + +std::string Dog::getIdea(int index) const { + return brain->getIdea(index); +} + +void Dog::setIdea(int const index, std::string const idea) const { + return brain->setIdea(index, idea); +} + +Dog* Dog::clone() const { + return new Dog(*this); +} + Dog::~Dog() { delete brain; - std::cout << "[Dog]\t\tDeleting the class" << std::endl; + std::cout << "[Dog]\t\tDeleting Dog class" << std::endl; } void Dog::makeSound() const { - std::cout << "🐶 | Wouf Wouf" << std::endl; + std::cout << "[Dog]\t\t🐶 | Wouf wouf" << std::endl; } diff --git a/cpp04/ex01/Dog.hpp b/cpp04/ex01/Dog.hpp index ba98c5f..5f76e58 100644 --- a/cpp04/ex01/Dog.hpp +++ b/cpp04/ex01/Dog.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */ -/* Updated: 2025/02/07 17:51:39 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:26:17 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:07:56 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,18 +15,20 @@ #include "Animal.hpp" #include "Brain.hpp" -#include class Dog : public Animal { public: Dog(); ~Dog(); + Dog(Dog const & copy); + Dog & operator=(Dog const & assign); virtual void makeSound() const; + std::string getIdea(int const index) const; + void setIdea(int const index, std::string const idea) const; + Dog* clone() const; protected: - - private: Brain *brain; - + std::string type; }; #endif diff --git a/cpp04/ex01/Makefile b/cpp04/ex01/Makefile index 12e6eaa..25e7ca8 100644 --- a/cpp04/ex01/Makefile +++ b/cpp04/ex01/Makefile @@ -1,38 +1,39 @@ # **************************************************************************** # + # ::: :::::::: # # Makefile :+: :+: :+: # # +:+ +:+ +:+ # # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/12/21 19:50:58 by rparodi ### ########.fr # +# Updated: 2025/02/18 17:11:17 by rparodi ### ########.fr # # # # **************************************************************************** # # Variables # Name -NAME = polyformism +NAME = open # Commands CXX = c++ RM = rm -rf # Flags -# Mandatory flags for 42 +# Mandatory flags for 42 cpp CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/ # Flags to debug and have the dependences (can be removed for correction) CXXFLAGS += -MMD -g3 # Flag to debug (TO REMOVE) # CXXFLAGS += -D DEBUG=1 # Sources -SRC = Animal.cpp \ +SRC = main.cpp \ Brain.cpp \ - Cat.cpp \ - Dog.cpp \ - WrongAnimal.cpp \ WrongCat.cpp \ - main.cpp \ + WrongAnimal.cpp \ + Dog.cpp \ + Animal.cpp \ + Cat.cpp # Objects OBJDIRNAME = ./build diff --git a/cpp04/ex01/WrongAnimal.cpp b/cpp04/ex01/WrongAnimal.cpp index 0afff32..f557caa 100644 --- a/cpp04/ex01/WrongAnimal.cpp +++ b/cpp04/ex01/WrongAnimal.cpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:54:23 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */ +/* Updated: 2025/02/18 17:20:01 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,25 @@ #include WrongAnimal::WrongAnimal() { - std::cout << "[WrongAnimal]\tCreating the class" << std::endl; - type = ""; + std::cout << "[WrongAnimal]\tCreating WrongAnimal class" << std::endl; + type = "WrongAnimal"; +} + +WrongAnimal::WrongAnimal(WrongAnimal const & copy) { + std::cout << "[WrongAnimal]\tCreating WrongAnimal class (copy)" << std::endl; + this->type = copy.type; +} + +WrongAnimal & WrongAnimal::operator=(WrongAnimal const & assign) { + std::cout << "[WrongAnimal]\tCreating WrongAnimal class (assign)" << std::endl; + this->type = assign.type; + return *this; } WrongAnimal::~WrongAnimal() { - std::cout << "[WrongAnimal]\tDeleting the class" << std::endl; -} - -std::string WrongAnimal::getType() const { - return (type); + std::cout << "[WrongAnimal]\tDeleting WrongAnimal class" << std::endl; } void WrongAnimal::makeSound() const { - std::cout << "🦊 | What does the fox say ?" << std::endl; + std::cout << "[WrongAnimal]\t🦊 | What does the fox say ?" << std::endl; } diff --git a/cpp04/ex01/WrongAnimal.hpp b/cpp04/ex01/WrongAnimal.hpp index 3e13252..f937c40 100644 --- a/cpp04/ex01/WrongAnimal.hpp +++ b/cpp04/ex01/WrongAnimal.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:34:06 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:30:56 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,17 +14,17 @@ #define WRONGANIMAL_HPP #include -#include class WrongAnimal { public: WrongAnimal(); virtual ~WrongAnimal(); - virtual void makeSound() const; - std::string getType() const; + WrongAnimal(WrongAnimal const & copy); + WrongAnimal & operator=(WrongAnimal const & assign); + void makeSound() const; + protected: std::string type; - private: }; #endif diff --git a/cpp04/ex01/WrongCat.cpp b/cpp04/ex01/WrongCat.cpp index e7abd44..b2b130d 100644 --- a/cpp04/ex01/WrongCat.cpp +++ b/cpp04/ex01/WrongCat.cpp @@ -5,22 +5,34 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:54:35 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */ +/* Updated: 2025/02/18 17:17:44 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "WrongCat.hpp" +#include WrongCat::WrongCat() { - std::cout << "[WrongCat]\tCreating the class" << std::endl; + std::cout << "[WrongCat]\tCreating WrongCat class" << std::endl; type = "WrongCat"; } +WrongCat::WrongCat(WrongCat const & copy) { + std::cout << "[WrongCat]\tCreating WrongCat class (copy)" << std::endl; + this->type = copy.type; +} + +WrongCat & WrongCat::operator=(WrongCat const & assign) { + std::cout << "[WrongCat]\tCreating WrongCat class (assign)" << std::endl; + this->type = assign.type; + return *this; +} + WrongCat::~WrongCat() { - std::cout << "[WrongCat]\tDeleting the class" << std::endl; + std::cout << "[WrongCat]\tDeleting WrongCat class" << std::endl; } void WrongCat::makeSound() const { - std::cout << "šŸ™€ | Help me I transform my self in cat" << std::endl; + std::cout << "[WrongCat]\t🐱 | Wouf wouf" << std::endl; } diff --git a/cpp04/ex01/WrongCat.hpp b/cpp04/ex01/WrongCat.hpp index d9e55b6..c228107 100644 --- a/cpp04/ex01/WrongCat.hpp +++ b/cpp04/ex01/WrongCat.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:37:00 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:48:00 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,17 +14,16 @@ #define WRONGCAT_HPP #include "WrongAnimal.hpp" -#include class WrongCat : public WrongAnimal { public: WrongCat(); ~WrongCat(); + WrongCat(WrongCat const & copy); + WrongCat & operator=(WrongCat const & assign); virtual void makeSound() const; protected: - - private: - + std::string type; }; #endif diff --git a/cpp04/ex01/color.hpp b/cpp04/ex01/color.hpp new file mode 100644 index 0000000..e1c3f79 --- /dev/null +++ b/cpp04/ex01/color.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* color.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/17 15:27:54 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:43:18 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef COLOR_HPP + #define COLOR_HPP + + #define RESET "\033[0m" + + #define BLACK "\033[0;30m" + #define RED "\033[0;31m" + #define GREEN "\033[0;32m" + #define YELLOW "\033[0;33m" + #define BLUE "\033[0;34m" + #define MAGENTA "\033[0;35m" + #define CYAN "\033[0;36m" + #define WHITE "\033[0;37m" + #define GOLD "\033[38;5;220m" + #define GREY "\033[38;5;240m" + + #define L_BLACK "\033[0;90m" + #define L_RED "\033[0;91m" + #define L_GREEN "\033[0;92m" + #define L_YELLOW "\033[0;93m" + #define L_BLUE "\033[0;94m" + #define L_MAGENTA "\033[0;95m" + #define L_CYAN "\033[0;96m" + #define L_WHITE "\033[0;97m" + + #define B_BLACK "\033[1;30m" + #define B_RED "\033[1;31m" + #define B_GREEN "\033[1;32m" + #define B_YELLOW "\033[1;33m" + #define B_BLUE "\033[1;34m" + #define B_MAGENTA "\033[1;35m" + #define B_CYAN "\033[1;36m" + #define B_WHITE "\033[1;37m" + +#endif diff --git a/cpp04/ex01/main.cpp b/cpp04/ex01/main.cpp index 93f3c9d..c1b43b4 100644 --- a/cpp04/ex01/main.cpp +++ b/cpp04/ex01/main.cpp @@ -5,47 +5,67 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */ -/* Updated: 2025/02/10 12:40:53 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:11 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:09:18 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Animal.hpp" -#include "Dog.hpp" #include "Cat.hpp" +#include "Dog.hpp" #include "WrongAnimal.hpp" #include "WrongCat.hpp" +#include "color.hpp" #include +#include int main() { - const unsigned int n = 42; - if (n % 2 != 0) { - std::cerr << "n must be an even number, if not i can't create the same number of Cat and Animal" << std::endl; - return (1); + const int nb = 42; + + if (nb % 2 != 0) { + std::cerr << RED << "Error: Please enter an odd number." << RESET << std::endl; + return 1; + } + if (nb < 0) { + std::cerr << RED << "Error: Please enter a positive number." << RESET << std::endl; + return 2; } - std::cout << "\033[0;33m[ Building classes ]\033[0m" << std::endl; - Animal *animals[n]; - for (unsigned int i = 0; i < n; i++) { - std::cout << "(" << i + 1 << ") "; - if (i % 2 == 0) { - animals[i] = new Dog(); - } else { - animals[i] = new Cat(); - } + Animal *tab[nb]; + + std::cout << YELLOW << "\t\t[ Constructor ]" << RESET << std::endl; + for (int i = 0; i < nb && i < nb; i++) { + std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl; + if (i % 2 == 0) + tab[i] = new Dog(); + else + tab[i] = new Cat(); } - std::cout << "\033[0;33m[ Making sounds ]\033[0m" << std::endl; - for (unsigned int i = 0; i < n; i++) { - std::cout << "(" << i + 1 << ") "; - animals[i]->makeSound(); + std::cout << std::endl << YELLOW << "\t\t[ Make Sound ]" << RESET << std::endl; + for (int i = 0; i < nb && i < nb; i++) { + std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET; + tab[i]->makeSound(); } - std::cout << "\033[0;33m[ Deleting classes ]\033[0m" << std::endl; - for (unsigned int i = 0; i < n; i++) { - std::cout << "(" << i + 1 << ") "; - delete animals[i]; + std::cout << std::endl << YELLOW << "\t\t[ Destructor ]" << RESET << std::endl; + for (int i = 0; i < nb && i < nb; i++) { + std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl; + delete tab[i]; } + std::cout << std::endl << YELLOW << "\t\t[ Brains deepCopy ]" << RESET << std::endl; + Animal *cat = new Cat(); + Animal *newCat; + + newCat = cat->clone(); + std::cout << cat->getIdea(41) << " "<< __LINE__ << std::endl; + cat->setIdea(41, "🧠 | New Idea"); + std::cout << cat->getIdea(41) << " "<< __LINE__ << std::endl; + std::cout << newCat->getIdea(41) << " "<< __LINE__ << std::endl; + + delete cat; + delete newCat; + return 0; } diff --git a/cpp04/ex01/polyformism b/cpp04/ex01/polyformism deleted file mode 100755 index a02db6c..0000000 Binary files a/cpp04/ex01/polyformism and /dev/null differ diff --git a/cpp04/ex02/AAnimal.cpp b/cpp04/ex02/AAnimal.cpp new file mode 100644 index 0000000..7e3dde0 --- /dev/null +++ b/cpp04/ex02/AAnimal.cpp @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* AAnimal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:10:59 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "AAnimal.hpp" +#include + +AAnimal::AAnimal() { + std::cout << "[AAnimal]\tCreating AAnimal class" << std::endl; + type = "AAnimal"; +} + +AAnimal::AAnimal(AAnimal const & copy) { + std::cout << "[AAnimal]\tCreating AAnimal class (copy)" << std::endl; + this->type = copy.type; +} + +AAnimal & AAnimal::operator=(AAnimal const & assign) { + std::cout << "[AAnimal]\tCreating AAnimal class (assign)" << std::endl; + this->type = assign.type; + return *this; +} + +AAnimal::~AAnimal() { + std::cout << "[AAnimal]\tDeleting AAnimal class" << std::endl; +} + +void AAnimal::makeSound() const { + std::cout << "[AAnimal]\t🦊 | What does the fox say ?" << std::endl; +} diff --git a/cpp04/ex02/Animal.hpp b/cpp04/ex02/AAnimal.hpp similarity index 57% rename from cpp04/ex02/Animal.hpp rename to cpp04/ex02/AAnimal.hpp index bfb8474..540b6b0 100644 --- a/cpp04/ex02/Animal.hpp +++ b/cpp04/ex02/AAnimal.hpp @@ -1,30 +1,33 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* Animal.hpp :+: :+: :+: */ +/* AAnimal.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:23:05 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:14:43 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef ANIMAL_HPP -#define ANIMAL_HPP +#ifndef AAnimal_HPP +#define AAnimal_HPP #include -#include -class Animal { +class AAnimal { public: - Animal(); - virtual ~Animal(); - virtual void makeSound() const; - std::string getType() const; + AAnimal(); + virtual ~AAnimal(); + AAnimal(AAnimal const & copy); + AAnimal & operator=(AAnimal const & assign); + virtual void makeSound() const = 0; + virtual AAnimal* clone() const = 0; + virtual std::string getIdea(int const index) const = 0; + virtual void setIdea(int const index, std::string const idea) const = 0; + protected: std::string type; - private: }; #endif diff --git a/cpp04/ex02/Animal.cpp b/cpp04/ex02/Animal.cpp deleted file mode 100644 index b80a082..0000000 --- a/cpp04/ex02/Animal.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* Animal.cpp :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:53:47 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "Animal.hpp" -#include - -Animal::Animal() { - std::cout << "[Animal]\tCreating the class" << std::endl; - type = ""; -} - -Animal::~Animal() { - std::cout << "[Animal]\tDeleting the class" << std::endl; -} - -std::string Animal::getType() const { - return (type); -} - -void Animal::makeSound() const { - std::cout << "šŸ¤” | thinking how to make a sound" << std::endl; -} diff --git a/cpp04/ex02/Brain.cpp b/cpp04/ex02/Brain.cpp index 3ed559c..38e9838 100644 --- a/cpp04/ex02/Brain.cpp +++ b/cpp04/ex02/Brain.cpp @@ -5,27 +5,49 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/06 15:17:41 by rparodi #+# #+# */ -/* Updated: 2025/02/07 17:51:50 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:57:51 by rparodi #+# #+# */ +/* Updated: 2025/02/18 18:45:33 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Brain.hpp" +#include #include -#include Brain::Brain() { + std::cout << "[Brain]\t\tCreating Brain class" << std::endl; for (int i = 0; i < 100; i++) { - std::ostringstream oss; - oss << "I'm thinking about the number " << (i + 1); - idea[i] = oss.str(); + std::stringstream oss; + oss << "🧠 | Idea " << (i + 1); + ideas[i] = oss.str(); } } +Brain::Brain(Brain const & copy) { + std::cout << "[Brain]\t\tCreating Brain class (copy)" << std::endl; + for (int i = 0; i < 100; i++) { + this->ideas[i] = std::string(copy.ideas[i]); + } +} + +Brain& Brain::operator=(Brain const & assign) { + if (this != &assign) { + std::cout << "[Brain]\t\tCreating Brain class (assign)" << std::endl; + for (int i = 0; i < 100; i++) { + this->ideas[i] = std::string(assign.ideas[i]); + } + } + return *this; +} + Brain::~Brain() { - + std::cout << "[Brain]\t\tDeleting Brain class" << std::endl; } -Brain& Brain::operator=(Brain &value) { - return (value); +std::string Brain::getIdea(int index) const { + return ideas[index % 100]; +} + +void Brain::setIdea(int index, std::string idea) { + this->ideas[index % 100] = idea; } diff --git a/cpp04/ex02/Brain.hpp b/cpp04/ex02/Brain.hpp index 3e7e09a..c3534f4 100644 --- a/cpp04/ex02/Brain.hpp +++ b/cpp04/ex02/Brain.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/06 15:17:49 by rparodi #+# #+# */ -/* Updated: 2025/02/07 17:51:43 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:58:06 by rparodi #+# #+# */ +/* Updated: 2025/02/18 18:51:23 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,17 +15,16 @@ #include -class Brain { +class Brain { public: Brain(); + Brain(const Brain ©); + Brain& operator=(const Brain &assign); ~Brain(); - std::string idea[100]; - Brain& operator=(Brain &value); - - protected: - + std::string getIdea(int index) const; + void setIdea(int const index, std::string const idea); private: - + std::string ideas[100]; }; #endif diff --git a/cpp04/ex02/Cat.cpp b/cpp04/ex02/Cat.cpp index c045f91..1be2376 100644 --- a/cpp04/ex02/Cat.cpp +++ b/cpp04/ex02/Cat.cpp @@ -5,24 +5,54 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ -/* Updated: 2025/02/10 12:22:32 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:14:10 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Cat.hpp" +#include Cat::Cat() { - std::cout << "[Cat]\t\tCreating the class" << std::endl; + std::cout << "[Cat]\t\tCreating Cat class" << std::endl; type = "Cat"; brain = new Brain(); } +Cat::Cat(Cat const & copy) { + std::cout << "[Cat]\t\tCreating Cat class (copy)" << std::endl; + this->type = copy.type; + this->brain = new Brain(*copy.brain); +} + +Cat & Cat::operator=(Cat const & assign) { + if (this != &assign) { + std::cout << "[Cat]\t\tCreating Cat class (assign)" << std::endl; + this->type = assign.type; + for (int i = 0; i < 100; i++) + this->brain[i] = assign.brain[i]; + } + return *this; +} + +Cat* Cat::clone() const { + std::cout << "[Cat]\t\tCopying Cat class (DeepCopy)" << std::endl; + return new Cat(*this); +} + Cat::~Cat() { delete brain; - std::cout << "[Cat]\t\tDeleting the class" << std::endl; + std::cout << "[Cat]\t\tDeleting Cat class" << std::endl; +} + +void Cat::setIdea(int const index, std::string const idea) const { + brain->setIdea(index, idea); +} + +std::string Cat::getIdea(int const index) const { + return brain->getIdea(index); } void Cat::makeSound() const { - std::cout << "🐱 | Meow Meow" << std::endl; + std::cout << "[Cat]\t\t🐱 | Meow meow" << std::endl; } diff --git a/cpp04/ex02/Cat.hpp b/cpp04/ex02/Cat.hpp index 78e9530..78d70e0 100644 --- a/cpp04/ex02/Cat.hpp +++ b/cpp04/ex02/Cat.hpp @@ -5,27 +5,30 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */ -/* Updated: 2025/02/10 12:20:07 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:11:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef CAT_HPP #define CAT_HPP -#include "Animal.hpp" +#include "AAnimal.hpp" #include "Brain.hpp" -#include -class Cat : public Animal { +class Cat : public AAnimal { public: Cat(); ~Cat(); + Cat(Cat const & copy); + Cat & operator=(Cat const & assign); virtual void makeSound() const; + virtual Cat* clone() const; + std::string getIdea(int const index) const; + void setIdea(int const index, std::string const idea) const; protected: - - private: Brain *brain; + std::string type; }; #endif diff --git a/cpp04/ex02/Dog.cpp b/cpp04/ex02/Dog.cpp index 1eb69f7..a9bd109 100644 --- a/cpp04/ex02/Dog.cpp +++ b/cpp04/ex02/Dog.cpp @@ -5,25 +5,51 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */ -/* Updated: 2025/02/10 12:19:22 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:02 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:13:30 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Dog.hpp" -#include "Brain.hpp" +#include Dog::Dog() { - std::cout << "[Dog]\t\tCreating the class" << std::endl; + std::cout << "[Dog]\t\tCreating Dog class" << std::endl; type = "Dog"; brain = new Brain(); } +Dog::Dog(Dog const & copy) { + std::cout << "[Dog]\t\tCreating Dog class (copy)" << std::endl; + this->type = copy.type; + this->brain = new Brain(); +} + +Dog & Dog::operator=(Dog const & assign) { + std::cout << "[Dog]\t\tCreating Dog class (assign)" << std::endl; + (void)assign; + this->brain = new Brain(); + return *this; +} + +std::string Dog::getIdea(int index) const { + return brain->getIdea(index); +} + +void Dog::setIdea(int const index, std::string const idea) const { + return brain->setIdea(index, idea); +} + +Dog* Dog::clone() const { + std::cout << "[Dog]\t\tCopying Dog class (DeepCopy)" << std::endl; + return new Dog(*this); +} + Dog::~Dog() { delete brain; - std::cout << "[Dog]\t\tDeleting the class" << std::endl; + std::cout << "[Dog]\t\tDeleting Dog class" << std::endl; } void Dog::makeSound() const { - std::cout << "🐶 | Wouf Wouf" << std::endl; + std::cout << "[Dog]\t\t🐶 | Wouf wouf" << std::endl; } diff --git a/cpp04/ex02/Dog.hpp b/cpp04/ex02/Dog.hpp index ba98c5f..52c90f8 100644 --- a/cpp04/ex02/Dog.hpp +++ b/cpp04/ex02/Dog.hpp @@ -5,28 +5,30 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */ -/* Updated: 2025/02/07 17:51:39 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:26:17 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:11:18 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef DOG_HPP #define DOG_HPP -#include "Animal.hpp" +#include "AAnimal.hpp" #include "Brain.hpp" -#include -class Dog : public Animal { +class Dog : public AAnimal { public: Dog(); ~Dog(); + Dog(Dog const & copy); + Dog & operator=(Dog const & assign); virtual void makeSound() const; + std::string getIdea(int const index) const; + void setIdea(int const index, std::string const idea) const; + Dog* clone() const; protected: - - private: Brain *brain; - + std::string type; }; #endif diff --git a/cpp04/ex02/Makefile b/cpp04/ex02/Makefile index 12e6eaa..b30d548 100644 --- a/cpp04/ex02/Makefile +++ b/cpp04/ex02/Makefile @@ -1,38 +1,39 @@ # **************************************************************************** # + # ::: :::::::: # # Makefile :+: :+: :+: # # +:+ +:+ +:+ # # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/12/21 19:50:58 by rparodi ### ########.fr # +# Updated: 2025/02/18 20:12:03 by rparodi ### ########.fr # # # # **************************************************************************** # # Variables # Name -NAME = polyformism +NAME = open # Commands CXX = c++ RM = rm -rf # Flags -# Mandatory flags for 42 +# Mandatory flags for 42 cpp CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/ # Flags to debug and have the dependences (can be removed for correction) CXXFLAGS += -MMD -g3 # Flag to debug (TO REMOVE) # CXXFLAGS += -D DEBUG=1 # Sources -SRC = Animal.cpp \ +SRC = main.cpp \ Brain.cpp \ - Cat.cpp \ - Dog.cpp \ - WrongAnimal.cpp \ WrongCat.cpp \ - main.cpp \ + WrongAnimal.cpp \ + Dog.cpp \ + AAnimal.cpp \ + Cat.cpp # Objects OBJDIRNAME = ./build diff --git a/cpp04/ex02/WrongAnimal.cpp b/cpp04/ex02/WrongAnimal.cpp index 0afff32..f557caa 100644 --- a/cpp04/ex02/WrongAnimal.cpp +++ b/cpp04/ex02/WrongAnimal.cpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:54:23 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */ +/* Updated: 2025/02/18 17:20:01 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,25 @@ #include WrongAnimal::WrongAnimal() { - std::cout << "[WrongAnimal]\tCreating the class" << std::endl; - type = ""; + std::cout << "[WrongAnimal]\tCreating WrongAnimal class" << std::endl; + type = "WrongAnimal"; +} + +WrongAnimal::WrongAnimal(WrongAnimal const & copy) { + std::cout << "[WrongAnimal]\tCreating WrongAnimal class (copy)" << std::endl; + this->type = copy.type; +} + +WrongAnimal & WrongAnimal::operator=(WrongAnimal const & assign) { + std::cout << "[WrongAnimal]\tCreating WrongAnimal class (assign)" << std::endl; + this->type = assign.type; + return *this; } WrongAnimal::~WrongAnimal() { - std::cout << "[WrongAnimal]\tDeleting the class" << std::endl; -} - -std::string WrongAnimal::getType() const { - return (type); + std::cout << "[WrongAnimal]\tDeleting WrongAnimal class" << std::endl; } void WrongAnimal::makeSound() const { - std::cout << "🦊 | What does the fox say ?" << std::endl; + std::cout << "[WrongAnimal]\t🦊 | What does the fox say ?" << std::endl; } diff --git a/cpp04/ex02/WrongAnimal.hpp b/cpp04/ex02/WrongAnimal.hpp index 3e13252..f937c40 100644 --- a/cpp04/ex02/WrongAnimal.hpp +++ b/cpp04/ex02/WrongAnimal.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:34:06 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:30:56 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,17 +14,17 @@ #define WRONGANIMAL_HPP #include -#include class WrongAnimal { public: WrongAnimal(); virtual ~WrongAnimal(); - virtual void makeSound() const; - std::string getType() const; + WrongAnimal(WrongAnimal const & copy); + WrongAnimal & operator=(WrongAnimal const & assign); + void makeSound() const; + protected: std::string type; - private: }; #endif diff --git a/cpp04/ex02/WrongCat.cpp b/cpp04/ex02/WrongCat.cpp index e7abd44..b2b130d 100644 --- a/cpp04/ex02/WrongCat.cpp +++ b/cpp04/ex02/WrongCat.cpp @@ -5,22 +5,34 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:54:35 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */ +/* Updated: 2025/02/18 17:17:44 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "WrongCat.hpp" +#include WrongCat::WrongCat() { - std::cout << "[WrongCat]\tCreating the class" << std::endl; + std::cout << "[WrongCat]\tCreating WrongCat class" << std::endl; type = "WrongCat"; } +WrongCat::WrongCat(WrongCat const & copy) { + std::cout << "[WrongCat]\tCreating WrongCat class (copy)" << std::endl; + this->type = copy.type; +} + +WrongCat & WrongCat::operator=(WrongCat const & assign) { + std::cout << "[WrongCat]\tCreating WrongCat class (assign)" << std::endl; + this->type = assign.type; + return *this; +} + WrongCat::~WrongCat() { - std::cout << "[WrongCat]\tDeleting the class" << std::endl; + std::cout << "[WrongCat]\tDeleting WrongCat class" << std::endl; } void WrongCat::makeSound() const { - std::cout << "šŸ™€ | Help me I transform my self in cat" << std::endl; + std::cout << "[WrongCat]\t🐱 | Wouf wouf" << std::endl; } diff --git a/cpp04/ex02/WrongCat.hpp b/cpp04/ex02/WrongCat.hpp index d9e55b6..c228107 100644 --- a/cpp04/ex02/WrongCat.hpp +++ b/cpp04/ex02/WrongCat.hpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:37:00 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:48:00 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,17 +14,16 @@ #define WRONGCAT_HPP #include "WrongAnimal.hpp" -#include class WrongCat : public WrongAnimal { public: WrongCat(); ~WrongCat(); + WrongCat(WrongCat const & copy); + WrongCat & operator=(WrongCat const & assign); virtual void makeSound() const; protected: - - private: - + std::string type; }; #endif diff --git a/cpp04/ex02/color.hpp b/cpp04/ex02/color.hpp new file mode 100644 index 0000000..e1c3f79 --- /dev/null +++ b/cpp04/ex02/color.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* color.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/17 15:27:54 by rparodi #+# #+# */ +/* Updated: 2025/02/18 16:43:18 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef COLOR_HPP + #define COLOR_HPP + + #define RESET "\033[0m" + + #define BLACK "\033[0;30m" + #define RED "\033[0;31m" + #define GREEN "\033[0;32m" + #define YELLOW "\033[0;33m" + #define BLUE "\033[0;34m" + #define MAGENTA "\033[0;35m" + #define CYAN "\033[0;36m" + #define WHITE "\033[0;37m" + #define GOLD "\033[38;5;220m" + #define GREY "\033[38;5;240m" + + #define L_BLACK "\033[0;90m" + #define L_RED "\033[0;91m" + #define L_GREEN "\033[0;92m" + #define L_YELLOW "\033[0;93m" + #define L_BLUE "\033[0;94m" + #define L_MAGENTA "\033[0;95m" + #define L_CYAN "\033[0;96m" + #define L_WHITE "\033[0;97m" + + #define B_BLACK "\033[1;30m" + #define B_RED "\033[1;31m" + #define B_GREEN "\033[1;32m" + #define B_YELLOW "\033[1;33m" + #define B_BLUE "\033[1;34m" + #define B_MAGENTA "\033[1;35m" + #define B_CYAN "\033[1;36m" + #define B_WHITE "\033[1;37m" + +#endif diff --git a/cpp04/ex02/main.cpp b/cpp04/ex02/main.cpp index 93f3c9d..920d1e8 100644 --- a/cpp04/ex02/main.cpp +++ b/cpp04/ex02/main.cpp @@ -5,47 +5,65 @@ /* +:+ +:+ +:+ */ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */ -/* Updated: 2025/02/10 12:40:53 by rparodi ### ########.fr */ +/* Created: 2025/02/18 16:22:11 by rparodi #+# #+# */ +/* Updated: 2025/02/18 20:12:27 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ -#include "Animal.hpp" -#include "Dog.hpp" +#include "AAnimal.hpp" #include "Cat.hpp" -#include "WrongAnimal.hpp" -#include "WrongCat.hpp" +#include "Dog.hpp" +#include "color.hpp" #include +#include int main() { - const unsigned int n = 42; - if (n % 2 != 0) { - std::cerr << "n must be an even number, if not i can't create the same number of Cat and Animal" << std::endl; - return (1); + const int nb = 42; + + if (nb % 2 != 0) { + std::cerr << RED << "Error: Please enter an odd number." << RESET << std::endl; + return 1; + } + if (nb < 0) { + std::cerr << RED << "Error: Please enter a positive number." << RESET << std::endl; + return 2; } - std::cout << "\033[0;33m[ Building classes ]\033[0m" << std::endl; - Animal *animals[n]; - for (unsigned int i = 0; i < n; i++) { - std::cout << "(" << i + 1 << ") "; - if (i % 2 == 0) { - animals[i] = new Dog(); - } else { - animals[i] = new Cat(); - } + AAnimal *tab[nb]; + + std::cout << YELLOW << "\t\t[ Constructor ]" << RESET << std::endl; + for (int i = 0; i < nb && i < nb; i++) { + std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl; + if (i % 2 == 0) + tab[i] = new Dog(); + else + tab[i] = new Cat(); } - std::cout << "\033[0;33m[ Making sounds ]\033[0m" << std::endl; - for (unsigned int i = 0; i < n; i++) { - std::cout << "(" << i + 1 << ") "; - animals[i]->makeSound(); + std::cout << std::endl << YELLOW << "\t\t[ Make Sound ]" << RESET << std::endl; + for (int i = 0; i < nb && i < nb; i++) { + std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET; + tab[i]->makeSound(); } - std::cout << "\033[0;33m[ Deleting classes ]\033[0m" << std::endl; - for (unsigned int i = 0; i < n; i++) { - std::cout << "(" << i + 1 << ") "; - delete animals[i]; + std::cout << std::endl << YELLOW << "\t\t[ Destructor ]" << RESET << std::endl; + for (int i = 0; i < nb && i < nb; i++) { + std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl; + delete tab[i]; } + std::cout << std::endl << YELLOW << "\t\t[ Brains deepCopy ]" << RESET << std::endl; + AAnimal *cat = new Cat(); + AAnimal *newCat; + + newCat = cat->clone(); + std::cout << cat->getIdea(41) << " "<< __LINE__ << std::endl; + cat->setIdea(41, "🧠 | New Idea"); + std::cout << cat->getIdea(41) << " "<< __LINE__ << std::endl; + std::cout << newCat->getIdea(41) << " "<< __LINE__ << std::endl; + + delete cat; + delete newCat; + return 0; }