diff --git a/cpp04/ex00/WrongCat.cpp b/cpp04/ex00/WrongCat.cpp index e7abd44..3fa7a60 100644 --- a/cpp04/ex00/WrongCat.cpp +++ b/cpp04/ex00/WrongCat.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:54:35 by rparodi ### ########.fr */ +/* Updated: 2025/02/10 12:48:59 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,3 @@ WrongCat::WrongCat() { WrongCat::~WrongCat() { std::cout << "[WrongCat]\tDeleting the class" << std::endl; } - -void WrongCat::makeSound() const { - std::cout << "🙀 | Help me I transform my self in cat" << std::endl; -} diff --git a/cpp04/ex00/WrongCat.hpp b/cpp04/ex00/WrongCat.hpp index d9e55b6..76f621a 100644 --- a/cpp04/ex00/WrongCat.hpp +++ b/cpp04/ex00/WrongCat.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:37:00 by rparodi ### ########.fr */ +/* Updated: 2025/02/10 12:49:13 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,6 @@ class WrongCat : public WrongAnimal { public: WrongCat(); ~WrongCat(); - virtual void makeSound() const; protected: private: diff --git a/cpp04/ex01/Cat.cpp b/cpp04/ex01/Cat.cpp index 5e2ef4c..c045f91 100644 --- a/cpp04/ex01/Cat.cpp +++ b/cpp04/ex01/Cat.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:54:03 by rparodi ### ########.fr */ +/* Updated: 2025/02/10 12:22:32 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,9 +15,11 @@ Cat::Cat() { std::cout << "[Cat]\t\tCreating the class" << std::endl; type = "Cat"; + brain = new Brain(); } Cat::~Cat() { + delete brain; std::cout << "[Cat]\t\tDeleting the class" << std::endl; } diff --git a/cpp04/ex01/Cat.hpp b/cpp04/ex01/Cat.hpp index f770266..78e9530 100644 --- a/cpp04/ex01/Cat.hpp +++ b/cpp04/ex01/Cat.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */ -/* Updated: 2025/01/31 18:24:18 by rparodi ### ########.fr */ +/* Updated: 2025/02/10 12:20:07 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #define CAT_HPP #include "Animal.hpp" +#include "Brain.hpp" #include class Cat : public Animal { @@ -24,7 +25,7 @@ class Cat : public Animal { protected: private: - + Brain *brain; }; #endif diff --git a/cpp04/ex01/Dog.cpp b/cpp04/ex01/Dog.cpp index 12e0083..1eb69f7 100644 --- a/cpp04/ex01/Dog.cpp +++ b/cpp04/ex01/Dog.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */ -/* Updated: 2025/02/07 16:04:29 by rparodi ### ########.fr */ +/* Updated: 2025/02/10 12:19:22 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ Dog::Dog() { } Dog::~Dog() { + delete brain; std::cout << "[Dog]\t\tDeleting the class" << std::endl; } diff --git a/cpp04/ex01/main.cpp b/cpp04/ex01/main.cpp index 3d8220d..93f3c9d 100644 --- a/cpp04/ex01/main.cpp +++ b/cpp04/ex01/main.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */ -/* Updated: 2025/01/31 19:52:09 by rparodi ### ########.fr */ +/* Updated: 2025/02/10 12:40:53 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,36 +15,37 @@ #include "Cat.hpp" #include "WrongAnimal.hpp" #include "WrongCat.hpp" +#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); + } + 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(); + 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(); + } + } - 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 << "\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 << "\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 << "\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; return 0; } diff --git a/cpp04/ex01/polyformism b/cpp04/ex01/polyformism new file mode 100755 index 0000000..a02db6c Binary files /dev/null and b/cpp04/ex01/polyformism differ