├── .gitignore ├── 00 ├── ex00 │ ├── .gitignore │ ├── Makefile │ └── megaphone.cpp ├── ex01 │ ├── .gitignore │ ├── Annuaire.cpp │ ├── Annuaire.hpp │ ├── Contact.cpp │ ├── Contact.hpp │ ├── Makefile │ └── main.cpp └── ex02 │ ├── .gitignore │ └── Account.class.cpp ├── 01 ├── README.md ├── ex00 │ ├── .gitignore │ ├── Pony.cpp │ ├── Pony.hpp │ └── main.cpp ├── ex01 │ └── ex01.cpp ├── ex02 │ ├── .gitignore │ ├── Zombie.cpp │ ├── Zombie.hpp │ ├── ZombieEvent.cpp │ ├── ZombieEvent.hpp │ └── main.cpp ├── ex03 │ ├── .gitignore │ ├── Zombie.cpp │ ├── Zombie.hpp │ ├── ZombieHorde.cpp │ ├── ZombieHorde.hpp │ └── main.cpp ├── ex04 │ └── ex04.cpp ├── ex05 │ ├── Brain.cpp │ ├── Brain.hpp │ ├── Human.cpp │ ├── Human.hpp │ └── main.cpp ├── ex06 │ ├── HumanA.cpp │ ├── HumanA.hpp │ ├── HumanB.cpp │ ├── HumanB.hpp │ ├── Weapon.cpp │ ├── Weapon.hpp │ └── main.cpp ├── ex07 │ ├── .gitignore │ ├── Makefile │ ├── Sed.cpp │ ├── Sed.hpp │ ├── main.cpp │ └── tests │ │ ├── 1 │ │ └── 2 ├── ex08 │ ├── Human.cpp │ ├── Human.hpp │ └── main.cpp ├── ex09 │ ├── .gitignore │ ├── Logger.cpp │ ├── Logger.hpp │ └── main.cpp └── ex10 │ ├── .gitignore │ ├── Makefile │ ├── Reader.cpp │ ├── Reader.hpp │ └── main.cpp ├── 02 ├── README.md ├── ex00 │ ├── .gitignore │ ├── Fixed.cpp │ └── Fixed.hpp ├── ex01 │ ├── .gitignore │ ├── Fixed.cpp │ └── Fixed.hpp ├── ex02 │ ├── .gitignore │ ├── Fixed.cpp │ └── Fixed.hpp └── ex03 │ ├── .gitignore │ ├── Expression.cpp │ ├── Expression.hpp │ ├── Fixed.cpp │ ├── Fixed.hpp │ ├── Makefile │ └── main.cpp ├── 03 ├── README.md ├── ex00 │ ├── FragTrap.cpp │ ├── FragTrap.hpp │ └── main.cpp ├── ex01 │ ├── FragTrap.cpp │ ├── FragTrap.hpp │ ├── ScavTrap.cpp │ ├── ScavTrap.hpp │ └── main.cpp ├── ex02 │ ├── ClapTrap.cpp │ ├── ClapTrap.hpp │ ├── FragTrap.cpp │ ├── FragTrap.hpp │ ├── ScavTrap.cpp │ ├── ScavTrap.hpp │ └── main.cpp ├── ex03 │ ├── ClapTrap.cpp │ ├── ClapTrap.hpp │ ├── FragTrap.cpp │ ├── FragTrap.hpp │ ├── NinjaTrap.cpp │ ├── NinjaTrap.hpp │ ├── ScavTrap.cpp │ ├── ScavTrap.hpp │ └── main.cpp └── ex04 │ ├── ClapTrap.cpp │ ├── ClapTrap.hpp │ ├── FragTrap.cpp │ ├── FragTrap.hpp │ ├── NinjaTrap.cpp │ ├── NinjaTrap.hpp │ ├── ScavTrap.cpp │ ├── ScavTrap.hpp │ ├── SuperTrap.cpp │ ├── SuperTrap.hpp │ └── main.cpp ├── 04 ├── README.md ├── ex00 │ ├── Peon.cpp │ ├── Peon.hpp │ ├── Sorcerer.cpp │ ├── Sorcerer.hpp │ ├── Victim.cpp │ ├── Victim.hpp │ └── main.cpp ├── ex01 │ ├── AWeapon.cpp │ ├── AWeapon.hpp │ ├── Character.cpp │ ├── Character.hpp │ ├── Enemy.cpp │ ├── Enemy.hpp │ ├── PlasmaRifle.cpp │ ├── PlasmaRifle.hpp │ ├── PowerFist.cpp │ ├── PowerFist.hpp │ ├── RadScorpion.cpp │ ├── RadScorpion.hpp │ ├── SuperMutant.cpp │ ├── SuperMutant.hpp │ └── main.cpp ├── ex02 │ ├── AssaultTerminator.cpp │ ├── AssaultTerminator.hpp │ ├── ISpaceMarine.hpp │ ├── ISquad.hpp │ ├── Squad.cpp │ ├── Squad.hpp │ ├── TacticalMarine.cpp │ ├── TacticalMarine.hpp │ └── main.cpp ├── ex03 │ ├── AMateria.cpp │ ├── AMateria.hpp │ ├── Character.cpp │ ├── Character.hpp │ ├── Cure.cpp │ ├── Cure.hpp │ ├── ICharacter.hpp │ ├── IMateriaSource.hpp │ ├── Ice.cpp │ ├── Ice.hpp │ ├── MateriaSource.cpp │ ├── MateriaSource.hpp │ └── main.cpp └── ex04 │ ├── AsteroKreog.cpp │ ├── AsteroKreog.hpp │ ├── DeepCoreMiner.cpp │ ├── DeepCoreMiner.hpp │ ├── IAsteroid.hpp │ ├── IMiningLaser.hpp │ ├── KoalaSteroid.cpp │ ├── KoalaSteroid.hpp │ ├── MiningBarge.cpp │ ├── MiningBarge.hpp │ ├── StripMiner.cpp │ ├── StripMiner.hpp │ └── main.cpp ├── 05 ├── ex00 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ └── main.cpp ├── ex01 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Form.cpp │ ├── Form.hpp │ └── main.cpp ├── ex02 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Form.cpp │ ├── Form.hpp │ ├── PresidentialPardonForm.cpp │ ├── PresidentialPardonForm.hpp │ ├── RobotomyRequestForm.cpp │ ├── RobotomyRequestForm.hpp │ ├── ShrubberyCreationForm.cpp │ ├── ShrubberyCreationForm.hpp │ └── main.cpp ├── ex03 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Form.cpp │ ├── Form.hpp │ ├── Intern.cpp │ ├── Intern.hpp │ ├── PresidentialPardonForm.cpp │ ├── PresidentialPardonForm.hpp │ ├── RobotomyRequestForm.cpp │ ├── RobotomyRequestForm.hpp │ ├── ShrubberyCreationForm.cpp │ ├── ShrubberyCreationForm.hpp │ └── main.cpp ├── ex04 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Form.cpp │ ├── Form.hpp │ ├── Intern.cpp │ ├── Intern.hpp │ ├── OfficeBlock.cpp │ ├── OfficeBlock.hpp │ ├── PresidentialPardonForm.cpp │ ├── PresidentialPardonForm.hpp │ ├── RobotomyRequestForm.cpp │ ├── RobotomyRequestForm.hpp │ ├── ShrubberyCreationForm.cpp │ ├── ShrubberyCreationForm.hpp │ └── main.cpp └── ex05 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── CentralBureaucracy.cpp │ ├── CentralBureaucracy.hpp │ ├── Form.cpp │ ├── Form.hpp │ ├── Intern.cpp │ ├── Intern.hpp │ ├── OfficeBlock.cpp │ ├── OfficeBlock.hpp │ ├── PresidentialPardonForm.cpp │ ├── PresidentialPardonForm.hpp │ ├── RobotomyRequestForm.cpp │ ├── RobotomyRequestForm.hpp │ ├── ShrubberyCreationForm.cpp │ ├── ShrubberyCreationForm.hpp │ └── main.cpp ├── 06 ├── ex00 │ ├── .gitignore │ ├── Interpreter.cpp │ ├── Interpreter.hpp │ ├── Makefile │ └── main.cpp ├── ex01 │ ├── .gitignore │ ├── Data.cpp │ ├── Data.hpp │ ├── Makefile │ └── main.cpp └── ex02 │ ├── .gitignore │ ├── A.hpp │ ├── B.hpp │ ├── Base.hpp │ ├── C.hpp │ ├── Detector.cpp │ ├── Detector.hpp │ ├── Makefile │ └── main.cpp ├── 07 ├── .gitignore ├── ex00 │ ├── Makefile │ └── whatever.cpp ├── ex01 │ ├── Makefile │ └── iter.cpp └── ex02 │ ├── Array.hpp │ ├── Array.ipp │ ├── Makefile │ └── main.cpp ├── 08 ├── README.md ├── ex00 │ ├── easyfind.hpp │ └── main.cpp ├── ex01 │ ├── Span.cpp │ ├── Span.hpp │ ├── Span.ipp │ └── main.cpp ├── ex02 │ ├── MutantStack.hpp │ ├── MutantStack.ipp │ └── main.cpp ├── ex03 │ ├── .gitignore │ ├── Instruction.cpp │ ├── Instruction.hpp │ ├── Instructions │ │ ├── Decr.cpp │ │ ├── Decr.hpp │ │ ├── DecrPtr.cpp │ │ ├── DecrPtr.hpp │ │ ├── Incr.cpp │ │ ├── Incr.hpp │ │ ├── IncrPtr.cpp │ │ ├── IncrPtr.hpp │ │ ├── Input.cpp │ │ ├── Input.hpp │ │ ├── LoopEnd.cpp │ │ ├── LoopEnd.hpp │ │ ├── LoopStart.cpp │ │ ├── LoopStart.hpp │ │ ├── Output.cpp │ │ └── Output.hpp │ ├── Makefile │ ├── MindOpen.cpp │ ├── MindOpen.hpp │ ├── Program.cpp │ ├── Program.hpp │ ├── main.cpp │ └── programs │ │ ├── ascii.b │ │ ├── beer.b │ │ ├── dbf2c.b │ │ ├── hanoi.b │ │ ├── helloword.b │ │ ├── mandelbrot.b │ │ ├── numwarp.b │ │ ├── quine505.b │ │ ├── random.b │ │ ├── rot13.b │ │ └── yapi.b ├── ex03v2 │ ├── .gitignore │ ├── Makefile │ ├── MindOpen.cpp │ ├── MindOpen.hpp │ ├── Program.cpp │ ├── Program.hpp │ ├── main.cpp │ └── programs │ │ ├── ascii.b │ │ ├── beer.b │ │ ├── dbf2c.b │ │ ├── hanoi.b │ │ ├── helloword.b │ │ ├── mandelbrot.b │ │ ├── numwarp.b │ │ ├── quine505.b │ │ ├── random.b │ │ ├── rot13.b │ │ └── yapi.b └── ex04 │ ├── .gitignore │ ├── Makefile │ ├── Postfix.cpp │ ├── Postfix.hpp │ ├── Token.cpp │ ├── Token.hpp │ ├── Tokens │ ├── Num.cpp │ ├── Num.hpp │ ├── Op.cpp │ ├── Op.hpp │ ├── ParClose.cpp │ ├── ParClose.hpp │ ├── ParOpen.cpp │ └── ParOpen.hpp │ └── main.cpp └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | .vscode 3 | exe -------------------------------------------------------------------------------- /00/ex00/.gitignore: -------------------------------------------------------------------------------- 1 | megaphone -------------------------------------------------------------------------------- /00/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/13 18:47:47 by ncolomer #+# #+# # 9 | # Updated: 2019/12/28 16:05:10 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = megaphone.cpp 14 | OBJS = $(SRCS:.cpp=.o) 15 | 16 | CXX = clang++ 17 | RM = rm -f 18 | CXXFLAGS = -Wall -Wextra -Werror -I. 19 | 20 | NAME = megaphone 21 | 22 | all: $(NAME) 23 | 24 | $(NAME): $(OBJS) 25 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 26 | 27 | clean: 28 | $(RM) $(OBJS) 29 | 30 | fclean: clean 31 | $(RM) $(NAME) 32 | 33 | re: fclean $(NAME) 34 | 35 | test: $(NAME) 36 | ./megaphone "shhhhh... I think the students are asleep..." 37 | ./megaphone Damnit " ! " "Sorry students, I thought this thing was off." 38 | ./megaphone 39 | 40 | .PHONY: all clean fclean re test 41 | -------------------------------------------------------------------------------- /00/ex00/megaphone.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* megaphone.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/13 18:47:50 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 17:37:28 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int 18 | main(int argc, char const *argv[]) 19 | { 20 | if (argc == 1) 21 | std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *" << std::endl; 22 | else 23 | { 24 | for (int i = 1; i < argc; i++) 25 | { 26 | std::string str(argv[i]); 27 | for (size_t j = 0; j < str.length(); j++) 28 | std::cout << (char)std::toupper(str[j]); 29 | } 30 | std::cout << std::endl; 31 | } 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /00/ex01/.gitignore: -------------------------------------------------------------------------------- 1 | directory -------------------------------------------------------------------------------- /00/ex01/Annuaire.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Annuaire.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 16:08:49 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:53 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ANNUAIRE_HPP 14 | # define ANNUAIRE_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | # include "Contact.hpp" 20 | 21 | class Annuaire 22 | { 23 | private: 24 | Contact contacts[8]; 25 | int amount; 26 | public: 27 | Annuaire(); 28 | virtual ~Annuaire(); 29 | 30 | void show_startup(void); 31 | void add_contact(void); 32 | void search_contact(void); 33 | void show_search_header(void); 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /00/ex01/Contact.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Contact.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/13 19:04:23 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:50 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CONTACT_HPP 14 | # define CONTACT_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | 20 | class Contact 21 | { 22 | private: 23 | int index; 24 | static std::string fields_name[11]; 25 | std::string informations[11]; 26 | 27 | enum Field { 28 | FirstName = 0, 29 | LastName, 30 | Nickname, 31 | Login, 32 | Address, 33 | Email, 34 | Phone, 35 | Birthday, 36 | FavoriteMeal, 37 | UnderwearColor, 38 | Secret 39 | }; 40 | public: 41 | Contact(); 42 | virtual ~Contact(); 43 | 44 | bool set_informations(int index); 45 | void display_header(void); 46 | void display(void); 47 | }; 48 | 49 | #endif -------------------------------------------------------------------------------- /00/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/13 18:47:47 by ncolomer #+# #+# # 9 | # Updated: 2019/12/28 16:03:57 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = main.cpp Annuaire.cpp Contact.cpp 14 | OBJS = $(SRCS:.cpp=.o) 15 | 16 | CXX = clang++ 17 | RM = rm -f 18 | CXXFLAGS = -Wall -Wextra -Werror -I. 19 | 20 | NAME = directory 21 | 22 | all: $(NAME) 23 | 24 | $(NAME): $(OBJS) 25 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 26 | 27 | clean: 28 | $(RM) $(OBJS) 29 | 30 | fclean: clean 31 | $(RM) $(NAME) 32 | 33 | re: fclean $(NAME) 34 | 35 | .PHONY: all clean fclean re 36 | -------------------------------------------------------------------------------- /00/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/13 19:00:09 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 17:38:36 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Annuaire.hpp" 14 | 15 | int 16 | main(void) 17 | { 18 | Annuaire annuaire; 19 | bool run; 20 | std::string command; 21 | 22 | annuaire.show_startup(); 23 | run = true; 24 | while (run) 25 | { 26 | std::cout << ">"; 27 | std::getline(std::cin, command); 28 | if (command == "ADD") 29 | annuaire.add_contact(); 30 | else if (command == "SEARCH") 31 | annuaire.search_contact(); 32 | else if (command == "EXIT") 33 | { 34 | std::cout << "# Bye." << std::endl; 35 | run = false; 36 | } 37 | } 38 | return (0); 39 | } 40 | -------------------------------------------------------------------------------- /00/ex02/.gitignore: -------------------------------------------------------------------------------- 1 | Account.class.hpp 2 | logs 3 | main.cpp 4 | Makefile 5 | management 6 | -------------------------------------------------------------------------------- /01/README.md: -------------------------------------------------------------------------------- 1 | # Module 01 2 | 3 | ## Ressources 4 | 5 | * [Files in C++](http://www.cplusplus.com/doc/tutorial/files/) 6 | -------------------------------------------------------------------------------- /01/ex00/.gitignore: -------------------------------------------------------------------------------- 1 | pony -------------------------------------------------------------------------------- /01/ex00/Pony.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Pony.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 18:04:44 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 19:55:31 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Pony.hpp" 14 | 15 | Pony::Pony(std::string const &name): 16 | name(name) 17 | { 18 | std::cout << "Pony \"" << this->name << "\" has been constructed !" << std::endl; 19 | } 20 | 21 | Pony::~Pony() 22 | { 23 | std::cout << "Pony \"" << this->name << "\" is being destructed !" << std::endl; 24 | } 25 | 26 | void Pony::cry(void) 27 | { 28 | std::cout << this->name << ": MY NAME IS " << this->name << std::endl; 29 | } 30 | 31 | void Pony::run(void) 32 | { 33 | std::cout << this->name << ": I'm tired..." << std::endl; 34 | } 35 | -------------------------------------------------------------------------------- /01/ex00/Pony.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Pony.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 18:04:46 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:42 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PONY_HPP 14 | # define PONY_HPP 15 | 16 | # include 17 | # include 18 | 19 | class Pony 20 | { 21 | private: 22 | std::string const &name; 23 | public: 24 | Pony(std::string const &name); 25 | virtual ~Pony(); 26 | 27 | void cry(void); 28 | void run(void); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /01/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 18:04:41 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/15 19:45:41 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Pony.hpp" 14 | 15 | void ponyOnTheStack(void) 16 | { 17 | Pony onTheStack("Stack Man"); 18 | 19 | onTheStack.cry(); 20 | onTheStack.run(); 21 | } 22 | 23 | void ponyOnTheHeap(void) 24 | { 25 | Pony *onTheHeap; 26 | 27 | onTheHeap = new Pony("Heap Man"); 28 | onTheHeap->run(); 29 | onTheHeap->cry(); 30 | delete onTheHeap; 31 | } 32 | 33 | int main(void) 34 | { 35 | std::cout << "# ponyOnTheStack:" << std::endl; 36 | ponyOnTheStack(); 37 | std::cout << "# ponyOnTheHeap:" << std::endl; 38 | ponyOnTheHeap(); 39 | std::cout << "# Done" << std::endl; 40 | return (0); 41 | } 42 | -------------------------------------------------------------------------------- /01/ex01/ex01.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ex01.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 18:22:19 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/14 18:23:09 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void memoryLeak(void) 17 | { 18 | std::string *panthere = new std::string("String panthere"); 19 | std::cout << *panthere << std::endl; 20 | delete panthere; 21 | } 22 | -------------------------------------------------------------------------------- /01/ex02/.gitignore: -------------------------------------------------------------------------------- 1 | zombies -------------------------------------------------------------------------------- /01/ex02/Zombie.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Zombie.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 18:24:33 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:38 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ZOMBIE_HPP 14 | # define ZOMBIE_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | 20 | class Zombie 21 | { 22 | private: 23 | std::string type; 24 | std::string name; 25 | public: 26 | Zombie(); 27 | Zombie(std::string const &type, std::string const &name); 28 | virtual ~Zombie(); 29 | 30 | void setCharacteristics(std::string const &type, std::string const &name); 31 | static std::string randomName(std::string::size_type length); 32 | void announce(void); 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /01/ex02/ZombieEvent.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ZombieEvent.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 18:32:55 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 20:29:35 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ZombieEvent.hpp" 14 | 15 | ZombieEvent::ZombieEvent() 16 | { 17 | this->type = ""; 18 | } 19 | 20 | ZombieEvent::~ZombieEvent() 21 | { 22 | } 23 | 24 | void ZombieEvent::setZombieType(std::string const &type) 25 | { 26 | this->type = type; 27 | } 28 | 29 | Zombie *ZombieEvent::newZombie(std::string const &name) 30 | { 31 | return (new Zombie(this->type, name)); 32 | } 33 | 34 | Zombie *ZombieEvent::randomChump(void) 35 | { 36 | Zombie *zombie; 37 | 38 | zombie = new Zombie(this->type, Zombie::randomName(10)); 39 | zombie->announce(); 40 | return (zombie); 41 | } 42 | -------------------------------------------------------------------------------- /01/ex02/ZombieEvent.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ZombieEvent.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 18:32:25 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:36 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ZOMBIEVENT_HPP 14 | # define ZOMBIEVENT_HPP 15 | 16 | # include 17 | # include 18 | # include "Zombie.hpp" 19 | 20 | class ZombieEvent 21 | { 22 | private: 23 | std::string type; 24 | public: 25 | ZombieEvent(); 26 | virtual ~ZombieEvent(); 27 | 28 | void setZombieType(std::string const &type); 29 | Zombie *newZombie(std::string const &name); 30 | Zombie *randomChump(void); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /01/ex03/.gitignore: -------------------------------------------------------------------------------- 1 | zombies -------------------------------------------------------------------------------- /01/ex03/Zombie.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Zombie.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 18:24:33 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:31 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ZOMBIE_HPP 14 | # define ZOMBIE_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | 20 | class Zombie 21 | { 22 | private: 23 | std::string type; 24 | std::string name; 25 | public: 26 | Zombie(); 27 | Zombie(std::string const &type, std::string const &name); 28 | virtual ~Zombie(); 29 | 30 | void setCharacteristics(std::string const &type, std::string const &name); 31 | static std::string randomName(std::string::size_type length); 32 | void announce(void); 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /01/ex03/ZombieHorde.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ZombieHorde.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 19:12:56 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:33 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ZOMBIEHORDE_HPP 14 | # define ZOMBIEHORDE_HPP 15 | 16 | # include "Zombie.hpp" 17 | 18 | class ZombieHorde 19 | { 20 | private: 21 | std::string type; 22 | int size; 23 | Zombie *zombies; 24 | public: 25 | ZombieHorde(int size); 26 | ZombieHorde(std::string const &type, int size); 27 | virtual ~ZombieHorde(); 28 | 29 | void announce(void); 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /01/ex04/ex04.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ex04.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/14 19:59:39 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/14 20:02:00 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int main(void) 17 | { 18 | std::string str = std::string("HI THIS IS BRAIN"); 19 | std::string *str_ptr = &str; 20 | std::string &str_ref = str; 21 | std::cout << " str: " << str << std::endl; 22 | std::cout << "ptr_str: " << *str_ptr << std::endl; 23 | std::cout << "ref_str: " << str_ref << std::endl; 24 | return (0); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /01/ex05/Brain.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Brain.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 16:07:35 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 18:02:33 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Brain.hpp" 14 | 15 | Brain::Brain(): 16 | neurones(1) 17 | { 18 | } 19 | 20 | Brain::~Brain() 21 | { 22 | } 23 | 24 | int Brain::getNeurones(void) const 25 | { 26 | return (this->neurones); 27 | } 28 | 29 | std::string Brain::identify(void) const 30 | { 31 | const long adr = (long)this; 32 | 33 | std::stringstream ss; 34 | ss << "0x" << std::uppercase << std::hex << adr; 35 | return (ss.str()); 36 | } 37 | -------------------------------------------------------------------------------- /01/ex05/Brain.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Brain.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 16:07:11 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:27 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef BRAIN_HPP 14 | # define BRAIN_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | 20 | class Brain 21 | { 22 | private: 23 | int neurones; 24 | public: 25 | Brain(); 26 | virtual ~Brain(); 27 | 28 | int getNeurones(void) const; 29 | std::string identify(void) const; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /01/ex05/Human.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Human.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 16:07:46 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/15 16:12:45 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Human.hpp" 14 | 15 | Human::Human() 16 | { 17 | } 18 | 19 | Human::~Human() 20 | { 21 | } 22 | 23 | const Brain &Human::getBrain(void) const 24 | { 25 | return (this->brain); 26 | } 27 | 28 | std::string Human::identify(void) const 29 | { 30 | return (this->brain.identify()); 31 | } 32 | -------------------------------------------------------------------------------- /01/ex05/Human.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Human.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 15:58:26 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:25 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HUMAN_HPP 14 | # define HUMAN_HPP 15 | 16 | # include 17 | # include 18 | # include "Brain.hpp" 19 | 20 | class Human 21 | { 22 | private: 23 | const Brain brain; 24 | public: 25 | Human(); 26 | virtual ~Human(); 27 | 28 | const Brain &getBrain(void) const; 29 | std::string identify(void) const; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /01/ex05/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 15:57:39 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 18:04:54 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "Human.hpp" 15 | 16 | int main(void) 17 | { 18 | Human bob; 19 | 20 | std::cout << "Bob identify: \t" << bob.identify() << std::endl; 21 | std::cout << "Brain identify: " << bob.getBrain().identify() << std::endl; 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /01/ex06/HumanA.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanA.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 16:37:50 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 20:28:27 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "HumanA.hpp" 14 | 15 | HumanA::HumanA(std::string const &name, const Weapon &weapon): 16 | name(name), weapon(weapon) 17 | { 18 | } 19 | 20 | HumanA::~HumanA() 21 | { 22 | } 23 | 24 | void HumanA::attack(void) const 25 | { 26 | std::cout << this->name << " attacks with his " << this->weapon.getType() << std::endl; 27 | } 28 | -------------------------------------------------------------------------------- /01/ex06/HumanA.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanA.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 16:37:35 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:22 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HUMANA_HPP 14 | # define HUMANA_HPP 15 | 16 | # include 17 | # include 18 | # include "Weapon.hpp" 19 | 20 | class HumanA 21 | { 22 | private: 23 | std::string name; 24 | const Weapon &weapon; 25 | public: 26 | HumanA(std::string const &name, const Weapon &weapon); 27 | virtual ~HumanA(); 28 | 29 | void attack(void) const; 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /01/ex06/HumanB.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanB.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 16:38:13 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 20:28:21 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "HumanB.hpp" 14 | 15 | HumanB::HumanB(std::string const &name): 16 | name(name), weapon(NULL) 17 | { 18 | } 19 | 20 | HumanB::~HumanB() 21 | { 22 | } 23 | 24 | void HumanB::setWeapon(const Weapon &weapon) 25 | { 26 | this->weapon = &weapon; 27 | } 28 | 29 | void HumanB::attack(void) const 30 | { 31 | if (this->weapon) 32 | std::cout << this->name << " attacks with his " << this->weapon->getType() << std::endl; 33 | else 34 | std::cout << this->name << " can't attack because he has no Weapon !" << std::endl; 35 | } 36 | -------------------------------------------------------------------------------- /01/ex06/HumanB.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanB.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 16:37:25 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 18:00:00 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HUMANB_HPP 14 | # define HUMANB_HPP 15 | 16 | # include 17 | # include 18 | # include "Weapon.hpp" 19 | 20 | class HumanB 21 | { 22 | private: 23 | std::string name; 24 | const Weapon *weapon; 25 | public: 26 | HumanB(std::string const &name); 27 | virtual ~HumanB(); 28 | 29 | void setWeapon(const Weapon &weapon); 30 | void attack(void) const; 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /01/ex06/Weapon.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Weapon.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 16:38:24 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 20:28:08 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Weapon.hpp" 14 | 15 | Weapon::Weapon(): 16 | type("") 17 | { 18 | } 19 | 20 | Weapon::Weapon(std::string const &type): 21 | type(type) 22 | { 23 | } 24 | 25 | Weapon::~Weapon() 26 | { 27 | } 28 | 29 | void Weapon::setType(std::string const &type) 30 | { 31 | this->type = type; 32 | } 33 | 34 | std::string const &Weapon::getType(void) const 35 | { 36 | return (this->type); 37 | } 38 | -------------------------------------------------------------------------------- /01/ex06/Weapon.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Weapon.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 16:36:59 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:14 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef WEAPON_HPP 14 | # define WEAPON_HPP 15 | 16 | # include 17 | # include 18 | 19 | class Weapon 20 | { 21 | private: 22 | std::string type; 23 | public: 24 | Weapon(); 25 | Weapon(std::string const &type); 26 | virtual ~Weapon(); 27 | 28 | void setType(std::string const &type); 29 | std::string const &getType(void) const; 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /01/ex06/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 16:36:37 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/15 19:44:47 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "Weapon.hpp" 15 | #include "HumanA.hpp" 16 | #include "HumanB.hpp" 17 | 18 | int main(void) 19 | { 20 | { 21 | Weapon club = Weapon("Crude Spiked Club"); 22 | HumanA bob("Bob", club); 23 | 24 | bob.attack(); 25 | club.setType("Some other type of Club"); 26 | bob.attack(); 27 | } 28 | { 29 | Weapon club = Weapon("Crude Spiked Club"); 30 | HumanB jim("Jim"); 31 | 32 | jim.setWeapon(club); 33 | jim.attack(); 34 | club.setType("Some other type of Club"); 35 | jim.attack(); 36 | } 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /01/ex07/.gitignore: -------------------------------------------------------------------------------- 1 | */*.replace 2 | replace -------------------------------------------------------------------------------- /01/ex07/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/15 17:06:28 by ncolomer #+# #+# # 9 | # Updated: 2019/12/28 16:03:18 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = main.cpp Sed.cpp 14 | OBJS = $(SRCS:.cpp=.o) 15 | 16 | CXX = clang++ 17 | RM = rm -f 18 | CXXFLAGS = -Wall -Wextra -Werror -I. 19 | 20 | NAME = replace 21 | 22 | all: $(NAME) 23 | 24 | $(NAME): $(OBJS) 25 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 26 | 27 | clean: 28 | $(RM) $(OBJS) 29 | 30 | fclean: clean 31 | $(RM) $(NAME) *.replace */*.replace 32 | 33 | re: fclean $(NAME) 34 | 35 | test: $(NAME) 36 | ./replace Makefile " " "." 37 | ./replace tests/1 "e" "E" 38 | ./replace tests/2 "cheval" "poney" 39 | 40 | .PHONY: all clean fclean re test 41 | -------------------------------------------------------------------------------- /01/ex07/Sed.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Sed.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 17:16:00 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:59:11 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SED_HPP 14 | # define SED_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | 20 | class Sed 21 | { 22 | private: 23 | static std::string strReplace(std::string const &line, std::string const &search, std::string const &replace); 24 | public: 25 | Sed(); 26 | virtual ~Sed(); 27 | 28 | static void replace(std::string const &filename, std::string const &search, std::string const &replace); 29 | }; 30 | 31 | #endif -------------------------------------------------------------------------------- /01/ex07/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 17:06:44 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 18:13:53 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "Sed.hpp" 15 | 16 | int main(int argc, char const *argv[]) 17 | { 18 | if (argc != 4) 19 | std::cout << "error: Invalid number of arguments.\nusage: filename search replace" << std::endl; 20 | else 21 | { 22 | try 23 | { 24 | Sed::replace(argv[1], argv[2], argv[3]); 25 | } 26 | catch(char const *e) 27 | { 28 | std::cerr << "replace: error: " << e << std::endl; 29 | } 30 | } 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /01/ex08/Human.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Human.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 18:26:32 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 19:11:00 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HUMAN_HPP 14 | # define HUMAN_HPP 15 | 16 | # include 17 | # include 18 | 19 | class Human 20 | { 21 | private: 22 | void meleeAttack(std::string const &target); 23 | void rangedAttack(std::string const &target); 24 | void intimidatingShout(std::string const &target); 25 | public: 26 | void action(std::string const &action_name, std::string const &target); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /01/ex08/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 18:27:20 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 20:16:08 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Human.hpp" 14 | 15 | int main(void) 16 | { 17 | Human h; 18 | 19 | try 20 | { 21 | h.action("meleeAttack", "You"); 22 | h.action("rangedAttack", "You"); 23 | h.action("intimidatingShout", "YOU"); 24 | //h.action("no", "YOU"); 25 | } 26 | catch(char const *e) 27 | { 28 | std::cerr << "human: exception: " << e << std::endl; 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /01/ex09/.gitignore: -------------------------------------------------------------------------------- 1 | log -------------------------------------------------------------------------------- /01/ex09/Logger.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Logger.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 19:24:06 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:58:54 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LOGGER_HPP 14 | # define LOGGER_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | # include 22 | 23 | class Logger 24 | { 25 | private: 26 | std::ofstream olog; 27 | 28 | std::string makeLogEntry(std::string const &value); 29 | void logToConsole(std::string const &value); 30 | void logToFile(std::string const &value); 31 | public: 32 | Logger(std::string const &logfile); 33 | virtual ~Logger(); 34 | 35 | void log(std::string const &dest, std::string const &message); 36 | }; 37 | 38 | #endif -------------------------------------------------------------------------------- /01/ex09/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 19:23:35 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 20:16:14 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Logger.hpp" 14 | 15 | int main(void) 16 | { 17 | Logger logger("log"); 18 | 19 | try 20 | { 21 | logger.log("logToConsole", "Initialization..."); 22 | logger.log("logToConsole", "Starting engines..."); 23 | logger.log("logToConsole", "Next messages will be sent to file"); 24 | logger.log("logToFile", "Logging messages of Logger"); 25 | logger.log("logToFile", "I'm on another line"); 26 | logger.log("logToFile", "This is the last message"); 27 | logger.log("logToConsole", "It's over."); 28 | //logger.log("logToUndefined", "I shall throw."); 29 | } 30 | catch(char const *e) 31 | { 32 | std::cerr << "logger: exception: " << e << std::endl; 33 | } 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /01/ex10/.gitignore: -------------------------------------------------------------------------------- 1 | cato9tails -------------------------------------------------------------------------------- /01/ex10/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/15 17:06:28 by ncolomer #+# #+# # 9 | # Updated: 2019/12/21 16:04:04 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = main.cpp Reader.cpp 14 | OBJS = $(SRCS:.cpp=.o) 15 | 16 | CXX = clang++ 17 | RM = rm -f 18 | CXXFLAGS = -Wall -Wextra -Werror -I. 19 | 20 | NAME = cato9tails 21 | 22 | all: $(NAME) 23 | 24 | $(NAME): $(OBJS) 25 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 26 | 27 | clean: 28 | $(RM) $(OBJS) 29 | 30 | fclean: clean 31 | $(RM) $(NAME) 32 | 33 | re: fclean $(NAME) 34 | 35 | .PHONY: all clean fclean re 36 | -------------------------------------------------------------------------------- /01/ex10/Reader.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Reader.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 19:47:40 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:58:51 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef READER_HPP 14 | # define READER_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | 20 | class Reader 21 | { 22 | private: 23 | public: 24 | Reader(); 25 | virtual ~Reader(); 26 | 27 | static void readFile(std::istream &stream); 28 | static void openReadFile(std::string const &filename); 29 | }; 30 | 31 | #endif -------------------------------------------------------------------------------- /01/ex10/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/15 19:43:55 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/15 19:54:30 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Reader.hpp" 14 | 15 | int main(int argc, char const *argv[]) 16 | { 17 | Reader reader; 18 | 19 | if (argc == 1) 20 | Reader::readFile(std::cin); 21 | else 22 | { 23 | for (int i = 1; i < argc; i++) 24 | Reader::openReadFile(argv[i]); 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /02/README.md: -------------------------------------------------------------------------------- 1 | # Module 02 2 | 3 | ## Ressources 4 | 5 | * [One line formula for conversion](https://embeddedartistry.com/blog/2018/07/12/simple-fixed-point-conversion-in-c/) 6 | * [Fixed point arithmetic](https://spin.atomicobject.com/2012/03/15/simple-fixed-point-math/) 7 | -------------------------------------------------------------------------------- /02/ex00/.gitignore: -------------------------------------------------------------------------------- 1 | main.cpp -------------------------------------------------------------------------------- /02/ex00/Fixed.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Fixed.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/16 17:14:08 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:58:47 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FIXED_HPP 14 | # define FIXED_HPP 15 | 16 | # include 17 | 18 | class Fixed 19 | { 20 | private: 21 | int value; 22 | static const int bits = 8; 23 | public: 24 | Fixed(); 25 | Fixed(Fixed const &other); 26 | virtual ~Fixed(); 27 | 28 | Fixed &operator=(Fixed const &other); 29 | 30 | int getRawBits(void) const; 31 | void setRawBits(int const raw); 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /02/ex01/.gitignore: -------------------------------------------------------------------------------- 1 | main.cpp -------------------------------------------------------------------------------- /02/ex01/Fixed.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Fixed.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/16 17:14:08 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:58:44 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FIXED_HPP 14 | # define FIXED_HPP 15 | 16 | # include 17 | # include 18 | 19 | class Fixed 20 | { 21 | private: 22 | int value; 23 | static const int bits = 8; 24 | public: 25 | Fixed(); 26 | Fixed(int const value); 27 | Fixed(float const value); 28 | Fixed(Fixed const &other); 29 | virtual ~Fixed(); 30 | 31 | Fixed &operator=(Fixed const &other); 32 | 33 | int getRawBits(void) const; 34 | void setRawBits(int const raw); 35 | 36 | float toFloat(void) const; 37 | int toInt(void) const; 38 | }; 39 | 40 | std::ostream &operator<<(std::ostream &out, Fixed const &value); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /02/ex02/.gitignore: -------------------------------------------------------------------------------- 1 | main.cpp -------------------------------------------------------------------------------- /02/ex03/.gitignore: -------------------------------------------------------------------------------- 1 | eval_expr -------------------------------------------------------------------------------- /02/ex03/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/16 17:46:46 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/19 20:20:07 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "Fixed.hpp" 15 | #include "Expression.hpp" 16 | 17 | int main(int argc, char const **argv) 18 | { 19 | if (argc != 2) 20 | { 21 | std::cout << "eval_expr: error: bad arguments.\n"; 22 | std::cout << " usage: expression" << std::endl; 23 | } 24 | else 25 | { 26 | try 27 | { 28 | Expression expr(argv[1]); 29 | std::cout << expr.calculate() << std::endl; 30 | } 31 | catch (char const *e) 32 | { 33 | std::cerr << "eval_expr: error: " << e << std::endl; 34 | } 35 | } 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /03/README.md: -------------------------------------------------------------------------------- 1 | # CPP Module 3 2 | 3 | ## Ressources 4 | 5 | * Classes and Inheritance from the Guillaume Revy course. 6 | * [Virtual Inheritance](https://en.wikipedia.org/wiki/Virtual_inheritance) 7 | * [StackOverflow post about Inheritance](https://stackoverflow.com/questions/2659116/how-does-virtual-inheritance-solve-the-diamond-multiple-inheritance-ambiguit) 8 | * [Does {Parent} get called twice ?](https://stackoverflow.com/questions/7405839/are-multiple-inherited-constructors-called-multiple-times) 9 | * [Claptrap quotes](https://borderlands.fandom.com/wiki/Claptrap/Quotes) 10 | -------------------------------------------------------------------------------- /03/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/18 16:59:59 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/18 18:48:33 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "FragTrap.hpp" 15 | 16 | int main(void) 17 | { 18 | FragTrap frag("FR4G"); 19 | 20 | srand(time(NULL)); 21 | frag.vaulthunter_dot_exe("CL4P-TP"); 22 | frag.meleeAttack("CL4P-TP"); 23 | frag.rangedAttack("CL4P-TP"); 24 | frag.takeDamage(24); 25 | frag.beRepaired(50); 26 | frag.takeDamage(42); 27 | frag.takeDamage(100); 28 | frag.beRepaired(125); 29 | frag.vaulthunter_dot_exe("CL4P-TP"); 30 | frag.vaulthunter_dot_exe("CL4P-TP"); 31 | frag.vaulthunter_dot_exe("CL4P-TP"); 32 | frag.vaulthunter_dot_exe("CL4P-TP"); 33 | return (0); 34 | } 35 | -------------------------------------------------------------------------------- /03/ex02/FragTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* FragTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/18 17:00:10 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:58:18 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FRAGTRAP_HPP 14 | # define FRAGTRAP_HPP 15 | 16 | # include 17 | # include 18 | # include "ClapTrap.hpp" 19 | 20 | class FragTrap: virtual public ClapTrap 21 | { 22 | private: 23 | FragTrap(); 24 | protected: 25 | static const int nbrQuotes = 5; 26 | static std::string quotes[FragTrap::nbrQuotes]; 27 | public: 28 | FragTrap(std::string const &name); 29 | FragTrap(FragTrap const &other); 30 | virtual ~FragTrap(); 31 | 32 | FragTrap &operator=(FragTrap const &other); 33 | 34 | void meleeAttack(std::string const &target); 35 | void rangedAttack(std::string const &target); 36 | void vaulthunter_dot_exe(std::string const &target); 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /03/ex02/ScavTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ScavTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/18 18:20:26 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:58:16 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SCAVTRAP_HPP 14 | # define SCAVTRAP_HPP 15 | 16 | # include 17 | # include 18 | # include "ClapTrap.hpp" 19 | 20 | class ScavTrap: virtual public ClapTrap 21 | { 22 | private: 23 | ScavTrap(); 24 | protected: 25 | static const int nbrChalls = 5; 26 | static std::string challenges[ScavTrap::nbrChalls]; 27 | public: 28 | ScavTrap(std::string const &name); 29 | ScavTrap(ScavTrap const &other); 30 | virtual ~ScavTrap(); 31 | 32 | ScavTrap &operator=(ScavTrap const &other); 33 | 34 | void meleeAttack(std::string const &target); 35 | void rangedAttack(std::string const &target); 36 | void challengeNewcomer(void); 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /03/ex03/FragTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* FragTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/18 17:00:10 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:58:12 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FRAGTRAP_HPP 14 | # define FRAGTRAP_HPP 15 | 16 | # include 17 | # include 18 | # include "ClapTrap.hpp" 19 | 20 | class FragTrap: virtual public ClapTrap 21 | { 22 | private: 23 | FragTrap(); 24 | protected: 25 | static const int nbrQuotes = 5; 26 | static std::string quotes[FragTrap::nbrQuotes]; 27 | public: 28 | FragTrap(std::string const &name); 29 | FragTrap(FragTrap const &other); 30 | virtual ~FragTrap(); 31 | 32 | FragTrap &operator=(FragTrap const &other); 33 | 34 | void meleeAttack(std::string const &target); 35 | void rangedAttack(std::string const &target); 36 | void vaulthunter_dot_exe(std::string const &target); 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /03/ex03/ScavTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ScavTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/18 18:20:26 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:58:07 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SCAVTRAP_HPP 14 | # define SCAVTRAP_HPP 15 | 16 | # include 17 | # include 18 | # include "ClapTrap.hpp" 19 | 20 | class ScavTrap: virtual public ClapTrap 21 | { 22 | private: 23 | ScavTrap(); 24 | protected: 25 | static const int nbrChalls = 5; 26 | static std::string challenges[ScavTrap::nbrChalls]; 27 | public: 28 | ScavTrap(std::string const &name); 29 | ScavTrap(ScavTrap const &other); 30 | virtual ~ScavTrap(); 31 | 32 | ScavTrap &operator=(ScavTrap const &other); 33 | 34 | void meleeAttack(std::string const &target); 35 | void rangedAttack(std::string const &target); 36 | void challengeNewcomer(void); 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /03/ex04/FragTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* FragTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/18 17:00:10 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/27 14:35:02 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FRAGTRAP_HPP 14 | # define FRAGTRAP_HPP 15 | 16 | # include 17 | # include 18 | # include "ClapTrap.hpp" 19 | 20 | class FragTrap: virtual public ClapTrap 21 | { 22 | private: 23 | FragTrap(); 24 | protected: 25 | static const int nbrQuotes = 5; 26 | static std::string quotes[FragTrap::nbrQuotes]; 27 | public: 28 | FragTrap(std::string const &name); 29 | FragTrap(FragTrap const &other); 30 | virtual ~FragTrap(); 31 | 32 | FragTrap &operator=(FragTrap const &other); 33 | 34 | void meleeAttack(std::string const &target); 35 | void rangedAttack(std::string const &target); 36 | void vaulthunter_dot_exe(std::string const &target); 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /03/ex04/ScavTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ScavTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/18 18:20:26 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/20 16:49:49 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SCAVTRAP_HPP 14 | # define SCAVTRAP_HPP 15 | 16 | # include 17 | # include 18 | # include "ClapTrap.hpp" 19 | 20 | class ScavTrap: virtual public ClapTrap 21 | { 22 | private: 23 | ScavTrap(); 24 | protected: 25 | static const int nbrChalls = 5; 26 | static std::string challenges[ScavTrap::nbrChalls]; 27 | public: 28 | ScavTrap(std::string const &name); 29 | ScavTrap(ScavTrap const &other); 30 | virtual ~ScavTrap(); 31 | 32 | ScavTrap &operator=(ScavTrap const &other); 33 | 34 | void meleeAttack(std::string const &target); 35 | void rangedAttack(std::string const &target); 36 | void challengeNewcomer(void); 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /03/ex04/SuperTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* SuperTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/18 19:36:31 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/27 14:42:05 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SUPERTRAP_HPP 14 | # define SUPERTRAP_HPP 15 | 16 | # include 17 | # include 18 | # include "NinjaTrap.hpp" 19 | # include "FragTrap.hpp" 20 | 21 | class SuperTrap: public NinjaTrap, public FragTrap 22 | { 23 | private: 24 | SuperTrap(); 25 | public: 26 | SuperTrap(std::string const &name); 27 | SuperTrap(SuperTrap const &other); 28 | virtual ~SuperTrap(); 29 | 30 | SuperTrap &operator=(SuperTrap const &other); 31 | 32 | void rangedAttack(std::string const &target); 33 | void meleeAttack(std::string const &target); 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /04/README.md: -------------------------------------------------------------------------------- 1 | # CPP Module 4 2 | 3 | ## Ressources 4 | 5 | * [Allocate an array of pointers](https://stackoverflow.com/questions/368976/how-to-allocate-memory-to-an-array-of-instances-using-an-abstract-class) 6 | * [Circular dependencies](https://en.wikipedia.org/wiki/Circular_dependency) 7 | -------------------------------------------------------------------------------- /04/ex00/Peon.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Peon.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 13:56:01 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/20 17:08:30 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Peon.hpp" 14 | 15 | Peon::Peon(std::string const &name): 16 | Victim(name) 17 | { 18 | std::cout << "Zog zog." << std::endl; 19 | } 20 | 21 | Peon::Peon(Peon const &other): 22 | Victim(other.name) 23 | { 24 | std::cout << "Zog zog." << std::endl; 25 | } 26 | 27 | Peon::~Peon() 28 | { 29 | std::cout << "Bleuark..." << std::endl; 30 | } 31 | 32 | Peon &Peon::operator=(Peon const &other) 33 | { 34 | this->name = other.name; 35 | return (*this); 36 | } 37 | 38 | 39 | void Peon::getPolymorphed(void) const 40 | { 41 | std::cout << this->name << " has been turned into a pink pony !" << std::endl; 42 | } 43 | -------------------------------------------------------------------------------- /04/ex00/Peon.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Peon.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 13:56:25 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:49 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PEON_HPP 14 | # define PEON_HPP 15 | 16 | # include "Victim.hpp" 17 | 18 | class Peon: public Victim 19 | { 20 | private: 21 | Peon(); 22 | public: 23 | Peon(std::string const &name); 24 | Peon(Peon const &peon); 25 | virtual ~Peon(); 26 | 27 | Peon &operator=(const Peon& other); 28 | 29 | void getPolymorphed(void) const; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /04/ex00/Victim.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Victim.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 13:49:01 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/20 16:40:31 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef VICTIM_HPP 14 | # define VICTIM_HPP 15 | 16 | # include 17 | # include 18 | 19 | class Victim 20 | { 21 | protected: 22 | Victim(); 23 | 24 | std::string name; 25 | public: 26 | Victim(std::string const &name); 27 | Victim(const Victim& other); 28 | virtual ~Victim(); 29 | 30 | Victim &operator=(const Victim& other); 31 | 32 | std::string const &getName(void) const; 33 | virtual void getPolymorphed(void) const; 34 | }; 35 | 36 | std::ostream &operator<<(std::ostream &out, Victim const &sorcerer); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /04/ex01/AWeapon.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* AWeapon.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 15:00:35 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/20 16:37:11 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef AWEAPON_HPP 14 | # define AWEAPON_HPP 15 | 16 | # include 17 | # include 18 | 19 | class AWeapon 20 | { 21 | protected: 22 | AWeapon(); 23 | 24 | std::string name; 25 | int apCost; 26 | int damage; 27 | public: 28 | AWeapon(std::string const &name, int apcost, int damage); 29 | AWeapon(AWeapon const &other); 30 | virtual ~AWeapon(); 31 | 32 | AWeapon &operator=(AWeapon const &other); 33 | 34 | std::string const &getName(void) const; 35 | int getAPCost(void) const; 36 | int getDamage(void) const; 37 | 38 | virtual void attack() const = 0; 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /04/ex01/Enemy.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Enemy.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 15:17:47 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/20 16:37:06 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ENEMY_HPP 14 | # define ENEMY_HPP 15 | 16 | # include 17 | # include 18 | 19 | class Enemy 20 | { 21 | protected: 22 | Enemy(); 23 | 24 | std::string type; 25 | int hp; 26 | public: 27 | Enemy(int hp, std::string const &type); 28 | Enemy(Enemy const &other); 29 | virtual ~Enemy(); 30 | 31 | Enemy &operator=(Enemy const &other); 32 | 33 | std::string const &getType(void) const; 34 | int getHP(void) const; 35 | 36 | virtual void takeDamage(int damage); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /04/ex01/PlasmaRifle.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PlasmaRifle.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 15:07:38 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/20 16:14:08 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "PlasmaRifle.hpp" 14 | 15 | PlasmaRifle::PlasmaRifle(): 16 | AWeapon("Plasma Rifle", 5, 21) 17 | { 18 | } 19 | 20 | PlasmaRifle::PlasmaRifle(PlasmaRifle const &other): 21 | AWeapon(other) 22 | { 23 | } 24 | 25 | PlasmaRifle::~PlasmaRifle() 26 | { 27 | } 28 | 29 | PlasmaRifle &PlasmaRifle::operator=(PlasmaRifle const &other) 30 | { 31 | this->name = other.name; 32 | this->apCost = other.apCost; 33 | this->damage = other.damage; 34 | return (*this); 35 | } 36 | 37 | void PlasmaRifle::attack(void) const 38 | { 39 | std::cout << "* piouuu piouuu piouu *" << std::endl; 40 | } 41 | -------------------------------------------------------------------------------- /04/ex01/PlasmaRifle.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PlasmaRifle.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 15:07:36 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:36 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PLASMARIFLE_HPP 14 | # define PLASMARIFLE_HPP 15 | 16 | # include "AWeapon.hpp" 17 | 18 | class PlasmaRifle: public AWeapon 19 | { 20 | public: 21 | PlasmaRifle(); 22 | PlasmaRifle(PlasmaRifle const &other); 23 | virtual ~PlasmaRifle(); 24 | 25 | PlasmaRifle &operator=(PlasmaRifle const &other); 26 | 27 | void attack(void) const; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /04/ex01/PowerFist.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PowerFist.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 15:14:53 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/20 16:14:56 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "PowerFist.hpp" 14 | 15 | PowerFist::PowerFist(): 16 | AWeapon("Power Fist", 8, 50) 17 | { 18 | } 19 | 20 | PowerFist::PowerFist(PowerFist const &other): 21 | AWeapon(other) 22 | { 23 | } 24 | 25 | PowerFist::~PowerFist() 26 | { 27 | } 28 | 29 | PowerFist &PowerFist::operator=(PowerFist const &other) 30 | { 31 | this->name = other.name; 32 | this->apCost = other.apCost; 33 | this->damage = other.damage; 34 | return (*this); 35 | } 36 | 37 | void PowerFist::attack(void) const 38 | { 39 | std::cout << "* pschhh... SBAM! *" << std::endl; 40 | } 41 | -------------------------------------------------------------------------------- /04/ex01/PowerFist.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PowerFist.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 15:14:59 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:34 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef POWERFIST_HPP 14 | # define POWERFIST_HPP 15 | 16 | # include "AWeapon.hpp" 17 | 18 | class PowerFist: public AWeapon 19 | { 20 | public: 21 | PowerFist(); 22 | PowerFist(PowerFist const &other); 23 | virtual ~PowerFist(); 24 | 25 | PowerFist &operator=(PowerFist const &other); 26 | 27 | void attack(void) const; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /04/ex01/RadScorpion.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* RadScorpion.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 15:41:15 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/20 16:14:05 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "RadScorpion.hpp" 14 | 15 | RadScorpion::RadScorpion(): 16 | Enemy(80, "RadScorpion") 17 | { 18 | std::cout << "* click click click *" << std::endl; 19 | } 20 | 21 | RadScorpion::RadScorpion(RadScorpion const &other): 22 | Enemy(other) 23 | { 24 | std::cout << "* click click click *" << std::endl; 25 | } 26 | 27 | RadScorpion::~RadScorpion() 28 | { 29 | std::cout << "* SPROTCH *" << std::endl; 30 | } 31 | 32 | RadScorpion &RadScorpion::operator=(RadScorpion const &other) 33 | { 34 | this->type = other.type; 35 | this->hp = other.hp; 36 | return (*this); 37 | } 38 | -------------------------------------------------------------------------------- /04/ex01/RadScorpion.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* RadScorpion.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 15:40:56 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:33 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef RADSCORPION_HPP 14 | # define RADSCORPION_HPP 15 | 16 | # include "Enemy.hpp" 17 | 18 | class RadScorpion: public Enemy 19 | { 20 | public: 21 | RadScorpion(); 22 | RadScorpion(RadScorpion const &other); 23 | virtual ~RadScorpion(); 24 | 25 | RadScorpion &operator=(RadScorpion const &other); 26 | 27 | using Enemy::takeDamage; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /04/ex01/SuperMutant.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* SuperMutant.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 15:33:34 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:30 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SUPERMUTANT_HPP 14 | # define SUPERMUTANT_HPP 15 | 16 | # include "Enemy.hpp" 17 | 18 | class SuperMutant: public Enemy 19 | { 20 | public: 21 | SuperMutant(); 22 | SuperMutant(SuperMutant const &other); 23 | virtual ~SuperMutant(); 24 | 25 | SuperMutant &operator=(SuperMutant const &other); 26 | 27 | void takeDamage(int damage); 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /04/ex02/AssaultTerminator.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* AssaultTerminator.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 17:28:02 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:22 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ASSAULTTERMINATOR_HPP 14 | # define ASSAULTTERMINATOR_HPP 15 | 16 | # include "ISpaceMarine.hpp" 17 | 18 | class AssaultTerminator: public ISpaceMarine 19 | { 20 | public: 21 | AssaultTerminator(); 22 | AssaultTerminator(AssaultTerminator const &other); 23 | virtual ~AssaultTerminator(); 24 | 25 | AssaultTerminator &operator=(AssaultTerminator const &other); 26 | 27 | ISpaceMarine *clone(void) const; 28 | void battleCry(void) const; 29 | void rangedAttack(void) const; 30 | void meleeAttack(void) const; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /04/ex02/ISpaceMarine.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ISpaceMarine.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 17:18:11 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 16:32:05 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ISPACEMARINE_HPP 14 | # define ISPACEMARINE_HPP 15 | 16 | # include 17 | 18 | class ISpaceMarine 19 | { 20 | public: 21 | virtual ~ISpaceMarine() {} 22 | virtual ISpaceMarine *clone(void) const = 0; 23 | virtual void battleCry(void) const = 0; 24 | virtual void rangedAttack(void) const = 0; 25 | virtual void meleeAttack(void) const = 0; 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /04/ex02/ISquad.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ISquad.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 17:17:18 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 16:32:02 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ISQUAD_HPP 14 | # define ISQUAD_HPP 15 | 16 | # include "ISpaceMarine.hpp" 17 | 18 | class ISquad 19 | { 20 | public: 21 | virtual ~ISquad() {}; 22 | virtual int getCount(void) const = 0; 23 | virtual ISpaceMarine *getUnit(int index) const = 0; 24 | virtual int push(ISpaceMarine *unit) = 0; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /04/ex02/Squad.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Squad.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 17:19:22 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:25 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SQUAD_HPP 14 | # define SQUAD_HPP 15 | 16 | # include 17 | # include "ISquad.hpp" 18 | 19 | class Squad: public ISquad 20 | { 21 | private: 22 | int count; 23 | ISpaceMarine **units; 24 | public: 25 | Squad(); 26 | Squad(Squad const &other); 27 | virtual ~Squad(); 28 | 29 | Squad &operator=(Squad const &other); 30 | 31 | int getCount(void) const; 32 | ISpaceMarine *getUnit(int index) const; 33 | 34 | int push(ISpaceMarine *unit); 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /04/ex02/TacticalMarine.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* TacticalMarine.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/20 17:27:14 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:27 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef TACTICALMARINE_HPP 14 | # define TACTICALMARINE_HPP 15 | 16 | # include "ISpaceMarine.hpp" 17 | 18 | class TacticalMarine: public ISpaceMarine 19 | { 20 | public: 21 | TacticalMarine(); 22 | TacticalMarine(TacticalMarine const &other); 23 | virtual ~TacticalMarine(); 24 | 25 | TacticalMarine &operator=(TacticalMarine const &other); 26 | 27 | ISpaceMarine *clone(void) const; 28 | void battleCry(void) const; 29 | void rangedAttack(void) const; 30 | void meleeAttack(void) const; 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /04/ex03/AMateria.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* AMateria.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 14:43:11 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 15:26:49 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "AMateria.hpp" 14 | 15 | AMateria::AMateria(std::string const &type): 16 | _type(type), _xp(0) 17 | { 18 | } 19 | 20 | AMateria::~AMateria() 21 | { 22 | } 23 | 24 | std::string const &AMateria::getType(void) const 25 | { 26 | return (this->_type); 27 | } 28 | 29 | unsigned int AMateria::getXP(void) const 30 | { 31 | return (this->_xp); 32 | } 33 | 34 | void AMateria::use(ICharacter &target) 35 | { 36 | (void)target; 37 | this->_xp += 10; 38 | } 39 | -------------------------------------------------------------------------------- /04/ex03/AMateria.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* AMateria.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 14:42:59 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 15:31:44 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef AMATERIA_HPP 14 | # define AMATERIA_HPP 15 | 16 | # include 17 | # include 18 | class AMateria; 19 | # include "ICharacter.hpp" 20 | 21 | class AMateria 22 | { 23 | private: 24 | AMateria(); 25 | protected: 26 | std::string _type; 27 | unsigned int _xp; 28 | public: 29 | AMateria(std::string const &type); 30 | virtual ~AMateria(); 31 | 32 | std::string const &getType(void) const; 33 | unsigned int getXP(void) const; 34 | 35 | virtual AMateria *clone(void) const = 0; 36 | virtual void use(ICharacter &target); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /04/ex03/Character.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Character.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 15:06:27 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:12 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CHARACTER_HPP 14 | # define CHARACTER_HPP 15 | 16 | # include "ICharacter.hpp" 17 | 18 | class Character: public ICharacter 19 | { 20 | private: 21 | Character(); 22 | 23 | std::string name; 24 | int equipped; 25 | AMateria *inventory[4]; 26 | public: 27 | Character(std::string const &name); 28 | Character(Character const &other); 29 | virtual ~Character(); 30 | 31 | Character &operator=(Character const &other); 32 | 33 | std::string const &getName(void) const; 34 | 35 | void equip(AMateria *m); 36 | void unequip(int idx); 37 | void use(int idx, ICharacter &target); 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /04/ex03/Cure.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cure.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 14:50:48 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 15:05:59 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Cure.hpp" 14 | 15 | Cure::Cure(): 16 | AMateria("cure") 17 | { 18 | } 19 | 20 | Cure::Cure(Cure const &other): 21 | AMateria("cure") 22 | { 23 | this->_xp = other._xp; 24 | } 25 | 26 | Cure::~Cure() 27 | { 28 | } 29 | 30 | Cure &Cure::operator=(Cure const &other) 31 | { 32 | this->_xp = other._xp; 33 | return (*this); 34 | } 35 | 36 | AMateria *Cure::clone(void) const 37 | { 38 | Cure *cpy = new Cure(*this); 39 | return (cpy); 40 | } 41 | 42 | void Cure::use(ICharacter &target) 43 | { 44 | AMateria::use(target); 45 | std::cout << "* shoots an ice bolt at " << target.getName() << " *" << std::endl; 46 | } 47 | -------------------------------------------------------------------------------- /04/ex03/Cure.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cure.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 14:50:58 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 15:01:58 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CURE_HPP 14 | # define CURE_HPP 15 | 16 | # include "AMateria.hpp" 17 | 18 | class Cure: public AMateria 19 | { 20 | public: 21 | Cure(); 22 | Cure(Cure const &other); 23 | virtual ~Cure(); 24 | 25 | Cure &operator=(Cure const &other); 26 | 27 | AMateria *clone(void) const; 28 | void use(ICharacter &target); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /04/ex03/ICharacter.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ICharacter.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 14:45:12 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 16:18:11 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ICHARACTER_HPP 14 | # define ICHARACTER_HPP 15 | 16 | # include 17 | class ICharacter; 18 | # include "AMateria.hpp" 19 | 20 | class ICharacter 21 | { 22 | public: 23 | virtual ~ICharacter() {} 24 | virtual std::string const &getName(void) const = 0; 25 | virtual void equip(AMateria *m) = 0; 26 | virtual void unequip(int idx) = 0; 27 | virtual void use(int idx, ICharacter &target) = 0; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /04/ex03/IMateriaSource.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* IMateriaSource.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 14:45:25 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 15:52:12 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef IMATERIASOURCE_HPP 14 | # define IMATERIASOURCE_HPP 15 | 16 | # include "AMateria.hpp" 17 | 18 | class IMateriaSource 19 | { 20 | public: 21 | virtual ~IMateriaSource() {} 22 | virtual void learnMateria(AMateria *m) = 0; 23 | virtual AMateria *createMateria(std::string const &type) = 0; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /04/ex03/Ice.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Ice.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 14:52:02 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 15:05:56 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Ice.hpp" 14 | 15 | Ice::Ice(): 16 | AMateria("ice") 17 | { 18 | } 19 | 20 | Ice::Ice(Ice const &other): 21 | AMateria("ice") 22 | { 23 | this->_xp = other._xp; 24 | } 25 | 26 | Ice::~Ice() 27 | { 28 | } 29 | 30 | Ice &Ice::operator=(Ice const &other) 31 | { 32 | this->_xp = other._xp; 33 | return (*this); 34 | } 35 | 36 | AMateria *Ice::clone(void) const 37 | { 38 | Ice *cpy = new Ice(*this); 39 | return (cpy); 40 | } 41 | 42 | void Ice::use(ICharacter &target) 43 | { 44 | AMateria::use(target); 45 | std::cout << "* heals " << target.getName() << "’s wounds *" << std::endl; 46 | } 47 | -------------------------------------------------------------------------------- /04/ex03/Ice.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Ice.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 14:52:07 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 15:02:04 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ICE_HPP 14 | # define ICE_HPP 15 | 16 | # include "AMateria.hpp" 17 | 18 | class Ice: public AMateria 19 | { 20 | private: 21 | public: 22 | Ice(); 23 | Ice(Ice const &other); 24 | virtual ~Ice(); 25 | 26 | Ice &operator=(Ice const &other); 27 | 28 | AMateria *clone(void) const; 29 | void use(ICharacter &target); 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /04/ex03/MateriaSource.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* MateriaSource.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 15:32:18 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 15:52:06 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef MATERIASOURCE_HPP 14 | # define MATERIASOURCE_HPP 15 | 16 | # include 17 | # include "IMateriaSource.hpp" 18 | 19 | class MateriaSource: public IMateriaSource 20 | { 21 | private: 22 | int amount; 23 | AMateria *sources[4]; 24 | public: 25 | MateriaSource(); 26 | MateriaSource(MateriaSource const &other); 27 | virtual ~MateriaSource(); 28 | 29 | MateriaSource &operator=(MateriaSource const &other); 30 | 31 | void learnMateria(AMateria *m); 32 | AMateria* createMateria(std::string const &type); 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /04/ex04/AsteroKreog.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* AsteroKreog.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 16:27:17 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:56:51 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ASTEROKREOG_HPP 14 | # define ASTEROKREOG_HPP 15 | 16 | # include "IAsteroid.hpp" 17 | 18 | class AsteroKreog: public IAsteroid 19 | { 20 | private: 21 | std::string name; 22 | public: 23 | AsteroKreog(); 24 | AsteroKreog(std::string const &name); 25 | AsteroKreog(AsteroKreog const &other); 26 | virtual ~AsteroKreog(); 27 | 28 | AsteroKreog &operator=(AsteroKreog const &other); 29 | 30 | std::string getName(void) const; 31 | 32 | std::string beMined(DeepCoreMiner *laser) const; 33 | std::string beMined(StripMiner *laser) const; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /04/ex04/DeepCoreMiner.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* DeepCoreMiner.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 16:19:16 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 16:52:39 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "DeepCoreMiner.hpp" 14 | 15 | DeepCoreMiner::DeepCoreMiner() 16 | { 17 | } 18 | 19 | DeepCoreMiner::DeepCoreMiner(DeepCoreMiner const &other) 20 | { 21 | (void)other; 22 | } 23 | 24 | DeepCoreMiner::~DeepCoreMiner() 25 | { 26 | } 27 | 28 | DeepCoreMiner &DeepCoreMiner::operator=(DeepCoreMiner const &other) 29 | { 30 | (void)other; 31 | return (*this); 32 | } 33 | 34 | void DeepCoreMiner::mine(IAsteroid *asteroid) 35 | { 36 | if (asteroid == nullptr) 37 | return ; 38 | std::cout << "* mining deep ... got " << asteroid->beMined(this) << " ! *" << std::endl; 39 | } 40 | -------------------------------------------------------------------------------- /04/ex04/DeepCoreMiner.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* DeepCoreMiner.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 16:19:35 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:56:54 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DEEPCOREMINER_HPP 14 | # define DEEPCOREMINER_HPP 15 | 16 | # include "IMiningLaser.hpp" 17 | 18 | class DeepCoreMiner: public IMiningLaser 19 | { 20 | public: 21 | DeepCoreMiner(); 22 | DeepCoreMiner(DeepCoreMiner const &other); 23 | virtual ~DeepCoreMiner(); 24 | 25 | DeepCoreMiner &operator=(DeepCoreMiner const &other); 26 | 27 | void mine(IAsteroid *asteroid); 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /04/ex04/IAsteroid.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* IAsteroid.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 16:17:21 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 17:04:04 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef IASTEROID_HPP 14 | # define IASTEROID_HPP 15 | 16 | # include 17 | class DeepCoreMiner; 18 | class StripMiner; 19 | 20 | class IAsteroid 21 | { 22 | public: 23 | virtual ~IAsteroid() {} 24 | virtual std::string beMined(DeepCoreMiner *laser) const = 0; 25 | virtual std::string beMined(StripMiner *laser) const = 0; 26 | virtual std::string getName(void) const = 0; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /04/ex04/IMiningLaser.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* IMiningLaser.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 16:16:33 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 17:03:54 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef IMININGLASER_HPP 14 | # define IMININGLASER_HPP 15 | 16 | # include 17 | # include "IAsteroid.hpp" 18 | 19 | class IMiningLaser 20 | { 21 | public: 22 | virtual ~IMiningLaser() {} 23 | virtual void mine(IAsteroid *asteroid) = 0; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /04/ex04/KoalaSteroid.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* KoalaSteroid.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 16:26:32 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:56:57 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef KOALASTEROID_HPP 14 | # define KOALASTEROID_HPP 15 | 16 | # include "IAsteroid.hpp" 17 | 18 | class KoalaSteroid: public IAsteroid 19 | { 20 | private: 21 | std::string name; 22 | public: 23 | KoalaSteroid(); 24 | KoalaSteroid(std::string const &name); 25 | KoalaSteroid(KoalaSteroid const &other); 26 | virtual ~KoalaSteroid(); 27 | 28 | KoalaSteroid &operator=(KoalaSteroid const &other); 29 | 30 | std::string getName(void) const; 31 | 32 | std::string beMined(DeepCoreMiner *laser) const; 33 | std::string beMined(StripMiner *laser) const; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /04/ex04/MiningBarge.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* MiningBarge.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 16:41:24 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:03 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef MININGBARGE_HPP 14 | # define MININGBARGE_HPP 15 | 16 | # include "IMiningLaser.hpp" 17 | # include "IAsteroid.hpp" 18 | 19 | class MiningBarge 20 | { 21 | private: 22 | int amount; 23 | IMiningLaser *lasers[4]; 24 | public: 25 | MiningBarge(); 26 | MiningBarge(MiningBarge const &other); 27 | virtual ~MiningBarge(); 28 | 29 | MiningBarge &operator=(MiningBarge const &other); 30 | 31 | void equip(IMiningLaser *laser); 32 | void mine(IAsteroid *asteroid) const; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /04/ex04/StripMiner.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* StripMiner.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 16:19:26 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/21 16:52:57 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "StripMiner.hpp" 14 | 15 | StripMiner::StripMiner() 16 | { 17 | } 18 | 19 | StripMiner::StripMiner(StripMiner const &other) 20 | { 21 | (void)other; 22 | } 23 | 24 | StripMiner::~StripMiner() 25 | { 26 | } 27 | 28 | StripMiner &StripMiner::operator=(StripMiner const &other) 29 | { 30 | (void)other; 31 | return (*this); 32 | } 33 | 34 | void StripMiner::mine(IAsteroid *asteroid) 35 | { 36 | if (asteroid == nullptr) 37 | return ; 38 | std::cout << "* strip mining ... got " << asteroid->beMined(this) << " ! *" << std::endl; 39 | } 40 | -------------------------------------------------------------------------------- /04/ex04/StripMiner.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* StripMiner.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 16:19:51 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/22 17:57:06 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef STRIPMINER_HPP 14 | # define STRIPMINER_HPP 15 | 16 | # include "IMiningLaser.hpp" 17 | 18 | class StripMiner: public IMiningLaser 19 | { 20 | public: 21 | StripMiner(); 22 | StripMiner(StripMiner const &other); 23 | virtual ~StripMiner(); 24 | 25 | StripMiner &operator=(StripMiner const &other); 26 | 27 | void mine(IAsteroid *asteroid); 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /05/ex02/PresidentialPardonForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PresidentialPardonForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 19:41:12 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/23 14:56:48 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PRESIDENTIALPARDONFORM_HPP 14 | # define PRESIDENTIALPARDONFORM_HPP 15 | 16 | # include 17 | # include "Form.hpp" 18 | 19 | class PresidentialPardonForm: public Form 20 | { 21 | private: 22 | PresidentialPardonForm(); 23 | 24 | std::string const target; 25 | public: 26 | PresidentialPardonForm(std::string const &target); 27 | PresidentialPardonForm(PresidentialPardonForm const &other); 28 | virtual ~PresidentialPardonForm(); 29 | 30 | static std::string const &name; 31 | 32 | PresidentialPardonForm &operator=(PresidentialPardonForm const &other); 33 | 34 | void execute(Bureaucrat const &executor) const; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /05/ex02/RobotomyRequestForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* RobotomyRequestForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/21 19:41:16 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/23 14:56:46 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ROBOTOMYREQUESTFORM_HPP 14 | # define ROBOTOMYREQUESTFORM_HPP 15 | 16 | # include 17 | # include "Form.hpp" 18 | 19 | class RobotomyRequestForm: public Form 20 | { 21 | private: 22 | RobotomyRequestForm(); 23 | 24 | std::string const target; 25 | public: 26 | RobotomyRequestForm(std::string const &target); 27 | RobotomyRequestForm(RobotomyRequestForm const &other); 28 | virtual ~RobotomyRequestForm(); 29 | 30 | static std::string const &name; 31 | 32 | RobotomyRequestForm &operator=(RobotomyRequestForm const &other); 33 | 34 | void execute(Bureaucrat const &executor) const; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /06/ex00/.gitignore: -------------------------------------------------------------------------------- 1 | convert -------------------------------------------------------------------------------- /06/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/23 17:28:09 by ncolomer #+# #+# */ 9 | /* Updated: 2020/01/03 18:20:16 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "Interpreter.hpp" 15 | 16 | int main(int argc, char const *argv[]) 17 | { 18 | if (argc != 2) 19 | { 20 | std::cout << "convert: error: bad arguments\n" 21 | << " usage: value" << std::endl; 22 | } 23 | else 24 | { 25 | Interpreter p(argv[1]); 26 | std::cout << p << std::endl; 27 | } 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /06/ex01/.gitignore: -------------------------------------------------------------------------------- 1 | serializer -------------------------------------------------------------------------------- /06/ex01/Data.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Data.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/27 17:34:38 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/27 18:55:28 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DATA_HPP 14 | # define DATA_HPP 15 | 16 | # include 17 | 18 | struct Data 19 | { 20 | std::string s1; 21 | int n; 22 | std::string s2; 23 | }; 24 | 25 | void *serialize(void); 26 | 27 | Data *deserialize(void *raw); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /06/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/17 19:21:17 by ncolomer #+# #+# # 9 | # Updated: 2019/12/28 16:02:54 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = main.cpp Data.cpp 14 | OBJS = $(SRCS:.cpp=.o) 15 | 16 | CXX = clang++ 17 | RM = rm -f 18 | CXXFLAGS = -Wall -Wextra -Werror -I. 19 | 20 | NAME = serializer 21 | 22 | all: $(NAME) 23 | 24 | $(NAME): $(OBJS) 25 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 26 | 27 | clean: 28 | $(RM) $(OBJS) 29 | 30 | fclean: clean 31 | $(RM) $(NAME) 32 | 33 | re: fclean $(NAME) 34 | 35 | test: $(NAME) 36 | ./serializer 37 | 38 | .PHONY: all clean fclean re test 39 | -------------------------------------------------------------------------------- /06/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/23 17:28:09 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/27 18:58:53 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "Data.hpp" 15 | 16 | int main(void) 17 | { 18 | srand(time(NULL)); 19 | 20 | for (int i = 0; i < 5; i++) 21 | { 22 | std::cout << "test " << i << ": " << '\n'; 23 | void *raw = serialize(); 24 | Data *dt = deserialize(raw); 25 | 26 | std::cout << "\tstr1: " << dt->s1 << '\n'; 27 | std::cout << "\tn: " << dt->n << '\n'; 28 | std::cout << "\tstr2: " << dt->s2 << std::endl; 29 | 30 | delete static_cast(raw); 31 | delete dt; 32 | } 33 | 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /06/ex02/.gitignore: -------------------------------------------------------------------------------- 1 | detector -------------------------------------------------------------------------------- /06/ex02/A.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* A.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/27 19:01:36 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/27 19:15:39 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef A_HPP 14 | # define A_HPP 15 | 16 | # include "Base.hpp" 17 | 18 | class A: public Base 19 | { 20 | virtual ~A() {}; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /06/ex02/B.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* B.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/27 19:01:41 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/27 19:15:33 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef B_HPP 14 | # define B_HPP 15 | 16 | # include "Base.hpp" 17 | 18 | class B: public Base 19 | { 20 | virtual ~B() {}; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /06/ex02/Base.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Base.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/27 19:01:48 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/27 19:15:41 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef BASE_HPP 14 | # define BASE_HPP 15 | 16 | class Base 17 | { 18 | public: 19 | virtual ~Base() {}; 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /06/ex02/C.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* C.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/27 19:03:14 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/27 19:15:26 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef C_HPP 14 | # define C_HPP 15 | 16 | # include "Base.hpp" 17 | 18 | class C: public Base 19 | { 20 | virtual ~C() {}; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /06/ex02/Detector.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Detector.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/27 19:05:20 by ncolomer #+# #+# */ 9 | /* Updated: 2020/01/07 11:38:13 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Detector.hpp" 14 | 15 | Base *generate(void) 16 | { 17 | int r = rand() % 100; 18 | 19 | if (r > 66) 20 | return (new A); 21 | if (r > 33) 22 | return (new B); 23 | return (new C); 24 | } 25 | 26 | void identify_from_pointer(Base *p) 27 | { 28 | if (dynamic_cast(p) != nullptr) 29 | std::cout << "A"; 30 | else if (dynamic_cast(p) != nullptr) 31 | std::cout << "B"; 32 | else if (dynamic_cast(p) != nullptr) 33 | std::cout << "C"; 34 | } 35 | 36 | void identify_from_reference(Base &p) 37 | { 38 | identify_from_pointer(&p); 39 | } 40 | -------------------------------------------------------------------------------- /06/ex02/Detector.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Detector.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/27 19:04:10 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/27 19:09:14 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DETECTOR_HPP 14 | # define DETECTOR_HPP 15 | 16 | # include 17 | # include 18 | # include "Base.hpp" 19 | # include "A.hpp" 20 | # include "B.hpp" 21 | # include "C.hpp" 22 | 23 | Base *generate(void); 24 | 25 | void identify_from_pointer(Base *p); 26 | void identify_from_reference(Base &p); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /06/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/17 19:21:17 by ncolomer #+# #+# # 9 | # Updated: 2019/12/28 16:02:41 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = main.cpp Detector.cpp 14 | OBJS = $(SRCS:.cpp=.o) 15 | 16 | CXX = clang++ 17 | RM = rm -f 18 | CXXFLAGS = -Wall -Wextra -Werror -I. 19 | 20 | NAME = detector 21 | 22 | all: $(NAME) 23 | 24 | $(NAME): $(OBJS) 25 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 26 | 27 | clean: 28 | $(RM) $(OBJS) 29 | 30 | fclean: clean 31 | $(RM) $(NAME) 32 | 33 | re: fclean $(NAME) 34 | 35 | test: $(NAME) 36 | ./detector 37 | 38 | .PHONY: all clean fclean re test 39 | -------------------------------------------------------------------------------- /06/ex02/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/27 19:03:45 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/27 19:25:35 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "Detector.hpp" 15 | 16 | int main(void) 17 | { 18 | srand(time(NULL)); 19 | 20 | for (int i = 0; i < 50; i++) 21 | { 22 | Base *o = generate(); 23 | std::cout << "Test " << i << ": "; 24 | identify_from_pointer(o); 25 | std::cout << ", "; 26 | identify_from_reference(*o); 27 | std::cout << std::endl; 28 | delete o; 29 | } 30 | 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /07/.gitignore: -------------------------------------------------------------------------------- 1 | intro_templates 2 | array -------------------------------------------------------------------------------- /07/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/17 19:21:17 by ncolomer #+# #+# # 9 | # Updated: 2020/01/07 17:54:11 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = whatever.cpp 14 | OBJS = $(SRCS:.cpp=.o) 15 | 16 | CXX = clang++ 17 | RM = rm -f 18 | CXXFLAGS = -Wall -Wextra -Werror -I. 19 | 20 | NAME = intro_templates 21 | 22 | all: $(NAME) 23 | 24 | $(NAME): $(OBJS) 25 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 26 | 27 | clean: 28 | $(RM) $(OBJS) 29 | 30 | fclean: clean 31 | $(RM) $(NAME) 32 | 33 | re: fclean $(NAME) 34 | 35 | test: $(NAME) 36 | ./intro_templates 37 | 38 | .PHONY: all clean fclean re test 39 | -------------------------------------------------------------------------------- /07/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/17 19:21:17 by ncolomer #+# #+# # 9 | # Updated: 2020/01/07 11:53:39 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = iter.cpp 14 | OBJS = $(SRCS:.cpp=.o) 15 | 16 | CXX = clang++ 17 | RM = rm -f 18 | CXXFLAGS = -Wall -Wextra -Werror -I. 19 | 20 | NAME = intro_templates 21 | 22 | all: $(NAME) 23 | 24 | $(NAME): $(OBJS) 25 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 26 | 27 | clean: 28 | $(RM) $(OBJS) 29 | 30 | fclean: clean 31 | $(RM) $(NAME) 32 | 33 | re: fclean $(NAME) 34 | 35 | test: $(NAME) 36 | ./intro_templates 37 | 38 | .PHONY: all clean fclean re test 39 | -------------------------------------------------------------------------------- /07/ex02/Array.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Array.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/28 15:31:54 by ncolomer #+# #+# */ 9 | /* Updated: 2020/01/09 14:32:41 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ARRAY_HPP 14 | # define ARRAY_HPP 15 | 16 | # include 17 | # include 18 | 19 | template 20 | class Array 21 | { 22 | private: 23 | size_t length; 24 | T *elts; 25 | public: 26 | Array(); 27 | Array(size_t n); 28 | Array(Array const &other); 29 | virtual ~Array(); 30 | 31 | class OutOfBoundsException: public std::exception { 32 | virtual const char* what() const throw(); 33 | }; 34 | 35 | Array &operator=(Array const &other); 36 | T &operator[](size_t index); 37 | T const &operator[](size_t index) const; 38 | 39 | size_t size(void) const; 40 | }; 41 | 42 | # include "Array.ipp" 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /07/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/17 19:21:17 by ncolomer #+# #+# # 9 | # Updated: 2020/01/07 11:54:24 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = main.cpp 14 | OBJS = $(SRCS:.cpp=.o) 15 | 16 | CXX = clang++ 17 | RM = rm -f 18 | CXXFLAGS = -Wall -Wextra -Werror -I. 19 | 20 | NAME = array 21 | 22 | all: $(NAME) 23 | 24 | $(NAME): $(OBJS) 25 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 26 | 27 | clean: 28 | $(RM) $(OBJS) 29 | 30 | fclean: clean 31 | $(RM) $(NAME) 32 | 33 | re: fclean $(NAME) 34 | 35 | test: $(NAME) 36 | ./array 37 | 38 | .PHONY: all clean fclean re test 39 | -------------------------------------------------------------------------------- /08/README.md: -------------------------------------------------------------------------------- 1 | # CPP Module 8 2 | 3 | >The MindOpen interpreter use a lot of classes for no reasons, but follow the subject rules of having 1 class per Instruction and a all instructions in a queue... The *v2* doesn't care about that. 4 | 5 | ## Ressources 6 | 7 | * [~~Brainfuck~~ MindOpen](https://en.wikipedia.org/wiki/Brainfuck#Commands) 8 | * [MindOpen programs](https://copy.sh/brainfuck/) 9 | * [Postix notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation) 10 | * [Infix to Postfix](https://codeburst.io/conversion-of-infix-expression-to-postfix-expression-using-stack-data-structure-3faf9c212ab8) 11 | -------------------------------------------------------------------------------- /08/ex01/Span.ipp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Span.ipp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/28 17:54:46 by ncolomer #+# #+# */ 9 | /* Updated: 2020/01/08 18:02:02 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | template 14 | void Span::addNumber(InputIterator begin, InputIterator end) 15 | { 16 | if (this->numbers.size() + std::distance(begin, end) > this->max) 17 | throw Span::FullSpanException(); 18 | this->numbers.insert(begin, end); 19 | } 20 | -------------------------------------------------------------------------------- /08/ex03/.gitignore: -------------------------------------------------------------------------------- 1 | mindopen -------------------------------------------------------------------------------- /08/ex03/Instruction.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Instruction.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 16:58:19 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:47:30 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Instruction.hpp" 14 | 15 | Instruction::Instruction(Program &mindOpen): 16 | mo(mindOpen) 17 | { 18 | } 19 | 20 | Instruction::Instruction(Instruction const &other): 21 | mo(other.mo) 22 | { 23 | } 24 | 25 | Instruction::~Instruction() 26 | { 27 | } 28 | 29 | Instruction &Instruction::operator=(Instruction const &other) 30 | { 31 | (void)other; 32 | return (*this); 33 | } 34 | -------------------------------------------------------------------------------- /08/ex03/Instruction.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Instruction.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 16:58:23 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:50:13 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef INSTRUCTION_HPP 14 | # define INSTRUCTION_HPP 15 | 16 | class Program; 17 | # include "Program.hpp" 18 | 19 | class Instruction 20 | { 21 | private: 22 | Instruction(); 23 | protected: 24 | Program &mo; 25 | public: 26 | Instruction(Program &mo); 27 | Instruction(Instruction const &other); 28 | virtual ~Instruction(); 29 | 30 | Instruction &operator=(Instruction const &other); 31 | 32 | virtual void execute(void) = 0; 33 | virtual int getType(void) const = 0; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /08/ex03/Instructions/Decr.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Decr.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:38:56 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:52:12 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Decr.hpp" 14 | 15 | Decr::Decr(Program &mindOpen): 16 | Instruction(mindOpen) 17 | { 18 | } 19 | 20 | Decr::Decr(Decr const &other): 21 | Instruction(other) 22 | { 23 | } 24 | 25 | Decr::~Decr() 26 | { 27 | } 28 | 29 | Decr &Decr::operator=(Decr const &other) 30 | { 31 | (void)other; 32 | return (*this); 33 | } 34 | 35 | void Decr::execute(void) 36 | { 37 | this->mo.decrData(); 38 | } 39 | 40 | int Decr::getType(void) const 41 | { 42 | return (2); 43 | } 44 | -------------------------------------------------------------------------------- /08/ex03/Instructions/Decr.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Decr.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:38:58 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:43:43 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DECR_HPP 14 | # define DECR_HPP 15 | 16 | # include "Program.hpp" 17 | # include "Instruction.hpp" 18 | 19 | class Decr: public Instruction 20 | { 21 | private: 22 | Decr(); 23 | public: 24 | Decr(Program &mindOpen); 25 | Decr(Decr const &other); 26 | virtual ~Decr(); 27 | 28 | Decr &operator=(Decr const &other); 29 | 30 | void execute(void); 31 | int getType(void) const; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /08/ex03/Instructions/DecrPtr.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* DecrPtr.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:23 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:47:38 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "DecrPtr.hpp" 14 | 15 | DecrPtr::DecrPtr(Program &mindOpen): 16 | Instruction(mindOpen) 17 | { 18 | } 19 | 20 | DecrPtr::DecrPtr(DecrPtr const &other): 21 | Instruction(other) 22 | { 23 | } 24 | 25 | DecrPtr::~DecrPtr() 26 | { 27 | } 28 | 29 | DecrPtr &DecrPtr::operator=(DecrPtr const &other) 30 | { 31 | (void)other; 32 | return (*this); 33 | } 34 | 35 | void DecrPtr::execute(void) 36 | { 37 | this->mo.decrPtr(); 38 | } 39 | 40 | int DecrPtr::getType(void) const 41 | { 42 | return (3); 43 | } 44 | -------------------------------------------------------------------------------- /08/ex03/Instructions/DecrPtr.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* DecrPtr.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:21 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:43:46 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DECRPTR_HPP 14 | # define DECRPTR_HPP 15 | 16 | # include "Program.hpp" 17 | # include "Instruction.hpp" 18 | 19 | class DecrPtr: public Instruction 20 | { 21 | private: 22 | DecrPtr(); 23 | public: 24 | DecrPtr(Program &mindOpen); 25 | DecrPtr(DecrPtr const &other); 26 | virtual ~DecrPtr(); 27 | 28 | DecrPtr &operator=(DecrPtr const &other); 29 | 30 | void execute(void); 31 | int getType(void) const; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /08/ex03/Instructions/Incr.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Incr.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:01 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:47:37 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Incr.hpp" 14 | 15 | Incr::Incr(Program &mindOpen): 16 | Instruction(mindOpen) 17 | { 18 | } 19 | 20 | Incr::Incr(Incr const &other): 21 | Instruction(other) 22 | { 23 | } 24 | 25 | Incr::~Incr() 26 | { 27 | } 28 | 29 | Incr &Incr::operator=(Incr const &other) 30 | { 31 | (void)other; 32 | return (*this); 33 | } 34 | 35 | void Incr::execute(void) 36 | { 37 | this->mo.incrData(); 38 | } 39 | 40 | int Incr::getType(void) const 41 | { 42 | return (0); 43 | } 44 | -------------------------------------------------------------------------------- /08/ex03/Instructions/Incr.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Incr.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:03 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:43:48 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef INCR_HPP 14 | # define INCR_HPP 15 | 16 | # include "Program.hpp" 17 | # include "Instruction.hpp" 18 | 19 | class Incr: public Instruction 20 | { 21 | private: 22 | Incr(); 23 | public: 24 | Incr(Program &mindOpen); 25 | Incr(Incr const &other); 26 | virtual ~Incr(); 27 | 28 | Incr &operator=(Incr const &other); 29 | 30 | void execute(void); 31 | int getType(void) const; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /08/ex03/Instructions/IncrPtr.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* IncrPtr.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:05 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:47:36 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "IncrPtr.hpp" 14 | 15 | IncrPtr::IncrPtr(Program &mindOpen): 16 | Instruction(mindOpen) 17 | { 18 | } 19 | 20 | IncrPtr::IncrPtr(IncrPtr const &other): 21 | Instruction(other) 22 | { 23 | } 24 | 25 | IncrPtr::~IncrPtr() 26 | { 27 | } 28 | 29 | IncrPtr &IncrPtr::operator=(IncrPtr const &other) 30 | { 31 | (void)other; 32 | return (*this); 33 | } 34 | 35 | void IncrPtr::execute(void) 36 | { 37 | this->mo.incrPtr(); 38 | } 39 | 40 | int IncrPtr::getType(void) const 41 | { 42 | return (1); 43 | } 44 | -------------------------------------------------------------------------------- /08/ex03/Instructions/IncrPtr.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* IncrPtr.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:09 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:43:50 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef INCRPTR_HPP 14 | # define INCRPTR_HPP 15 | 16 | # include "Program.hpp" 17 | # include "Instruction.hpp" 18 | 19 | class IncrPtr: public Instruction 20 | { 21 | private: 22 | IncrPtr(); 23 | public: 24 | IncrPtr(Program &mindOpen); 25 | IncrPtr(IncrPtr const &other); 26 | virtual ~IncrPtr(); 27 | 28 | IncrPtr &operator=(IncrPtr const &other); 29 | 30 | void execute(void); 31 | int getType(void) const; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /08/ex03/Instructions/Input.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Input.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:28 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 19:21:56 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Input.hpp" 14 | 15 | Input::Input(Program &mindOpen): 16 | Instruction(mindOpen) 17 | { 18 | } 19 | 20 | Input::Input(Input const &other): 21 | Instruction(other) 22 | { 23 | } 24 | 25 | Input::~Input() 26 | { 27 | } 28 | 29 | Input &Input::operator=(Input const &other) 30 | { 31 | (void)other; 32 | return (*this); 33 | } 34 | 35 | void Input::execute(void) 36 | { 37 | char c; 38 | 39 | std::cin >> c; 40 | this->mo.setPtrData(c); 41 | } 42 | 43 | int Input::getType(void) const 44 | { 45 | return (4); 46 | } 47 | -------------------------------------------------------------------------------- /08/ex03/Instructions/Input.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Input.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:30 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:43:52 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef INPUT_HPP 14 | # define INPUT_HPP 15 | 16 | # include "Program.hpp" 17 | # include "Instruction.hpp" 18 | 19 | class Input: public Instruction 20 | { 21 | private: 22 | Input(); 23 | public: 24 | Input(Program &mindOpen); 25 | Input(Input const &other); 26 | virtual ~Input(); 27 | 28 | Input &operator=(Input const &other); 29 | 30 | void execute(void); 31 | int getType(void) const; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /08/ex03/Instructions/LoopEnd.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* LoopEnd.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:32 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 19:12:35 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "LoopEnd.hpp" 14 | 15 | LoopEnd::LoopEnd(Program &mindOpen): 16 | Instruction(mindOpen) 17 | { 18 | } 19 | 20 | LoopEnd::LoopEnd(LoopEnd const &other): 21 | Instruction(other) 22 | { 23 | } 24 | 25 | LoopEnd::~LoopEnd() 26 | { 27 | } 28 | 29 | LoopEnd &LoopEnd::operator=(LoopEnd const &other) 30 | { 31 | (void)other; 32 | return (*this); 33 | } 34 | 35 | void LoopEnd::execute(void) 36 | { 37 | if (this->mo.getPtrData() != 0) 38 | this->mo.moveToPreviousLoop(); 39 | } 40 | 41 | int LoopEnd::getType(void) const 42 | { 43 | return (7); 44 | } 45 | -------------------------------------------------------------------------------- /08/ex03/Instructions/LoopEnd.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* LoopEnd.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:34 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:43:54 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LOOPEND_HPP 14 | # define LOOPEND_HPP 15 | 16 | # include "Program.hpp" 17 | # include "Instruction.hpp" 18 | 19 | class LoopEnd: public Instruction 20 | { 21 | private: 22 | LoopEnd(); 23 | public: 24 | LoopEnd(Program &mindOpen); 25 | LoopEnd(LoopEnd const &other); 26 | virtual ~LoopEnd(); 27 | 28 | LoopEnd &operator=(LoopEnd const &other); 29 | 30 | void execute(void); 31 | int getType(void) const; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /08/ex03/Instructions/LoopStart.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* LoopStart.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:38 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 19:12:24 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "LoopStart.hpp" 14 | 15 | LoopStart::LoopStart(Program &mindOpen): 16 | Instruction(mindOpen) 17 | { 18 | } 19 | 20 | LoopStart::LoopStart(LoopStart const &other): 21 | Instruction(other) 22 | { 23 | } 24 | 25 | LoopStart::~LoopStart() 26 | { 27 | } 28 | 29 | LoopStart &LoopStart::operator=(LoopStart const &other) 30 | { 31 | (void)other; 32 | return (*this); 33 | } 34 | 35 | void LoopStart::execute(void) 36 | { 37 | if (this->mo.getPtrData() == 0) 38 | this->mo.moveToNextLoop(); 39 | } 40 | 41 | int LoopStart::getType(void) const 42 | { 43 | return (6); 44 | } 45 | -------------------------------------------------------------------------------- /08/ex03/Instructions/LoopStart.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* LoopStart.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:40 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:43:56 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LOOPSTART_HPP 14 | # define LOOPSTART_HPP 15 | 16 | # include "Program.hpp" 17 | # include "Instruction.hpp" 18 | 19 | class LoopStart: public Instruction 20 | { 21 | private: 22 | LoopStart(); 23 | public: 24 | LoopStart(Program &mindOpen); 25 | LoopStart(LoopStart const &other); 26 | virtual ~LoopStart(); 27 | 28 | LoopStart &operator=(LoopStart const &other); 29 | 30 | void execute(void); 31 | int getType(void) const; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /08/ex03/Instructions/Output.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Output.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:42 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:47:32 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Output.hpp" 14 | 15 | Output::Output(Program &mindOpen): 16 | Instruction(mindOpen) 17 | { 18 | } 19 | 20 | Output::Output(Output const &other): 21 | Instruction(other) 22 | { 23 | } 24 | 25 | Output::~Output() 26 | { 27 | } 28 | 29 | Output &Output::operator=(Output const &other) 30 | { 31 | (void)other; 32 | return (*this); 33 | } 34 | 35 | void Output::execute(void) 36 | { 37 | std::cout << this->mo.getPtrData(); 38 | } 39 | 40 | int Output::getType(void) const 41 | { 42 | return (5); 43 | } 44 | -------------------------------------------------------------------------------- /08/ex03/Instructions/Output.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Output.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 17:39:44 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 18:43:59 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef OUTPUT_HPP 14 | # define OUTPUT_HPP 15 | 16 | # include "Program.hpp" 17 | # include "Instruction.hpp" 18 | 19 | class Output: public Instruction 20 | { 21 | private: 22 | Output(); 23 | public: 24 | Output(Program &mindOpen); 25 | Output(Output const &other); 26 | virtual ~Output(); 27 | 28 | Output &operator=(Output const &other); 29 | 30 | void execute(void); 31 | int getType(void) const; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /08/ex03/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/29 18:01:14 by ncolomer #+# #+# # 9 | # Updated: 2019/12/29 18:49:15 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = main.cpp MindOpen.cpp Instruction.cpp Program.cpp \ 14 | Instructions/Decr.cpp Instructions/Incr.cpp Instructions/DecrPtr.cpp \ 15 | Instructions/IncrPtr.cpp Instructions/Input.cpp Instructions/Output.cpp \ 16 | Instructions/LoopStart.cpp Instructions/LoopEnd.cpp 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = clang++ 20 | RM = rm -f 21 | CXXFLAGS = -Wall -Wextra -Werror -I. 22 | 23 | NAME = mindopen 24 | 25 | all: $(NAME) 26 | 27 | $(NAME): $(OBJS) 28 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 29 | 30 | clean: 31 | $(RM) $(OBJS) 32 | 33 | fclean: clean 34 | $(RM) $(NAME) 35 | 36 | re: fclean $(NAME) 37 | 38 | .PHONY: all clean fclean re 39 | -------------------------------------------------------------------------------- /08/ex03/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 16:54:20 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 19:39:46 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "MindOpen.hpp" 15 | 16 | int main(int argc, char const *argv[]) 17 | { 18 | if (argc != 2) 19 | { 20 | std::cerr << "MindOpen: error: missing program name" << std::endl; 21 | } 22 | else 23 | { 24 | MindOpen mo; 25 | if (!mo.loadFromFile(argv[1])) 26 | std::cerr << "MindOpen: error: could not load program " << argv[1] << std::endl; 27 | else 28 | mo.execute(); 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /08/ex03/programs/ascii.b: -------------------------------------------------------------------------------- 1 | [Displays the ASCII character set, Jeffry Johnston 2001] 2 | .+[.+] 3 | @ 4 | -------------------------------------------------------------------------------- /08/ex03/programs/dbf2c.b: -------------------------------------------------------------------------------- 1 | +++[>+++++<-]>>+<[>>++++>++>+++++>+++++>+>>+<++[++<]>---] 2 | 3 | >++++.>>>.+++++.>------.<--.+++++++++.>+.+.<<<<---.[>]<<.<<<.-------.>++++. 4 | <+++++.+.>-----.>+.<++++.>>++.>-----. 5 | 6 | <<<-----.+++++.-------.<--.<<<.>>>.<<+.>------.-..--.+++.-----<++.<--[>+<-] 7 | >>>>>--.--.<++++.>>-.<<<.>>>--.>. 8 | 9 | <<<<-----.>----.++++++++.----<+.+++++++++>>--.+.++<<<<.[>]<.>> 10 | 11 | ,[>>+++[<+++++++>-]<[<[-[-<]]>>[>]<-]<[<+++++>-[<+++>-[<-->-[<+++>- 12 | [<++++[>[->>]<[>>]<<-]>[<+++>-[<--->-[<++++>-[<+++[>[-[-[-[->>]]]]<[>>]<<-] 13 | >[<+>-[<->-[<++>-[<[-]>-]]]]]]]]]]]]] 14 | 15 | <[ 16 | -[-[>+<-]>] 17 | <[<<<<.>+++.+.+++.-------.>---.++.<.>-.++<<<<.[>]>>>>>>>>>] 18 | <[[<]>++.--[>]>>>>>>>>] 19 | <[<<++..-->>>>>>] 20 | <[<<..>>>>>] 21 | <[<<..-.+>>>>] 22 | <[<<++..---.+>>>] 23 | <[<<<.>>.>>>>>] 24 | <[<<<<-----.+++++>.----.+++.+>---.<<<-.[>]>] 25 | <[<<<<.-----.>++++.<++.+++>----.>---.<<<.-[>]] 26 | <[<<<<<----.>>.<<.+++++.>>>+.++>.>>] 27 | <.> 28 | ]> 29 | ,] 30 | 31 | <<<<<.<+.>++++.<----.>>---.<<<-.>>>+.>.>.[<]>++.[>]<. 32 | >[Translates brainfuck to C. Assumes no-change-on-EOF or EOF->0. 33 | Generated C does no-change-on-EOF, and uses unistd.h read and write calls. 34 | Daniel B Cristofani (cristofdathevanetdotcom) 35 | http://www.hevanet.com/cristofd/brainfuck/] 36 | -------------------------------------------------------------------------------- /08/ex03/programs/helloword.b: -------------------------------------------------------------------------------- 1 | ++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>++.>+.+++++++..+++.<<++.>+++++++++++++++.>.+++.------.--------.<<+.<. -------------------------------------------------------------------------------- /08/ex03/programs/numwarp.b: -------------------------------------------------------------------------------- 1 | >>>>+>+++>+++>>>>>+++>>+[ 2 | -,[----------[---[+<++++[>-----<-]+>[<+>--------[<+>- 3 | [--->>+++++++++++++[<<[-<+>>]>[<]>-]<< 4 | [+>+++++[<-------->-]<[<+>-]]]]]]]] 5 | < 6 | [<<++[>>>>>>>>>>>+<<<<<<<<<<<-]<<+>+>+>>>+>+>>+>+<<<<<- 7 | [<<+>>>+>+>>>+<<<<<- 8 | [<<<<+>>->>>>->>+<<<<- 9 | [<<<<->+>>>>->>>->-<<<<<- 10 | [<<<->>>>+<- 11 | [<<<+>>>>->+>>+<<<<- 12 | [<<<<+>->+>>>+>>>>+<<<<<- 13 | [<<->>>->->>>-<<<<<- 14 | [<<<<->+>>>>+>+>>>+<<<<<- 15 | [<<<<+>>>>>>-<<- 16 | [<<+>>>->>>>-<<<<<- 17 | [>+>>>->+<<<<<- 18 | [>>+<<- 19 | [<<<->->>>->->>+<<<<- 20 | [<<<+>+>>>+>+<<- 21 | [>->-<<- 22 | [<<->>>+>+<<- 23 | [<<+>>>>>>->-<<<<<- 24 | [<<<<->>->>- 25 | [<<<<+>>>>>>>>+<<<<- 26 | [<<<<->>+>>>>>>>+<<<<<- 27 | [>->>>-<<<<-]]]]]]]]]]]]]]]]]]]]] 28 | >[[<<<<<<<<<<<+>>>>>>>>>>>-]>]+>>>>>>>+>>+<]> 29 | ]<<[-]<[-[>>>>+<<<<-]]<<<<<<++<+++<+++[>]<[ 30 | >>>>>++++++++[<++++++<++++>>-]>>>[-[<+<<<<.>>>>>-]]<<+<<-<<<<[ 31 | -[-[>+<-]>]>>>[.[>]]<<[<+>-]>>>[<<-[<++>-]>>-] 32 | <<[++[<+>--]>+<]>>>[<+>-]<<<<<<<< 33 | ]>>>>>++++++++++.>+[[-]<]<<< 34 | ] 35 | [Enter a number using ()-./0123456789abcdef and space, and hit return. 36 | Daniel B Cristofani (cristofdathevanetdotcom) 37 | http://www.hevanet.com/cristofd/brainfuck/] 38 | -------------------------------------------------------------------------------- /08/ex03/programs/quine505.b: -------------------------------------------------------------------------------- 1 | Written by Erik Bosman 2 | 3 | -->+++>+>+>+>+++++>++>++>->+++>++>+>>>>>>>>>>>>>>>>->++++>>>>->+++>+++>+++>+++>+++>+++>+>+>>>->->>++++>+>>>>->>++++>+>+>>->->++>++>++>++++>+>++>->++>++++>+>+>++>++>->->++>++>++++>+>+>>>>>->>->>++++>++>++>++++>>>>>->>>>>+++>->++++>->->->+++>>>+>+>+++>+>++++>>+++>->>>>>->>>++++>++>++>+>+++>->++++>>->->+++>+>+++>+>++++>>>+++>->++++>>->->++>++++>++>++++>>++[-[->>+[>]++[<]<]>>+[>]<--[++>++++>]+[<]<<++]>>>[>]++++>++++[--[+>+>++++<<[-->>--<<[->-<[--->>+<<[+>+++<[+>>++<<]]]]]]>+++[>+++++++++++++++<-]>--.<<<] 4 | -------------------------------------------------------------------------------- /08/ex03/programs/random.b: -------------------------------------------------------------------------------- 1 | >>>++[ 2 | <++++++++[ 3 | <[<++>-]>>[>>]+>>+[ 4 | -[->>+<<<[<[<<]<+>]>[>[>>]]] 5 | <[>>[-]]>[>[-<<]>[<+<]]+<< 6 | ]<[>+<-]>>- 7 | ]<.[-]>> 8 | ] 9 | "Random" byte generator using the Rule 30 automaton. 10 | Doesn't terminate; you will have to kill it. 11 | To get x bytes you need 32x+4 cells. 12 | Turn off any newline translation! 13 | Daniel B Cristofani (cristofdathevanetdotcom) 14 | http://www.hevanet.com/cristofd/brainfuck/ -------------------------------------------------------------------------------- /08/ex03/programs/rot13.b: -------------------------------------------------------------------------------- 1 | , 2 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 3 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 4 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 5 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 6 | [>++++++++++++++<- 7 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 8 | [>>+++++[<----->-]<<- 9 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 10 | [>++++++++++++++<- 11 | [>+<-[>+<-[>+<-[>+<-[>+<- 12 | [>++++++++++++++<- 13 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 14 | [>>+++++[<----->-]<<- 15 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 16 | [>++++++++++++++<- 17 | [>+<-]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] 18 | ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]>.[-]<,] 19 | 20 | of course any function char f(char) can be made easily on the same principle 21 | 22 | [Daniel B Cristofani (cristofdathevanetdotcom) 23 | http://www.hevanet.com/cristofd/brainfuck/] 24 | -------------------------------------------------------------------------------- /08/ex03/programs/yapi.b: -------------------------------------------------------------------------------- 1 | > +++++ +++++ +++++ (15 digits) 2 | 3 | [<+>>>>>>>>++++++++++<<<<<<<-]>+++++[<+++++++++>-]+>>>>>>+[<<+++[>>[-<]<[>]<-]>> 4 | [>+>]<[<]>]>[[->>>>+<<<<]>>>+++>-]<[<<<<]<<<<<<<<+[->>>>>>>>>>>>[<+[->>>>+<<<<]> 5 | >>>>]<<<<[>>>>>[<<<<+>>>>-]<<<<<-[<<++++++++++>>-]>>>[<<[<+<<+>>>-]<[>+<-]<++<<+ 6 | >>>>>>-]<<[-]<<-<[->>+<-[>>>]>[[<+>-]>+>>]<<<<<]>[-]>+<<<-[>>+<<-]<]<<<<+>>>>>>> 7 | >[-]>[<<<+>>>-]<<++++++++++<[->>+<-[>>>]>[[<+>-]>+>>]<<<<<]>[-]>+>[<<+<+>>>-]<<< 8 | <+<+>>[-[-[-[-[-[-[-[-[-<->[-<+<->>]]]]]]]]]]<[+++++[<<<++++++++<++++++++>>>>-]< 9 | <<<+<->>>>[>+<<<+++++++++<->>>-]<<<<<[>>+<<-]+<[->-<]>[>>.<<<<[+.[-]]>>-]>[>>.<< 10 | -]>[-]>[-]>>>[>>[<<<<<<<<+>>>>>>>>-]<<-]]>>[-]<<<[-]<<<<<<<<]++++++++++. 11 | -------------------------------------------------------------------------------- /08/ex03v2/.gitignore: -------------------------------------------------------------------------------- 1 | mindopen -------------------------------------------------------------------------------- /08/ex03v2/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncolomer +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2019/12/29 18:01:14 by ncolomer #+# #+# # 9 | # Updated: 2019/12/30 15:33:45 by ncolomer ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | SRCS = main.cpp MindOpen.cpp Program.cpp 14 | OBJS = $(SRCS:.cpp=.o) 15 | 16 | CXX = clang++ 17 | RM = rm -f 18 | CXXFLAGS = -Wall -Wextra -Werror -I. 19 | 20 | NAME = mindopen 21 | 22 | all: $(NAME) 23 | 24 | $(NAME): $(OBJS) 25 | $(CXX) $(CXXFLAGS) -o $(NAME) $(OBJS) 26 | 27 | clean: 28 | $(RM) $(OBJS) 29 | 30 | fclean: clean 31 | $(RM) $(NAME) 32 | 33 | re: fclean $(NAME) 34 | 35 | .PHONY: all clean fclean re 36 | -------------------------------------------------------------------------------- /08/ex03v2/MindOpen.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* MindOpen.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 16:54:37 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/30 14:45:25 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef MINDOPEN_HPP 14 | # define MINDOPEN_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | # include 22 | # include "Program.hpp" 23 | 24 | class MindOpen 25 | { 26 | private: 27 | std::string moriginal; 28 | Program program; 29 | public: 30 | MindOpen(); 31 | MindOpen(MindOpen const &other); 32 | virtual ~MindOpen(); 33 | 34 | MindOpen &operator=(MindOpen const &other); 35 | 36 | bool loadFromString(std::string const &str); 37 | bool loadFromFile(std::string const &filename); 38 | 39 | void execute(void); 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /08/ex03v2/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 16:54:20 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/29 19:39:46 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "MindOpen.hpp" 15 | 16 | int main(int argc, char const *argv[]) 17 | { 18 | if (argc != 2) 19 | { 20 | std::cerr << "MindOpen: error: missing program name" << std::endl; 21 | } 22 | else 23 | { 24 | MindOpen mo; 25 | if (!mo.loadFromFile(argv[1])) 26 | std::cerr << "MindOpen: error: could not load program " << argv[1] << std::endl; 27 | else 28 | mo.execute(); 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /08/ex03v2/programs/ascii.b: -------------------------------------------------------------------------------- 1 | [Displays the ASCII character set, Jeffry Johnston 2001] 2 | .+[.+] 3 | @ 4 | -------------------------------------------------------------------------------- /08/ex03v2/programs/dbf2c.b: -------------------------------------------------------------------------------- 1 | +++[>+++++<-]>>+<[>>++++>++>+++++>+++++>+>>+<++[++<]>---] 2 | 3 | >++++.>>>.+++++.>------.<--.+++++++++.>+.+.<<<<---.[>]<<.<<<.-------.>++++. 4 | <+++++.+.>-----.>+.<++++.>>++.>-----. 5 | 6 | <<<-----.+++++.-------.<--.<<<.>>>.<<+.>------.-..--.+++.-----<++.<--[>+<-] 7 | >>>>>--.--.<++++.>>-.<<<.>>>--.>. 8 | 9 | <<<<-----.>----.++++++++.----<+.+++++++++>>--.+.++<<<<.[>]<.>> 10 | 11 | ,[>>+++[<+++++++>-]<[<[-[-<]]>>[>]<-]<[<+++++>-[<+++>-[<-->-[<+++>- 12 | [<++++[>[->>]<[>>]<<-]>[<+++>-[<--->-[<++++>-[<+++[>[-[-[-[->>]]]]<[>>]<<-] 13 | >[<+>-[<->-[<++>-[<[-]>-]]]]]]]]]]]]] 14 | 15 | <[ 16 | -[-[>+<-]>] 17 | <[<<<<.>+++.+.+++.-------.>---.++.<.>-.++<<<<.[>]>>>>>>>>>] 18 | <[[<]>++.--[>]>>>>>>>>] 19 | <[<<++..-->>>>>>] 20 | <[<<..>>>>>] 21 | <[<<..-.+>>>>] 22 | <[<<++..---.+>>>] 23 | <[<<<.>>.>>>>>] 24 | <[<<<<-----.+++++>.----.+++.+>---.<<<-.[>]>] 25 | <[<<<<.-----.>++++.<++.+++>----.>---.<<<.-[>]] 26 | <[<<<<<----.>>.<<.+++++.>>>+.++>.>>] 27 | <.> 28 | ]> 29 | ,] 30 | 31 | <<<<<.<+.>++++.<----.>>---.<<<-.>>>+.>.>.[<]>++.[>]<. 32 | >[Translates brainfuck to C. Assumes no-change-on-EOF or EOF->0. 33 | Generated C does no-change-on-EOF, and uses unistd.h read and write calls. 34 | Daniel B Cristofani (cristofdathevanetdotcom) 35 | http://www.hevanet.com/cristofd/brainfuck/] 36 | -------------------------------------------------------------------------------- /08/ex03v2/programs/helloword.b: -------------------------------------------------------------------------------- 1 | ++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>++.>+.+++++++..+++.<<++.>+++++++++++++++.>.+++.------.--------.<<+.<. -------------------------------------------------------------------------------- /08/ex03v2/programs/numwarp.b: -------------------------------------------------------------------------------- 1 | >>>>+>+++>+++>>>>>+++>>+[ 2 | -,[----------[---[+<++++[>-----<-]+>[<+>--------[<+>- 3 | [--->>+++++++++++++[<<[-<+>>]>[<]>-]<< 4 | [+>+++++[<-------->-]<[<+>-]]]]]]]] 5 | < 6 | [<<++[>>>>>>>>>>>+<<<<<<<<<<<-]<<+>+>+>>>+>+>>+>+<<<<<- 7 | [<<+>>>+>+>>>+<<<<<- 8 | [<<<<+>>->>>>->>+<<<<- 9 | [<<<<->+>>>>->>>->-<<<<<- 10 | [<<<->>>>+<- 11 | [<<<+>>>>->+>>+<<<<- 12 | [<<<<+>->+>>>+>>>>+<<<<<- 13 | [<<->>>->->>>-<<<<<- 14 | [<<<<->+>>>>+>+>>>+<<<<<- 15 | [<<<<+>>>>>>-<<- 16 | [<<+>>>->>>>-<<<<<- 17 | [>+>>>->+<<<<<- 18 | [>>+<<- 19 | [<<<->->>>->->>+<<<<- 20 | [<<<+>+>>>+>+<<- 21 | [>->-<<- 22 | [<<->>>+>+<<- 23 | [<<+>>>>>>->-<<<<<- 24 | [<<<<->>->>- 25 | [<<<<+>>>>>>>>+<<<<- 26 | [<<<<->>+>>>>>>>+<<<<<- 27 | [>->>>-<<<<-]]]]]]]]]]]]]]]]]]]]] 28 | >[[<<<<<<<<<<<+>>>>>>>>>>>-]>]+>>>>>>>+>>+<]> 29 | ]<<[-]<[-[>>>>+<<<<-]]<<<<<<++<+++<+++[>]<[ 30 | >>>>>++++++++[<++++++<++++>>-]>>>[-[<+<<<<.>>>>>-]]<<+<<-<<<<[ 31 | -[-[>+<-]>]>>>[.[>]]<<[<+>-]>>>[<<-[<++>-]>>-] 32 | <<[++[<+>--]>+<]>>>[<+>-]<<<<<<<< 33 | ]>>>>>++++++++++.>+[[-]<]<<< 34 | ] 35 | [Enter a number using ()-./0123456789abcdef and space, and hit return. 36 | Daniel B Cristofani (cristofdathevanetdotcom) 37 | http://www.hevanet.com/cristofd/brainfuck/] 38 | -------------------------------------------------------------------------------- /08/ex03v2/programs/quine505.b: -------------------------------------------------------------------------------- 1 | Written by Erik Bosman 2 | 3 | -->+++>+>+>+>+++++>++>++>->+++>++>+>>>>>>>>>>>>>>>>->++++>>>>->+++>+++>+++>+++>+++>+++>+>+>>>->->>++++>+>>>>->>++++>+>+>>->->++>++>++>++++>+>++>->++>++++>+>+>++>++>->->++>++>++++>+>+>>>>>->>->>++++>++>++>++++>>>>>->>>>>+++>->++++>->->->+++>>>+>+>+++>+>++++>>+++>->>>>>->>>++++>++>++>+>+++>->++++>>->->+++>+>+++>+>++++>>>+++>->++++>>->->++>++++>++>++++>>++[-[->>+[>]++[<]<]>>+[>]<--[++>++++>]+[<]<<++]>>>[>]++++>++++[--[+>+>++++<<[-->>--<<[->-<[--->>+<<[+>+++<[+>>++<<]]]]]]>+++[>+++++++++++++++<-]>--.<<<] 4 | -------------------------------------------------------------------------------- /08/ex03v2/programs/random.b: -------------------------------------------------------------------------------- 1 | >>>++[ 2 | <++++++++[ 3 | <[<++>-]>>[>>]+>>+[ 4 | -[->>+<<<[<[<<]<+>]>[>[>>]]] 5 | <[>>[-]]>[>[-<<]>[<+<]]+<< 6 | ]<[>+<-]>>- 7 | ]<.[-]>> 8 | ] 9 | "Random" byte generator using the Rule 30 automaton. 10 | Doesn't terminate; you will have to kill it. 11 | To get x bytes you need 32x+4 cells. 12 | Turn off any newline translation! 13 | Daniel B Cristofani (cristofdathevanetdotcom) 14 | http://www.hevanet.com/cristofd/brainfuck/ -------------------------------------------------------------------------------- /08/ex03v2/programs/rot13.b: -------------------------------------------------------------------------------- 1 | , 2 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 3 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 4 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 5 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 6 | [>++++++++++++++<- 7 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 8 | [>>+++++[<----->-]<<- 9 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 10 | [>++++++++++++++<- 11 | [>+<-[>+<-[>+<-[>+<-[>+<- 12 | [>++++++++++++++<- 13 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 14 | [>>+++++[<----->-]<<- 15 | [>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<- 16 | [>++++++++++++++<- 17 | [>+<-]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] 18 | ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]>.[-]<,] 19 | 20 | of course any function char f(char) can be made easily on the same principle 21 | 22 | [Daniel B Cristofani (cristofdathevanetdotcom) 23 | http://www.hevanet.com/cristofd/brainfuck/] 24 | -------------------------------------------------------------------------------- /08/ex03v2/programs/yapi.b: -------------------------------------------------------------------------------- 1 | > +++++ +++++ +++++ (15 digits) 2 | 3 | [<+>>>>>>>>++++++++++<<<<<<<-]>+++++[<+++++++++>-]+>>>>>>+[<<+++[>>[-<]<[>]<-]>> 4 | [>+>]<[<]>]>[[->>>>+<<<<]>>>+++>-]<[<<<<]<<<<<<<<+[->>>>>>>>>>>>[<+[->>>>+<<<<]> 5 | >>>>]<<<<[>>>>>[<<<<+>>>>-]<<<<<-[<<++++++++++>>-]>>>[<<[<+<<+>>>-]<[>+<-]<++<<+ 6 | >>>>>>-]<<[-]<<-<[->>+<-[>>>]>[[<+>-]>+>>]<<<<<]>[-]>+<<<-[>>+<<-]<]<<<<+>>>>>>> 7 | >[-]>[<<<+>>>-]<<++++++++++<[->>+<-[>>>]>[[<+>-]>+>>]<<<<<]>[-]>+>[<<+<+>>>-]<<< 8 | <+<+>>[-[-[-[-[-[-[-[-[-<->[-<+<->>]]]]]]]]]]<[+++++[<<<++++++++<++++++++>>>>-]< 9 | <<<+<->>>>[>+<<<+++++++++<->>>-]<<<<<[>>+<<-]+<[->-<]>[>>.<<<<[+.[-]]>>-]>[>>.<< 10 | -]>[-]>[-]>>>[>>[<<<<<<<<+>>>>>>>>-]<<-]]>>[-]<<<[-]<<<<<<<<]++++++++++. 11 | -------------------------------------------------------------------------------- /08/ex04/.gitignore: -------------------------------------------------------------------------------- 1 | postfix -------------------------------------------------------------------------------- /08/ex04/Token.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Token.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:44:06 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/30 17:57:16 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Token.hpp" 14 | 15 | Token::Token() 16 | { 17 | } 18 | 19 | Token::Token(Token const &other) 20 | { 21 | (void)other; 22 | } 23 | 24 | Token::~Token() 25 | { 26 | } 27 | 28 | Token &Token::operator=(Token const &other) 29 | { 30 | (void)other; 31 | return (*this); 32 | } 33 | -------------------------------------------------------------------------------- /08/ex04/Token.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Token.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:43:59 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/31 20:05:32 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef TOKEN_HPP 14 | # define TOKEN_HPP 15 | 16 | # include 17 | 18 | class Token 19 | { 20 | private: 21 | public: 22 | Token(); 23 | Token(Token const &other); 24 | virtual ~Token(); 25 | 26 | Token &operator=(Token const &other); 27 | 28 | enum TokenType { 29 | TokenNum, 30 | TokenOp, 31 | TokenParOpen, 32 | TokenParClose 33 | }; 34 | 35 | virtual int getType(void) const = 0; 36 | virtual void display(void) const = 0; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /08/ex04/Tokens/Num.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Num.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:45:41 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/31 20:05:38 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Num.hpp" 14 | 15 | Num::Num(int value): 16 | value(value) 17 | { 18 | } 19 | 20 | Num::Num(Num const &other): 21 | value(other.value) 22 | { 23 | } 24 | 25 | Num::~Num() 26 | { 27 | } 28 | 29 | Num &Num::operator=(Num const &other) 30 | { 31 | this->value = other.value; 32 | return (*this); 33 | } 34 | 35 | int Num::getType(void) const 36 | { 37 | return (TokenNum); 38 | } 39 | 40 | int Num::getValue(void) const 41 | { 42 | return (this->value); 43 | } 44 | 45 | void Num::display(void) const 46 | { 47 | std::cout << "Num(" << this->value << ")"; 48 | } 49 | -------------------------------------------------------------------------------- /08/ex04/Tokens/Num.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Num.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:45:44 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/30 17:41:47 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef NUM_HPP 14 | # define NUM_HPP 15 | 16 | # include "Token.hpp" 17 | 18 | class Num: public Token 19 | { 20 | private: 21 | Num(); 22 | 23 | int value; 24 | public: 25 | Num(int number); 26 | Num(Num const &other); 27 | virtual ~Num(); 28 | 29 | Num &operator=(Num const &other); 30 | 31 | int getValue(void) const; 32 | int getType(void) const; 33 | void display(void) const; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /08/ex04/Tokens/Op.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Op.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:46:07 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/31 20:05:45 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Op.hpp" 14 | 15 | Op::Op(char op): 16 | op(op) 17 | { 18 | } 19 | 20 | Op::Op(Op const &other): 21 | op(other.op) 22 | { 23 | } 24 | 25 | Op::~Op() 26 | { 27 | } 28 | 29 | Op &Op::operator=(Op const &other) 30 | { 31 | this->op = other.op; 32 | return (*this); 33 | } 34 | 35 | int Op::getType(void) const 36 | { 37 | return (TokenOp); 38 | } 39 | 40 | char Op::getOp(void) const 41 | { 42 | return (this->op); 43 | } 44 | 45 | void Op::display(void) const 46 | { 47 | std::cout << "Op(" << this->op << ")"; 48 | } 49 | -------------------------------------------------------------------------------- /08/ex04/Tokens/Op.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Op.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:46:10 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/30 17:46:23 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef OP_HPP 14 | # define OP_HPP 15 | 16 | # include "Token.hpp" 17 | 18 | class Op: public Token 19 | { 20 | private: 21 | Op(); 22 | 23 | char op; 24 | public: 25 | Op(char op); 26 | Op(Op const &other); 27 | virtual ~Op(); 28 | 29 | Op &operator=(Op const &other); 30 | 31 | int getType(void) const; 32 | char getOp(void) const; 33 | void display(void) const; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /08/ex04/Tokens/ParClose.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ParClose.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:46:19 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/31 20:08:08 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ParClose.hpp" 14 | 15 | ParClose::ParClose() 16 | { 17 | } 18 | 19 | ParClose::ParClose(ParClose const &other) 20 | { 21 | (void)other; 22 | } 23 | 24 | ParClose::~ParClose() 25 | { 26 | } 27 | 28 | ParClose &ParClose::operator=(ParClose const &other) 29 | { 30 | (void)other; 31 | return (*this); 32 | } 33 | 34 | int ParClose::getType(void) const 35 | { 36 | return (TokenParClose); 37 | } 38 | 39 | void ParClose::display(void) const 40 | { 41 | std::cout << "ParClose"; 42 | } 43 | -------------------------------------------------------------------------------- /08/ex04/Tokens/ParClose.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ParClose.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:46:21 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/30 17:41:42 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PARCLOSE_HPP 14 | # define PARCLOSE_HPP 15 | 16 | # include "Token.hpp" 17 | 18 | class ParClose: public Token 19 | { 20 | private: 21 | public: 22 | ParClose(); 23 | ParClose(ParClose const &other); 24 | virtual ~ParClose(); 25 | 26 | ParClose &operator=(ParClose const &other); 27 | 28 | int getType(void) const; 29 | void display(void) const; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /08/ex04/Tokens/ParOpen.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ParOpen.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:46:29 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/31 20:06:57 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ParOpen.hpp" 14 | 15 | ParOpen::ParOpen() 16 | { 17 | } 18 | 19 | ParOpen::ParOpen(ParOpen const &other) 20 | { 21 | (void)other; 22 | } 23 | 24 | ParOpen::~ParOpen() 25 | { 26 | } 27 | 28 | ParOpen &ParOpen::operator=(ParOpen const &other) 29 | { 30 | (void)other; 31 | return (*this); 32 | } 33 | 34 | int ParOpen::getType(void) const 35 | { 36 | return (TokenParOpen); 37 | } 38 | 39 | void ParOpen::display(void) const 40 | { 41 | std::cout << "ParOpen"; 42 | } 43 | -------------------------------------------------------------------------------- /08/ex04/Tokens/ParOpen.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ParOpen.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:46:30 by ncolomer #+# #+# */ 9 | /* Updated: 2019/12/31 20:06:55 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PAROPEN_HPP 14 | # define PAROPEN_HPP 15 | 16 | # include "Token.hpp" 17 | 18 | class ParOpen: public Token 19 | { 20 | private: 21 | public: 22 | ParOpen(); 23 | ParOpen(ParOpen const &other); 24 | virtual ~ParOpen(); 25 | 26 | ParOpen &operator=(ParOpen const &other); 27 | 28 | int getType(void) const; 29 | void display(void) const; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /08/ex04/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncolomer +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/12/29 19:35:59 by ncolomer #+# #+# */ 9 | /* Updated: 2020/01/01 19:32:23 by ncolomer ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "Postfix.hpp" 15 | 16 | int main(int argc, char const *argv[]) 17 | { 18 | if (argc != 2) 19 | std::cerr << "Postfix: error: missing expression" << std::endl; 20 | else 21 | { 22 | try 23 | { 24 | Postfix poland(argv[1]); 25 | poland.tokenize(); 26 | poland.displayTokens(); 27 | poland.polish(); 28 | poland.displayPostfix(); 29 | poland.calculate(); 30 | } 31 | catch(const std::exception& e) 32 | { 33 | std::cerr << e.what() << std::endl; 34 | } 35 | } 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CPP Module 2 | 3 | ## Ressources 4 | 5 | * Excellent course from Guillaume Revy (In French). 6 | [Introduction](https://perso.univ-perp.fr/guillaume.revy/teaching/201516/ProgrammationOrienteeObjet/C1-ProgrammationOrienteeObjet.pdf), [Constructors, Destructors and memory](https://perso.univ-perp.fr/guillaume.revy/teaching/201516/ProgrammationOrienteeObjet/C2-ProgrammationOrienteeObjet.pdf), [friend and inheritance](https://perso.univ-perp.fr/guillaume.revy/teaching/201516/ProgrammationOrienteeObjet/C3-ProgrammationOrienteeObjet.pdf), [overload and polymorphism](https://perso.univ-perp.fr/guillaume.revy/teaching/201516/ProgrammationOrienteeObjet/C4-ProgrammationOrienteeObjet.pdf), [Multiple inheritance](https://perso.univ-perp.fr/guillaume.revy/teaching/201516/ProgrammationOrienteeObjet/C5-ProgrammationOrienteeObjet.pdf), [STL, Containers and Iterators](https://perso.univ-perp.fr/guillaume.revy/teaching/201516/ProgrammationOrienteeObjet/C6-ProgrammationOrienteeObjet.pdf), [Abstract types and templates](https://perso.univ-perp.fr/guillaume.revy/teaching/201516/ProgrammationOrienteeObjet/C7-ProgrammationOrienteeObjet.pdf) and [Exceptions](https://perso.univ-perp.fr/guillaume.revy/teaching/201516/ProgrammationOrienteeObjet/C8-ProgrammationOrienteeObjet.pdf). 7 | --------------------------------------------------------------------------------