From 098a0cea33cec807d306791c30ada7efdea2ab42 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 15 Nov 2025 15:37:47 +0000 Subject: [PATCH] push --- .vscode/settings.json | 51 +++++++++++++++++++++ ex00/Animal.cpp | 38 ++++++++++++++++ ex00/Animal.hpp | 20 ++++++++ ex00/Cat.cpp | 36 +++++++++++++++ ex00/Cat.hpp | 19 ++++++++ ex00/Dog.cpp | 36 +++++++++++++++ ex00/Dog.hpp | 19 ++++++++ ex00/Main.cpp | 45 ++++++++++++++++++ ex00/Makefile | 36 +++++++++++++++ ex00/WrongAnimal.cpp | 38 ++++++++++++++++ ex00/WrongAnimal.hpp | 21 +++++++++ ex00/WrongCat.cpp | 36 +++++++++++++++ ex00/WrongCat.hpp | 18 ++++++++ ex01/Animal.cpp | 38 ++++++++++++++++ ex01/Animal.hpp | 22 +++++++++ ex01/Brain.cpp | 37 +++++++++++++++ ex01/Brain.hpp | 18 ++++++++ ex01/Cat.cpp | 62 +++++++++++++++++++++++++ ex01/Cat.hpp | 25 ++++++++++ ex01/Dog.cpp | 62 +++++++++++++++++++++++++ ex01/Dog.hpp | 25 ++++++++++ ex01/Main.cpp | 81 +++++++++++++++++++++++++++++++++ ex01/Makefile | 36 +++++++++++++++ ex01/WrongAnimal.cpp | 38 ++++++++++++++++ ex01/WrongAnimal.hpp | 21 +++++++++ ex01/WrongCat.cpp | 36 +++++++++++++++ ex01/WrongCat.hpp | 19 ++++++++ ex02/AAnimal.cpp | 38 ++++++++++++++++ ex02/AAnimal.hpp | 22 +++++++++ ex02/Brain.cpp | 37 +++++++++++++++ ex02/Brain.hpp | 18 ++++++++ ex02/Cat.cpp | 62 +++++++++++++++++++++++++ ex02/Cat.hpp | 25 ++++++++++ ex02/Dog.cpp | 62 +++++++++++++++++++++++++ ex02/Dog.hpp | 25 ++++++++++ ex02/Main.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++ ex02/Makefile | 36 +++++++++++++++ ex02/WrongAnimal.cpp | 38 ++++++++++++++++ ex02/WrongAnimal.hpp | 21 +++++++++ ex02/WrongCat.cpp | 36 +++++++++++++++ ex02/WrongCat.hpp | 19 ++++++++ 41 files changed, 1475 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 ex00/Animal.cpp create mode 100644 ex00/Animal.hpp create mode 100644 ex00/Cat.cpp create mode 100644 ex00/Cat.hpp create mode 100644 ex00/Dog.cpp create mode 100644 ex00/Dog.hpp create mode 100644 ex00/Main.cpp create mode 100644 ex00/Makefile create mode 100644 ex00/WrongAnimal.cpp create mode 100644 ex00/WrongAnimal.hpp create mode 100644 ex00/WrongCat.cpp create mode 100644 ex00/WrongCat.hpp create mode 100644 ex01/Animal.cpp create mode 100644 ex01/Animal.hpp create mode 100644 ex01/Brain.cpp create mode 100644 ex01/Brain.hpp create mode 100644 ex01/Cat.cpp create mode 100644 ex01/Cat.hpp create mode 100644 ex01/Dog.cpp create mode 100644 ex01/Dog.hpp create mode 100644 ex01/Main.cpp create mode 100644 ex01/Makefile create mode 100644 ex01/WrongAnimal.cpp create mode 100644 ex01/WrongAnimal.hpp create mode 100644 ex01/WrongCat.cpp create mode 100644 ex01/WrongCat.hpp create mode 100644 ex02/AAnimal.cpp create mode 100644 ex02/AAnimal.hpp create mode 100644 ex02/Brain.cpp create mode 100644 ex02/Brain.hpp create mode 100644 ex02/Cat.cpp create mode 100644 ex02/Cat.hpp create mode 100644 ex02/Dog.cpp create mode 100644 ex02/Dog.hpp create mode 100644 ex02/Main.cpp create mode 100644 ex02/Makefile create mode 100644 ex02/WrongAnimal.cpp create mode 100644 ex02/WrongAnimal.hpp create mode 100644 ex02/WrongCat.cpp create mode 100644 ex02/WrongCat.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0e70f71 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,51 @@ +{ + "files.associations": { + "iostream": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "ranges": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/ex00/Animal.cpp b/ex00/Animal.cpp new file mode 100644 index 0000000..0c513b3 --- /dev/null +++ b/ex00/Animal.cpp @@ -0,0 +1,38 @@ +# include "Animal.hpp" + +Animal::Animal (std::string type) : _type(type) +{ + std::cout << "Animal constructor called\n"; +} + +Animal::Animal() : _type("Default") +{ + std::cout << "Animal def constructor called\n"; +} + +Animal::Animal(const Animal &other) : _type(other._type) +{ + std::cout << "Animal copy constructor called\n"; +} + +Animal &Animal::operator=(const Animal &other) +{ + _type = other._type; + std::cout << "Animal copy assignment constructor called\n"; + return (*this); +} + +Animal::~Animal() +{ + std::cout << "Animal deconstructor called\n"; +} + +void Animal::makeSound() const +{ + std::cout << "Animal can make different sounds.\n"; +} + +std::string Animal::getType() const +{ + return (_type); +} \ No newline at end of file diff --git a/ex00/Animal.hpp b/ex00/Animal.hpp new file mode 100644 index 0000000..3746d7e --- /dev/null +++ b/ex00/Animal.hpp @@ -0,0 +1,20 @@ +#ifndef ANIMAL_HPP +# define ANIMAL_HPP + +# include +class Animal +{ + protected : + std::string _type; + public : + Animal(); + Animal(std::string type); + Animal(const Animal &other); + virtual ~Animal(); + Animal & operator=(const Animal &other); + + virtual void makeSound() const; + std::string getType() const; +}; + +#endif \ No newline at end of file diff --git a/ex00/Cat.cpp b/ex00/Cat.cpp new file mode 100644 index 0000000..7c6ac5c --- /dev/null +++ b/ex00/Cat.cpp @@ -0,0 +1,36 @@ +# include "Cat.hpp" + +Cat::Cat () : Animal() +{ + _type = "Cat"; + std::cout << "Cat constructor called\n"; +} + +Cat::Cat (std::string type) : Animal(type) +{ + _type = type; + std::cout << "Cat constructor called\n"; +} + +Cat::Cat(const Cat &other) : Animal() +{ + *this = other; + std::cout << "Cat copy constructor called\n"; +} + +Cat &Cat::operator=(const Cat &other) +{ + _type = other._type; + std::cout << "Cat copy assignment constructor called\n"; + return (*this); +} + +Cat::~Cat() +{ + std::cout << "Cat deconstructor called\n"; +} + +void Cat::makeSound() const +{ + std::cout << "miaou miaou miaou (je suis relou) miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou\n"; +} \ No newline at end of file diff --git a/ex00/Cat.hpp b/ex00/Cat.hpp new file mode 100644 index 0000000..9da51b9 --- /dev/null +++ b/ex00/Cat.hpp @@ -0,0 +1,19 @@ +#ifndef CAT_HPP +# define CAT_HPP + +# include +# include "Animal.hpp" + +class Cat : public Animal +{ + public : + Cat(); + Cat(std::string type); + Cat(const Cat &other); + virtual ~Cat(); + Cat & operator=(const Cat &other); + + virtual void makeSound() const; +}; + +#endif \ No newline at end of file diff --git a/ex00/Dog.cpp b/ex00/Dog.cpp new file mode 100644 index 0000000..ef017bf --- /dev/null +++ b/ex00/Dog.cpp @@ -0,0 +1,36 @@ +# include "Dog.hpp" + +Dog::Dog() : Animal() +{ + _type = "Dog"; + std::cout << "Dog default constructor called\n"; +} + +Dog::Dog (std::string type) : Animal(type) +{ + _type = type; + std::cout << "Dog constructor called\n"; +} + +Dog::Dog(const Dog &other) : Animal(other) +{ + *this = other; + std::cout << "Dog copy constructor called\n"; +} + +Dog &Dog::operator=(const Dog &other) +{ + _type = other._type; + std::cout << "Dog copy assignment constructor called\n"; + return (*this); +} + +Dog::~Dog() +{ + std::cout << "Dog deconstructor called\n"; +} + +void Dog::makeSound() const +{ + std::cout << "Waf Waf Waf\n"; +} \ No newline at end of file diff --git a/ex00/Dog.hpp b/ex00/Dog.hpp new file mode 100644 index 0000000..d46efb3 --- /dev/null +++ b/ex00/Dog.hpp @@ -0,0 +1,19 @@ +#ifndef DOG_HPP +# define DOG_HPP + +# include +# include "Animal.hpp" + +class Dog : public Animal +{ + public : + Dog(); + Dog(std::string type); + Dog(const Dog &other); + virtual ~Dog(); + Dog & operator=(const Dog &other); + + virtual void makeSound() const; +}; + +#endif \ No newline at end of file diff --git a/ex00/Main.cpp b/ex00/Main.cpp new file mode 100644 index 0000000..72abd49 --- /dev/null +++ b/ex00/Main.cpp @@ -0,0 +1,45 @@ +# include "Animal.hpp" +# include "WrongAnimal.hpp" +# include "Dog.hpp" +# include "Cat.hpp" +# include "WrongCat.hpp" + +int main() +{ +std::cout << "========== TEST 1: Basic Animal ==========" << std::endl; + { + std::cout << "\n========== Animal ==========" << std::endl; + const Animal* meta = new Animal(); + std::cout << meta->getType() << " " << std::endl; + meta->makeSound(); + delete meta; + + std::cout << "\n========== Dog ==========" << std::endl; + const Animal* j = new Dog(); + std::cout << j->getType() << " " << std::endl; + j->makeSound(); + delete j; + + std::cout << "\n========== Cat ==========" << std::endl; + const Animal* i = new Cat(); + std::cout << i->getType() << " " << std::endl; + j->makeSound(); + delete i; + } + + std::cout << "\n========== TEST 2: Wrong Animal (No Virtual) ==========" << std::endl; + { + std::cout << "\n========== WrongAnimal ==========" << std::endl; + const WrongAnimal* k = new WrongAnimal(); + std::cout << "WrongAnimal type: " << k->getType() << std::endl; + k->makeSound(); // WrongAnimal sound + delete k; + + std::cout << "\n========== WrongCat ==========" << std::endl; + const WrongAnimal* l = new WrongCat(); + std::cout << "WrongCat type: " << l->getType() << std::endl; + l->makeSound(); // WrongAnimal sound aussi (pas de polymorphisme!) + delete l; + } + return (0); +} diff --git a/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..08d0c3d --- /dev/null +++ b/ex00/Makefile @@ -0,0 +1,36 @@ +CXX = c++ +CXXFLAGS = -Wall -Wextra -Werror -std=c++98 +OBJDIR = obj +SOURCES = Main.cpp Dog.cpp Cat.cpp Animal.cpp WrongAnimal.cpp WrongCat.cpp +OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o)) +NAME = Animal + +all: $(NAME) + +$(OBJDIR): + @echo "๐Ÿ“ Creating obj directory..." + @mkdir -p $(OBJDIR) + +$(OBJDIR)/%.o: %.cpp | $(OBJDIR) + @echo "๐Ÿง  Compiling $< ..." + @$(CXX) $(CXXFLAGS) -c $< -o $@ + @echo "โœ… $@ ready!" + +$(NAME): $(OBJECTS) + @echo "๐Ÿ”— Linking $(NAME) ..." + @$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME) + @echo "๐ŸŽ‰ $(NAME) is ready!" + +clean: + @echo "๐Ÿงน Cleaning object files..." + @rm -rf $(OBJDIR) + @echo "โœจ Objects cleaned!" + +fclean: clean + @echo "๐Ÿ—‘๏ธ Removing $(NAME)..." + @rm -f $(NAME) + @echo "๐Ÿ’€ Full clean complete!" + +re: fclean all + +.PHONY: all clean fclean re \ No newline at end of file diff --git a/ex00/WrongAnimal.cpp b/ex00/WrongAnimal.cpp new file mode 100644 index 0000000..f1ef74b --- /dev/null +++ b/ex00/WrongAnimal.cpp @@ -0,0 +1,38 @@ +# include "WrongAnimal.hpp" + +WrongAnimal::WrongAnimal (std::string type) : _type(type) +{ + std::cout << "WrongAnimal constructor called\n"; +} + +WrongAnimal::WrongAnimal() : _type("Default") +{ + std::cout << "WrongAnimal def constructor called\n"; +} + +WrongAnimal::WrongAnimal(const WrongAnimal &other) : _type(other._type) +{ + std::cout << "WrongAnimal copy constructor called\n"; +} + +WrongAnimal &WrongAnimal::operator=(const WrongAnimal &other) +{ + _type = other._type; + std::cout << "WrongAnimal copy assignment constructor called\n"; + return (*this); +} + +WrongAnimal::~WrongAnimal() +{ + std::cout << "WrongAnimal deconstructor called\n"; +} + +void WrongAnimal::makeSound() const +{ + std::cout << "WrongAnimal can make different sounds.\n"; +} + +std::string WrongAnimal::getType() const +{ + return (_type); +} \ No newline at end of file diff --git a/ex00/WrongAnimal.hpp b/ex00/WrongAnimal.hpp new file mode 100644 index 0000000..5801377 --- /dev/null +++ b/ex00/WrongAnimal.hpp @@ -0,0 +1,21 @@ +#ifndef WRONGANIMAL_HPP +# define WRONGANIMAL_HPP + +# include + +class WrongAnimal +{ + protected : + std::string _type; + public : + WrongAnimal(); + WrongAnimal(std::string type); + WrongAnimal(const WrongAnimal &other); + virtual ~WrongAnimal(); + WrongAnimal & operator=(const WrongAnimal &other); + + void makeSound() const; + std::string getType() const; +}; + +#endif \ No newline at end of file diff --git a/ex00/WrongCat.cpp b/ex00/WrongCat.cpp new file mode 100644 index 0000000..9b76f42 --- /dev/null +++ b/ex00/WrongCat.cpp @@ -0,0 +1,36 @@ +# include "WrongCat.hpp" + +WrongCat::WrongCat () : WrongAnimal() +{ + _type = "WrongCat"; + std::cout << "WrongCat constructor called\n"; +} + +WrongCat::WrongCat (std::string type) : WrongAnimal(type) +{ + _type = type; + std::cout << "WrongCat constructor called\n"; +} + +WrongCat::WrongCat(const WrongCat &other) : WrongAnimal() +{ + *this = other; + std::cout << "WrongCat copy constructor called\n"; +} + +WrongCat &WrongCat::operator=(const WrongCat &other) +{ + _type = other._type; + std::cout << "WrongCat copy assignment constructor called\n"; + return (*this); +} + +WrongCat::~WrongCat() +{ + std::cout << "WrongCat deconstructor called\n"; +} + +void WrongCat::makeSound() const +{ + std::cout << "wrongmiaou wrongmiaou wrongmiaou\n"; +} \ No newline at end of file diff --git a/ex00/WrongCat.hpp b/ex00/WrongCat.hpp new file mode 100644 index 0000000..1629003 --- /dev/null +++ b/ex00/WrongCat.hpp @@ -0,0 +1,18 @@ +#ifndef WrongCat_HPP +# define WrongCat_HPP + +# include +# include "WrongAnimal.hpp" + +class WrongCat : public WrongAnimal +{ + public : + WrongCat(); + WrongCat(std::string type); + WrongCat(const WrongCat &other); + virtual ~WrongCat(); + WrongCat & operator=(const WrongCat &other); + + virtual void makeSound() const; +}; +#endif \ No newline at end of file diff --git a/ex01/Animal.cpp b/ex01/Animal.cpp new file mode 100644 index 0000000..0c513b3 --- /dev/null +++ b/ex01/Animal.cpp @@ -0,0 +1,38 @@ +# include "Animal.hpp" + +Animal::Animal (std::string type) : _type(type) +{ + std::cout << "Animal constructor called\n"; +} + +Animal::Animal() : _type("Default") +{ + std::cout << "Animal def constructor called\n"; +} + +Animal::Animal(const Animal &other) : _type(other._type) +{ + std::cout << "Animal copy constructor called\n"; +} + +Animal &Animal::operator=(const Animal &other) +{ + _type = other._type; + std::cout << "Animal copy assignment constructor called\n"; + return (*this); +} + +Animal::~Animal() +{ + std::cout << "Animal deconstructor called\n"; +} + +void Animal::makeSound() const +{ + std::cout << "Animal can make different sounds.\n"; +} + +std::string Animal::getType() const +{ + return (_type); +} \ No newline at end of file diff --git a/ex01/Animal.hpp b/ex01/Animal.hpp new file mode 100644 index 0000000..5208841 --- /dev/null +++ b/ex01/Animal.hpp @@ -0,0 +1,22 @@ +#ifndef ANIMAL_HPP +# define ANIMAL_HPP + +# include +# include "Brain.hpp" +class Animal +{ + protected : + std::string _type; + + public : + Animal(); + Animal(std::string type); + Animal(const Animal &other); + virtual ~Animal(); + Animal & operator=(const Animal &other); + + virtual void makeSound() const; + std::string getType() const; +}; + +#endif \ No newline at end of file diff --git a/ex01/Brain.cpp b/ex01/Brain.cpp new file mode 100644 index 0000000..176c1b1 --- /dev/null +++ b/ex01/Brain.cpp @@ -0,0 +1,37 @@ +#include "Brain.hpp" + +Brain::Brain() +{ + int i = 0; + while (i < 100) + { + std::ostringstream oss; + oss << "idea" << i; + ideas[i] = oss.str(); + i++; + } + std::cout << "Brain def constructor called\n"; +} + +Brain::Brain(const Brain &other) +{ + *this = other; + std::cout << "Brain copy constructor called\n"; +} + +Brain &Brain::operator=(const Brain &other) +{ + int i = 0; + while (i < 100) + { + ideas[i] = other.ideas[i]; + i++; + } + std::cout << "Brain copy assignment constructor called\n"; + return (*this); +} + +Brain::~Brain() +{ + std::cout << "Brain deconstructor called\n"; +} \ No newline at end of file diff --git a/ex01/Brain.hpp b/ex01/Brain.hpp new file mode 100644 index 0000000..f4817f3 --- /dev/null +++ b/ex01/Brain.hpp @@ -0,0 +1,18 @@ +#ifndef BRAIN_HPP +# define BRAIN_HPP + +# include +# include + +class Brain +{ + public: + Brain(); + Brain(const Brain &other); + Brain &operator=(const Brain &other); + ~Brain(); + + std::string ideas[100]; +}; + +#endif \ No newline at end of file diff --git a/ex01/Cat.cpp b/ex01/Cat.cpp new file mode 100644 index 0000000..6fd12c7 --- /dev/null +++ b/ex01/Cat.cpp @@ -0,0 +1,62 @@ +# include "Cat.hpp" + +Cat::Cat () : Animal() +{ + _type = "Cat"; + _brain = new Brain(); + std::cout << "Cat constructor called\n"; +} + +Cat::Cat (std::string type) : Animal(type) +{ + _type = type; + _brain = new Brain(); + std::cout << "Cat constructor called\n"; +} + +Cat::Cat(const Cat &other) : Animal() +{ + _brain = new Brain(*(other._brain)); + std::cout << "Cat copy constructor called\n"; +} + +Cat &Cat::operator=(const Cat &other) +{ + _type = other._type; + delete _brain; + _brain = new Brain(*(other._brain)); + std::cout << "Cat copy assignment constructor called\n"; + return (*this); +} + +Cat::~Cat() +{ + delete _brain; + std::cout << "Cat deconstructor called\n"; +} + +void Cat::makeSound() const +{ + std::cout << "miaou miaou miaou (je suis relou) miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou\n"; +} + +std::string Cat::getIdea(int n_idea) const +{ + if (n_idea < 0) + return "Negative ideas number is not posible.\n"; + else if (n_idea > 99) + return "A cat's brain can have up to 100 ideas.\n"; + else + return _brain->ideas[n_idea]; + +} + +void Cat::setIdea(int n_idea, std::string idea) +{ + if (n_idea < 0) + std::cout << "Negative idea number is not posible.\n"; + else if (n_idea > 99) + std::cout << "A cat's brain can have up to 100 ideas.\n"; + else + _brain->ideas[n_idea] = idea; +} \ No newline at end of file diff --git a/ex01/Cat.hpp b/ex01/Cat.hpp new file mode 100644 index 0000000..9464a4b --- /dev/null +++ b/ex01/Cat.hpp @@ -0,0 +1,25 @@ +#ifndef CAT_HPP +# define CAT_HPP + +# include +# include "Animal.hpp" +# include "Brain.hpp" + +class Cat : public Animal +{ + private: + Brain *_brain; + + public : + Cat(); + Cat(std::string type); + Cat(const Cat &other); + virtual ~Cat(); + Cat & operator=(const Cat &other); + + virtual void makeSound() const; + std::string getIdea(int n_idea) const; + void setIdea(int n_idea, std::string idea); +}; + +#endif \ No newline at end of file diff --git a/ex01/Dog.cpp b/ex01/Dog.cpp new file mode 100644 index 0000000..b4bd103 --- /dev/null +++ b/ex01/Dog.cpp @@ -0,0 +1,62 @@ +# include "Dog.hpp" + +Dog::Dog() : Animal() +{ + _type = "Dog"; + _brain = new Brain(); + std::cout << "Dog default constructor called\n"; +} + +Dog::Dog (std::string type) : Animal(type) +{ + _type = type; + _brain = new Brain(); + std::cout << "Dog constructor called\n"; +} + +Dog::Dog(const Dog &other) : Animal(other) +{ + _brain = new Brain(*(other._brain)); + std::cout << "Dog copy constructor called\n"; +} + +Dog &Dog::operator=(const Dog &other) +{ + _type = other._type; + delete _brain; + _brain = new Brain(*(other._brain)); + std::cout << "Dog copy assignment constructor called\n"; + return (*this); +} + +Dog::~Dog() +{ + delete _brain; + std::cout << "Dog deconstructor called\n"; +} + +void Dog::makeSound() const +{ + std::cout << "Waf Waf Waf\n"; +} + +std::string Dog::getIdea(int n_idea) const +{ + if (n_idea < 0) + return "Negative ideas number is not posible.\n"; + else if (n_idea > 99) + return "A dog's brain can have up to 100 ideas.\n"; + else + return _brain->ideas[n_idea]; + +} + +void Dog::setIdea(int n_idea, std::string idea) +{ + if (n_idea < 0) + std::cout << "Negative idea number is not posible.\n"; + else if (n_idea > 99) + std::cout << "A dog's brain can have up to 100 ideas.\n"; + else + _brain->ideas[n_idea] = idea; +} \ No newline at end of file diff --git a/ex01/Dog.hpp b/ex01/Dog.hpp new file mode 100644 index 0000000..d4c432c --- /dev/null +++ b/ex01/Dog.hpp @@ -0,0 +1,25 @@ +#ifndef DOG_HPP +# define DOG_HPP + +# include +# include "Animal.hpp" +# include "Brain.hpp" + +class Dog : public Animal +{ + private: + Brain *_brain; + + public : + Dog(); + Dog(std::string type); + Dog(const Dog &other); + virtual ~Dog(); + Dog & operator=(const Dog &other); + + virtual void makeSound() const; + std::string getIdea(int n_idea) const; + void setIdea(int n_idea, std::string idea); +}; + +#endif \ No newline at end of file diff --git a/ex01/Main.cpp b/ex01/Main.cpp new file mode 100644 index 0000000..18656c8 --- /dev/null +++ b/ex01/Main.cpp @@ -0,0 +1,81 @@ +# include "Animal.hpp" +# include "WrongAnimal.hpp" +# include "Dog.hpp" +# include "Cat.hpp" +# include "WrongCat.hpp" + +int main() +{ + std::cout << "========== TEST 1: Array of 10 Animals ==========" << std::endl; + { + const int size = 10; + Animal* animals[size]; + + int i = 0; + while (i < size) + { + if (i % 2 == 0) + animals[i] = new Dog(); + else + animals[i] = new Cat(); + i++; + } + std::cout << "\n--- Making sounds ---" << std::endl; + i = 0; + while (i < size) + { + std::cout << "Animal " << i << " (" << animals[i]->getType() << "): "; + animals[i]->makeSound(); + i++; + } + std::cout << "\n--- Deleting animals ---" << std::endl; + i = 0; + while (i < size) + { + delete animals[i]; + i++; + } + } + + std::cout << "\n========== TEST 2: Get Ideas from Brain ==========" << std::endl; + { + Dog dog; + Cat cat; + + std::cout << "\n--- Dog ideas ---" << std::endl; + std::cout << "Idea 0: " << dog.getIdea(0) << std::endl; + std::cout << "Idea 42: " << dog.getIdea(42) << std::endl; + std::cout << "Idea 99: " << dog.getIdea(99) << std::endl; + std::cout << "\n--- Cat ideas ---" << std::endl; + std::cout << "Idea 5: " << cat.getIdea(5) << std::endl; + std::cout << "Idea 50: " << cat.getIdea(50) << std::endl; + std::cout << "Idea 98: " << cat.getIdea(98) << std::endl; + std::cout << "\n========== Index Out of Range ==========\n" << std::endl; + std::cout << "Trying to access idea 100: " << dog.getIdea(100) << std::endl; + std::cout << "Trying to access idea 150: " << dog.getIdea(150) << std::endl; + std::cout << "Trying to access idea -1: " << dog.getIdea(-1) << std::endl; + } + + std::cout << "\n========== TEST 4: Deep Copy Test ==========" << std::endl; + { + std::cout << "--- Creating original dog ---" << std::endl; + Dog* original = new Dog(); + original->setIdea(10, "idee test"); + std::cout << "\nOriginal dog idea 10: " << original->getIdea(10) << std::endl; + std::cout << "\n--- Creating copy ---" << std::endl; + Dog* copy = new Dog(*original); + std::cout << "\nCopy dog idea 10: " << copy->getIdea(10) << std::endl; + std::cout << "\n--- Modifying original's idea ---" << std::endl; + original->setIdea(10, "Modified idea in original"); + std::cout << "\nOriginal dog idea 10 after modification: " << original->getIdea(10) << std::endl; + std::cout << "Copy dog idea 10 (should be unchanged): " << copy->getIdea(10) << std::endl; + std::cout << "\n--- Deleting original ---" << std::endl; + delete original; + std::cout << "\n--- Copy still works after original deleted ---" << std::endl; + std::cout << "Copy dog idea 10: " << copy->getIdea(10) << std::endl; + copy->makeSound(); + std::cout << "\n--- Deleting copy ---" << std::endl; + delete copy; + } + return 0; +} \ No newline at end of file diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..25ba639 --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,36 @@ +CXX = c++ +CXXFLAGS = -Wall -Wextra -Werror -std=c++98 +OBJDIR = obj +SOURCES = Main.cpp Dog.cpp Cat.cpp Animal.cpp WrongAnimal.cpp WrongCat.cpp Brain.cpp +OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o)) +NAME = Animal + +all: $(NAME) + +$(OBJDIR): + @echo "๐Ÿ“ Creating obj directory..." + @mkdir -p $(OBJDIR) + +$(OBJDIR)/%.o: %.cpp | $(OBJDIR) + @echo "๐Ÿง  Compiling $< ..." + @$(CXX) $(CXXFLAGS) -c $< -o $@ + @echo "โœ… $@ ready!" + +$(NAME): $(OBJECTS) + @echo "๐Ÿ”— Linking $(NAME) ..." + @$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME) + @echo "๐ŸŽ‰ $(NAME) is ready!" + +clean: + @echo "๐Ÿงน Cleaning object files..." + @rm -rf $(OBJDIR) + @echo "โœจ Objects cleaned!" + +fclean: clean + @echo "๐Ÿ—‘๏ธ Removing $(NAME)..." + @rm -f $(NAME) + @echo "๐Ÿ’€ Full clean complete!" + +re: fclean all + +.PHONY: all clean fclean re \ No newline at end of file diff --git a/ex01/WrongAnimal.cpp b/ex01/WrongAnimal.cpp new file mode 100644 index 0000000..f1ef74b --- /dev/null +++ b/ex01/WrongAnimal.cpp @@ -0,0 +1,38 @@ +# include "WrongAnimal.hpp" + +WrongAnimal::WrongAnimal (std::string type) : _type(type) +{ + std::cout << "WrongAnimal constructor called\n"; +} + +WrongAnimal::WrongAnimal() : _type("Default") +{ + std::cout << "WrongAnimal def constructor called\n"; +} + +WrongAnimal::WrongAnimal(const WrongAnimal &other) : _type(other._type) +{ + std::cout << "WrongAnimal copy constructor called\n"; +} + +WrongAnimal &WrongAnimal::operator=(const WrongAnimal &other) +{ + _type = other._type; + std::cout << "WrongAnimal copy assignment constructor called\n"; + return (*this); +} + +WrongAnimal::~WrongAnimal() +{ + std::cout << "WrongAnimal deconstructor called\n"; +} + +void WrongAnimal::makeSound() const +{ + std::cout << "WrongAnimal can make different sounds.\n"; +} + +std::string WrongAnimal::getType() const +{ + return (_type); +} \ No newline at end of file diff --git a/ex01/WrongAnimal.hpp b/ex01/WrongAnimal.hpp new file mode 100644 index 0000000..5801377 --- /dev/null +++ b/ex01/WrongAnimal.hpp @@ -0,0 +1,21 @@ +#ifndef WRONGANIMAL_HPP +# define WRONGANIMAL_HPP + +# include + +class WrongAnimal +{ + protected : + std::string _type; + public : + WrongAnimal(); + WrongAnimal(std::string type); + WrongAnimal(const WrongAnimal &other); + virtual ~WrongAnimal(); + WrongAnimal & operator=(const WrongAnimal &other); + + void makeSound() const; + std::string getType() const; +}; + +#endif \ No newline at end of file diff --git a/ex01/WrongCat.cpp b/ex01/WrongCat.cpp new file mode 100644 index 0000000..9b76f42 --- /dev/null +++ b/ex01/WrongCat.cpp @@ -0,0 +1,36 @@ +# include "WrongCat.hpp" + +WrongCat::WrongCat () : WrongAnimal() +{ + _type = "WrongCat"; + std::cout << "WrongCat constructor called\n"; +} + +WrongCat::WrongCat (std::string type) : WrongAnimal(type) +{ + _type = type; + std::cout << "WrongCat constructor called\n"; +} + +WrongCat::WrongCat(const WrongCat &other) : WrongAnimal() +{ + *this = other; + std::cout << "WrongCat copy constructor called\n"; +} + +WrongCat &WrongCat::operator=(const WrongCat &other) +{ + _type = other._type; + std::cout << "WrongCat copy assignment constructor called\n"; + return (*this); +} + +WrongCat::~WrongCat() +{ + std::cout << "WrongCat deconstructor called\n"; +} + +void WrongCat::makeSound() const +{ + std::cout << "wrongmiaou wrongmiaou wrongmiaou\n"; +} \ No newline at end of file diff --git a/ex01/WrongCat.hpp b/ex01/WrongCat.hpp new file mode 100644 index 0000000..f69af98 --- /dev/null +++ b/ex01/WrongCat.hpp @@ -0,0 +1,19 @@ +#ifndef WrongCat_HPP +# define WrongCat_HPP + +# include +# include "WrongAnimal.hpp" + +class WrongCat : public WrongAnimal +{ + public : + WrongCat(); + WrongCat(std::string type); + WrongCat(const WrongCat &other); + virtual ~WrongCat(); + WrongCat & operator=(const WrongCat &other); + + virtual void makeSound() const; +}; + +#endif \ No newline at end of file diff --git a/ex02/AAnimal.cpp b/ex02/AAnimal.cpp new file mode 100644 index 0000000..31ff559 --- /dev/null +++ b/ex02/AAnimal.cpp @@ -0,0 +1,38 @@ +# include "AAnimal.hpp" + +AAnimal::AAnimal (std::string type) : _type(type) +{ + std::cout << "AAnimal constructor called\n"; +} + +AAnimal::AAnimal() : _type("Default") +{ + std::cout << "AAnimal def constructor called\n"; +} + +AAnimal::AAnimal(const AAnimal &other) : _type(other._type) +{ + std::cout << "AAnimal copy constructor called\n"; +} + +AAnimal &AAnimal::operator=(const AAnimal &other) +{ + _type = other._type; + std::cout << "AAnimal copy assignment constructor called\n"; + return (*this); +} + +AAnimal::~AAnimal() +{ + std::cout << "AAnimal deconstructor called\n"; +} + +void AAnimal::makeSound() const +{ + std::cout << "AAnimal can make different sounds.\n"; +} + +std::string AAnimal::getType() const +{ + return (_type); +} \ No newline at end of file diff --git a/ex02/AAnimal.hpp b/ex02/AAnimal.hpp new file mode 100644 index 0000000..5a4de4e --- /dev/null +++ b/ex02/AAnimal.hpp @@ -0,0 +1,22 @@ +#ifndef AANIMAL_HPP +# define AANIMAL_HPP + +# include +# include "Brain.hpp" +class AAnimal +{ + protected : + std::string _type; + + public : + AAnimal(); + AAnimal(std::string type); + AAnimal(const AAnimal &other); + virtual ~AAnimal(); + AAnimal & operator=(const AAnimal &other); + + virtual void makeSound() const = 0; + std::string getType() const; +}; + +#endif \ No newline at end of file diff --git a/ex02/Brain.cpp b/ex02/Brain.cpp new file mode 100644 index 0000000..176c1b1 --- /dev/null +++ b/ex02/Brain.cpp @@ -0,0 +1,37 @@ +#include "Brain.hpp" + +Brain::Brain() +{ + int i = 0; + while (i < 100) + { + std::ostringstream oss; + oss << "idea" << i; + ideas[i] = oss.str(); + i++; + } + std::cout << "Brain def constructor called\n"; +} + +Brain::Brain(const Brain &other) +{ + *this = other; + std::cout << "Brain copy constructor called\n"; +} + +Brain &Brain::operator=(const Brain &other) +{ + int i = 0; + while (i < 100) + { + ideas[i] = other.ideas[i]; + i++; + } + std::cout << "Brain copy assignment constructor called\n"; + return (*this); +} + +Brain::~Brain() +{ + std::cout << "Brain deconstructor called\n"; +} \ No newline at end of file diff --git a/ex02/Brain.hpp b/ex02/Brain.hpp new file mode 100644 index 0000000..f4817f3 --- /dev/null +++ b/ex02/Brain.hpp @@ -0,0 +1,18 @@ +#ifndef BRAIN_HPP +# define BRAIN_HPP + +# include +# include + +class Brain +{ + public: + Brain(); + Brain(const Brain &other); + Brain &operator=(const Brain &other); + ~Brain(); + + std::string ideas[100]; +}; + +#endif \ No newline at end of file diff --git a/ex02/Cat.cpp b/ex02/Cat.cpp new file mode 100644 index 0000000..056787e --- /dev/null +++ b/ex02/Cat.cpp @@ -0,0 +1,62 @@ +# include "Cat.hpp" + +Cat::Cat () : AAnimal() +{ + _type = "Cat"; + _brain = new Brain(); + std::cout << "Cat constructor called\n"; +} + +Cat::Cat (std::string type) : AAnimal(type) +{ + _type = type; + _brain = new Brain(); + std::cout << "Cat constructor called\n"; +} + +Cat::Cat(const Cat &other) : AAnimal() +{ + _brain = new Brain(*(other._brain)); + std::cout << "Cat copy constructor called\n"; +} + +Cat &Cat::operator=(const Cat &other) +{ + _type = other._type; + delete _brain; + _brain = new Brain(*(other._brain)); + std::cout << "Cat copy assignment constructor called\n"; + return (*this); +} + +Cat::~Cat() +{ + delete _brain; + std::cout << "Cat deconstructor called\n"; +} + +void Cat::makeSound() const +{ + std::cout << "miaou miaou miaou (je suis relou) miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou miaou\n"; +} + +std::string Cat::getIdea(int n_idea) const +{ + if (n_idea < 0) + return "Negative ideas number is not posible.\n"; + else if (n_idea > 99) + return "A cat's brain can have up to 100 ideas.\n"; + else + return _brain->ideas[n_idea]; + +} + +void Cat::setIdea(int n_idea, std::string idea) +{ + if (n_idea < 0) + std::cout << "Negative idea number is not posible.\n"; + else if (n_idea > 99) + std::cout << "A cat's brain can have up to 100 ideas.\n"; + else + _brain->ideas[n_idea] = idea; +} \ No newline at end of file diff --git a/ex02/Cat.hpp b/ex02/Cat.hpp new file mode 100644 index 0000000..c0ee4d7 --- /dev/null +++ b/ex02/Cat.hpp @@ -0,0 +1,25 @@ +#ifndef CAT_HPP +# define CAT_HPP + +# include +# include "AAnimal.hpp" +# include "Brain.hpp" + +class Cat : public AAnimal +{ + private: + Brain *_brain; + + public : + Cat(); + Cat(std::string type); + Cat(const Cat &other); + virtual ~Cat(); + Cat & operator=(const Cat &other); + + virtual void makeSound() const; + std::string getIdea(int n_idea) const; + void setIdea(int n_idea, std::string idea); +}; + +#endif \ No newline at end of file diff --git a/ex02/Dog.cpp b/ex02/Dog.cpp new file mode 100644 index 0000000..2c9e4a6 --- /dev/null +++ b/ex02/Dog.cpp @@ -0,0 +1,62 @@ +# include "Dog.hpp" + +Dog::Dog() : AAnimal() +{ + _type = "Dog"; + _brain = new Brain(); + std::cout << "Dog default constructor called\n"; +} + +Dog::Dog (std::string type) : AAnimal(type) +{ + _type = type; + _brain = new Brain(); + std::cout << "Dog constructor called\n"; +} + +Dog::Dog(const Dog &other) : AAnimal(other) +{ + _brain = new Brain(*(other._brain)); + std::cout << "Dog copy constructor called\n"; +} + +Dog &Dog::operator=(const Dog &other) +{ + _type = other._type; + delete _brain; + _brain = new Brain(*(other._brain)); + std::cout << "Dog copy assignment constructor called\n"; + return (*this); +} + +Dog::~Dog() +{ + delete _brain; + std::cout << "Dog deconstructor called\n"; +} + +void Dog::makeSound() const +{ + std::cout << "Waf Waf Waf\n"; +} + +std::string Dog::getIdea(int n_idea) const +{ + if (n_idea < 0) + return "Negative ideas number is not posible.\n"; + else if (n_idea > 99) + return "A dog's brain can have up to 100 ideas.\n"; + else + return _brain->ideas[n_idea]; + +} + +void Dog::setIdea(int n_idea, std::string idea) +{ + if (n_idea < 0) + std::cout << "Negative idea number is not posible.\n"; + else if (n_idea > 99) + std::cout << "A dog's brain can have up to 100 ideas.\n"; + else + _brain->ideas[n_idea] = idea; +} \ No newline at end of file diff --git a/ex02/Dog.hpp b/ex02/Dog.hpp new file mode 100644 index 0000000..c85c0fe --- /dev/null +++ b/ex02/Dog.hpp @@ -0,0 +1,25 @@ +#ifndef DOG_HPP +# define DOG_HPP + +# include +# include "AAnimal.hpp" +# include "Brain.hpp" + +class Dog : public AAnimal +{ + private: + Brain *_brain; + + public : + Dog(); + Dog(std::string type); + Dog(const Dog &other); + virtual ~Dog(); + Dog & operator=(const Dog &other); + + virtual void makeSound() const; + std::string getIdea(int n_idea) const; + void setIdea(int n_idea, std::string idea); +}; + +#endif \ No newline at end of file diff --git a/ex02/Main.cpp b/ex02/Main.cpp new file mode 100644 index 0000000..88c5f08 --- /dev/null +++ b/ex02/Main.cpp @@ -0,0 +1,103 @@ +# include "AAnimal.hpp" +# include "WrongAnimal.hpp" +# include "Dog.hpp" +# include "Cat.hpp" +# include "WrongCat.hpp" + +int main() +{ + std::cout << "========== TEST 1: Basic AAnimal ==========" << std::endl; + { + // decom for testing + + // std::cout << "\n========== AAnimal ==========" << std::endl; + // const AAnimal* meta = new AAnimal(); + // std::cout << meta->getType() << " " << std::endl; + // meta->makeSound(); + // delete meta; + + std::cout << "\n========== Dog ==========" << std::endl; + const AAnimal* j = new Dog(); + std::cout << j->getType() << " " << std::endl; + j->makeSound(); + delete j; + + std::cout << "\n========== Cat ==========" << std::endl; + const AAnimal* i = new Cat(); + std::cout << i->getType() << " " << std::endl; + i->makeSound(); + delete i; + } + std::cout << "\n========== TEST 1: Array of 10 Animals ==========" << std::endl; + { + const int size = 10; + AAnimal* animals[size]; + + int i = 0; + while (i < size) + { + if (i % 2 == 0) + animals[i] = new Dog(); + else + animals[i] = new Cat(); + i++; + } + std::cout << "\n--- Making sounds ---" << std::endl; + i = 0; + while (i < size) + { + std::cout << "AAnimal " << i << " (" << animals[i]->getType() << "): "; + animals[i]->makeSound(); + i++; + } + std::cout << "\n--- Deleting animals ---" << std::endl; + i = 0; + while (i < size) + { + delete animals[i]; + i++; + } + } + + std::cout << "\n========== TEST 2: Get Ideas from Brain ==========" << std::endl; + { + Dog dog; + Cat cat; + + std::cout << "\n--- Dog ideas ---" << std::endl; + std::cout << "Idea 0: " << dog.getIdea(0) << std::endl; + std::cout << "Idea 42: " << dog.getIdea(42) << std::endl; + std::cout << "Idea 99: " << dog.getIdea(99) << std::endl; + std::cout << "\n--- Cat ideas ---" << std::endl; + std::cout << "Idea 5: " << cat.getIdea(5) << std::endl; + std::cout << "Idea 50: " << cat.getIdea(50) << std::endl; + std::cout << "Idea 98: " << cat.getIdea(98) << std::endl; + std::cout << "\n========== Index Out of Range ==========\n" << std::endl; + std::cout << "Trying to access idea 100: " << dog.getIdea(100) << std::endl; + std::cout << "Trying to access idea 150: " << dog.getIdea(150) << std::endl; + std::cout << "Trying to access idea -1: " << dog.getIdea(-1) << std::endl; + } + + std::cout << "\n========== TEST 4: Deep Copy Test ==========" << std::endl; + { + std::cout << "--- Creating original dog ---" << std::endl; + Dog* original = new Dog(); + original->setIdea(10, "idee test"); + std::cout << "\nOriginal dog idea 10: " << original->getIdea(10) << std::endl; + std::cout << "\n--- Creating copy ---" << std::endl; + Dog* copy = new Dog(*original); + std::cout << "\nCopy dog idea 10: " << copy->getIdea(10) << std::endl; + std::cout << "\n--- Modifying original's idea ---" << std::endl; + original->setIdea(10, "Modified idea in original"); + std::cout << "\nOriginal dog idea 10 after modification: " << original->getIdea(10) << std::endl; + std::cout << "Copy dog idea 10 (should be unchanged): " << copy->getIdea(10) << std::endl; + std::cout << "\n--- Deleting original ---" << std::endl; + delete original; + std::cout << "\n--- Copy still works after original deleted ---" << std::endl; + std::cout << "Copy dog idea 10: " << copy->getIdea(10) << std::endl; + copy->makeSound(); + std::cout << "\n--- Deleting copy ---" << std::endl; + delete copy; + } + return 0; +} \ No newline at end of file diff --git a/ex02/Makefile b/ex02/Makefile new file mode 100644 index 0000000..5b8851e --- /dev/null +++ b/ex02/Makefile @@ -0,0 +1,36 @@ +CXX = c++ +CXXFLAGS = -Wall -Wextra -Werror -std=c++98 +OBJDIR = obj +SOURCES = Main.cpp Dog.cpp Cat.cpp AAnimal.cpp WrongAnimal.cpp WrongCat.cpp Brain.cpp +OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o)) +NAME = AAnimal + +all: $(NAME) + +$(OBJDIR): + @echo "๐Ÿ“ Creating obj directory..." + @mkdir -p $(OBJDIR) + +$(OBJDIR)/%.o: %.cpp | $(OBJDIR) + @echo "๐Ÿง  Compiling $< ..." + @$(CXX) $(CXXFLAGS) -c $< -o $@ + @echo "โœ… $@ ready!" + +$(NAME): $(OBJECTS) + @echo "๐Ÿ”— Linking $(NAME) ..." + @$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME) + @echo "๐ŸŽ‰ $(NAME) is ready!" + +clean: + @echo "๐Ÿงน Cleaning object files..." + @rm -rf $(OBJDIR) + @echo "โœจ Objects cleaned!" + +fclean: clean + @echo "๐Ÿ—‘๏ธ Removing $(NAME)..." + @rm -f $(NAME) + @echo "๐Ÿ’€ Full clean complete!" + +re: fclean all + +.PHONY: all clean fclean re \ No newline at end of file diff --git a/ex02/WrongAnimal.cpp b/ex02/WrongAnimal.cpp new file mode 100644 index 0000000..f1ef74b --- /dev/null +++ b/ex02/WrongAnimal.cpp @@ -0,0 +1,38 @@ +# include "WrongAnimal.hpp" + +WrongAnimal::WrongAnimal (std::string type) : _type(type) +{ + std::cout << "WrongAnimal constructor called\n"; +} + +WrongAnimal::WrongAnimal() : _type("Default") +{ + std::cout << "WrongAnimal def constructor called\n"; +} + +WrongAnimal::WrongAnimal(const WrongAnimal &other) : _type(other._type) +{ + std::cout << "WrongAnimal copy constructor called\n"; +} + +WrongAnimal &WrongAnimal::operator=(const WrongAnimal &other) +{ + _type = other._type; + std::cout << "WrongAnimal copy assignment constructor called\n"; + return (*this); +} + +WrongAnimal::~WrongAnimal() +{ + std::cout << "WrongAnimal deconstructor called\n"; +} + +void WrongAnimal::makeSound() const +{ + std::cout << "WrongAnimal can make different sounds.\n"; +} + +std::string WrongAnimal::getType() const +{ + return (_type); +} \ No newline at end of file diff --git a/ex02/WrongAnimal.hpp b/ex02/WrongAnimal.hpp new file mode 100644 index 0000000..5801377 --- /dev/null +++ b/ex02/WrongAnimal.hpp @@ -0,0 +1,21 @@ +#ifndef WRONGANIMAL_HPP +# define WRONGANIMAL_HPP + +# include + +class WrongAnimal +{ + protected : + std::string _type; + public : + WrongAnimal(); + WrongAnimal(std::string type); + WrongAnimal(const WrongAnimal &other); + virtual ~WrongAnimal(); + WrongAnimal & operator=(const WrongAnimal &other); + + void makeSound() const; + std::string getType() const; +}; + +#endif \ No newline at end of file diff --git a/ex02/WrongCat.cpp b/ex02/WrongCat.cpp new file mode 100644 index 0000000..9b76f42 --- /dev/null +++ b/ex02/WrongCat.cpp @@ -0,0 +1,36 @@ +# include "WrongCat.hpp" + +WrongCat::WrongCat () : WrongAnimal() +{ + _type = "WrongCat"; + std::cout << "WrongCat constructor called\n"; +} + +WrongCat::WrongCat (std::string type) : WrongAnimal(type) +{ + _type = type; + std::cout << "WrongCat constructor called\n"; +} + +WrongCat::WrongCat(const WrongCat &other) : WrongAnimal() +{ + *this = other; + std::cout << "WrongCat copy constructor called\n"; +} + +WrongCat &WrongCat::operator=(const WrongCat &other) +{ + _type = other._type; + std::cout << "WrongCat copy assignment constructor called\n"; + return (*this); +} + +WrongCat::~WrongCat() +{ + std::cout << "WrongCat deconstructor called\n"; +} + +void WrongCat::makeSound() const +{ + std::cout << "wrongmiaou wrongmiaou wrongmiaou\n"; +} \ No newline at end of file diff --git a/ex02/WrongCat.hpp b/ex02/WrongCat.hpp new file mode 100644 index 0000000..f69af98 --- /dev/null +++ b/ex02/WrongCat.hpp @@ -0,0 +1,19 @@ +#ifndef WrongCat_HPP +# define WrongCat_HPP + +# include +# include "WrongAnimal.hpp" + +class WrongCat : public WrongAnimal +{ + public : + WrongCat(); + WrongCat(std::string type); + WrongCat(const WrongCat &other); + virtual ~WrongCat(); + WrongCat & operator=(const WrongCat &other); + + virtual void makeSound() const; +}; + +#endif \ No newline at end of file