diff --git a/cpp04/ex01/Animal.cpp b/cpp04/ex01/Animal.cpp index 410e2e7..b80a082 100644 --- a/cpp04/ex01/Animal.cpp +++ b/cpp04/ex01/Animal.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */ -/* Updated: 2025/01/30 13:37:51 by rparodi ### ########.fr */ +/* Updated: 2025/01/31 19:53:47 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,19 +14,18 @@ #include Animal::Animal() { - std::cout << "[Animal] Creating the class" << std::endl; + std::cout << "[Animal]\tCreating the class" << std::endl; type = ""; } Animal::~Animal() { - std::cout << "[Animal] Deleting the class" << std::endl; + std::cout << "[Animal]\tDeleting the class" << std::endl; } -void Animal::makeSound() { - if (type.compare("Cat")) - std::cout << "🐱 | Meow Meow" << std::endl; - else if (type.compare("Dog")) - std::cout << "🐶 | Wouf Wouf" << std::endl; - else +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/ex01/Animal.hpp b/cpp04/ex01/Animal.hpp index bcd273a..bfb8474 100644 --- a/cpp04/ex01/Animal.hpp +++ b/cpp04/ex01/Animal.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */ -/* Updated: 2025/01/30 13:42:23 by rparodi ### ########.fr */ +/* Updated: 2025/01/31 19:23:05 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,9 +19,9 @@ class Animal { public: Animal(); - ~Animal(); - void makeSound(); - std::string getType(); + virtual ~Animal(); + virtual void makeSound() const; + std::string getType() const; protected: std::string type; private: diff --git a/cpp04/ex01/Brain.cpp b/cpp04/ex01/Brain.cpp index 2c6db6f..dd24df0 100644 --- a/cpp04/ex01/Brain.cpp +++ b/cpp04/ex01/Brain.cpp @@ -6,16 +6,19 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/06 15:17:41 by rparodi #+# #+# */ -/* Updated: 2025/02/06 17:56:18 by rparodi ### ########.fr */ +/* Updated: 2025/02/06 23:28:28 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Brain.hpp" +#include #include Brain::Brain() { for (int i = 0; i < 100; i++) { - idea[i] = "I'm thinking about the number " + std::to_string(i + 1); + std::ostringstream oss; + oss << "I'm thinking about the number " << (i + 1); + idea[i] = oss.str(); } } diff --git a/cpp04/ex01/Cat.cpp b/cpp04/ex01/Cat.cpp index 207c674..5e2ef4c 100644 --- a/cpp04/ex01/Cat.cpp +++ b/cpp04/ex01/Cat.cpp @@ -6,21 +6,21 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ -/* Updated: 2025/01/30 13:38:46 by rparodi ### ########.fr */ +/* Updated: 2025/01/31 19:54:03 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Cat.hpp" Cat::Cat() { - std::cout << "[Cat] Creating the class" << std::endl; + std::cout << "[Cat]\t\tCreating the class" << std::endl; type = "Cat"; } Cat::~Cat() { - std::cout << "[Cat] Deleting the class" << std::endl; + std::cout << "[Cat]\t\tDeleting the class" << std::endl; } -std::string Cat::getType() { - return (type); +void Cat::makeSound() const { + std::cout << "🐱 | Meow Meow" << std::endl; } diff --git a/cpp04/ex01/Cat.hpp b/cpp04/ex01/Cat.hpp index 130e8ed..f770266 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/30 13:41:27 by rparodi ### ########.fr */ +/* Updated: 2025/01/31 18:24:18 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ class Cat : public Animal { public: Cat(); ~Cat(); + virtual void makeSound() const; protected: private: diff --git a/cpp04/ex01/Dog.cpp b/cpp04/ex01/Dog.cpp index cf6a045..7b8c767 100644 --- a/cpp04/ex01/Dog.cpp +++ b/cpp04/ex01/Dog.cpp @@ -6,21 +6,21 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */ -/* Updated: 2025/01/30 13:40:51 by rparodi ### ########.fr */ +/* Updated: 2025/01/31 19:53:02 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Dog.hpp" Dog::Dog() { - std::cout << "[Dog] Creating the class" << std::endl; + std::cout << "[Dog]\t\tCreating the class" << std::endl; type = "Dog"; } Dog::~Dog() { - std::cout << "[Dog] Deleting the class" << std::endl; + std::cout << "[Dog]\t\tDeleting the class" << std::endl; } -std::string Dog::getType() { - return (type); +void Dog::makeSound() const { + std::cout << "🐶 | Wouf Wouf" << std::endl; } diff --git a/cpp04/ex01/Dog.hpp b/cpp04/ex01/Dog.hpp index 80c5361..9d67241 100644 --- a/cpp04/ex01/Dog.hpp +++ b/cpp04/ex01/Dog.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */ -/* Updated: 2025/01/30 13:32:28 by rparodi ### ########.fr */ +/* Updated: 2025/01/31 18:24:07 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ class Dog : public Animal { public: Dog(); ~Dog(); - std::string getType(); + virtual void makeSound() const; protected: private: diff --git a/cpp04/ex01/Makefile b/cpp04/ex01/Makefile index 8380d2b..12e6eaa 100644 --- a/cpp04/ex01/Makefile +++ b/cpp04/ex01/Makefile @@ -19,13 +19,20 @@ CXX = c++ RM = rm -rf # Flags -# Mandatory flags for 42 CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/ +# Mandatory flags for 42 +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 = main.cpp +SRC = Animal.cpp \ + Brain.cpp \ + Cat.cpp \ + Dog.cpp \ + WrongAnimal.cpp \ + WrongCat.cpp \ + main.cpp \ # Objects OBJDIRNAME = ./build diff --git a/cpp04/ex01/WrongAnimal.cpp b/cpp04/ex01/WrongAnimal.cpp new file mode 100644 index 0000000..0afff32 --- /dev/null +++ b/cpp04/ex01/WrongAnimal.cpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */ +/* Updated: 2025/01/31 19:54:23 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "WrongAnimal.hpp" +#include + +WrongAnimal::WrongAnimal() { + std::cout << "[WrongAnimal]\tCreating the class" << std::endl; + type = ""; +} + +WrongAnimal::~WrongAnimal() { + std::cout << "[WrongAnimal]\tDeleting the class" << std::endl; +} + +std::string WrongAnimal::getType() const { + return (type); +} + +void WrongAnimal::makeSound() const { + std::cout << "🦊 | What does the fox say ?" << std::endl; +} diff --git a/cpp04/ex01/WrongAnimal.hpp b/cpp04/ex01/WrongAnimal.hpp new file mode 100644 index 0000000..3e13252 --- /dev/null +++ b/cpp04/ex01/WrongAnimal.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */ +/* Updated: 2025/01/31 19:34:06 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef WRONGANIMAL_HPP +#define WRONGANIMAL_HPP + +#include +#include + +class WrongAnimal { + public: + WrongAnimal(); + virtual ~WrongAnimal(); + virtual void makeSound() const; + std::string getType() const; + protected: + std::string type; + private: +}; + +#endif diff --git a/cpp04/ex01/WrongCat.cpp b/cpp04/ex01/WrongCat.cpp new file mode 100644 index 0000000..e7abd44 --- /dev/null +++ b/cpp04/ex01/WrongCat.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ +/* Updated: 2025/01/31 19:54:35 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "WrongCat.hpp" + +WrongCat::WrongCat() { + std::cout << "[WrongCat]\tCreating the class" << std::endl; + type = "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/ex01/WrongCat.hpp b/cpp04/ex01/WrongCat.hpp new file mode 100644 index 0000000..d9e55b6 --- /dev/null +++ b/cpp04/ex01/WrongCat.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */ +/* Updated: 2025/01/31 19:37:00 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef WRONGCAT_HPP +#define WRONGCAT_HPP + +#include "WrongAnimal.hpp" +#include + +class WrongCat : public WrongAnimal { + public: + WrongCat(); + ~WrongCat(); + virtual void makeSound() const; + protected: + + private: + +}; + +#endif diff --git a/cpp04/ex01/a.out b/cpp04/ex01/a.out deleted file mode 100755 index 6233131..0000000 Binary files a/cpp04/ex01/a.out and /dev/null differ diff --git a/cpp04/ex01/main.cpp b/cpp04/ex01/main.cpp index abfe447..3d8220d 100644 --- a/cpp04/ex01/main.cpp +++ b/cpp04/ex01/main.cpp @@ -6,22 +6,45 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */ -/* Updated: 2025/01/30 13:12:32 by rparodi ### ########.fr */ +/* Updated: 2025/01/31 19:52:09 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "Animal.hpp" #include "Dog.hpp" #include "Cat.hpp" +#include "WrongAnimal.hpp" +#include "WrongCat.hpp" 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(); - std::cout << j->getType() << " " << std::endl; - std::cout << i->getType() << " " << std::endl; - i->makeSound(); //will output the cat sound! - j->makeSound(); + const WrongAnimal* k = new WrongAnimal(); + const WrongAnimal* l = 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 << "\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..18418be Binary files /dev/null and b/cpp04/ex01/polyformism differ