From 7a64f69133bcb26f1035d136b1537b848c3a052f Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Wed, 9 Aug 2023 14:50:52 +0000 Subject: [PATCH] add ex00 --- ex00/Makefile | 25 +++++++++++++++++++++++++ ex00/src/Animal.cpp | 34 ++++++++++++++++++++++++++++++++++ ex00/src/Animal.hpp | 19 +++++++++++++++++++ ex00/src/Cat.cpp | 30 ++++++++++++++++++++++++++++++ ex00/src/Cat.hpp | 16 ++++++++++++++++ ex00/src/Dog.cpp | 30 ++++++++++++++++++++++++++++++ ex00/src/Dog.hpp | 16 ++++++++++++++++ ex00/src/WrongAnimal.cpp | 34 ++++++++++++++++++++++++++++++++++ ex00/src/WrongAnimal.hpp | 19 +++++++++++++++++++ ex00/src/WrongCat.cpp | 24 ++++++++++++++++++++++++ ex00/src/WrongCat.hpp | 14 ++++++++++++++ ex00/src/main.cpp | 24 ++++++++++++++++++++++++ 12 files changed, 285 insertions(+) create mode 100644 ex00/Makefile create mode 100644 ex00/src/Animal.cpp create mode 100644 ex00/src/Animal.hpp create mode 100644 ex00/src/Cat.cpp create mode 100644 ex00/src/Cat.hpp create mode 100644 ex00/src/Dog.cpp create mode 100644 ex00/src/Dog.hpp create mode 100644 ex00/src/WrongAnimal.cpp create mode 100644 ex00/src/WrongAnimal.hpp create mode 100644 ex00/src/WrongCat.cpp create mode 100644 ex00/src/WrongCat.hpp create mode 100644 ex00/src/main.cpp diff --git a/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..b10e2f7 --- /dev/null +++ b/ex00/Makefile @@ -0,0 +1,25 @@ +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +SRCDIR = src +OBJDIR = obj +NAME = ex00 + +SRCS = $(wildcard $(SRCDIR)/*.cpp) +OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS)) + +all: $(NAME) + +$(OBJDIR)/%.o: $(SRCDIR)/%.cpp + mkdir -p obj + $(CXX) $(CPPFLAGS) -c $< -o $@ + +$(NAME): $(OBJS) + $(CXX) $(CPPFLAGS) $^ -o $@ + +clean: + rm -rf $(OBJDIR)/*.o + +fclean: clean + rm -fr $(NAME) + +re: fclean all diff --git a/ex00/src/Animal.cpp b/ex00/src/Animal.cpp new file mode 100644 index 0000000..82f2e76 --- /dev/null +++ b/ex00/src/Animal.cpp @@ -0,0 +1,34 @@ +#include "Animal.hpp" +#include +#include + +Animal::Animal() +{ + std::cout << "Animal()" << std::endl; +} + +Animal::Animal(const Animal& src) +{ + *this = src; +} + +Animal& Animal::operator=(const Animal &src) +{ + this->type = src.type; + return *this; +} + +Animal::~Animal() +{ + std::cout << "~Animal()" << std::endl; +} + +void Animal::makeSound() const +{ + std::cout << "OuGABounga" << std::endl; +} + +std::string Animal::getType() const +{ + return this->type; +} diff --git a/ex00/src/Animal.hpp b/ex00/src/Animal.hpp new file mode 100644 index 0000000..56a00f6 --- /dev/null +++ b/ex00/src/Animal.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +class Animal +{ + public: + Animal(); + Animal(const Animal& src); + Animal &operator=(const Animal& src); + virtual ~Animal(); + + std::string getType() const; + + virtual void makeSound() const; + + protected: + std::string type; +}; diff --git a/ex00/src/Cat.cpp b/ex00/src/Cat.cpp new file mode 100644 index 0000000..51342b5 --- /dev/null +++ b/ex00/src/Cat.cpp @@ -0,0 +1,30 @@ +#include "Cat.hpp" +#include "Animal.hpp" +#include + +Cat::Cat() +{ + this->type = "Cat"; + std::cout << "Cat()" << std::endl; +} + +Cat& Cat::operator=(const Cat& src) +{ + this->type = src.type; + return *this; +} + +Cat::~Cat() +{ + std::cout << "~Cat()" << std::endl; +} + +Cat::Cat(const Cat& src): Animal() +{ + *this = src; +} + +void Cat::makeSound() const +{ + std::cout << "Meow Meow !" << std::endl; +} diff --git a/ex00/src/Cat.hpp b/ex00/src/Cat.hpp new file mode 100644 index 0000000..8492a66 --- /dev/null +++ b/ex00/src/Cat.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include "./Animal.hpp" + +class Cat : public Animal +{ + public: + Cat(const Cat& src); + Cat &operator=(const Cat& src); + Cat(); + ~Cat(); + + void makeSound() const; +}; diff --git a/ex00/src/Dog.cpp b/ex00/src/Dog.cpp new file mode 100644 index 0000000..1feba48 --- /dev/null +++ b/ex00/src/Dog.cpp @@ -0,0 +1,30 @@ +#include "Dog.hpp" +#include "Animal.hpp" +#include + +Dog::Dog() +{ + this->type = "Dog"; + std::cout << "Dog()" << std::endl; +} + +Dog& Dog::operator=(const Dog& src) +{ + this->type = src.type; + return *this; +} + +Dog::~Dog() +{ + std::cout << "~Dog()" << std::endl; +} + +Dog::Dog(const Dog& src): Animal() +{ + *this = src; +} + +void Dog::makeSound() const +{ + std::cout << "Ouaf ouaf !" << std::endl; +} diff --git a/ex00/src/Dog.hpp b/ex00/src/Dog.hpp new file mode 100644 index 0000000..2f94f96 --- /dev/null +++ b/ex00/src/Dog.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include "./Animal.hpp" + +class Dog : public Animal +{ + public: + Dog(const Dog& src); + Dog &operator=(const Dog& src); + Dog(); + ~Dog(); + + void makeSound() const; +}; diff --git a/ex00/src/WrongAnimal.cpp b/ex00/src/WrongAnimal.cpp new file mode 100644 index 0000000..fd22d4f --- /dev/null +++ b/ex00/src/WrongAnimal.cpp @@ -0,0 +1,34 @@ +#include "WrongAnimal.hpp" +#include +#include + +WrongAnimal::WrongAnimal() +{ + std::cout << "WrongAnimal()" << std::endl; +} + +WrongAnimal::WrongAnimal(const WrongAnimal& src) +{ + *this = src; +} + +WrongAnimal& WrongAnimal::operator=(const WrongAnimal &src) +{ + this->type = src.type; + return *this; +} + +WrongAnimal::~WrongAnimal() +{ + std::cout << "~WrongAnimal()" << std::endl; +} + +void WrongAnimal::makeSound() const +{ + std::cout << "OuGABounga" << std::endl; +} + +std::string WrongAnimal::getType() const +{ + return this->type; +} diff --git a/ex00/src/WrongAnimal.hpp b/ex00/src/WrongAnimal.hpp new file mode 100644 index 0000000..850f4f0 --- /dev/null +++ b/ex00/src/WrongAnimal.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +class WrongAnimal +{ + public: + WrongAnimal(); + WrongAnimal(const WrongAnimal& src); + WrongAnimal &operator=(const WrongAnimal& src); + virtual ~WrongAnimal(); + + std::string getType() const; + + void makeSound() const; + + protected: + std::string type; +}; diff --git a/ex00/src/WrongCat.cpp b/ex00/src/WrongCat.cpp new file mode 100644 index 0000000..5dd473c --- /dev/null +++ b/ex00/src/WrongCat.cpp @@ -0,0 +1,24 @@ +#include "WrongCat.hpp" +#include + +WrongCat::WrongCat() +{ + this->type = "WrongCat"; + std::cout << "WrongCat()" << std::endl; +} + +WrongCat& WrongCat::operator=(const WrongCat& src) +{ + this->type = src.type; + return *this; +} + +WrongCat::~WrongCat() +{ + std::cout << "~WrongCat()" << std::endl; +} + +WrongCat::WrongCat(const WrongCat& src): WrongAnimal() +{ + *this = src; +} diff --git a/ex00/src/WrongCat.hpp b/ex00/src/WrongCat.hpp new file mode 100644 index 0000000..e2b6f10 --- /dev/null +++ b/ex00/src/WrongCat.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +#include "./WrongAnimal.hpp" + +class WrongCat : public WrongAnimal +{ + public: + WrongCat(const WrongCat& src); + WrongCat &operator=(const WrongCat& src); + WrongCat(); + ~WrongCat(); +}; diff --git a/ex00/src/main.cpp b/ex00/src/main.cpp new file mode 100644 index 0000000..c4c702f --- /dev/null +++ b/ex00/src/main.cpp @@ -0,0 +1,24 @@ +#include + +#include "Cat.hpp" +#include "Dog.hpp" +#include "WrongCat.hpp" + +int main() +{ + 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(); + meta->makeSound(); + delete meta; + delete j; + delete i; + const WrongCat* kitten = new WrongCat(); + kitten->makeSound(); + delete kitten; + return 0; +}