From 5ab7e97c1e51bf94356b60c219023b65c7377c45 Mon Sep 17 00:00:00 2001 From: Angel Ortigosa Perez Date: Mon, 10 Nov 2025 11:18:08 +0100 Subject: [PATCH] Project finished --- ex00/Makefile | 8 ++++-- ex00/WrongAnimal/WrongAnimal.cpp | 47 +++++++++++++++++++++++++++++++ ex00/WrongAnimal/WrongAnimal.hpp | 33 ++++++++++++++++++++++ ex00/WrongCat/WrongCat.cpp | 48 ++++++++++++++++++++++++++++++++ ex00/WrongCat/WrongCat.hpp | 32 +++++++++++++++++++++ ex00/main.cpp | 22 +++++++++------ 6 files changed, 179 insertions(+), 11 deletions(-) create mode 100644 ex00/WrongAnimal/WrongAnimal.cpp create mode 100644 ex00/WrongAnimal/WrongAnimal.hpp create mode 100644 ex00/WrongCat/WrongCat.cpp create mode 100644 ex00/WrongCat/WrongCat.hpp diff --git a/ex00/Makefile b/ex00/Makefile index f1ca206..b74e1c5 100644 --- a/ex00/Makefile +++ b/ex00/Makefile @@ -1,6 +1,8 @@ NAME = animals -SRCS = main.cpp Animal/Animal.cpp Dog/Dog.cpp Cat/Cat.cpp +SRCS = main.cpp Animal/Animal.cpp Dog/Dog.cpp Cat/Cat.cpp \ + WrongAnimal/WrongAnimal.cpp WrongCat/WrongCat.cpp + OBJS = $(SRCS:.cpp=.o) CC = c++ @@ -11,8 +13,8 @@ all: $(NAME) $(NAME): $(OBJS) $(CC) $(CFLAGS) $(OBJS) -o $(NAME) -%.o: %cpp - $(CC) $(CFLAGS) -c $@ -o $< +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ clean: rm -f $(OBJS) diff --git a/ex00/WrongAnimal/WrongAnimal.cpp b/ex00/WrongAnimal/WrongAnimal.cpp new file mode 100644 index 0000000..5573a0b --- /dev/null +++ b/ex00/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/ex00/WrongAnimal/WrongAnimal.hpp b/ex00/WrongAnimal/WrongAnimal.hpp new file mode 100644 index 0000000..1f54504 --- /dev/null +++ b/ex00/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/ex00/WrongCat/WrongCat.cpp b/ex00/WrongCat/WrongCat.cpp new file mode 100644 index 0000000..757a725 --- /dev/null +++ b/ex00/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/ex00/WrongCat/WrongCat.hpp b/ex00/WrongCat/WrongCat.hpp new file mode 100644 index 0000000..a383995 --- /dev/null +++ b/ex00/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/ex00/main.cpp b/ex00/main.cpp index 570be1a..b895cb7 100644 --- a/ex00/main.cpp +++ b/ex00/main.cpp @@ -6,13 +6,15 @@ /* By: aortigos getType() << " " << std::endl; - std::cout << i->getType() << " " << std::endl; - - std::cout << std::endl << "----- Making sounds ------" << std::endl; - i->makeSound(); + std::cout << std::endl << "----- Animal sounds ------" << std::endl; + + std::cout << j->getType() << " says: "; j->makeSound(); - meta->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); }