From 42fd870ab03ed98dcabeebfa79f1d25606727567 Mon Sep 17 00:00:00 2001 From: narnaud Date: Fri, 24 Jun 2022 18:14:54 +0200 Subject: [PATCH] cpp3-5 --- CPP03/ex00/ClapTrap.hpp | 4 +-- CPP03/ex01/ClapTrap.hpp | 4 +-- CPP03/ex01/ScavTrap.cpp | 11 ++------ CPP03/ex02/ClapTrap.hpp | 4 +-- CPP03/ex02/FragTrap.cpp | 19 +++++++------ CPP03/ex02/FragTrap.hpp | 3 +- CPP03/ex02/ScavTrap.cpp | 11 ++------ CPP03/ex02/main.cpp | 3 +- CPP04/ex00/Animal.cpp | 43 ++++++++++++++++++++++++++++ CPP04/ex00/Animal.hpp | 32 +++++++++++++++++++++ CPP04/ex00/Cat.cpp | 24 ++++++++++++++++ CPP04/ex00/Cat.hpp | 22 +++++++++++++++ CPP04/ex00/Dog.cpp | 24 ++++++++++++++++ CPP04/ex00/Dog.hpp | 21 ++++++++++++++ CPP04/ex00/Makefile | 20 +++++++++++++ CPP04/ex00/WrongAnimal.cpp | 42 ++++++++++++++++++++++++++++ CPP04/ex00/WrongAnimal.hpp | 32 +++++++++++++++++++++ CPP04/ex00/WrongCat.cpp | 24 ++++++++++++++++ CPP04/ex00/WrongCat.hpp | 22 +++++++++++++++ CPP04/ex00/main.cpp | 32 +++++++++++++++++++++ CPP04/ex01/Animal.cpp | 43 ++++++++++++++++++++++++++++ CPP04/ex01/Animal.hpp | 32 +++++++++++++++++++++ CPP04/ex01/Brain.cpp | 33 ++++++++++++++++++++++ CPP04/ex01/Brain.hpp | 28 +++++++++++++++++++ CPP04/ex01/Cat.cpp | 26 +++++++++++++++++ CPP04/ex01/Cat.hpp | 25 +++++++++++++++++ CPP04/ex01/Dog.cpp | 26 +++++++++++++++++ CPP04/ex01/Dog.hpp | 24 ++++++++++++++++ CPP04/ex01/Makefile | 20 +++++++++++++ CPP04/ex01/main.cpp | 32 +++++++++++++++++++++ CPP04/ex02/AAnimal.cpp | 43 ++++++++++++++++++++++++++++ CPP04/ex02/AAnimal.hpp | 32 +++++++++++++++++++++ CPP04/ex02/Brain.cpp | 33 ++++++++++++++++++++++ CPP04/ex02/Brain.hpp | 28 +++++++++++++++++++ CPP04/ex02/Cat.cpp | 26 +++++++++++++++++ CPP04/ex02/Cat.hpp | 25 +++++++++++++++++ CPP04/ex02/Dog.cpp | 26 +++++++++++++++++ CPP04/ex02/Dog.hpp | 24 ++++++++++++++++ CPP04/ex02/Makefile | 20 +++++++++++++ CPP04/ex02/main.cpp | 32 +++++++++++++++++++++ CPP05/ex00/Bureaucrat.cpp | 57 ++++++++++++++++++++++++++++++++++++++ CPP05/ex00/Bureaucrat.hpp | 51 ++++++++++++++++++++++++++++++++++ CPP05/ex00/Makefile | 20 +++++++++++++ CPP05/ex00/main.cpp | 26 +++++++++++++++++ 44 files changed, 1094 insertions(+), 35 deletions(-) create mode 100644 CPP04/ex00/Animal.cpp create mode 100644 CPP04/ex00/Animal.hpp create mode 100644 CPP04/ex00/Cat.cpp create mode 100644 CPP04/ex00/Cat.hpp create mode 100644 CPP04/ex00/Dog.cpp create mode 100644 CPP04/ex00/Dog.hpp create mode 100644 CPP04/ex00/Makefile create mode 100644 CPP04/ex00/WrongAnimal.cpp create mode 100644 CPP04/ex00/WrongAnimal.hpp create mode 100644 CPP04/ex00/WrongCat.cpp create mode 100644 CPP04/ex00/WrongCat.hpp create mode 100644 CPP04/ex00/main.cpp create mode 100644 CPP04/ex01/Animal.cpp create mode 100644 CPP04/ex01/Animal.hpp create mode 100644 CPP04/ex01/Brain.cpp create mode 100644 CPP04/ex01/Brain.hpp create mode 100644 CPP04/ex01/Cat.cpp create mode 100644 CPP04/ex01/Cat.hpp create mode 100644 CPP04/ex01/Dog.cpp create mode 100644 CPP04/ex01/Dog.hpp create mode 100644 CPP04/ex01/Makefile create mode 100644 CPP04/ex01/main.cpp create mode 100644 CPP04/ex02/AAnimal.cpp create mode 100644 CPP04/ex02/AAnimal.hpp create mode 100644 CPP04/ex02/Brain.cpp create mode 100644 CPP04/ex02/Brain.hpp create mode 100644 CPP04/ex02/Cat.cpp create mode 100644 CPP04/ex02/Cat.hpp create mode 100644 CPP04/ex02/Dog.cpp create mode 100644 CPP04/ex02/Dog.hpp create mode 100644 CPP04/ex02/Makefile create mode 100644 CPP04/ex02/main.cpp create mode 100644 CPP05/ex00/Bureaucrat.cpp create mode 100644 CPP05/ex00/Bureaucrat.hpp create mode 100644 CPP05/ex00/Makefile create mode 100644 CPP05/ex00/main.cpp diff --git a/CPP03/ex00/ClapTrap.hpp b/CPP03/ex00/ClapTrap.hpp index a234c0a..4ce8a2e 100644 --- a/CPP03/ex00/ClapTrap.hpp +++ b/CPP03/ex00/ClapTrap.hpp @@ -6,14 +6,14 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/23 10:54:07 by narnaud #+# #+# */ -/* Updated: 2022/06/23 17:21:48 by narnaud ### ########.fr */ +/* Updated: 2022/06/24 07:50:53 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #define CT_HEALTH 10 #define CT_ENERGY 10 -#define CT_DMG 1 +#define CT_DMG 0 #include #include diff --git a/CPP03/ex01/ClapTrap.hpp b/CPP03/ex01/ClapTrap.hpp index a234c0a..384b1ab 100644 --- a/CPP03/ex01/ClapTrap.hpp +++ b/CPP03/ex01/ClapTrap.hpp @@ -6,14 +6,14 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/23 10:54:07 by narnaud #+# #+# */ -/* Updated: 2022/06/23 17:21:48 by narnaud ### ########.fr */ +/* Updated: 2022/06/24 07:51:12 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #define CT_HEALTH 10 #define CT_ENERGY 10 -#define CT_DMG 1 +#define CT_DMG 0 #include #include diff --git a/CPP03/ex01/ScavTrap.cpp b/CPP03/ex01/ScavTrap.cpp index 26914d0..bb54637 100644 --- a/CPP03/ex01/ScavTrap.cpp +++ b/CPP03/ex01/ScavTrap.cpp @@ -6,21 +6,14 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/23 15:19:54 by narnaud #+# #+# */ -/* Updated: 2022/06/23 17:55:34 by narnaud ### ########.fr */ +/* Updated: 2022/06/24 07:49:17 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "ScavTrap.hpp" ScavTrap::ScavTrap (std::string name, size_t hp, size_t ep, size_t atk):ClapTrap(name, hp, ep, atk){ - if (ScavTrap::amount >= 128) - { - delete ScavTrap::registery[amount % 128]; - cout << "There are already too many Traps" << endl; - } - cout << "ScavTrap " << name << " was created" << endl; - ScavTrap::registery[ScavTrap::amount % 128] = this; - ScavTrap::amount++; + cout << "ClapTrap " << name << " evolved to ScavTrap" << endl; } ScavTrap::~ScavTrap (void) { diff --git a/CPP03/ex02/ClapTrap.hpp b/CPP03/ex02/ClapTrap.hpp index a234c0a..a4271bc 100644 --- a/CPP03/ex02/ClapTrap.hpp +++ b/CPP03/ex02/ClapTrap.hpp @@ -6,14 +6,14 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/23 10:54:07 by narnaud #+# #+# */ -/* Updated: 2022/06/23 17:21:48 by narnaud ### ########.fr */ +/* Updated: 2022/06/24 07:51:21 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #define CT_HEALTH 10 #define CT_ENERGY 10 -#define CT_DMG 1 +#define CT_DMG 0 #include #include diff --git a/CPP03/ex02/FragTrap.cpp b/CPP03/ex02/FragTrap.cpp index 6864f32..ceb544e 100644 --- a/CPP03/ex02/FragTrap.cpp +++ b/CPP03/ex02/FragTrap.cpp @@ -6,21 +6,14 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/23 15:19:54 by narnaud #+# #+# */ -/* Updated: 2022/06/23 18:04:05 by narnaud ### ########.fr */ +/* Updated: 2022/06/24 07:46:44 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "FragTrap.hpp" FragTrap::FragTrap (std::string name, size_t hp, size_t ep, size_t atk):ClapTrap(name, hp, ep, atk){ - if (FragTrap::amount >= 128) - { - delete FragTrap::registery[amount % 128]; - cout << "There are already too many Traps" << endl; - } - cout << "FragTrap " << name << " was created" << endl; - FragTrap::registery[FragTrap::amount % 128] = this; - FragTrap::amount++; + cout << "ClapTrap " << name << " evolved to FragTrap" << endl; } FragTrap::~FragTrap (void) { @@ -37,3 +30,11 @@ void FragTrap::attack(const std::string& target) { _energy--; } } + +void FragTrap::highFivesGuys(void) { + for (int i = 0; i < 128; i++) + { + if (ClapTrap::registery[i]) + cout << _name << " high five " << ClapTrap::registery[i]->getName() << endl; + } +} diff --git a/CPP03/ex02/FragTrap.hpp b/CPP03/ex02/FragTrap.hpp index 9539778..904cf21 100644 --- a/CPP03/ex02/FragTrap.hpp +++ b/CPP03/ex02/FragTrap.hpp @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/23 15:17:41 by narnaud #+# #+# */ -/* Updated: 2022/06/23 17:59:52 by narnaud ### ########.fr */ +/* Updated: 2022/06/24 07:33:33 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,4 +24,5 @@ class FragTrap : public ClapTrap { size_t ep = FT_ENERGY, size_t atk = FT_DMG); ~FragTrap (void); void attack(const std::string& target); + void highFivesGuys(void); }; diff --git a/CPP03/ex02/ScavTrap.cpp b/CPP03/ex02/ScavTrap.cpp index 26914d0..71a46c5 100644 --- a/CPP03/ex02/ScavTrap.cpp +++ b/CPP03/ex02/ScavTrap.cpp @@ -6,21 +6,14 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/23 15:19:54 by narnaud #+# #+# */ -/* Updated: 2022/06/23 17:55:34 by narnaud ### ########.fr */ +/* Updated: 2022/06/24 07:47:54 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "ScavTrap.hpp" ScavTrap::ScavTrap (std::string name, size_t hp, size_t ep, size_t atk):ClapTrap(name, hp, ep, atk){ - if (ScavTrap::amount >= 128) - { - delete ScavTrap::registery[amount % 128]; - cout << "There are already too many Traps" << endl; - } - cout << "ScavTrap " << name << " was created" << endl; - ScavTrap::registery[ScavTrap::amount % 128] = this; - ScavTrap::amount++; + cout << "ClapTrap " << name << " evolved to ScavTrap" << endl; } ScavTrap::~ScavTrap (void) { diff --git a/CPP03/ex02/main.cpp b/CPP03/ex02/main.cpp index 0627af7..40f02d6 100644 --- a/CPP03/ex02/main.cpp +++ b/CPP03/ex02/main.cpp @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/23 10:53:16 by narnaud #+# #+# */ -/* Updated: 2022/06/23 17:59:14 by narnaud ### ########.fr */ +/* Updated: 2022/06/24 07:41:01 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,4 +22,5 @@ int main(void) a.attack("B"); b.attack("C"); c.attack("B"); + c.highFivesGuys(); } diff --git a/CPP04/ex00/Animal.cpp b/CPP04/ex00/Animal.cpp new file mode 100644 index 0000000..71a3e72 --- /dev/null +++ b/CPP04/ex00/Animal.cpp @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:11 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:22:10 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Animal.hpp" + +Animal::Animal (void) { + cout << "Animal default constructor called " << endl; +} + +Animal::Animal (string type):_type(type) { + cout << "Animal parameter constructor called" << endl; +} + +Animal::Animal (Animal const & src) { + (void)src; + cout << "Animal copy constructor called" << endl; +} + +Animal & Animal::operator= (Animal const & src) { + (void)src; + cout << "Animal assignment operator called" << endl; + return (*this); +} + +Animal::~Animal (void) { + + cout << "Animal default destructor called" << endl; +} +string Animal::getType(void) const { + return (_type); +} +void Animal::makeSound(void) const { + cout << "..." << endl; +} diff --git a/CPP04/ex00/Animal.hpp b/CPP04/ex00/Animal.hpp new file mode 100644 index 0000000..6b84dcf --- /dev/null +++ b/CPP04/ex00/Animal.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:10 by narnaud #+# #+# */ +/* Updated: 2022/06/24 10:07:53 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include +using std::string; +using std::cout; +using std::endl; + +class Animal{ + public: + Animal(void); + Animal(string type); + Animal(Animal const & src); + virtual ~Animal(void); + Animal & operator= (Animal const & src); + string getType(void) const; + virtual void makeSound(void) const; + protected: + string _type; +}; diff --git a/CPP04/ex00/Cat.cpp b/CPP04/ex00/Cat.cpp new file mode 100644 index 0000000..079bd67 --- /dev/null +++ b/CPP04/ex00/Cat.cpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ +/* Updated: 2022/06/24 10:08:55 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Cat.hpp" + +Cat::Cat (void):Animal("Cat") { + cout << "Cat default constructor called" << endl; +} + +Cat::~Cat (void) { + cout << "Cat default destructor called" << endl; +} +void Cat::makeSound(void) const { + cout << "Miaou" << endl; +} diff --git a/CPP04/ex00/Cat.hpp b/CPP04/ex00/Cat.hpp new file mode 100644 index 0000000..e8e53a6 --- /dev/null +++ b/CPP04/ex00/Cat.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ +/* Updated: 2022/06/24 10:09:35 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "Animal.hpp" +class Cat: public Animal { + public: + Cat(void); + ~Cat(void); + void makeSound(void) const; +}; + diff --git a/CPP04/ex00/Dog.cpp b/CPP04/ex00/Dog.cpp new file mode 100644 index 0000000..c90c791 --- /dev/null +++ b/CPP04/ex00/Dog.cpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ +/* Updated: 2022/06/24 10:10:00 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Dog.hpp" + +Dog::Dog (void):Animal("Dog") { + cout << "Dog default constructor called" << endl; +} + +Dog::~Dog (void) { + cout << "Dog default destructor called" << endl; +} +void Dog::makeSound(void) const { + cout << "Waouf" << endl; +} diff --git a/CPP04/ex00/Dog.hpp b/CPP04/ex00/Dog.hpp new file mode 100644 index 0000000..baa869f --- /dev/null +++ b/CPP04/ex00/Dog.hpp @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ +/* Updated: 2022/06/24 10:09:29 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "Animal.hpp" +class Dog: public Animal { + public: + Dog(void); + ~Dog(void); + void makeSound(void) const; +}; diff --git a/CPP04/ex00/Makefile b/CPP04/ex00/Makefile new file mode 100644 index 0000000..112e5a3 --- /dev/null +++ b/CPP04/ex00/Makefile @@ -0,0 +1,20 @@ +NAME = dumb_animals +SRCS = main.cpp Animal.cpp Dog.cpp Cat.cpp WrongAnimal.cpp WrongCat.cpp +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME) : $(OBJS) + c++ $(SRCS) -o $(NAME) + +all : $(NAME) + +clean : + rm -rf $(OBJS) + +fclean : clean + rm -rf $(NAME) + +re : fclean all + +.PHONY : all clean fclean re diff --git a/CPP04/ex00/WrongAnimal.cpp b/CPP04/ex00/WrongAnimal.cpp new file mode 100644 index 0000000..2c07637 --- /dev/null +++ b/CPP04/ex00/WrongAnimal.cpp @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:11 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:22:03 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "WrongAnimal.hpp" + +WrongAnimal::WrongAnimal (void) { + cout << "WrongAnimal default constructor called " << endl; +} + +WrongAnimal::WrongAnimal (string type):_type(type) { + cout << "WrongAnimal parameter constructor called" << endl; +} + +WrongAnimal::WrongAnimal (WrongAnimal const & src) { + (void)src; + cout << "WrongAnimal copy constructor called" << endl; +} + +WrongAnimal & WrongAnimal::operator= (WrongAnimal const & src) { + (void)src; + cout << "WrongAnimal assignment operator called" << endl; + return (*this); +} + +WrongAnimal::~WrongAnimal (void) { + cout << "WrongAnimal default destructor called" << endl; +} +string WrongAnimal::getType(void) const { + return (_type); +} +void WrongAnimal::makeSound(void) const { + cout << "..." << endl; +} diff --git a/CPP04/ex00/WrongAnimal.hpp b/CPP04/ex00/WrongAnimal.hpp new file mode 100644 index 0000000..2a4af65 --- /dev/null +++ b/CPP04/ex00/WrongAnimal.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongAnimal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:10 by narnaud #+# #+# */ +/* Updated: 2022/06/24 10:15:37 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include +using std::string; +using std::cout; +using std::endl; + +class WrongAnimal{ + public: + WrongAnimal(void); + WrongAnimal(string type); + WrongAnimal(WrongAnimal const & src); + virtual ~WrongAnimal(void); + WrongAnimal & operator= (WrongAnimal const & src); + string getType(void) const; + void makeSound(void) const; + protected: + string _type; +}; diff --git a/CPP04/ex00/WrongCat.cpp b/CPP04/ex00/WrongCat.cpp new file mode 100644 index 0000000..2be2889 --- /dev/null +++ b/CPP04/ex00/WrongCat.cpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ +/* Updated: 2022/06/24 10:15:11 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "WrongCat.hpp" + +WrongCat::WrongCat (void):WrongAnimal("WrongCat") { + cout << "WrongCat default constructor called" << endl; +} + +WrongCat::~WrongCat (void) { + cout << "WrongCat default destructor called" << endl; +} +void WrongCat::makeSound(void) const { + cout << "Miaou" << endl; +} diff --git a/CPP04/ex00/WrongCat.hpp b/CPP04/ex00/WrongCat.hpp new file mode 100644 index 0000000..4180db6 --- /dev/null +++ b/CPP04/ex00/WrongCat.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* WrongCat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ +/* Updated: 2022/06/24 10:13:28 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "WrongAnimal.hpp" +class WrongCat: public WrongAnimal { + public: + WrongCat(void); + ~WrongCat(void); + void makeSound(void) const; +}; + diff --git a/CPP04/ex00/main.cpp b/CPP04/ex00/main.cpp new file mode 100644 index 0000000..9882379 --- /dev/null +++ b/CPP04/ex00/main.cpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 08:28:40 by narnaud #+# #+# */ +/* Updated: 2022/06/24 10:16:31 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Dog.hpp" +#include "Cat.hpp" +#include "WrongCat.hpp" + +int main(void) +{ + const Animal* meta = new Animal(); + const Animal* i = new Cat(); + const Animal* j = new Dog(); + const WrongAnimal *k = new WrongCat(); + + std::cout << i->getType() << " " << std::endl; + std::cout << j->getType() << " " << std::endl; + i->makeSound(); //will output the cat sound! + j->makeSound(); + meta->makeSound(); + + k->makeSound(); + return (0); +} diff --git a/CPP04/ex01/Animal.cpp b/CPP04/ex01/Animal.cpp new file mode 100644 index 0000000..70ccf9d --- /dev/null +++ b/CPP04/ex01/Animal.cpp @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:11 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:23:19 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Animal.hpp" + +Animal::Animal (void) { + cout << "Animal default constructor called " << endl; +} + +Animal::Animal (string type):_type(type) { + cout << "Animal parameter constructor called" << endl; +} + +Animal::Animal (Animal const & src) { + (void)src; + cout << "Animal copy constructor called" << endl; +} + +Animal & Animal::operator= (Animal const & src) { + (void)src; + cout << "Animal assignment operator called" << endl; + return (*this); +} + +Animal::~Animal (void) { + + cout << "Animal default destructor called" << endl; +} +string Animal::getType(void) const { + return (_type); +} +void Animal::makeSound(void) const { + cout << "..." << endl; +} diff --git a/CPP04/ex01/Animal.hpp b/CPP04/ex01/Animal.hpp new file mode 100644 index 0000000..6b84dcf --- /dev/null +++ b/CPP04/ex01/Animal.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:10 by narnaud #+# #+# */ +/* Updated: 2022/06/24 10:07:53 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include +using std::string; +using std::cout; +using std::endl; + +class Animal{ + public: + Animal(void); + Animal(string type); + Animal(Animal const & src); + virtual ~Animal(void); + Animal & operator= (Animal const & src); + string getType(void) const; + virtual void makeSound(void) const; + protected: + string _type; +}; diff --git a/CPP04/ex01/Brain.cpp b/CPP04/ex01/Brain.cpp new file mode 100644 index 0000000..2d69c0b --- /dev/null +++ b/CPP04/ex01/Brain.cpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 11:24:53 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:57:44 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Brain.hpp" + +Brain::Brain (void) { + cout << "Brain default constructor called " << endl; +} + +Brain::Brain (Brain const & src) { + (void)src; + cout << "Brain copy constructor called" << endl; +} + +Brain & Brain::operator= (Brain const & src) { + (void)src; + cout << "Brain assignment operator called" << endl; + return (*this); +} + +Brain::~Brain (void) { + + cout << "Brain default destructor called" << endl; +} diff --git a/CPP04/ex01/Brain.hpp b/CPP04/ex01/Brain.hpp new file mode 100644 index 0000000..4598a81 --- /dev/null +++ b/CPP04/ex01/Brain.hpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 11:24:53 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:56:58 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include +using std::cout; +using std::endl; +using std::string; + +class Brain{ + string ideas[100]; + public: + Brain(void); + Brain(Brain const & src); + virtual ~Brain(void); + Brain & operator= (Brain const & src); +}; diff --git a/CPP04/ex01/Cat.cpp b/CPP04/ex01/Cat.cpp new file mode 100644 index 0000000..114e2c3 --- /dev/null +++ b/CPP04/ex01/Cat.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:47:13 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Cat.hpp" + +Cat::Cat (void):Animal("Cat") { + _brain = new Brain(); + cout << "Cat default constructor called" << endl; +} + +Cat::~Cat (void) { + delete _brain; + cout << "Cat default destructor called" << endl; +} +void Cat::makeSound(void) const { + cout << "Miaou" << endl; +} diff --git a/CPP04/ex01/Cat.hpp b/CPP04/ex01/Cat.hpp new file mode 100644 index 0000000..73167bc --- /dev/null +++ b/CPP04/ex01/Cat.hpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:46:12 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "Animal.hpp" +#include "Brain.hpp" + +class Cat: public Animal { + Brain *_brain; + public: + Cat(void); + ~Cat(void); + void makeSound(void) const; +}; + diff --git a/CPP04/ex01/Dog.cpp b/CPP04/ex01/Dog.cpp new file mode 100644 index 0000000..6a71731 --- /dev/null +++ b/CPP04/ex01/Dog.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:47:22 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Dog.hpp" + +Dog::Dog (void):Animal("Dog") { + _brain = new Brain(); + cout << "Dog default constructor called" << endl; +} + +Dog::~Dog (void) { + delete _brain; + cout << "Dog default destructor called" << endl; +} +void Dog::makeSound(void) const { + cout << "Waouf" << endl; +} diff --git a/CPP04/ex01/Dog.hpp b/CPP04/ex01/Dog.hpp new file mode 100644 index 0000000..1cefb3e --- /dev/null +++ b/CPP04/ex01/Dog.hpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:46:17 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "Animal.hpp" +#include "Brain.hpp" + +class Dog: public Animal { + Brain *_brain; + public: + Dog(void); + ~Dog(void); + void makeSound(void) const; +}; diff --git a/CPP04/ex01/Makefile b/CPP04/ex01/Makefile new file mode 100644 index 0000000..53b65d6 --- /dev/null +++ b/CPP04/ex01/Makefile @@ -0,0 +1,20 @@ +NAME = smart_animals +SRCS = main.cpp Animal.cpp Dog.cpp Cat.cpp Brain.cpp +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME) : $(OBJS) + c++ $(SRCS) -o $(NAME) + +all : $(NAME) + +clean : + rm -rf $(OBJS) + +fclean : clean + rm -rf $(NAME) + +re : fclean all + +.PHONY : all clean fclean re diff --git a/CPP04/ex01/main.cpp b/CPP04/ex01/main.cpp new file mode 100644 index 0000000..62e5ffb --- /dev/null +++ b/CPP04/ex01/main.cpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 08:28:40 by narnaud #+# #+# */ +/* Updated: 2022/06/24 12:00:44 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Dog.hpp" +#include "Cat.hpp" +#define NB_ANIMALS 4 + +int main(void) +{ + Animal *animals[NB_ANIMALS]; + + int i = 0; + while (i < NB_ANIMALS / 2) + animals[i++] = new Dog(); + while (i < NB_ANIMALS) + animals[i++] = new Cat(); + i = 0; + while (i < NB_ANIMALS / 2) + delete animals[i++]; + while (i < NB_ANIMALS) + delete animals[i++]; + return (0); +} diff --git a/CPP04/ex02/AAnimal.cpp b/CPP04/ex02/AAnimal.cpp new file mode 100644 index 0000000..7c80aea --- /dev/null +++ b/CPP04/ex02/AAnimal.cpp @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* AAnimal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:11 by narnaud #+# #+# */ +/* Updated: 2022/06/24 12:10:54 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "AAnimal.hpp" + +AAnimal::AAnimal (void) { + cout << "AAnimal default constructor called " << endl; +} + +AAnimal::AAnimal (string type):_type(type) { + cout << "AAnimal parameter constructor called" << endl; +} + +AAnimal::AAnimal (AAnimal const & src) { + (void)src; + cout << "AAnimal copy constructor called" << endl; +} + +AAnimal & AAnimal::operator= (AAnimal const & src) { + (void)src; + cout << "AAnimal assignment operator called" << endl; + return (*this); +} + +AAnimal::~AAnimal (void) { + + cout << "AAnimal default destructor called" << endl; +} +string AAnimal::getType(void) const { + return (_type); +} +void AAnimal::makeSound(void) const { + cout << "..." << endl; +} diff --git a/CPP04/ex02/AAnimal.hpp b/CPP04/ex02/AAnimal.hpp new file mode 100644 index 0000000..c412d5c --- /dev/null +++ b/CPP04/ex02/AAnimal.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* AAnimal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:10 by narnaud #+# #+# */ +/* Updated: 2022/06/24 12:14:54 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include +using std::string; +using std::cout; +using std::endl; + +class AAnimal{ + public: + AAnimal(void); + AAnimal(string type); + AAnimal(AAnimal const & src); + virtual ~AAnimal(void); + AAnimal & operator= (AAnimal const & src); + string getType(void) const; + virtual void makeSound(void) const = 0; + protected: + string _type; +}; diff --git a/CPP04/ex02/Brain.cpp b/CPP04/ex02/Brain.cpp new file mode 100644 index 0000000..2d69c0b --- /dev/null +++ b/CPP04/ex02/Brain.cpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 11:24:53 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:57:44 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Brain.hpp" + +Brain::Brain (void) { + cout << "Brain default constructor called " << endl; +} + +Brain::Brain (Brain const & src) { + (void)src; + cout << "Brain copy constructor called" << endl; +} + +Brain & Brain::operator= (Brain const & src) { + (void)src; + cout << "Brain assignment operator called" << endl; + return (*this); +} + +Brain::~Brain (void) { + + cout << "Brain default destructor called" << endl; +} diff --git a/CPP04/ex02/Brain.hpp b/CPP04/ex02/Brain.hpp new file mode 100644 index 0000000..4598a81 --- /dev/null +++ b/CPP04/ex02/Brain.hpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 11:24:53 by narnaud #+# #+# */ +/* Updated: 2022/06/24 11:56:58 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include +using std::cout; +using std::endl; +using std::string; + +class Brain{ + string ideas[100]; + public: + Brain(void); + Brain(Brain const & src); + virtual ~Brain(void); + Brain & operator= (Brain const & src); +}; diff --git a/CPP04/ex02/Cat.cpp b/CPP04/ex02/Cat.cpp new file mode 100644 index 0000000..e733cba --- /dev/null +++ b/CPP04/ex02/Cat.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ +/* Updated: 2022/06/24 12:10:57 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Cat.hpp" + +Cat::Cat (void):AAnimal("Cat") { + _brain = new Brain(); + cout << "Cat default constructor called" << endl; +} + +Cat::~Cat (void) { + delete _brain; + cout << "Cat default destructor called" << endl; +} +void Cat::makeSound(void) const { + cout << "Miaou" << endl; +} diff --git a/CPP04/ex02/Cat.hpp b/CPP04/ex02/Cat.hpp new file mode 100644 index 0000000..9bed744 --- /dev/null +++ b/CPP04/ex02/Cat.hpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ +/* Updated: 2022/06/24 12:11:30 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "AAnimal.hpp" +#include "Brain.hpp" + +class Cat: public AAnimal { + Brain *_brain; + public: + Cat(void); + ~Cat(void); + void makeSound(void) const; +}; + diff --git a/CPP04/ex02/Dog.cpp b/CPP04/ex02/Dog.cpp new file mode 100644 index 0000000..44d8278 --- /dev/null +++ b/CPP04/ex02/Dog.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ +/* Updated: 2022/06/24 12:10:57 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Dog.hpp" + +Dog::Dog (void):AAnimal("Dog") { + _brain = new Brain(); + cout << "Dog default constructor called" << endl; +} + +Dog::~Dog (void) { + delete _brain; + cout << "Dog default destructor called" << endl; +} +void Dog::makeSound(void) const { + cout << "Waouf" << endl; +} diff --git a/CPP04/ex02/Dog.hpp b/CPP04/ex02/Dog.hpp new file mode 100644 index 0000000..9b67b8a --- /dev/null +++ b/CPP04/ex02/Dog.hpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ +/* Updated: 2022/06/24 12:11:18 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "AAnimal.hpp" +#include "Brain.hpp" + +class Dog: public AAnimal { + Brain *_brain; + public: + Dog(void); + ~Dog(void); + void makeSound(void) const; +}; diff --git a/CPP04/ex02/Makefile b/CPP04/ex02/Makefile new file mode 100644 index 0000000..8e95bd3 --- /dev/null +++ b/CPP04/ex02/Makefile @@ -0,0 +1,20 @@ +NAME = abstract_animals +SRCS = main.cpp AAnimal.cpp Dog.cpp Cat.cpp Brain.cpp +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME) : $(OBJS) + c++ $(SRCS) -o $(NAME) + +all : $(NAME) + +clean : + rm -rf $(OBJS) + +fclean : clean + rm -rf $(NAME) + +re : fclean all + +.PHONY : all clean fclean re diff --git a/CPP04/ex02/main.cpp b/CPP04/ex02/main.cpp new file mode 100644 index 0000000..b535f02 --- /dev/null +++ b/CPP04/ex02/main.cpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 08:28:40 by narnaud #+# #+# */ +/* Updated: 2022/06/24 12:10:57 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Dog.hpp" +#include "Cat.hpp" +#define NB_ANIMALS 4 + +int main(void) +{ + AAnimal *animals[NB_ANIMALS]; + + int i = 0; + while (i < NB_ANIMALS / 2) + animals[i++] = new Dog(); + while (i < NB_ANIMALS) + animals[i++] = new Cat(); + i = 0; + while (i < NB_ANIMALS / 2) + delete animals[i++]; + while (i < NB_ANIMALS) + delete animals[i++]; + return (0); +} diff --git a/CPP05/ex00/Bureaucrat.cpp b/CPP05/ex00/Bureaucrat.cpp new file mode 100644 index 0000000..27b637d --- /dev/null +++ b/CPP05/ex00/Bureaucrat.cpp @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */ +/* Updated: 2022/06/24 17:42:27 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat (void) { + cout << "Bureaucrat default constructor called " << endl; +} + +Bureaucrat::Bureaucrat (string name, size_t grade) throw (char*): _name(name){ + + if (grade > 150) + throw Bureaucrat::GradeTooHighException(""); + _grade = grade; + cout << "Bureaucrat parameter constructor called" << endl; +} + +Bureaucrat::Bureaucrat (Bureaucrat const & src) { + (void)src; + cout << "Bureaucrat copy constructor called" << endl; +} + +Bureaucrat & Bureaucrat::operator= (Bureaucrat const & src) { + (void)src; + cout << "Bureaucrat assignment operator called" << endl; + return (*this); +} + +Bureaucrat::~Bureaucrat (void) { + cout << "Bureaucrat default destructor called" << endl; +} + +string Bureaucrat::getName(void) { + return (_name); +} + +size_t Bureaucrat::getGrade(void) { + return (_grade); +} + +GTHE::GTHE(void) { + +} + +std::ostream &operator<< (std::ostream &out, Bureaucrat const &b) { + out << b._name << ", bureaucrat grade " << b._grade << endl; +} + diff --git a/CPP05/ex00/Bureaucrat.hpp b/CPP05/ex00/Bureaucrat.hpp new file mode 100644 index 0000000..3a39ed6 --- /dev/null +++ b/CPP05/ex00/Bureaucrat.hpp @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */ +/* Updated: 2022/06/24 16:57:34 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include +#include +using std::cout; +using std::endl; +using std::string; + +class Bureaucrat{ + string _name; + size_t _grade; + public: + Bureaucrat(void); + Bureaucrat(string name, size_t grade) throw (char*); + Bureaucrat(Bureaucrat const & src); + virtual ~Bureaucrat(void); + Bureaucrat & operator= (Bureaucrat const & src); + string getName(void); + size_t getGrade(void); + + typedef class GradeTooHighException GTHE; + class GradeTooHighException: virtual public std::exception + { + GTHE(void); + ~GTHE(void); + const char *GTHE::what(void); + }; + typedef class GradeTooLowException GTLE; + class GradeTooLowException: virtual public std::exception + { + GTLE(void); + ~GTLE(void); + const char *GTLE::what(void); + }; + +}; + +std::ostream &operator<< (std::ostream &out, Bureaucrat const &b); diff --git a/CPP05/ex00/Makefile b/CPP05/ex00/Makefile new file mode 100644 index 0000000..0a9375a --- /dev/null +++ b/CPP05/ex00/Makefile @@ -0,0 +1,20 @@ +NAME = bureau +SRCS = main.cpp Bureaucrat.cpp +OBJS= $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME) : $(OBJS) + c++ $(OBJS) -o $(NAME) + +all : $(NAME) + +clean : + rm -rf $(OBJS) + +fclean : clean + rm -rf $(NAME) + +re : fclean all + +.PHONY : all clean fclean re diff --git a/CPP05/ex00/main.cpp b/CPP05/ex00/main.cpp new file mode 100644 index 0000000..cc49d77 --- /dev/null +++ b/CPP05/ex00/main.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/24 13:16:27 by narnaud #+# #+# */ +/* Updated: 2022/06/24 14:38:36 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Bureaucrat.hpp" + +int main(void) +{ + try { + Bureaucrat crat__one("first", 1); + Bureaucrat crat__two("last", 150); + Bureaucrat crat__three("trash", 151); + Bureaucrat crat__four("god", -55); + } + catch (std::exception & e) { + cout << "Issue :" << e.what(); + } +}