diff --git a/d04/ex00/Animal.cpp b/d04/ex00/Animal.cpp new file mode 100644 index 0000000..1277ab5 --- /dev/null +++ b/d04/ex00/Animal.cpp @@ -0,0 +1,51 @@ +#include "Animal.hpp" + +#define COPLIEN_COLOR B_CYAN + +/********************************************* + * CONSTRUCTORS + *********************************************/ + +Animal::Animal() { + std::cout << COPLIEN_COLOR "Animal constructor" RESET "\n"; + type = "animal"; + return; +} + +Animal::Animal( Animal const & src ) { + std::cout << COPLIEN_COLOR "Animal copy constructor" RESET "\n"; + *this = src; + return; +} + +/********************************************* + * DESTRUCTORS + *********************************************/ + +Animal::~Animal() { + std::cout << COPLIEN_COLOR "Animal destructor" RESET "\n"; + return; +} + +/********************************************* + * OPERATORS + *********************************************/ + +Animal & Animal::operator=( Animal const & rhs ) { + if ( this != &rhs ) + { + type = rhs.getType(); + } + return *this; +} + +std::string Animal::getType() const {return type;} + +/********************************************* + * PUBLIC MEMBER FUNCTIONS + *********************************************/ + +void Animal::makeSound() const { + std::cout << "*sound*\n"; +} + diff --git a/d04/ex00/Animal.hpp b/d04/ex00/Animal.hpp new file mode 100644 index 0000000..ded6349 --- /dev/null +++ b/d04/ex00/Animal.hpp @@ -0,0 +1,29 @@ +#ifndef ANIMAL_HPP +# define ANIMAL_HPP + +# include "color.h" +#include +#include + +class Animal { + +public: + + Animal( void ); + Animal( Animal const & src ); + virtual ~Animal( void ); + Animal & operator=( Animal const & rhs ); + + virtual void makeSound() const; + std::string getType() const; + +protected: + + std::string type; + +private: + +}; + +#endif + diff --git a/d04/ex00/Cat.cpp b/d04/ex00/Cat.cpp new file mode 100644 index 0000000..e1eff33 --- /dev/null +++ b/d04/ex00/Cat.cpp @@ -0,0 +1,47 @@ +#include "Cat.hpp" + +#define COPLIEN_COLOR B_CYAN + +/********************************************* + * CONSTRUCTORS + *********************************************/ + +Cat::Cat() { + std::cout << COPLIEN_COLOR "Cat constructor" RESET "\n"; + type = "cat"; + return; +} + +Cat::Cat( Cat const & src ) { + std::cout << COPLIEN_COLOR "Cat copy constructor" RESET "\n"; + *this = src; + return; +} + +/********************************************* + * DESTRUCTORS + *********************************************/ + +Cat::~Cat() { + std::cout << COPLIEN_COLOR "Cat destructor" RESET "\n"; + return; +} + +/********************************************* + * OPERATORS + *********************************************/ + +Cat & Cat::operator=( Cat const & rhs ) { + Animal::operator=(rhs); + + return *this; +} + +/********************************************* + * PUBLIC MEMBER FUNCTIONS + *********************************************/ + +void Cat::makeSound() const { + std::cout << "*miaow*\n"; +} + diff --git a/d04/ex00/Cat.hpp b/d04/ex00/Cat.hpp new file mode 100644 index 0000000..885bd94 --- /dev/null +++ b/d04/ex00/Cat.hpp @@ -0,0 +1,28 @@ +#ifndef CAT_HPP +# define CAT_HPP + +#include "color.h" +#include +#include + +#include "Animal.hpp" + +class Cat : public Animal { + +public: + + Cat( void ); + Cat( Cat const & src ); + ~Cat( void ); + Cat & operator=( Cat const & rhs ); + + void makeSound() const; + +protected: + +private: + +}; + +#endif + diff --git a/d04/ex00/Dog.cpp b/d04/ex00/Dog.cpp new file mode 100644 index 0000000..bb66bf2 --- /dev/null +++ b/d04/ex00/Dog.cpp @@ -0,0 +1,46 @@ +#include "Dog.hpp" + +#define COPLIEN_COLOR B_CYAN + +/********************************************* + * CONSTRUCTORS + *********************************************/ + +Dog::Dog() { + std::cout << COPLIEN_COLOR "Dog constructor" RESET "\n"; + type = "dog"; + return; +} + +Dog::Dog( Dog const & src ) { + std::cout << COPLIEN_COLOR "Dog copy constructor" RESET "\n"; + *this = src; + return; +} + +/********************************************* + * DESTRUCTORS + *********************************************/ + +Dog::~Dog() { + std::cout << COPLIEN_COLOR "Dog destructor" RESET "\n"; + return; +} + +/********************************************* + * OPERATORS + *********************************************/ + +Dog & Dog::operator=( Dog const & rhs ) { + Animal::operator=(rhs); + return *this; +} + +/********************************************* + * PUBLIC MEMBER FUNCTIONS + *********************************************/ + +void Dog::makeSound() const { + std::cout << "*woof*\n"; +} + diff --git a/d04/ex00/Dog.hpp b/d04/ex00/Dog.hpp new file mode 100644 index 0000000..e6be05b --- /dev/null +++ b/d04/ex00/Dog.hpp @@ -0,0 +1,24 @@ +#ifndef DOG_HPP +# define DOG_HPP + +# include "color.h" +# include +# include + +# include "Animal.hpp" + +class Dog : public Animal { + +public: + + Dog( void ); + Dog( Dog const & src ); + ~Dog( void ); + Dog & operator=( Dog const & rhs ); + + void makeSound() const; + +}; + +#endif + diff --git a/d04/Makefile b/d04/ex00/Makefile similarity index 100% rename from d04/Makefile rename to d04/ex00/Makefile diff --git a/d04/ex00/WrongAnimal.cpp b/d04/ex00/WrongAnimal.cpp new file mode 100644 index 0000000..0768ba2 --- /dev/null +++ b/d04/ex00/WrongAnimal.cpp @@ -0,0 +1,55 @@ +#include "WrongAnimal.hpp" + +#define COPLIEN_COLOR B_CYAN + +/********************************************* + * CONSTRUCTORS + *********************************************/ + +WrongAnimal::WrongAnimal() { + std::cout << COPLIEN_COLOR "WrongAnimal constructor" RESET "\n"; + type = "wrong_animal"; + return; +} + +WrongAnimal::WrongAnimal( WrongAnimal const & src ) { + std::cout << COPLIEN_COLOR "WrongAnimal copy constructor" RESET "\n"; + *this = src; + return; +} + +/********************************************* + * DESTRUCTORS + *********************************************/ + +WrongAnimal::~WrongAnimal() { + std::cout << COPLIEN_COLOR "WrongAnimal destructor" RESET "\n"; + return; +} + +/********************************************* + * OPERATORS + *********************************************/ + +WrongAnimal & WrongAnimal::operator=( WrongAnimal const & rhs ) { + if ( this != &rhs ) + { + type = rhs.getType(); + } + return *this; +} + +/********************************************* + * ACCESSORS + *********************************************/ + +std::string WrongAnimal::getType() const {return type;} + +/********************************************* + * PUBLIC MEMBER FUNCTIONS + *********************************************/ + +void WrongAnimal::makeSound() const { + std::cout << "*sound*\n"; +} + diff --git a/d04/ex00/WrongAnimal.hpp b/d04/ex00/WrongAnimal.hpp new file mode 100644 index 0000000..fecb304 --- /dev/null +++ b/d04/ex00/WrongAnimal.hpp @@ -0,0 +1,27 @@ +#ifndef WRONG_ANIMAL_HPP +# define WRONG_ANIMAL_HPP + +#include "color.h" +#include +#include + +class WrongAnimal { + +public: + + WrongAnimal( void ); + WrongAnimal( WrongAnimal const & src ); + virtual ~WrongAnimal( void ); + WrongAnimal & operator=( WrongAnimal const & rhs ); + + void makeSound() const; + std::string getType() const; + +protected: + + std::string type; + +}; + +#endif + diff --git a/d04/ex00/WrongCat.cpp b/d04/ex00/WrongCat.cpp new file mode 100644 index 0000000..1c27203 --- /dev/null +++ b/d04/ex00/WrongCat.cpp @@ -0,0 +1,45 @@ +#include "WrongCat.hpp" + +#define COPLIEN_COLOR B_CYAN + +/********************************************* + * CONSTRUCTORS + *********************************************/ + +WrongCat::WrongCat() { + std::cout << COPLIEN_COLOR "WrongCat constructor" RESET "\n"; + type = "wrong_cat"; + return; +} + +WrongCat::WrongCat( WrongCat const & src ) { + std::cout << COPLIEN_COLOR "WrongCat copy constructor" RESET "\n"; + *this = src; + return; +} + +/********************************************* + * DESTRUCTORS + *********************************************/ + +WrongCat::~WrongCat() { + std::cout << COPLIEN_COLOR "Cat destructor" RESET "\n"; + return; +} + +/********************************************* + * OPERATORS + *********************************************/ + +WrongCat & WrongCat::operator=( WrongCat const & rhs ) { + WrongAnimal::operator=(rhs); + return *this; +} + +/********************************************* + * PUBLIC MEMBER FUNCTIONS + *********************************************/ + +void WrongCat::makeSound() const { + std::cout << "*miaow*\n"; +} diff --git a/d04/ex00/WrongCat.hpp b/d04/ex00/WrongCat.hpp new file mode 100644 index 0000000..6f50467 --- /dev/null +++ b/d04/ex00/WrongCat.hpp @@ -0,0 +1,24 @@ +#ifndef WRONG_CAT_HPP +# define WRONG_CAT_HPP + +#include "color.h" +#include +#include + +#include "WrongAnimal.hpp" + +class WrongCat : public WrongAnimal { + +public: + + WrongCat( void ); + WrongCat( WrongCat const & src ); + ~WrongCat( void ); + WrongCat & operator=( WrongCat const & rhs ); + + void makeSound() const; + +}; + +#endif + diff --git a/d04/ex00/color.h b/d04/ex00/color.h new file mode 100644 index 0000000..e313f5f --- /dev/null +++ b/d04/ex00/color.h @@ -0,0 +1,24 @@ +#ifndef COLOR_H +# define COLOR_H + +# define GRAY "\e[0;30m" +# define RED "\e[0;31m" +# define GREEN "\e[0;32m" +# define YELLOW "\e[0;33m" +# define BLUE "\e[0;34m" +# define PURPLE "\e[0;35m" +# define CYAN "\e[0;36m" +# define WHITE "\e[0;37m" + +# define B_GRAY "\e[1;30m" +# define B_RED "\e[1;31m" +# define B_GREEN "\e[1;32m" +# define B_YELLOW "\e[1;33m" +# define B_BLUE "\e[1;34m" +# define B_PURPLE "\e[1;35m" +# define B_CYAN "\e[1;36m" +# define B_WHITE "\e[1;37m" + +# define RESET "\e[0m" + +#endif diff --git a/d04/fr.subject.pdf b/d04/ex00/fr.subject.pdf similarity index 100% rename from d04/fr.subject.pdf rename to d04/ex00/fr.subject.pdf diff --git a/d04/ex00/main.cpp b/d04/ex00/main.cpp new file mode 100644 index 0000000..a8d6d75 --- /dev/null +++ b/d04/ex00/main.cpp @@ -0,0 +1,63 @@ +#include "Animal.hpp" +#include "Dog.hpp" +#include "Cat.hpp" +#include "WrongAnimal.hpp" +#include "WrongCat.hpp" + +#include +#include + +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; + } + + { + std::cout << std::endl; + const Cat* i = new Cat(); + const Animal* j = new Cat(); + std::cout << j->getType() << " " << std::endl; + std::cout << i->getType() << " " << std::endl; + i->makeSound(); + j->makeSound(); + delete j; + delete i; + } + + { + std::cout << std::endl; + const WrongAnimal* i = new WrongAnimal(); + const WrongAnimal* j = new WrongCat(); + std::cout << i->getType() << " " << std::endl; + std::cout << j->getType() << " " << std::endl; + i->makeSound(); + j->makeSound(); + delete j; + delete i; + } + + { + std::cout << std::endl; + const WrongCat* i = new WrongCat(); + const WrongAnimal* j = new WrongCat(); + std::cout << j->getType() << " " << std::endl; + std::cout << i->getType() << " " << std::endl; + i->makeSound(); + j->makeSound(); + delete j; + delete i; + } + + return 0; +} + diff --git a/d04/ex00/poly b/d04/ex00/poly new file mode 100755 index 0000000..6b37710 Binary files /dev/null and b/d04/ex00/poly differ diff --git a/d04/Animal.cpp b/d04/ex01/Animal.cpp similarity index 100% rename from d04/Animal.cpp rename to d04/ex01/Animal.cpp diff --git a/d04/Animal.hpp b/d04/ex01/Animal.hpp similarity index 100% rename from d04/Animal.hpp rename to d04/ex01/Animal.hpp diff --git a/d04/Cat.cpp b/d04/ex01/Cat.cpp similarity index 100% rename from d04/Cat.cpp rename to d04/ex01/Cat.cpp diff --git a/d04/Cat.hpp b/d04/ex01/Cat.hpp similarity index 100% rename from d04/Cat.hpp rename to d04/ex01/Cat.hpp diff --git a/d04/Dog.cpp b/d04/ex01/Dog.cpp similarity index 100% rename from d04/Dog.cpp rename to d04/ex01/Dog.cpp diff --git a/d04/Dog.hpp b/d04/ex01/Dog.hpp similarity index 100% rename from d04/Dog.hpp rename to d04/ex01/Dog.hpp diff --git a/d04/ex01/Makefile b/d04/ex01/Makefile new file mode 100644 index 0000000..50eca1c --- /dev/null +++ b/d04/ex01/Makefile @@ -0,0 +1,84 @@ +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value \ . += append to a variable # +# VARIABLES . value . != set result of command # +# . name is case sensitive . ?= set if not already set # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +NAME = poly + +#TYPE = c +TYPE = cpp + +ifeq "$(TYPE)" "c" + CC = c + EXT = c +else ifeq "$(TYPE)" "cpp" + CC = c++ + EXT = cpp +endif + +CFLAGS = -Wall -Wextra -Werror $(INCLUDES) +ifeq "$(TYPE)" "cpp" + CFLAGS += -std=c++98 +endif + +VPATH = $(D_SRCS) + +LIBS = + +INCLUDES = -I$(D_HEADERS) + +D_SRCS = . +SRCS = main.cpp \ + Animal.cpp \ + Dog.cpp \ + Cat.cpp \ + WrongAnimal.cpp \ + WrongCat.cpp + +D_HEADERS = . +HEADERS = Animal.hpp \ + Dog.hpp \ + Cat.hpp \ + WrongAnimal.hpp \ + WrongCat.hpp + +D_OBJS = builds +OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) + +ifeq "$(D_OBJS)" "." + RM_OBJS = rm -f $(OBJS) +else + RM_OBJS = rm -rf $(D_OBJS) +endif + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +all: $(NAME) + +$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS) + $(CC) $(CFLAGS) -c $< -o $@ + +$(D_OBJS): + mkdir $@ + +$(OBJS): $(HEADERS:%=$(D_HEADERS)/%) + +$(NAME): $(OBJS) + $(CC) $(OBJS) -o $@ $(LIBS) + +clean: + $(RM_OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY : all clean fclean re + diff --git a/d04/WrongAnimal.cpp b/d04/ex01/WrongAnimal.cpp similarity index 100% rename from d04/WrongAnimal.cpp rename to d04/ex01/WrongAnimal.cpp diff --git a/d04/WrongAnimal.hpp b/d04/ex01/WrongAnimal.hpp similarity index 100% rename from d04/WrongAnimal.hpp rename to d04/ex01/WrongAnimal.hpp diff --git a/d04/WrongCat.cpp b/d04/ex01/WrongCat.cpp similarity index 100% rename from d04/WrongCat.cpp rename to d04/ex01/WrongCat.cpp diff --git a/d04/ex01/WrongCat.hpp b/d04/ex01/WrongCat.hpp new file mode 100644 index 0000000..158267d --- /dev/null +++ b/d04/ex01/WrongCat.hpp @@ -0,0 +1,23 @@ +#ifndef WRONG_CAT_HPP +# define WRONG_CAT_HPP + +# include "WrongAnimal.hpp" + +#include +#include + +class WrongCat : public WrongAnimal { + +public: + + WrongCat( void ); + WrongCat( WrongCat const & src ); + ~WrongCat( void ); + WrongCat & operator=( WrongCat const & rhs ); + + void makeSound() const; + +}; + +#endif + diff --git a/d04/ex01/fr.subject.pdf b/d04/ex01/fr.subject.pdf new file mode 100644 index 0000000..d3212de Binary files /dev/null and b/d04/ex01/fr.subject.pdf differ diff --git a/d04/main.cpp b/d04/ex01/main.cpp similarity index 100% rename from d04/main.cpp rename to d04/ex01/main.cpp diff --git a/d04/poly b/d04/poly deleted file mode 100755 index 386c7e6..0000000 Binary files a/d04/poly and /dev/null differ