From a6f3e7ea31f084d64bcd6e9693c751ac6787a2ae Mon Sep 17 00:00:00 2001 From: Angel Ortigosa Perez Date: Mon, 10 Nov 2025 11:47:40 +0100 Subject: [PATCH] Brain added --- ex01/Animal/Animal.cpp | 47 +++++++++++++++++++++++++++++++ ex01/Animal/Animal.hpp | 33 ++++++++++++++++++++++ ex01/Brain/Brain.cpp | 23 +++++++++++++++ ex01/Brain/Brain.hpp | 29 +++++++++++++++++++ ex01/Cat/Cat.cpp | 45 ++++++++++++++++++++++++++++++ ex01/Cat/Cat.hpp | 35 +++++++++++++++++++++++ ex01/Dog/Dog.cpp | 45 ++++++++++++++++++++++++++++++ ex01/Dog/Dog.hpp | 36 ++++++++++++++++++++++++ ex01/Makefile | 28 +++++++++++++++++++ ex01/WrongAnimal/WrongAnimal.cpp | 47 +++++++++++++++++++++++++++++++ ex01/WrongAnimal/WrongAnimal.hpp | 33 ++++++++++++++++++++++ ex01/WrongCat/WrongCat.cpp | 48 ++++++++++++++++++++++++++++++++ ex01/WrongCat/WrongCat.hpp | 32 +++++++++++++++++++++ ex01/main.cpp | 45 ++++++++++++++++++++++++++++++ 14 files changed, 526 insertions(+) create mode 100644 ex01/Animal/Animal.cpp create mode 100644 ex01/Animal/Animal.hpp create mode 100644 ex01/Brain/Brain.cpp create mode 100644 ex01/Brain/Brain.hpp create mode 100644 ex01/Cat/Cat.cpp create mode 100644 ex01/Cat/Cat.hpp create mode 100644 ex01/Dog/Dog.cpp create mode 100644 ex01/Dog/Dog.hpp create mode 100644 ex01/Makefile create mode 100644 ex01/WrongAnimal/WrongAnimal.cpp create mode 100644 ex01/WrongAnimal/WrongAnimal.hpp create mode 100644 ex01/WrongCat/WrongCat.cpp create mode 100644 ex01/WrongCat/WrongCat.hpp create mode 100644 ex01/main.cpp diff --git a/ex01/Animal/Animal.cpp b/ex01/Animal/Animal.cpp new file mode 100644 index 0000000..63dd2bf --- /dev/null +++ b/ex01/Animal/Animal.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos type = other.type; + return (*this); +} + +void Animal::makeSound() const +{ + std::cout << "Animal weird sounds..." << std::endl; +} + +std::string Animal::getType() const +{ + return (this->type); +} \ No newline at end of file diff --git a/ex01/Animal/Animal.hpp b/ex01/Animal/Animal.hpp new file mode 100644 index 0000000..88017c9 --- /dev/null +++ b/ex01/Animal/Animal.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +class Animal +{ + protected: + std::string type; + public: + Animal(); + virtual ~Animal(); + Animal(const Animal &other); + Animal& operator=(const Animal &other); + + virtual void makeSound() const; + std::string getType() const; +}; + +#endif diff --git a/ex01/Brain/Brain.cpp b/ex01/Brain/Brain.cpp new file mode 100644 index 0000000..66bdbc0 --- /dev/null +++ b/ex01/Brain/Brain.cpp @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +class Brain +{ + private: + std::string ideas[100]; + + public: + Brain(); + ~Brain(); +}; + +#endif diff --git a/ex01/Cat/Cat.cpp b/ex01/Cat/Cat.cpp new file mode 100644 index 0000000..dd178c6 --- /dev/null +++ b/ex01/Cat/Cat.cpp @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos type = "Cat"; + this->brain = new Brain(); +} + +Cat::~Cat() +{ + std::cout << "Cat has been destroyed" << std::endl; + delete (this->brain); +} + +Cat::Cat(const Cat &other) +{ + std::cout << "Cat copied" << std::endl; + *this = other; +} + +Cat& Cat::operator=(const Cat &other) +{ + std::cout << "Cat copy assignment called" << std::endl; + if (this != &other) + this->type = other.type; + return (*this); +} + +void Cat::makeSound() const +{ + std::cout << "Meow!" << std::endl; +} diff --git a/ex01/Cat/Cat.hpp b/ex01/Cat/Cat.hpp new file mode 100644 index 0000000..da72feb --- /dev/null +++ b/ex01/Cat/Cat.hpp @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +# include "../Animal/Animal.hpp" +# include "../Brain/Brain.hpp" + +class Cat : public Animal +{ + private: + Brain *brain; + + public: + Cat(); + ~Cat(); + Cat(const Cat &other); + Cat& operator=(const Cat &other); + + void makeSound() const; +}; + +#endif diff --git a/ex01/Dog/Dog.cpp b/ex01/Dog/Dog.cpp new file mode 100644 index 0000000..edcd4cf --- /dev/null +++ b/ex01/Dog/Dog.cpp @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos type = "Dog"; + this->brain = new Brain(); +} + +Dog::~Dog() +{ + std::cout << "Dog has been destroyed" << std::endl; + delete (this->brain); +} + +Dog::Dog(const Dog &other) +{ + std::cout << "Dog copied" << std::endl; + *this = other; +} + +Dog& Dog::operator=(const Dog &other) +{ + std::cout << "Dog copy assignment called" << std::endl; + if (this != &other) + this->type = other.type; + return (*this); +} + +void Dog::makeSound() const +{ + std::cout << "Woof!" << std::endl; +} diff --git a/ex01/Dog/Dog.hpp b/ex01/Dog/Dog.hpp new file mode 100644 index 0000000..d5448d7 --- /dev/null +++ b/ex01/Dog/Dog.hpp @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +# include "../Animal/Animal.hpp" +# include "../Brain/Brain.hpp" + +class Dog : public Animal +{ + private: + Brain *brain; + + public: + Dog(); + ~Dog(); + Dog(const Dog &other); + Dog& operator=(const Dog &other); + + void makeSound() const; + +}; + +#endif diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..9859137 --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,28 @@ +NAME = animals + +SRCS = main.cpp Animal/Animal.cpp Dog/Dog.cpp Cat/Cat.cpp \ + WrongAnimal/WrongAnimal.cpp WrongCat/WrongCat.cpp \ + Brain/Brain.cpp + +OBJS = $(SRCS:.cpp=.o) + +CC = c++ +CFLAGS = -Wall -Wextra -Werror -std=c++98 + +all: $(NAME) + +$(NAME): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $(NAME) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ex01/WrongAnimal/WrongAnimal.cpp b/ex01/WrongAnimal/WrongAnimal.cpp new file mode 100644 index 0000000..5573a0b --- /dev/null +++ b/ex01/WrongAnimal/WrongAnimal.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos type = other.type; + return (*this); +} + +void WrongAnimal::makeSound() const +{ + std::cout << "WrongAnimal weird sounds..." << std::endl; +} + +std::string WrongAnimal::getType() const +{ + return (this->type); +} \ No newline at end of file diff --git a/ex01/WrongAnimal/WrongAnimal.hpp b/ex01/WrongAnimal/WrongAnimal.hpp new file mode 100644 index 0000000..1f54504 --- /dev/null +++ b/ex01/WrongAnimal/WrongAnimal.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +class WrongAnimal +{ + protected: + std::string type; + public: + WrongAnimal(); + ~WrongAnimal(); + WrongAnimal(const WrongAnimal &other); + WrongAnimal& operator=(const WrongAnimal &other); + + void makeSound() const; + std::string getType() const; +}; + +#endif diff --git a/ex01/WrongCat/WrongCat.cpp b/ex01/WrongCat/WrongCat.cpp new file mode 100644 index 0000000..757a725 --- /dev/null +++ b/ex01/WrongCat/WrongCat.cpp @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos type = "WrongCat"; +} + +WrongCat::~WrongCat() +{ + std::cout << "Cat has been destroyed" << std::endl; +} + +WrongCat::WrongCat(const WrongCat &other) +{ + std::cout << "WrongCat copied" << std::endl; + *this = other; +} + +WrongCat& WrongCat::operator=(const WrongCat &other) +{ + std::cout << "WrongCat copy assignment called" << std::endl; + if (this != &other) + this->type = other.type; + return (*this); +} + +void WrongCat::makeSound() const +{ + std::cout << "WrongCat weird sounds..." << std::endl; +} + +std::string WrongCat::getType() const +{ + return (this->type); +} \ No newline at end of file diff --git a/ex01/WrongCat/WrongCat.hpp b/ex01/WrongCat/WrongCat.hpp new file mode 100644 index 0000000..a383995 --- /dev/null +++ b/ex01/WrongCat/WrongCat.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +# include "../WrongAnimal/WrongAnimal.hpp" + +class WrongCat : public WrongAnimal +{ + public: + WrongCat(); + ~WrongCat(); + WrongCat(const WrongCat &other); + WrongCat& operator=(const WrongCat &other); + + void makeSound() const; + std::string getType() const; +}; + +#endif diff --git a/ex01/main.cpp b/ex01/main.cpp new file mode 100644 index 0000000..b895cb7 --- /dev/null +++ b/ex01/main.cpp @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos getType() << " says: "; + j->makeSound(); + + std::cout << std::endl << i->getType() << " says "; + i->makeSound(); + + std::cout << std::endl << z->getType() << " says "; + z->makeSound(); + + std::cout << std::endl << "----- Free all! ------" << std::endl; + delete (meta); + delete (j); + delete (i); + delete (z); + + return (0); +}