From 2ba1ab346d7a2650535cb0e63a4447057268ca18 Mon Sep 17 00:00:00 2001 From: Xamora Date: Wed, 4 Dec 2024 17:29:31 +0100 Subject: [PATCH] all CPP in one repo --- CPP00/ex00/Makefile | 129 ++++++++++++++ CPP00/ex00/megaphone.cpp | 31 ++++ CPP00/ex01/Contact.cpp | 50 ++++++ CPP00/ex01/Contact.hpp | 28 +++ CPP00/ex01/Makefile | 129 ++++++++++++++ CPP00/ex01/PhoneBook.cpp | 107 ++++++++++++ CPP00/ex01/PhoneBook.hpp | 32 ++++ CPP00/ex01/main.cpp | 40 +++++ CPP01/ex00/Makefile | 129 ++++++++++++++ CPP01/ex00/Zombie.cpp | 25 +++ CPP01/ex00/Zombie.hpp | 33 ++++ CPP01/ex00/main.cpp | 30 ++++ CPP01/ex00/newZombie.cpp | 17 ++ CPP01/ex00/randomChump.cpp | 17 ++ CPP01/ex01/Makefile | 129 ++++++++++++++ CPP01/ex01/Zombie.cpp | 35 ++++ CPP01/ex01/Zombie.hpp | 36 ++++ CPP01/ex01/main.cpp | 25 +++ CPP01/ex01/zombieHorde.cpp | 21 +++ CPP01/ex02/Makefile | 129 ++++++++++++++ CPP01/ex02/main.cpp | 30 ++++ CPP01/ex03/HumanA.cpp | 21 +++ CPP01/ex03/HumanA.hpp | 29 ++++ CPP01/ex03/HumanB.cpp | 32 ++++ CPP01/ex03/HumanB.hpp | 31 ++++ CPP01/ex03/Makefile | 129 ++++++++++++++ CPP01/ex03/Weapon.cpp | 29 ++++ CPP01/ex03/Weapon.hpp | 30 ++++ CPP01/ex03/main.cpp | 45 +++++ CPP01/ex04/Makefile | 129 ++++++++++++++ CPP01/ex04/SedForLooser.cpp | 63 +++++++ CPP01/ex04/SedForLooser.hpp | 30 ++++ CPP01/ex04/main.cpp | 25 +++ CPP01/ex05/Harl.cpp | 41 +++++ CPP01/ex05/Harl.hpp | 30 ++++ CPP01/ex05/Makefile | 129 ++++++++++++++ CPP01/ex05/main.cpp | 22 +++ CPP01/ex06/Harl.cpp | 61 +++++++ CPP01/ex06/Harl.hpp | 30 ++++ CPP01/ex06/Makefile | 129 ++++++++++++++ CPP01/ex06/main.cpp | 22 +++ CPP02/ex00/Fixed.cpp | 33 ++++ CPP02/ex00/Fixed.hpp | 21 +++ CPP02/ex00/Makefile | 129 ++++++++++++++ CPP02/ex00/main.cpp | 36 ++++ CPP02/ex01/Fixed.cpp | 54 ++++++ CPP02/ex01/Fixed.hpp | 29 ++++ CPP02/ex01/Makefile | 129 ++++++++++++++ CPP02/ex01/main.cpp | 25 +++ CPP02/ex02/Fixed.cpp | 130 ++++++++++++++ CPP02/ex02/Fixed.hpp | 51 ++++++ CPP02/ex02/Makefile | 129 ++++++++++++++ CPP02/ex02/main.cpp | 87 ++++++++++ CPP03/ex00/ClapTrap.cpp | 66 ++++++++ CPP03/ex00/ClapTrap.hpp | 25 +++ CPP03/ex00/Makefile | 129 ++++++++++++++ CPP03/ex00/main.cpp | 38 +++++ CPP03/ex01/ClapTrap.cpp | 66 ++++++++ CPP03/ex01/ClapTrap.hpp | 25 +++ CPP03/ex01/Makefile | 129 ++++++++++++++ CPP03/ex01/ScavTrap.cpp | 52 ++++++ CPP03/ex01/ScavTrap.hpp | 19 +++ CPP03/ex01/main.cpp | 52 ++++++ CPP03/ex02/ClapTrap.cpp | 66 ++++++++ CPP03/ex02/ClapTrap.hpp | 25 +++ CPP03/ex02/FragTrap.cpp | 52 ++++++ CPP03/ex02/FragTrap.hpp | 19 +++ CPP03/ex02/Makefile | 129 ++++++++++++++ CPP03/ex02/ScavTrap.cpp | 72 ++++++++ CPP03/ex02/ScavTrap.hpp | 21 +++ CPP03/ex02/main.cpp | 54 ++++++ CPP04/ex00/Animal.cpp | 29 ++++ CPP04/ex00/Animal.hpp | 20 +++ CPP04/ex00/Cat.cpp | 25 +++ CPP04/ex00/Cat.hpp | 16 ++ CPP04/ex00/Dog.cpp | 25 +++ CPP04/ex00/Dog.hpp | 16 ++ CPP04/ex00/Makefile | 129 ++++++++++++++ CPP04/ex00/WrongAnimal.cpp | 29 ++++ CPP04/ex00/WrongAnimal.hpp | 20 +++ CPP04/ex00/WrongCat.cpp | 25 +++ CPP04/ex00/WrongCat.hpp | 16 ++ CPP04/ex00/main.cpp | 59 +++++++ CPP04/ex01/Animal.cpp | 29 ++++ CPP04/ex01/Animal.hpp | 20 +++ CPP04/ex01/Brain.cpp | 21 +++ CPP04/ex01/Brain.hpp | 18 ++ CPP04/ex01/Cat.cpp | 29 ++++ CPP04/ex01/Cat.hpp | 20 +++ CPP04/ex01/Dog.cpp | 29 ++++ CPP04/ex01/Dog.hpp | 20 +++ CPP04/ex01/Makefile | 129 ++++++++++++++ CPP04/ex01/WrongAnimal.cpp | 29 ++++ CPP04/ex01/WrongAnimal.hpp | 20 +++ CPP04/ex01/WrongCat.cpp | 25 +++ CPP04/ex01/WrongCat.hpp | 16 ++ CPP04/ex01/main.cpp | 33 ++++ CPP04/ex02/Animal.cpp | 25 +++ CPP04/ex02/Animal.hpp | 20 +++ CPP04/ex02/Brain.cpp | 21 +++ CPP04/ex02/Brain.hpp | 18 ++ CPP04/ex02/Cat.cpp | 29 ++++ CPP04/ex02/Cat.hpp | 20 +++ CPP04/ex02/Dog.cpp | 29 ++++ CPP04/ex02/Dog.hpp | 20 +++ CPP04/ex02/Makefile | 129 ++++++++++++++ CPP04/ex02/WrongAnimal.cpp | 29 ++++ CPP04/ex02/WrongAnimal.hpp | 20 +++ CPP04/ex02/WrongCat.cpp | 25 +++ CPP04/ex02/WrongCat.hpp | 16 ++ CPP04/ex02/main.cpp | 26 +++ CPP05/ex00/Bureaucrat.cpp | 61 +++++++ CPP05/ex00/Bureaucrat.hpp | 39 +++++ CPP05/ex00/Makefile | 129 ++++++++++++++ CPP05/ex00/main.cpp | 52 ++++++ CPP05/ex01/Bureaucrat.cpp | 74 ++++++++ CPP05/ex01/Bureaucrat.hpp | 41 +++++ CPP05/ex01/Form.cpp | 61 +++++++ CPP05/ex01/Form.hpp | 39 +++++ CPP05/ex01/Makefile | 129 ++++++++++++++ CPP05/ex01/main.cpp | 39 +++++ CPP05/ex02/AForm.cpp | 74 ++++++++ CPP05/ex02/AForm.hpp | 43 +++++ CPP05/ex02/Bureaucrat.cpp | 84 +++++++++ CPP05/ex02/Bureaucrat.hpp | 42 +++++ CPP05/ex02/Makefile | 129 ++++++++++++++ CPP05/ex02/PresidentialPardonForm.cpp | 9 + CPP05/ex02/PresidentialPardonForm.hpp | 11 ++ CPP05/ex02/RobotomyRequestForm.cpp | 13 ++ CPP05/ex02/RobotomyRequestForm.hpp | 11 ++ CPP05/ex02/ShrubberyCreationForm.cpp | 22 +++ CPP05/ex02/ShrubberyCreationForm.hpp | 11 ++ CPP05/ex02/main.cpp | 57 +++++++ CPP05/ex03/AForm.cpp | 73 ++++++++ CPP05/ex03/AForm.hpp | 43 +++++ CPP05/ex03/Bureaucrat.cpp | 84 +++++++++ CPP05/ex03/Bureaucrat.hpp | 42 +++++ CPP05/ex03/Intern.cpp | 39 +++++ CPP05/ex03/Intern.hpp | 15 ++ CPP05/ex03/Makefile | 129 ++++++++++++++ CPP05/ex03/PresidentialPardonForm.cpp | 9 + CPP05/ex03/PresidentialPardonForm.hpp | 11 ++ CPP05/ex03/RobotomyRequestForm.cpp | 13 ++ CPP05/ex03/RobotomyRequestForm.hpp | 11 ++ CPP05/ex03/ShrubberyCreationForm.cpp | 22 +++ CPP05/ex03/ShrubberyCreationForm.hpp | 11 ++ CPP05/ex03/main.cpp | 44 +++++ CPP06/ex00/Makefile | 129 ++++++++++++++ CPP06/ex00/ScalarConverter.cpp | 150 ++++++++++++++++ CPP06/ex00/ScalarConverter.hpp | 16 ++ CPP06/ex00/main.cpp | 8 + CPP06/ex01/Makefile | 129 ++++++++++++++ CPP06/ex01/Serializer.cpp | 23 +++ CPP06/ex01/Serializer.hpp | 21 +++ CPP06/ex01/main.cpp | 40 +++++ CPP06/ex02/Base.cpp | 47 ++++++ CPP06/ex02/Base.hpp | 28 +++ CPP06/ex02/Makefile | 129 ++++++++++++++ CPP06/ex02/main.cpp | 27 +++ CPP07/ex00/Makefile | 129 ++++++++++++++ CPP07/ex00/main.cpp | 51 ++++++ CPP07/ex00/whatever.hpp | 20 +++ CPP07/ex01/Makefile | 129 ++++++++++++++ CPP07/ex01/iter.hpp | 19 +++ CPP07/ex01/main.cpp | 55 ++++++ CPP07/ex02/Array.hpp | 39 +++++ CPP07/ex02/Makefile | 129 ++++++++++++++ CPP07/ex02/main.cpp | 54 ++++++ CPP08/ex00/Makefile | 129 ++++++++++++++ CPP08/ex00/easyfind.hpp | 15 ++ CPP08/ex00/main.cpp | 32 ++++ CPP08/ex01/Makefile | 129 ++++++++++++++ CPP08/ex01/Span.cpp | 51 ++++++ CPP08/ex01/Span.hpp | 25 +++ CPP08/ex01/main.cpp | 62 +++++++ CPP08/ex02/Makefile | 129 ++++++++++++++ CPP08/ex02/MutantStack.hpp | 23 +++ CPP08/ex02/main.cpp | 53 ++++++ CPP09/ex00/BitcoinExchange.cpp | 235 ++++++++++++++++++++++++++ CPP09/ex00/BitcoinExchange.hpp | 22 +++ CPP09/ex00/Makefile | 129 ++++++++++++++ CPP09/ex00/main.cpp | 18 ++ CPP09/ex01/Makefile | 129 ++++++++++++++ CPP09/ex01/main.cpp | 100 +++++++++++ CPP09/ex02/Makefile | 129 ++++++++++++++ CPP09/ex02/main.cpp | 124 ++++++++++++++ 186 files changed, 10047 insertions(+) create mode 100644 CPP00/ex00/Makefile create mode 100644 CPP00/ex00/megaphone.cpp create mode 100644 CPP00/ex01/Contact.cpp create mode 100644 CPP00/ex01/Contact.hpp create mode 100644 CPP00/ex01/Makefile create mode 100644 CPP00/ex01/PhoneBook.cpp create mode 100644 CPP00/ex01/PhoneBook.hpp create mode 100644 CPP00/ex01/main.cpp create mode 100644 CPP01/ex00/Makefile create mode 100644 CPP01/ex00/Zombie.cpp create mode 100644 CPP01/ex00/Zombie.hpp create mode 100644 CPP01/ex00/main.cpp create mode 100644 CPP01/ex00/newZombie.cpp create mode 100644 CPP01/ex00/randomChump.cpp create mode 100644 CPP01/ex01/Makefile create mode 100644 CPP01/ex01/Zombie.cpp create mode 100644 CPP01/ex01/Zombie.hpp create mode 100644 CPP01/ex01/main.cpp create mode 100644 CPP01/ex01/zombieHorde.cpp create mode 100644 CPP01/ex02/Makefile create mode 100644 CPP01/ex02/main.cpp create mode 100644 CPP01/ex03/HumanA.cpp create mode 100644 CPP01/ex03/HumanA.hpp create mode 100644 CPP01/ex03/HumanB.cpp create mode 100644 CPP01/ex03/HumanB.hpp create mode 100644 CPP01/ex03/Makefile create mode 100644 CPP01/ex03/Weapon.cpp create mode 100644 CPP01/ex03/Weapon.hpp create mode 100644 CPP01/ex03/main.cpp create mode 100644 CPP01/ex04/Makefile create mode 100644 CPP01/ex04/SedForLooser.cpp create mode 100644 CPP01/ex04/SedForLooser.hpp create mode 100644 CPP01/ex04/main.cpp create mode 100644 CPP01/ex05/Harl.cpp create mode 100644 CPP01/ex05/Harl.hpp create mode 100644 CPP01/ex05/Makefile create mode 100644 CPP01/ex05/main.cpp create mode 100644 CPP01/ex06/Harl.cpp create mode 100644 CPP01/ex06/Harl.hpp create mode 100644 CPP01/ex06/Makefile create mode 100644 CPP01/ex06/main.cpp create mode 100644 CPP02/ex00/Fixed.cpp create mode 100644 CPP02/ex00/Fixed.hpp create mode 100644 CPP02/ex00/Makefile create mode 100644 CPP02/ex00/main.cpp create mode 100644 CPP02/ex01/Fixed.cpp create mode 100644 CPP02/ex01/Fixed.hpp create mode 100644 CPP02/ex01/Makefile create mode 100644 CPP02/ex01/main.cpp create mode 100644 CPP02/ex02/Fixed.cpp create mode 100644 CPP02/ex02/Fixed.hpp create mode 100644 CPP02/ex02/Makefile create mode 100644 CPP02/ex02/main.cpp create mode 100644 CPP03/ex00/ClapTrap.cpp create mode 100644 CPP03/ex00/ClapTrap.hpp create mode 100644 CPP03/ex00/Makefile create mode 100644 CPP03/ex00/main.cpp create mode 100644 CPP03/ex01/ClapTrap.cpp create mode 100644 CPP03/ex01/ClapTrap.hpp create mode 100644 CPP03/ex01/Makefile create mode 100644 CPP03/ex01/ScavTrap.cpp create mode 100644 CPP03/ex01/ScavTrap.hpp create mode 100644 CPP03/ex01/main.cpp create mode 100644 CPP03/ex02/ClapTrap.cpp create mode 100644 CPP03/ex02/ClapTrap.hpp create mode 100644 CPP03/ex02/FragTrap.cpp create mode 100644 CPP03/ex02/FragTrap.hpp create mode 100644 CPP03/ex02/Makefile create mode 100644 CPP03/ex02/ScavTrap.cpp create mode 100644 CPP03/ex02/ScavTrap.hpp create mode 100644 CPP03/ex02/main.cpp create mode 100644 CPP04/ex00/Animal.cpp create mode 100644 CPP04/ex00/Animal.hpp create mode 100644 CPP04/ex00/Cat.cpp create mode 100644 CPP04/ex00/Cat.hpp create mode 100644 CPP04/ex00/Dog.cpp create mode 100644 CPP04/ex00/Dog.hpp create mode 100644 CPP04/ex00/Makefile create mode 100644 CPP04/ex00/WrongAnimal.cpp create mode 100644 CPP04/ex00/WrongAnimal.hpp create mode 100644 CPP04/ex00/WrongCat.cpp create mode 100644 CPP04/ex00/WrongCat.hpp create mode 100644 CPP04/ex00/main.cpp create mode 100644 CPP04/ex01/Animal.cpp create mode 100644 CPP04/ex01/Animal.hpp create mode 100644 CPP04/ex01/Brain.cpp create mode 100644 CPP04/ex01/Brain.hpp create mode 100644 CPP04/ex01/Cat.cpp create mode 100644 CPP04/ex01/Cat.hpp create mode 100644 CPP04/ex01/Dog.cpp create mode 100644 CPP04/ex01/Dog.hpp create mode 100644 CPP04/ex01/Makefile create mode 100644 CPP04/ex01/WrongAnimal.cpp create mode 100644 CPP04/ex01/WrongAnimal.hpp create mode 100644 CPP04/ex01/WrongCat.cpp create mode 100644 CPP04/ex01/WrongCat.hpp create mode 100644 CPP04/ex01/main.cpp create mode 100644 CPP04/ex02/Animal.cpp create mode 100644 CPP04/ex02/Animal.hpp create mode 100644 CPP04/ex02/Brain.cpp create mode 100644 CPP04/ex02/Brain.hpp create mode 100644 CPP04/ex02/Cat.cpp create mode 100644 CPP04/ex02/Cat.hpp create mode 100644 CPP04/ex02/Dog.cpp create mode 100644 CPP04/ex02/Dog.hpp create mode 100644 CPP04/ex02/Makefile create mode 100644 CPP04/ex02/WrongAnimal.cpp create mode 100644 CPP04/ex02/WrongAnimal.hpp create mode 100644 CPP04/ex02/WrongCat.cpp create mode 100644 CPP04/ex02/WrongCat.hpp create mode 100644 CPP04/ex02/main.cpp create mode 100644 CPP05/ex00/Bureaucrat.cpp create mode 100644 CPP05/ex00/Bureaucrat.hpp create mode 100644 CPP05/ex00/Makefile create mode 100644 CPP05/ex00/main.cpp create mode 100644 CPP05/ex01/Bureaucrat.cpp create mode 100644 CPP05/ex01/Bureaucrat.hpp create mode 100644 CPP05/ex01/Form.cpp create mode 100644 CPP05/ex01/Form.hpp create mode 100644 CPP05/ex01/Makefile create mode 100644 CPP05/ex01/main.cpp create mode 100644 CPP05/ex02/AForm.cpp create mode 100644 CPP05/ex02/AForm.hpp create mode 100644 CPP05/ex02/Bureaucrat.cpp create mode 100644 CPP05/ex02/Bureaucrat.hpp create mode 100644 CPP05/ex02/Makefile create mode 100644 CPP05/ex02/PresidentialPardonForm.cpp create mode 100644 CPP05/ex02/PresidentialPardonForm.hpp create mode 100644 CPP05/ex02/RobotomyRequestForm.cpp create mode 100644 CPP05/ex02/RobotomyRequestForm.hpp create mode 100644 CPP05/ex02/ShrubberyCreationForm.cpp create mode 100644 CPP05/ex02/ShrubberyCreationForm.hpp create mode 100644 CPP05/ex02/main.cpp create mode 100644 CPP05/ex03/AForm.cpp create mode 100644 CPP05/ex03/AForm.hpp create mode 100644 CPP05/ex03/Bureaucrat.cpp create mode 100644 CPP05/ex03/Bureaucrat.hpp create mode 100644 CPP05/ex03/Intern.cpp create mode 100644 CPP05/ex03/Intern.hpp create mode 100644 CPP05/ex03/Makefile create mode 100644 CPP05/ex03/PresidentialPardonForm.cpp create mode 100644 CPP05/ex03/PresidentialPardonForm.hpp create mode 100644 CPP05/ex03/RobotomyRequestForm.cpp create mode 100644 CPP05/ex03/RobotomyRequestForm.hpp create mode 100644 CPP05/ex03/ShrubberyCreationForm.cpp create mode 100644 CPP05/ex03/ShrubberyCreationForm.hpp create mode 100644 CPP05/ex03/main.cpp create mode 100644 CPP06/ex00/Makefile create mode 100644 CPP06/ex00/ScalarConverter.cpp create mode 100644 CPP06/ex00/ScalarConverter.hpp create mode 100644 CPP06/ex00/main.cpp create mode 100644 CPP06/ex01/Makefile create mode 100644 CPP06/ex01/Serializer.cpp create mode 100644 CPP06/ex01/Serializer.hpp create mode 100644 CPP06/ex01/main.cpp create mode 100644 CPP06/ex02/Base.cpp create mode 100644 CPP06/ex02/Base.hpp create mode 100644 CPP06/ex02/Makefile create mode 100644 CPP06/ex02/main.cpp create mode 100644 CPP07/ex00/Makefile create mode 100644 CPP07/ex00/main.cpp create mode 100644 CPP07/ex00/whatever.hpp create mode 100644 CPP07/ex01/Makefile create mode 100644 CPP07/ex01/iter.hpp create mode 100644 CPP07/ex01/main.cpp create mode 100644 CPP07/ex02/Array.hpp create mode 100644 CPP07/ex02/Makefile create mode 100644 CPP07/ex02/main.cpp create mode 100644 CPP08/ex00/Makefile create mode 100644 CPP08/ex00/easyfind.hpp create mode 100644 CPP08/ex00/main.cpp create mode 100644 CPP08/ex01/Makefile create mode 100644 CPP08/ex01/Span.cpp create mode 100644 CPP08/ex01/Span.hpp create mode 100644 CPP08/ex01/main.cpp create mode 100644 CPP08/ex02/Makefile create mode 100644 CPP08/ex02/MutantStack.hpp create mode 100644 CPP08/ex02/main.cpp create mode 100644 CPP09/ex00/BitcoinExchange.cpp create mode 100644 CPP09/ex00/BitcoinExchange.hpp create mode 100644 CPP09/ex00/Makefile create mode 100644 CPP09/ex00/main.cpp create mode 100644 CPP09/ex01/Makefile create mode 100644 CPP09/ex01/main.cpp create mode 100644 CPP09/ex02/Makefile create mode 100644 CPP09/ex02/main.cpp diff --git a/CPP00/ex00/Makefile b/CPP00/ex00/Makefile new file mode 100644 index 0000000..cdfb084 --- /dev/null +++ b/CPP00/ex00/Makefile @@ -0,0 +1,129 @@ +SRCS = megaphone.cpp +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror +NAME = Megaphone + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP00/ex00/megaphone.cpp b/CPP00/ex00/megaphone.cpp new file mode 100644 index 0000000..4dbb3e8 --- /dev/null +++ b/CPP00/ex00/megaphone.cpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Megaphone.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/08 17:08:17 by erey-bet #+# #+# */ +/* Updated: 2023/04/19 15:19:19 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +int main(int argc, char **argv) { + if (argc == 1) + std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *" << std::endl; + else { + argc--; + argv++; + for (int i = 0; i < argc; i++) { + for (int y = 0; y < (int)strlen(argv[i]); y++) { + argv[i][y] = toupper(argv[i][y]); + } + std::cout << argv[i] << std::flush; + } + std::cout << "\n" << std::flush; + } +} diff --git a/CPP00/ex01/Contact.cpp b/CPP00/ex01/Contact.cpp new file mode 100644 index 0000000..4dba7ad --- /dev/null +++ b/CPP00/ex01/Contact.cpp @@ -0,0 +1,50 @@ +#include "Contact.hpp" + +Contact::Contact(void) { + this->init = false; +} + +Contact::Contact(std::string fname, std::string lname, std::string nname, std::string phnbr, std::string drksct) { + this->init = true; + this->fname = fname; + this->lname = lname; + this->nname = nname; + this->phnbr = phnbr; + this->drksct = drksct; +} + +Contact& Contact::operator=(const Contact& other) { + if (this != &other) { + this->init = true; + this->fname = other.fname; + this->lname = other.lname; + this->nname = other.nname; + this->phnbr = other.phnbr; + this->drksct = other.drksct; + } + return (*this); +} + +std::string Contact::getFname(void) { + return (fname); +} + +std::string Contact::getLname(void) { + return (lname); +} + +std::string Contact::getNname(void) { + return (nname); +} + +std::string Contact::getPhnbr(void) { + return (phnbr); +} + +std::string Contact::getDrksct(void) { + return (drksct); +} + +bool Contact::getInit(void) { + return (init); +} diff --git a/CPP00/ex01/Contact.hpp b/CPP00/ex01/Contact.hpp new file mode 100644 index 0000000..9f3d654 --- /dev/null +++ b/CPP00/ex01/Contact.hpp @@ -0,0 +1,28 @@ +#ifndef CONTACT_HPP +# define CONTACT_HPP + +# include + +class Contact { + public: + Contact(); + Contact(std::string fname, std::string lname, std::string nname, std::string phnbr, std::string drksct); + Contact& operator=(const Contact& other); + + std::string getFname(void); + std::string getLname(void); + std::string getNname(void); + std::string getPhnbr(void); + std::string getDrksct(void); + bool getInit(void); + + private: + std::string fname; + std::string lname; + std::string nname; + std::string phnbr; + std::string drksct; + bool init; +}; + +#endif diff --git a/CPP00/ex01/Makefile b/CPP00/ex01/Makefile new file mode 100644 index 0000000..e6aebf4 --- /dev/null +++ b/CPP00/ex01/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = PhoneBook + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP00/ex01/PhoneBook.cpp b/CPP00/ex01/PhoneBook.cpp new file mode 100644 index 0000000..20047fe --- /dev/null +++ b/CPP00/ex01/PhoneBook.cpp @@ -0,0 +1,107 @@ +#include "PhoneBook.hpp" +#include "Contact.hpp" + +# include +# include +# include +# include + +PhoneBook::PhoneBook(void) { + size = 0; + index = 0; + std::cout << "New PhoneBook" << std::endl; +} + +std::string write_read(std::string text) +{ + std::string input; + while (input.size() == 0) + { + std::cout << text; + if (!std::getline(std::cin, input)) + exit(0); + } + return (input); +} + +void PhoneBook::add(void) { + std::string fname; + std::string lname; + std::string nname; + std::string phnbr; + std::string drksct; + + fname = write_read("firstname:"); + lname = write_read("lastname:"); + nname = write_read("nickname:"); + phnbr = write_read("phone number:"); + drksct = write_read("darkest secret:"); + + Contact contact; + contact = Contact(fname, lname, nname, phnbr, drksct); + contact_list[index % 8] = contact; + index++; + if (size < 8) + size++; + std::cout << "The contact has been added." << std::endl; +} + +bool isDigital(std::string str) { + for (unsigned long i = 0; i < str.size(); i++) { + if (!isdigit(str[i])) { + return false; + } + } + return true; +} + +void PhoneBook::search(void) { + if (size == 0) + { + std::cout << "No contact" << std::endl; + return ; + } + for (int i = 0; i < size; i++) { + std::string info[3]; + std::string list_info[3] = {contact_list[i].getFname(), contact_list[i].getLname(), + contact_list[i].getNname()}; + + for (int y = 0; y < 3; y++) { + info[y] = list_info[y].substr(0, 10); + if (list_info[y].size() > 10) + info[y][9] = '.'; + } + std::cout << std::left << std::setw(10) << i; + std::cout << " | "; + std::cout << std::left << std::setw(10) << info[0]; + std::cout << " | "; + std::cout << std::left << std::setw(10) << info[1]; + std::cout << " | "; + std::cout << std::left << std::setw(10) << info[2]; + std::cout << "\n"; + } + + std::string input; + while (input.size() == 0) + { + std::cout << "index:"; + if (!std::getline(std::cin, input)) + return ; + } + if (!isDigital(input)) + { + std::cout << "Error index" << std::endl; + return ; + } + int index = std::atoi(input.c_str()); + if (index > 7 || !contact_list[index].getInit()) + { + std::cout << "Out of range" << std::endl; + return ; + } + std::cout << "lastname: " + contact_list[index].getFname() << std::endl; + std::cout << "lastname: " + contact_list[index].getLname() << std::endl; + std::cout << "nickname: " + contact_list[index].getNname() << std::endl; + std::cout << "phone number: " + contact_list[index].getPhnbr() << std::endl; + std::cout << "darkest secret: " + contact_list[index].getDrksct() << std::endl; +} diff --git a/CPP00/ex01/PhoneBook.hpp b/CPP00/ex01/PhoneBook.hpp new file mode 100644 index 0000000..9159372 --- /dev/null +++ b/CPP00/ex01/PhoneBook.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* PhoneBook.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/08 17:41:02 by erey-bet #+# #+# */ +/* Updated: 2023/04/19 14:07:39 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef PHONEBOOK_HPP +# define PHONEBOOK_HPP + +# include "Contact.hpp" + +class PhoneBook { + public: + PhoneBook(void); + void add(void); + void search(void); + void exit(void); + + private: + Contact contact_list[8]; + int size; + int index; + +}; + +#endif diff --git a/CPP00/ex01/main.cpp b/CPP00/ex01/main.cpp new file mode 100644 index 0000000..be56e8b --- /dev/null +++ b/CPP00/ex01/main.cpp @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/08 17:58:31 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 14:47:32 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "PhoneBook.hpp" +#include +#include + +int main(void) { + std::string input; + PhoneBook PhoneB = PhoneBook(); + + while (true) { + std::cout << "PhoneBook Menu: ADD, SEARCH or EXIT to ... exit" << std::endl; + + if (!std::getline(std::cin, input)) + break; + + if (input.compare("ADD") == 0) + PhoneB.add(); + if (input.compare("SEARCH") == 0) + PhoneB.search(); + if (input.compare("EXIT") == 0) + break; + + std::cout << "You entered: " << input << std::endl; + } + + std::cout << "Exiting program..." << std::endl; + + return (0); +} diff --git a/CPP01/ex00/Makefile b/CPP01/ex00/Makefile new file mode 100644 index 0000000..51de5eb --- /dev/null +++ b/CPP01/ex00/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Zombie + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP01/ex00/Zombie.cpp b/CPP01/ex00/Zombie.cpp new file mode 100644 index 0000000..f56a495 --- /dev/null +++ b/CPP01/ex00/Zombie.cpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 13:50:14 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 15:21:06 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +Zombie::Zombie(std::string name) { + this->name = name; +} + +Zombie::~Zombie(void) { + std::cout << name + ": has been destroyed" << std::endl; +} + +void Zombie::announce(void) { + std::cout << name + ": BraiiiiiiinnnzzzZ..." << std::endl; +} diff --git a/CPP01/ex00/Zombie.hpp b/CPP01/ex00/Zombie.hpp new file mode 100644 index 0000000..8e7bd8d --- /dev/null +++ b/CPP01/ex00/Zombie.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 13:50:12 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 15:56:40 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ZOMBIE_HPP +# define ZOMBIE_HPP + +# include +# include +# include + +class Zombie { + public: + Zombie(std::string name); + ~Zombie(void); + void announce(void); + + private: + std::string name; +}; + +Zombie* newZombie(std::string name); +void randomChump(std::string name); + +#endif diff --git a/CPP01/ex00/main.cpp b/CPP01/ex00/main.cpp new file mode 100644 index 0000000..45aaef9 --- /dev/null +++ b/CPP01/ex00/main.cpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 15:14:34 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 15:38:31 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +int main(void) +{ + Zombie z1 = Zombie("z1"); + Zombie z2 = Zombie("z2"); + + z1.announce(); + z2.announce(); + + Zombie *nZombie = newZombie("NewZombie"); + nZombie->announce(); + + randomChump("randomChump"); + + delete(nZombie); + return (0); +} diff --git a/CPP01/ex00/newZombie.cpp b/CPP01/ex00/newZombie.cpp new file mode 100644 index 0000000..5dc9db0 --- /dev/null +++ b/CPP01/ex00/newZombie.cpp @@ -0,0 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* newZombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 13:50:38 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 15:56:43 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +Zombie *newZombie(std::string name) { + return (new Zombie(name)); +} diff --git a/CPP01/ex00/randomChump.cpp b/CPP01/ex00/randomChump.cpp new file mode 100644 index 0000000..30e24f7 --- /dev/null +++ b/CPP01/ex00/randomChump.cpp @@ -0,0 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* randomChump.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 13:50:48 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 15:23:25 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +void randomChump(std::string name) { + Zombie(name).announce(); +} diff --git a/CPP01/ex01/Makefile b/CPP01/ex01/Makefile new file mode 100644 index 0000000..51de5eb --- /dev/null +++ b/CPP01/ex01/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Zombie + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP01/ex01/Zombie.cpp b/CPP01/ex01/Zombie.cpp new file mode 100644 index 0000000..3169d9a --- /dev/null +++ b/CPP01/ex01/Zombie.cpp @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 13:50:14 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 16:34:18 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +Zombie::Zombie() { + this->name = ""; + std::cout << "noName : has been created" << std::endl; +} + +Zombie::Zombie(std::string name) { + this->name = name; + std::cout << name + ": has been created" << std::endl; +} + +Zombie::~Zombie(void) { + std::cout << name + ": has been destroyed" << std::endl; +} + +void Zombie::announce(void) { + std::cout << name + ": BraiiiiiiinnnzzzZ..." << std::endl; +} + +void Zombie::setName(std::string name) { + this->name = name; +} diff --git a/CPP01/ex01/Zombie.hpp b/CPP01/ex01/Zombie.hpp new file mode 100644 index 0000000..086d8b2 --- /dev/null +++ b/CPP01/ex01/Zombie.hpp @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 13:50:12 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 16:34:05 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ZOMBIE_HPP +# define ZOMBIE_HPP + +# include +# include +# include + +class Zombie { + public: + Zombie(); + Zombie(std::string name); + ~Zombie(); + void announce(void); + void setName(std::string name); + + private: + std::string name; +}; + +Zombie* newZombie(std::string name); +void randomChump(std::string name); +Zombie* zombieHorde(int N, std::string name); + +#endif diff --git a/CPP01/ex01/main.cpp b/CPP01/ex01/main.cpp new file mode 100644 index 0000000..7f23009 --- /dev/null +++ b/CPP01/ex01/main.cpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 15:14:34 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 16:38:53 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +int main(void) +{ + + Zombie* horde = zombieHorde(10, "Zombise"); + for (int i = 0; i < 10; i++) { + std::cout << i << "-"; + horde[i].announce(); + } + delete[] horde; + return (0); +} diff --git a/CPP01/ex01/zombieHorde.cpp b/CPP01/ex01/zombieHorde.cpp new file mode 100644 index 0000000..7ad2630 --- /dev/null +++ b/CPP01/ex01/zombieHorde.cpp @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* zombieHorde.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 16:27:00 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 16:33:02 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Zombie.hpp" + +Zombie* zombieHorde(int N, std::string name) +{ + Zombie* horde = new Zombie[N]; + for (int i = 0; i < N; i++) + horde[i].setName(name); + return (horde); +} diff --git a/CPP01/ex02/Makefile b/CPP01/ex02/Makefile new file mode 100644 index 0000000..51de5eb --- /dev/null +++ b/CPP01/ex02/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Zombie + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP01/ex02/main.cpp b/CPP01/ex02/main.cpp new file mode 100644 index 0000000..5b10768 --- /dev/null +++ b/CPP01/ex02/main.cpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 16:39:49 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 16:47:46 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +int main(void){ + std::string brain = "HI THIS IS BRAIN"; + std::string *stringPTR = &brain; + std::string &stringREF = brain; + + std::cout << &brain << std::endl; + std::cout << stringPTR << std::endl; + std::cout << &stringREF << std::endl; + + std::cout << brain << std::endl; + std::cout << *stringPTR << std::endl; + std::cout << stringREF << std::endl; + + return (0); +} diff --git a/CPP01/ex03/HumanA.cpp b/CPP01/ex03/HumanA.cpp new file mode 100644 index 0000000..e298d56 --- /dev/null +++ b/CPP01/ex03/HumanA.cpp @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanA.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 17:02:21 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 17:23:20 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "HumanA.hpp" + +HumanA::HumanA(std::string name, Weapon &weapon): weapon(weapon) { + this->name = name; +} + +void HumanA::attack(void) { + std::cout << name + " attacks with their " + weapon.getType() << std::endl; +} diff --git a/CPP01/ex03/HumanA.hpp b/CPP01/ex03/HumanA.hpp new file mode 100644 index 0000000..cfc53d3 --- /dev/null +++ b/CPP01/ex03/HumanA.hpp @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanA.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 16:56:55 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 17:19:21 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HUMANA_HPP +# define HUMANA_HPP + +# include "Weapon.hpp" +# include + +class HumanA { + public: + HumanA(std::string name, Weapon &weapon); + void attack(void); + + private: + std::string name; + Weapon &weapon; +}; + +#endif diff --git a/CPP01/ex03/HumanB.cpp b/CPP01/ex03/HumanB.cpp new file mode 100644 index 0000000..2fe084d --- /dev/null +++ b/CPP01/ex03/HumanB.cpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanB.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 17:02:21 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 17:32:17 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "HumanB.hpp" + +HumanB::HumanB(std::string name): weapon(NULL) { + this->name = name; +} + +HumanB::HumanB(std::string name, Weapon &weapon): weapon(&weapon) { + this->name = name; +} + +void HumanB::attack(void) { + if (weapon == NULL) + std::cout << name + " attacks with their fist"<< std::endl; + else + std::cout << name + " attacks with their " + weapon->getType() << std::endl; +} + +void HumanB::setWeapon(Weapon &weapon) { + this->weapon = &weapon; +} diff --git a/CPP01/ex03/HumanB.hpp b/CPP01/ex03/HumanB.hpp new file mode 100644 index 0000000..5e4bbaf --- /dev/null +++ b/CPP01/ex03/HumanB.hpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanB.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 16:56:55 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 17:32:28 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HUMANB_HPP +# define HUMANB_HPP + +# include "Weapon.hpp" +# include + +class HumanB { + public: + HumanB(std::string name); + HumanB(std::string name, Weapon &weapon); + void attack(void); + void setWeapon(Weapon &weapon); + + private: + std::string name; + Weapon *weapon; +}; + +#endif diff --git a/CPP01/ex03/Makefile b/CPP01/ex03/Makefile new file mode 100644 index 0000000..6ddf658 --- /dev/null +++ b/CPP01/ex03/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Weapon + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP01/ex03/Weapon.cpp b/CPP01/ex03/Weapon.cpp new file mode 100644 index 0000000..0e3d61a --- /dev/null +++ b/CPP01/ex03/Weapon.cpp @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Weapon.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 16:52:53 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 17:10:47 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Weapon.hpp" + +Weapon::Weapon(void) { + this->type = ""; +} + +Weapon::Weapon(std::string type) { + this->type = type; +} + +const std::string &Weapon::getType(void) { + return (this->type); +} + +void Weapon::setType(std::string type) { + this->type = type; +} diff --git a/CPP01/ex03/Weapon.hpp b/CPP01/ex03/Weapon.hpp new file mode 100644 index 0000000..3eca80e --- /dev/null +++ b/CPP01/ex03/Weapon.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Weapon.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 16:50:04 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 17:14:44 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef WEAPON_HPP +# define WEAPON_HPP + +# include +# include + +class Weapon { + public: + Weapon(); + Weapon(std::string type); + + const std::string &getType(void); + void setType(std::string type); + private: + std::string type; +}; + +#endif diff --git a/CPP01/ex03/main.cpp b/CPP01/ex03/main.cpp new file mode 100644 index 0000000..43bbfd2 --- /dev/null +++ b/CPP01/ex03/main.cpp @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 16:48:48 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 17:14:36 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Weapon.hpp" +#include "HumanA.hpp" +#include "HumanB.hpp" + +int main() +{ + { + Weapon club = Weapon("crude spiked club"); + HumanA bob("Bob", club); + bob.attack(); + club.setType("some other type of club"); + bob.attack(); + } + std::cout << "------------------------------" << std::endl; + { + Weapon club = Weapon("crude spiked club"); + HumanB jim("Jim"); + jim.attack(); + jim.setWeapon(club); + jim.attack(); + club.setType("some other type of club"); + jim.attack(); + } + std::cout << "------------------------------" << std::endl; + { + Weapon sword = Weapon("strange sword"); + HumanB jim("Timeo", sword); + jim.attack(); + sword.setType("other strange sword"); + jim.attack(); + } + return 0; +} diff --git a/CPP01/ex04/Makefile b/CPP01/ex04/Makefile new file mode 100644 index 0000000..455f995 --- /dev/null +++ b/CPP01/ex04/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = SedForLooser + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP01/ex04/SedForLooser.cpp b/CPP01/ex04/SedForLooser.cpp new file mode 100644 index 0000000..ab9c907 --- /dev/null +++ b/CPP01/ex04/SedForLooser.cpp @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* SedForLooser.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/21 15:56:56 by erey-bet #+# #+# */ +/* Updated: 2023/05/18 16:20:42 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "SedForLooser.hpp" +#include + +SedForLooser::SedForLooser(char *filename) { + this->filename = filename; +} + +void SedForLooser::replace(std::string s1, std::string s2) { + std::ifstream infile(this->filename); + if (infile == NULL) + { + if (errno == EACCES) + std::cout << "You don't have the permissions to open the file." << std::endl; + else + std::cout << "Error to open the file." << std::endl; + return ; + } + + std::ofstream outfile(strcat(this->filename, ".replace")); + if (infile == NULL) + { + if (errno == EACCES) + std::cout << "You don't have the permissions to open the file." << std::endl; + else + std::cout << "Error to open the file." << std::endl; + return ; + } + + std::string text; + std::string line; + while (std::getline(infile, line)) + text += line + "\n"; + infile.close(); + + std::string result; + for (std::size_t i = 0; i < text.size(); i++) + { + for (std::size_t y = 0; y < s1.size(); y++) + { + if (text[i] != s1[y]) + { + result += text[i]; + break; + } + else if (y == s1.size() - 1) + result += s2; + } + } + + outfile << result << std::endl; +} diff --git a/CPP01/ex04/SedForLooser.hpp b/CPP01/ex04/SedForLooser.hpp new file mode 100644 index 0000000..101273d --- /dev/null +++ b/CPP01/ex04/SedForLooser.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* SedForLooser.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/21 15:53:07 by erey-bet #+# #+# */ +/* Updated: 2023/04/21 15:56:01 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef SEDFORLOOSER_HPP +# define SEDFORLOOSER_HPP + +# include +# include +# include +# include + +class SedForLooser { + public: + SedForLooser(char *filename); + void replace(std::string s1, std::string s2); + + private: + char *filename; +}; + +#endif diff --git a/CPP01/ex04/main.cpp b/CPP01/ex04/main.cpp new file mode 100644 index 0000000..8c2d99f --- /dev/null +++ b/CPP01/ex04/main.cpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/21 15:51:24 by erey-bet #+# #+# */ +/* Updated: 2023/04/21 16:14:12 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "SedForLooser.hpp" + +int main(int argc, char **argv) { + if (argc != 4) { + std::cout << "Wrong Number of Argument" << std::endl; + return (1); + } + + SedForLooser Sfl = SedForLooser(argv[1]); + Sfl.replace(std::string(argv[2]), std::string(argv[3])); + + return (0); +} diff --git a/CPP01/ex05/Harl.cpp b/CPP01/ex05/Harl.cpp new file mode 100644 index 0000000..3d9a3ce --- /dev/null +++ b/CPP01/ex05/Harl.cpp @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 17:40:42 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 18:08:44 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +Harl::Harl(void) {} + +void Harl::debug(void) { + std::cout << "DEBUG" << std::endl; +} + +void Harl::info(void) { + std::cout << "INFO" << std::endl; +} + +void Harl::warning(void) { + std::cout << "WARNING" << std::endl; +} + +void Harl::error(void) { + std::cout << "ERROR" << std::endl; +} + +void Harl::complain(std::string level) { + void(Harl::*funcs[4])() = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error}; + std::string all_level[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; + + for (int i = 0; i < 4; i++) + if (all_level[i] == level) + return (this->*funcs[i])(); + std::cout << "Only 'DEBUG', 'INFO', 'WARNING', 'ERROR' was allowed" << std::endl; +} diff --git a/CPP01/ex05/Harl.hpp b/CPP01/ex05/Harl.hpp new file mode 100644 index 0000000..d4d2087 --- /dev/null +++ b/CPP01/ex05/Harl.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 17:36:19 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 18:00:04 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HARL_HPP +# define HARL_HPP + +# include + +class Harl { + public: + Harl(void); + void complain(std::string level); + + private: + void debug(void); + void info(void); + void warning(void); + void error(void); +}; + +#endif diff --git a/CPP01/ex05/Makefile b/CPP01/ex05/Makefile new file mode 100644 index 0000000..a00ccbd --- /dev/null +++ b/CPP01/ex05/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Harl + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP01/ex05/main.cpp b/CPP01/ex05/main.cpp new file mode 100644 index 0000000..84b0969 --- /dev/null +++ b/CPP01/ex05/main.cpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 18:09:58 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 18:18:44 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" +#include + +int main(int argc, char **argv) { + Harl harl = Harl(); + + if (argc == 2) + harl.complain(std::string(argv[1])); + return (0); +} diff --git a/CPP01/ex06/Harl.cpp b/CPP01/ex06/Harl.cpp new file mode 100644 index 0000000..88f43da --- /dev/null +++ b/CPP01/ex06/Harl.cpp @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 17:40:42 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 18:38:26 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +Harl::Harl(void) {} + +void Harl::debug(void) { + std::cout << "DEBUG" << std::endl; +} + +void Harl::info(void) { + std::cout << "INFO" << std::endl; +} + +void Harl::warning(void) { + std::cout << "WARNING" << std::endl; +} + +void Harl::error(void) { + std::cout << "ERROR" << std::endl; +} + +void Harl::complain(std::string level) { + void(Harl::*funcs[4])() = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error}; + std::string all_level[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; + + int i; + for (i = 0; i < 4; i++) + if (all_level[i] == level) + break ; + + switch (i) { + case 0: + (this->*funcs[0])(); + this->complain("INFO"); + break; + case 1: + (this->*funcs[1])(); + this->complain("WARNING"); + break; + case 2: + (this->*funcs[2])(); + this->complain("ERROR"); + break; + case 3: + (this->*funcs[3])(); + break; + default: + return ; + } +} diff --git a/CPP01/ex06/Harl.hpp b/CPP01/ex06/Harl.hpp new file mode 100644 index 0000000..d4d2087 --- /dev/null +++ b/CPP01/ex06/Harl.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 17:36:19 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 18:00:04 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HARL_HPP +# define HARL_HPP + +# include + +class Harl { + public: + Harl(void); + void complain(std::string level); + + private: + void debug(void); + void info(void); + void warning(void); + void error(void); +}; + +#endif diff --git a/CPP01/ex06/Makefile b/CPP01/ex06/Makefile new file mode 100644 index 0000000..a00ccbd --- /dev/null +++ b/CPP01/ex06/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Harl + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP01/ex06/main.cpp b/CPP01/ex06/main.cpp new file mode 100644 index 0000000..84b0969 --- /dev/null +++ b/CPP01/ex06/main.cpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/04/20 18:09:58 by erey-bet #+# #+# */ +/* Updated: 2023/04/20 18:18:44 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" +#include + +int main(int argc, char **argv) { + Harl harl = Harl(); + + if (argc == 2) + harl.complain(std::string(argv[1])); + return (0); +} diff --git a/CPP02/ex00/Fixed.cpp b/CPP02/ex00/Fixed.cpp new file mode 100644 index 0000000..0a29bc1 --- /dev/null +++ b/CPP02/ex00/Fixed.cpp @@ -0,0 +1,33 @@ +#include "Fixed.hpp" + +Fixed::Fixed() { + this->rawBits = 0; + std::cout << "Default constructor called" << std::endl; +} + +Fixed::~Fixed() { + std::cout << "Destructor called" << std::endl; +} + +Fixed& Fixed::operator=(const Fixed &fixed) { + if (this != &fixed) { + this->rawBits = fixed.rawBits; + } + std::cout << "Copy assignment operator called" << std::endl; + return *this; +} + +Fixed::Fixed(const Fixed &fixed) { + this->rawBits = fixed.rawBits; + std::cout << "Copy constructor called" << std::endl; +} + +int Fixed::getRawBits() const{ + std::cout << "getRawBits member function called "; + return this->rawBits; +} + +void Fixed::setRawBits(int const raw) { + this->rawBits = raw; + std::cout << "setRawBits member function called" << std::endl; +} diff --git a/CPP02/ex00/Fixed.hpp b/CPP02/ex00/Fixed.hpp new file mode 100644 index 0000000..e893e2b --- /dev/null +++ b/CPP02/ex00/Fixed.hpp @@ -0,0 +1,21 @@ +#ifndef FIXED_HPP +# define FIXED_HPP + +# include +# include + +class Fixed { + public: + Fixed(); + Fixed(const Fixed &fixed); + ~Fixed(); + Fixed& operator=(const Fixed &fixed); + + int getRawBits() const; + void setRawBits(int const raw); + private: + int rawBits; + const static int bits = 8; +}; + +#endif diff --git a/CPP02/ex00/Makefile b/CPP02/ex00/Makefile new file mode 100644 index 0000000..02232c2 --- /dev/null +++ b/CPP02/ex00/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Fixed + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP02/ex00/main.cpp b/CPP02/ex00/main.cpp new file mode 100644 index 0000000..23daae0 --- /dev/null +++ b/CPP02/ex00/main.cpp @@ -0,0 +1,36 @@ +#include "Fixed.hpp" + +int main() { + + { + Fixed a; + a.setRawBits(2); + Fixed b( a ); + Fixed c; + + c = b; + + std::cout << " a:" << a.getRawBits() << std::endl; + std::cout << " b:" << b.getRawBits() << std::endl; + std::cout << " c:" << c.getRawBits() << std::endl; + } + + std::cout << "---------------------" << std::endl; + + { + Fixed a; + a.setRawBits(5); + std::cout << " a:" << a.getRawBits() << std::endl; + Fixed b(a); + std::cout << " a:" << a.getRawBits() << std::endl; + std::cout << " b:" << b.getRawBits() << std::endl; + a.setRawBits(12); + std::cout << " a:" << a.getRawBits() << std::endl; + std::cout << " b:" << b.getRawBits() << std::endl; + b.setRawBits(2); + std::cout << " a:" << a.getRawBits() << std::endl; + std::cout << " b:" << b.getRawBits() << std::endl; + } + + return 0; +} diff --git a/CPP02/ex01/Fixed.cpp b/CPP02/ex01/Fixed.cpp new file mode 100644 index 0000000..770dd93 --- /dev/null +++ b/CPP02/ex01/Fixed.cpp @@ -0,0 +1,54 @@ +#include "Fixed.hpp" + +Fixed::Fixed(void) { + this->rawBits = 0; + std::cout << "Default constructor called" << std::endl; +} + +Fixed::Fixed(const int raw) { + this->rawBits = int(raw * (1 << bits)); + std::cout << "Int constructor called" << std::endl; +} + +Fixed::Fixed(const float raw) { + this->rawBits = int(roundf(raw * (1 << bits))); + std::cout << "Float constructor called" << std::endl; +} + +Fixed::~Fixed() { + std::cout << "Destructor called" << std::endl; +} + +Fixed& Fixed::operator=(const Fixed &fixed) { + if (this != &fixed) { + this->rawBits = fixed.rawBits; + } + std::cout << "Copy assignment operator called" << std::endl; + return *this; +} + +std::ostream& operator<<(std::ostream& os, const Fixed &fixed) { + os << fixed.toFloat(); + return os; +} + +Fixed::Fixed(const Fixed &fixed) { + this->rawBits = fixed.rawBits; + std::cout << "Copy constructor called" << std::endl; +} + +int Fixed::toInt(void) const{ + return int(this->rawBits) / int(1 << this->bits); +} + +float Fixed::toFloat(void) const{ + return float(this->rawBits) / float(1 << this->bits); +} + +int Fixed::getRawBits(void) const { + return this->rawBits; +} + +void Fixed::setRawBits(const int raw) { + this->rawBits = raw; +} diff --git a/CPP02/ex01/Fixed.hpp b/CPP02/ex01/Fixed.hpp new file mode 100644 index 0000000..622cc83 --- /dev/null +++ b/CPP02/ex01/Fixed.hpp @@ -0,0 +1,29 @@ +#ifndef FIXED_HPP +# define FIXED_HPP + +# include +# include +# include + +class Fixed { + public: + Fixed(void); + Fixed(int const raw); + Fixed(float const raw); + Fixed(const Fixed &fixed); + ~Fixed(); + Fixed& operator=(const Fixed &fixed); + + int toInt(void) const; + float toFloat(void) const; + + int getRawBits(void) const; + void setRawBits(int const raw); + private: + int rawBits; + const static int bits = 8; +}; + +std::ostream& operator<<(std::ostream& os, const Fixed& fixed); + +#endif diff --git a/CPP02/ex01/Makefile b/CPP02/ex01/Makefile new file mode 100644 index 0000000..02232c2 --- /dev/null +++ b/CPP02/ex01/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Fixed + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP02/ex01/main.cpp b/CPP02/ex01/main.cpp new file mode 100644 index 0000000..e2ee37f --- /dev/null +++ b/CPP02/ex01/main.cpp @@ -0,0 +1,25 @@ +#include "Fixed.hpp" + +int main( void ) { + Fixed a; + Fixed const b( 10 ); + Fixed const c( 42.42f ); + Fixed const d( b ); + a = Fixed( 1234.4321f ); + std::cout << "a is " << a << std::endl; + std::cout << "b is " << b << std::endl; + std::cout << "c is " << c << std::endl; + std::cout << "d is " << d << std::endl; + std::cout << "a is " << a.toInt() << " as integer" << std::endl; + std::cout << "b is " << b.toInt() << " as integer" << std::endl; + std::cout << "c is " << c.toInt() << " as integer" << std::endl; + std::cout << "d is " << d.toInt() << " as integer" << std::endl; + + std::cout << "-------------------------" << std::endl; + + std::cout << "a is " << a.getRawBits() << std::endl; + std::cout << "b is " << b.getRawBits() << std::endl; + std::cout << "c is " << c.getRawBits() << std::endl; + + return 0; +} diff --git a/CPP02/ex02/Fixed.cpp b/CPP02/ex02/Fixed.cpp new file mode 100644 index 0000000..1cc26e0 --- /dev/null +++ b/CPP02/ex02/Fixed.cpp @@ -0,0 +1,130 @@ +#include "Fixed.hpp" + +Fixed::Fixed(void) { + this->rawBits = 0; +} + +Fixed::Fixed(const int raw) { + this->rawBits = int(raw * (1 << bits)); +} + +Fixed::Fixed(const float raw) { + this->rawBits = int(roundf(raw * (1 << bits))); +} + +Fixed::~Fixed() { +} + +Fixed& Fixed::operator=(const Fixed &fixed) { + if (this != &fixed) { + this->rawBits = fixed.rawBits; + } + return *this; +} + +std::ostream& operator<<(std::ostream& os, const Fixed &fixed) { + os << fixed.toFloat(); + return os; +} + +Fixed::Fixed(const Fixed &fixed) { + this->rawBits = fixed.rawBits; +} + +int Fixed::toInt(void) const{ + return int(this->rawBits) / int(1 << this->bits); +} + +float Fixed::toFloat(void) const{ + return float(this->rawBits) / float(1 << this->bits); +} + +int Fixed::getRawBits(void) const { + return this->rawBits; +} + +void Fixed::setRawBits(const int raw) { + this->rawBits = raw; +} + +bool Fixed::operator>(const Fixed &fixed) const { + return this->rawBits > fixed.rawBits; +} + +bool Fixed::operator<(const Fixed &fixed) const { + return this->rawBits < fixed.rawBits; +} + +bool Fixed::operator>=(const Fixed &fixed) const { + return this->rawBits >= fixed.rawBits; +} + +bool Fixed::operator<=(const Fixed &fixed) const { + return this->rawBits <= fixed.rawBits; +} + +bool Fixed::operator==(const Fixed &fixed) const { + return this->rawBits == fixed.rawBits; +} + +bool Fixed::operator!=(const Fixed &fixed) const { + return this->rawBits != fixed.rawBits; +} + +Fixed Fixed::operator+(const Fixed &fixed) const { + Fixed result = Fixed(this->toFloat() + fixed.toFloat()); + return result; +} + +Fixed Fixed::operator-(const Fixed &fixed) const { + Fixed result = Fixed(this->toFloat() - fixed.toFloat()); + return result; +} + +Fixed Fixed::operator*(const Fixed &fixed) const { + Fixed result = Fixed(this->toFloat() * fixed.toFloat()); + return result; +} + +Fixed Fixed::operator/(const Fixed &fixed) const { + Fixed result = Fixed(this->toFloat() / fixed.toFloat()); + return result; +} + +Fixed& Fixed::operator++(void) { + this->rawBits++; + return *this; +} + +Fixed Fixed::operator++(int) { + Fixed tmp(*this); + this->rawBits++; + return tmp; +} + +Fixed& Fixed::operator--(void) { + this->rawBits--; + return *this; +} + +Fixed Fixed::operator--(int) { + Fixed tmp(*this); + this->rawBits--; + return tmp; +} + +const Fixed& Fixed::min(Fixed& a, Fixed& b) { + return (a < b) ? a : b; +} + +const Fixed& Fixed::min(const Fixed& a, const Fixed& b) { + return (a < b) ? a : b; +} + +const Fixed& Fixed::max(Fixed& a, Fixed& b) { + return (a > b) ? a : b; +} + +const Fixed& Fixed::max(const Fixed& a, const Fixed& b) { + return (a > b) ? a : b; +} diff --git a/CPP02/ex02/Fixed.hpp b/CPP02/ex02/Fixed.hpp new file mode 100644 index 0000000..f4a9a0d --- /dev/null +++ b/CPP02/ex02/Fixed.hpp @@ -0,0 +1,51 @@ +#ifndef FIXED_HPP +# define FIXED_HPP + +# include +# include +# include + +class Fixed { + public: + Fixed(void); + Fixed(int const raw); + Fixed(float const raw); + Fixed(const Fixed &fixed); + ~Fixed(); + Fixed& operator=(const Fixed &fixed); + + static const Fixed& min(Fixed& a, Fixed& b); + static const Fixed& max(Fixed& a, Fixed& b); + static const Fixed& min(const Fixed& a, const Fixed& b); + static const Fixed& max(const Fixed& a, const Fixed& b); + + bool operator>(const Fixed& fixed) const; + bool operator<(const Fixed& fixed) const; + bool operator>=(const Fixed& fixed) const; + bool operator<=(const Fixed& fixed) const; + bool operator==(const Fixed& fixed) const; + bool operator!=(const Fixed& fixed) const; + + Fixed operator+(const Fixed& fixed) const; + Fixed operator-(const Fixed& fixed) const; + Fixed operator*(const Fixed& fixed) const; + Fixed operator/(const Fixed& fixed) const; + + Fixed& operator++(); + Fixed operator++(int); + Fixed& operator--(); + Fixed operator--(int); + + int toInt(void) const; + float toFloat(void) const; + + int getRawBits(void) const; + void setRawBits(int const raw); + private: + int rawBits; + const static int bits = 8; +}; + +std::ostream& operator<<(std::ostream& os, const Fixed& fixed); + +#endif diff --git a/CPP02/ex02/Makefile b/CPP02/ex02/Makefile new file mode 100644 index 0000000..02232c2 --- /dev/null +++ b/CPP02/ex02/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Fixed + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP02/ex02/main.cpp b/CPP02/ex02/main.cpp new file mode 100644 index 0000000..e308cbd --- /dev/null +++ b/CPP02/ex02/main.cpp @@ -0,0 +1,87 @@ +#include "Fixed.hpp" + +void ft_test(bool test, std::string text) { + if (test) + std::cout << "test: " + text + ", bool: \033[1;32mTrue\033[0m" << std::endl; + else + std::cout << "test: " + text + ", bool: \033[1;31mFalse\033[0m" << std::endl; +} + +void bool_test(Fixed nbr1, Fixed nbr2, std::string name1, std::string name2) { + ft_test(nbr1 == nbr2, name1 + " == " + name2); + ft_test(nbr1 != nbr2, name1 + " != " + name2); + ft_test(nbr1 <= nbr2, name1 + " <= " + name2); + ft_test(nbr1 >= nbr2, name1 + " >= " + name2); + ft_test(nbr1 < nbr2, name1 + " < " + name2); + ft_test(nbr1 > nbr2, name1 + " > " + name2); +} + +void operator_test(Fixed nbr1, Fixed nbr2, std::string name1, std::string name2) { + + std::cout << "result: " << nbr1 * nbr2 << " waiting: " << nbr1.toFloat() * nbr2.toFloat() << std::endl; + ft_test(nbr1 * nbr2 == nbr1.toFloat() * nbr2.toFloat(), name1 + " * " + name2); + std::cout << "result: " << nbr1 / nbr2 << " waiting: " << nbr1.toFloat() / nbr2.toFloat() << std::endl; + ft_test(nbr1 / nbr2 == nbr1.toFloat() / nbr2.toFloat(), name1 + " / " + name2); + std::cout << "result: " << nbr1 + nbr2 << " waiting: " << nbr1.toFloat() + nbr2.toFloat() << std::endl; + ft_test(nbr1 + nbr2 == nbr1.toFloat() + nbr2.toFloat(), name1 + " + " + name2); + std::cout << "result: " << nbr1 - nbr2 << " waiting: " << nbr1.toFloat() - nbr2.toFloat() << std::endl; + ft_test(nbr1 - nbr2 == nbr1.toFloat() - nbr2.toFloat(), name1 + " - " + name2); +} + +int main( void ) { + + /* BOOL */ + { + std::cout << "\n--BOOL TEST--" << std::endl; + Fixed a(10); + Fixed b(10.1f); + Fixed c(9.9f); + + std::cout << "a:" << a << std::endl; + std::cout << "b:" << b << std::endl; + std::cout << "c:" << c << std::endl; + std::cout << "\n-------------------------------\n" << std::endl; + bool_test(a, b, "a", "b"); + std::cout << "\n-------------------------------\n" << std::endl; + bool_test(a, c, "a", "c"); + std::cout << "\n-------------------------------\n"<< std::endl; + bool_test(b, c, "b", "c"); + } + + /* OPERATOR */ + { + std::cout << "\n--OPERATOR TEST--" << std::endl; + Fixed a(2); + Fixed b(41.1f); + Fixed c(-2.9f); + + std::cout << "a:" << a << std::endl; + std::cout << "b:" << b << std::endl; + std::cout << "c:" << c << std::endl; + + std::cout << "\n-------------------------------\n" << std::endl; + operator_test(a, b, "a", "b"); + std::cout << "\n-------------------------------\n" << std::endl; + operator_test(a, c, "a", "c"); + std::cout << "\n-------------------------------\n"<< std::endl; + operator_test(b, c, "b", "c"); + } + + std::cout << "\n-------------------------------\n" << std::endl; + + /* OTHER */ + { + Fixed a; + Fixed const b( Fixed( 5.05f ) * Fixed( 2 ) ); + std::cout << "a:" << a << std::endl; + std::cout << "++a:" << ++a << std::endl; + std::cout << "a:" << a << std::endl; + std::cout << "a++:" << a++ << std::endl; + std::cout << "a:" << a << std::endl; + std::cout << "b:" << b << std::endl; + std::cout << "max(a,b):" << Fixed::max( a, b ) << std::endl; + std::cout << "min(a,b):" << Fixed::min( a, b ) << std::endl; + } + + return 0; +} diff --git a/CPP03/ex00/ClapTrap.cpp b/CPP03/ex00/ClapTrap.cpp new file mode 100644 index 0000000..d921673 --- /dev/null +++ b/CPP03/ex00/ClapTrap.cpp @@ -0,0 +1,66 @@ +#include "ClapTrap.hpp" + +ClapTrap::ClapTrap() { + this->name = "Default"; + this->hp = 10; + this->energy = 10; + this->damage = 0; + std::cout << this->name + " is created" << std::endl; +} + +ClapTrap::ClapTrap(std::string name) { + this->name = name; + this->hp = 10; + this->energy = 10; + this->damage = 0; + std::cout << this->name + " is created" << std::endl; +} + +ClapTrap::ClapTrap(const ClapTrap &clap) { + *this = clap; + std::cout << this->name + " is created" << std::endl; +} + +ClapTrap::~ClapTrap() { + std::cout << this->name + " is destroyed" << std::endl; +} + +ClapTrap& ClapTrap::operator=(const ClapTrap &clap) { + if (this != &clap) { + this->name = clap.name; + this->hp = clap.hp; + this->energy = clap.energy; + this->damage = clap.damage; + } + return *this; +} + +void ClapTrap::attack(const std::string& target) { + if (this->energy > 0 && this->hp > 0) { + std::cout << "ClapTrap " + this->name + " attacks " + target + ", causing " + << this->damage << " points of damage! " << std::endl; + this->energy--; + } + else + std::cout << "ClapTrap " + this->name + " is out of combat" << std::endl; +} + +void ClapTrap::takeDamage(unsigned int amount) { + if (this->hp > 0) { + std::cout << "ClapTrap " + this->name + " takes " << amount << " damages" << std::endl; + this->energy--; + this->hp -= amount; + } + else + std::cout << "ClapTrap " + this->name + " is out of combat" << std::endl; +} + +void ClapTrap::beRepaired(unsigned int amount) { + if (this->energy > 0 && this->hp > 0) { + std::cout << "ClapTrap " + this->name + " is repaired by " << amount << std::endl; + this->energy--; + this->hp += amount; + } + else + std::cout << "ClapTrap " + this->name + " is out of combat" << std::endl; +} diff --git a/CPP03/ex00/ClapTrap.hpp b/CPP03/ex00/ClapTrap.hpp new file mode 100644 index 0000000..762ea33 --- /dev/null +++ b/CPP03/ex00/ClapTrap.hpp @@ -0,0 +1,25 @@ +#ifndef CLAPTRAP_HPP +# define CLAPTRAP_HPP + +#include + +class ClapTrap { + public: + ClapTrap(); + ClapTrap(std::string name); + ~ClapTrap(); + ClapTrap(const ClapTrap &clap); + ClapTrap& operator=(const ClapTrap &clap); + + void attack(const std::string& target); + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + + private: + std::string name; + int hp; + int energy; + int damage; +}; + +#endif diff --git a/CPP03/ex00/Makefile b/CPP03/ex00/Makefile new file mode 100644 index 0000000..9b8ab9e --- /dev/null +++ b/CPP03/ex00/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = ClapTrap + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP03/ex00/main.cpp b/CPP03/ex00/main.cpp new file mode 100644 index 0000000..b021e3b --- /dev/null +++ b/CPP03/ex00/main.cpp @@ -0,0 +1,38 @@ +#include "ClapTrap.hpp" + +int main(void) { + ClapTrap none; + ClapTrap clapy("Clapy"); + ClapTrap clapo("Clapo"); + + std::cout << "\n----------------------------\n" << std::endl; + + none.attack("Clapy"); + none.takeDamage(20); + none.attack("Clapy"); + none.beRepaired(10); + + std::cout << "\n----------------------------\n" << std::endl; + + clapy.attack("Clapo"); + clapo.takeDamage(0); + clapy.takeDamage(5); + clapy.beRepaired(5); + clapy.takeDamage(5); + + for (int i = 0; i < 8; i++) + clapy.attack("Clapo"); + + std::cout << "\n----------------------------\n" << std::endl; + + std::cout << "/*ClapTrap clapy2(clapy);" << std::endl; + std::cout << "ClapTrap clapy3 = clapy;*/\n" << std::endl; + ClapTrap clapy2(clapy); + ClapTrap clapy3 = clapy; + + clapy2.attack("Clapo"); + clapy3.attack("Clapo"); + + std::cout << "\n----------------------------\n" << std::endl; + +} diff --git a/CPP03/ex01/ClapTrap.cpp b/CPP03/ex01/ClapTrap.cpp new file mode 100644 index 0000000..162fbf9 --- /dev/null +++ b/CPP03/ex01/ClapTrap.cpp @@ -0,0 +1,66 @@ +#include "ClapTrap.hpp" + +ClapTrap::ClapTrap() { + this->name = "Default"; + this->hp = 10; + this->energy = 10; + this->damage = 0; + std::cout << "ClapTrap " + this->name + " is created" << std::endl; +} + +ClapTrap::ClapTrap(std::string name) { + this->name = name; + this->hp = 10; + this->energy = 10; + this->damage = 0; + std::cout << "ClapTrap " + this->name + " is created" << std::endl; +} + +ClapTrap::ClapTrap(const ClapTrap &clap) { + *this = clap; + std::cout << "ClapTrap " + this->name + " is created" << std::endl; +} + +ClapTrap::~ClapTrap() { + std::cout << "ClapTrap " + this->name + " is destroyed" << std::endl; +} + +ClapTrap& ClapTrap::operator=(const ClapTrap &clap) { + if (this != &clap) { + this->name = clap.name; + this->hp = clap.hp; + this->energy = clap.energy; + this->damage = clap.damage; + } + return *this; +} + +void ClapTrap::attack(const std::string& target) { + if (this->energy > 0 && this->hp > 0) { + std::cout << "ClapTrap " + this->name + " attacks " + target + ", causing " + << this->damage << " points of damage! " << std::endl; + this->energy--; + } + else + std::cout << this->name + " is out of combat" << std::endl; +} + +void ClapTrap::takeDamage(unsigned int amount) { + if (this->hp > 0) { + std::cout << this->name + " takes " << amount << " damages" << std::endl; + this->energy--; + this->hp -= amount; + } + else + std::cout << this->name + " is out of combat" << std::endl; +} + +void ClapTrap::beRepaired(unsigned int amount) { + if (this->energy > 0 && this->hp > 0) { + std::cout << this->name + " is repaired by " << amount << std::endl; + this->energy--; + this->hp += amount; + } + else + std::cout << this->name + " is out of combat" << std::endl; +} diff --git a/CPP03/ex01/ClapTrap.hpp b/CPP03/ex01/ClapTrap.hpp new file mode 100644 index 0000000..78fb07c --- /dev/null +++ b/CPP03/ex01/ClapTrap.hpp @@ -0,0 +1,25 @@ +#ifndef CLAPTRAP_HPP +# define CLAPTRAP_HPP + +#include + +class ClapTrap { + public: + ClapTrap(); + ClapTrap(std::string name); + ~ClapTrap(); + ClapTrap(const ClapTrap &clap); + ClapTrap& operator=(const ClapTrap &clap); + + void attack(const std::string& target); + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + + protected: + std::string name; + int hp; + int energy; + int damage; +}; + +#endif diff --git a/CPP03/ex01/Makefile b/CPP03/ex01/Makefile new file mode 100644 index 0000000..20994e1 --- /dev/null +++ b/CPP03/ex01/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = ScavTrap + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP03/ex01/ScavTrap.cpp b/CPP03/ex01/ScavTrap.cpp new file mode 100644 index 0000000..5f8d342 --- /dev/null +++ b/CPP03/ex01/ScavTrap.cpp @@ -0,0 +1,52 @@ +#include "ScavTrap.hpp" + +ScavTrap::ScavTrap() : ClapTrap() { + this->name = "Default"; + this->hp = 100; + this->energy = 50; + this->damage = 20; + std::cout << "ScavTrap " + this->name + " is created" << std::endl; +} + +ScavTrap::ScavTrap(std::string name) : ClapTrap() { + this->name = name; + this->hp = 100; + this->energy = 50; + this->damage = 20; + std::cout << "ScavTrap " + this->name + " is created" << std::endl; +} + +ScavTrap::ScavTrap(const ScavTrap &scav) : ClapTrap(scav) { + *this = scav; + std::cout << "ScavTrap " + this->name + " is created" << std::endl; +} + +ScavTrap::~ScavTrap() { + std::cout << "ScavTrap " + this->name + " is destroyed" << std::endl; +} + +ScavTrap& ScavTrap::operator=(const ScavTrap &scav) { + if (this != &scav) { + ClapTrap::operator=(scav); + } + return *this; +} + +void ScavTrap::attack(const std::string& target) { + if (this->energy > 0 && this->hp > 0) { + std::cout << "ScavTrap " + this->name + " attacks " + target + ", causing " + << this->damage << " points of damage! " << std::endl; + this->energy--; + } + else + std::cout << this->name + " is out of combat" << std::endl; +} + +void ScavTrap::guardGate() { + if (this->energy > 0 && this->hp > 0) { + std::cout << "ScavTrap is now in Gate Keeper Mode" << std::endl; + this->energy--; + } + else + std::cout << "ScavTrap " + this->name + " is out of combat" << std::endl; +} diff --git a/CPP03/ex01/ScavTrap.hpp b/CPP03/ex01/ScavTrap.hpp new file mode 100644 index 0000000..2454354 --- /dev/null +++ b/CPP03/ex01/ScavTrap.hpp @@ -0,0 +1,19 @@ +#ifndef SCAVTRAP_HPP +# define SCAVTRAP_HPP + +#include "ClapTrap.hpp" +#include + +class ScavTrap : public ClapTrap { + public: + ScavTrap(); + ScavTrap(std::string name); + ~ScavTrap(); + ScavTrap(const ScavTrap &clap); + ScavTrap& operator=(const ScavTrap &clap); + + void attack(const std::string& target); + void guardGate(); +}; + +#endif diff --git a/CPP03/ex01/main.cpp b/CPP03/ex01/main.cpp new file mode 100644 index 0000000..4ccbf79 --- /dev/null +++ b/CPP03/ex01/main.cpp @@ -0,0 +1,52 @@ +#include "ClapTrap.hpp" +#include "ScavTrap.hpp" + +int main(void) { + std::cout << "\n"; + ScavTrap none; + ScavTrap clapy("Clapy"); + ClapTrap clapo("Clapo"); + + std::cout << "\n----------------------------\n" << std::endl; + + none.attack("Clapy"); + none.takeDamage(100); + none.attack("Clapy"); + none.beRepaired(10); + + std::cout << "\n----------------------------\n" << std::endl; + + { + clapy.attack("Clapo"); + clapo.takeDamage(0); + clapy.takeDamage(50); + clapy.beRepaired(5); + clapy.takeDamage(50); + + for (int i = 0; i < 50; i++) + clapy.attack("Clapo"); + } + + std::cout << "\n----------------------------\n" << std::endl; + + { + ScavTrap clapy2(clapy); + ScavTrap clapy3 = clapy; + + clapy2.attack("Clapo"); + clapy3.attack("Clapo"); + } + + std::cout << "\n----------------------------\n" << std::endl; + + { + ScavTrap guard("Gigi"); + + guard.guardGate(); + guard.takeDamage(100); + guard.guardGate(); + } + + std::cout << "\n----------------------------\n" << std::endl; + +} diff --git a/CPP03/ex02/ClapTrap.cpp b/CPP03/ex02/ClapTrap.cpp new file mode 100644 index 0000000..162fbf9 --- /dev/null +++ b/CPP03/ex02/ClapTrap.cpp @@ -0,0 +1,66 @@ +#include "ClapTrap.hpp" + +ClapTrap::ClapTrap() { + this->name = "Default"; + this->hp = 10; + this->energy = 10; + this->damage = 0; + std::cout << "ClapTrap " + this->name + " is created" << std::endl; +} + +ClapTrap::ClapTrap(std::string name) { + this->name = name; + this->hp = 10; + this->energy = 10; + this->damage = 0; + std::cout << "ClapTrap " + this->name + " is created" << std::endl; +} + +ClapTrap::ClapTrap(const ClapTrap &clap) { + *this = clap; + std::cout << "ClapTrap " + this->name + " is created" << std::endl; +} + +ClapTrap::~ClapTrap() { + std::cout << "ClapTrap " + this->name + " is destroyed" << std::endl; +} + +ClapTrap& ClapTrap::operator=(const ClapTrap &clap) { + if (this != &clap) { + this->name = clap.name; + this->hp = clap.hp; + this->energy = clap.energy; + this->damage = clap.damage; + } + return *this; +} + +void ClapTrap::attack(const std::string& target) { + if (this->energy > 0 && this->hp > 0) { + std::cout << "ClapTrap " + this->name + " attacks " + target + ", causing " + << this->damage << " points of damage! " << std::endl; + this->energy--; + } + else + std::cout << this->name + " is out of combat" << std::endl; +} + +void ClapTrap::takeDamage(unsigned int amount) { + if (this->hp > 0) { + std::cout << this->name + " takes " << amount << " damages" << std::endl; + this->energy--; + this->hp -= amount; + } + else + std::cout << this->name + " is out of combat" << std::endl; +} + +void ClapTrap::beRepaired(unsigned int amount) { + if (this->energy > 0 && this->hp > 0) { + std::cout << this->name + " is repaired by " << amount << std::endl; + this->energy--; + this->hp += amount; + } + else + std::cout << this->name + " is out of combat" << std::endl; +} diff --git a/CPP03/ex02/ClapTrap.hpp b/CPP03/ex02/ClapTrap.hpp new file mode 100644 index 0000000..78fb07c --- /dev/null +++ b/CPP03/ex02/ClapTrap.hpp @@ -0,0 +1,25 @@ +#ifndef CLAPTRAP_HPP +# define CLAPTRAP_HPP + +#include + +class ClapTrap { + public: + ClapTrap(); + ClapTrap(std::string name); + ~ClapTrap(); + ClapTrap(const ClapTrap &clap); + ClapTrap& operator=(const ClapTrap &clap); + + void attack(const std::string& target); + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + + protected: + std::string name; + int hp; + int energy; + int damage; +}; + +#endif diff --git a/CPP03/ex02/FragTrap.cpp b/CPP03/ex02/FragTrap.cpp new file mode 100644 index 0000000..79c2198 --- /dev/null +++ b/CPP03/ex02/FragTrap.cpp @@ -0,0 +1,52 @@ +#include "FragTrap.hpp" + +FragTrap::FragTrap() : ClapTrap() { + this->name = "Default"; + this->hp = 100; + this->energy = 100; + this->damage = 30; + std::cout << "FragTrap " + this->name + " is created" << std::endl; +} + +FragTrap::FragTrap(std::string name) : ClapTrap() { + this->name = name; + this->hp = 100; + this->energy = 100; + this->damage = 30; + std::cout << "FragTrap " + this->name + " is created" << std::endl; +} + +FragTrap::FragTrap(const FragTrap &frag) : ClapTrap(frag) { + *this = frag; + std::cout << "FragTrap " + this->name + " is created" << std::endl; +} + +FragTrap::~FragTrap() { + std::cout << "FragTrap " + this->name + " is destroyed" << std::endl; +} + +FragTrap& FragTrap::operator=(const FragTrap &frag) { + if (this != &frag) { + ClapTrap::operator=(frag); + } + return *this; +} + +void FragTrap::attack(const std::string& target) { + if (this->energy > 0 && this->hp > 0) { + std::cout << "FragTrap " + this->name + " attacks " + target + ", causing " + << this->damage << " points of damage! " << std::endl; + this->energy--; + } + else + std::cout << this->name + " is out of combat" << std::endl; +} + +void FragTrap::highFivesGuys() { + if (this->energy > 0 && this->hp > 0) { + std::cout << "FragTrap " + this->name + " making a high fives" << std::endl; + this->energy--; + } + else + std::cout << this->name + " is out of combat" << std::endl; +} diff --git a/CPP03/ex02/FragTrap.hpp b/CPP03/ex02/FragTrap.hpp new file mode 100644 index 0000000..db81095 --- /dev/null +++ b/CPP03/ex02/FragTrap.hpp @@ -0,0 +1,19 @@ +#ifndef SCAVTRAP_HPP +# define SCAVTRAP_HPP + +#include "ClapTrap.hpp" +#include + +class FragTrap : public ClapTrap { + public: + FragTrap(); + FragTrap(std::string name); + ~FragTrap(); + FragTrap(const FragTrap &clap); + FragTrap& operator=(const FragTrap &clap); + + void attack(const std::string& target); + void highFivesGuys(); +}; + +#endif diff --git a/CPP03/ex02/Makefile b/CPP03/ex02/Makefile new file mode 100644 index 0000000..f3873d0 --- /dev/null +++ b/CPP03/ex02/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = FragTrap + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP03/ex02/ScavTrap.cpp b/CPP03/ex02/ScavTrap.cpp new file mode 100644 index 0000000..4086526 --- /dev/null +++ b/CPP03/ex02/ScavTrap.cpp @@ -0,0 +1,72 @@ +#include "ScavTrap.hpp" + +ScavTrap::ScavTrap() : ClapTrap() { + this->name = "Default"; + this->hp = 100; + this->energy = 50; + this->damage = 20; + std::cout << "ScavTrap " + this->name + " is created" << std::endl; +} + +ScavTrap::ScavTrap(std::string name) : ClapTrap() { + this->name = name; + this->hp = 100; + this->energy = 50; + this->damage = 20; + std::cout << "ScavTrap " + this->name + " is created" << std::endl; +} + +ScavTrap::ScavTrap(const ScavTrap &scav) : ClapTrap(scav) { + *this = scav; + std::cout << "ScavTrap " + this->name + " is created" << std::endl; +} + +ScavTrap::~ScavTrap() { + std::cout << "ScavTrap " + this->name + " is destroyed" << std::endl; +} + +ScavTrap& ScavTrap::operator=(const ScavTrap &scav) { + if (this != &scav) { + ClapTrap::operator=(scav); + } + return *this; +} + +void ScavTrap::attack(const std::string& target) { + if (this->energy > 0 && this->hp > 0) { + std::cout << "ScavTrap " + this->name + " attacks " + target + ", causing " + << this->damage << " points of damage! " << std::endl; + this->energy--; + } + else + std::cout << "ScavTrap " + this->name + " is out of combat" << std::endl; +} + +void ScavTrap::takeDamage(unsigned int amount) { + if (this->hp > 0) { + std::cout << "ScavTrap " + this->name + " takes " << amount << " damages" << std::endl; + this->energy--; + this->hp -= amount; + } + else + std::cout << "ScavTrap " + this->name + " is out of combat" << std::endl; +} + +void ScavTrap::beRepaired(unsigned int amount) { + if (this->energy > 0 && this->hp > 0) { + std::cout << "ScavTrap " + this->name + " is repaired by " << amount << std::endl; + this->energy--; + this->hp += amount; + } + else + std::cout << "ScavTrap " + this->name + " is out of combat" << std::endl; +} + +void ScavTrap::guardGate() { + if (this->energy > 0 && this->hp > 0) { + std::cout << "ScavTrap is now in Gate Keeper Mode" << std::endl; + this->energy--; + } + else + std::cout << "ScavTrap " + this->name + " is out of combat" << std::endl; +} diff --git a/CPP03/ex02/ScavTrap.hpp b/CPP03/ex02/ScavTrap.hpp new file mode 100644 index 0000000..5be5ca5 --- /dev/null +++ b/CPP03/ex02/ScavTrap.hpp @@ -0,0 +1,21 @@ +#ifndef SCAVTRAP_HPP +# define SCAVTRAP_HPP + +#include "ClapTrap.hpp" +#include + +class ScavTrap : public ClapTrap { + public: + ScavTrap(); + ScavTrap(std::string name); + ~ScavTrap(); + ScavTrap(const ScavTrap &clap); + ScavTrap& operator=(const ScavTrap &clap); + + void attack(const std::string& target); + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + void guardGate(); +}; + +#endif diff --git a/CPP03/ex02/main.cpp b/CPP03/ex02/main.cpp new file mode 100644 index 0000000..8fdeeab --- /dev/null +++ b/CPP03/ex02/main.cpp @@ -0,0 +1,54 @@ +#include "ClapTrap.hpp" +#include "FragTrap.hpp" + +int main(void) { + std::cout << "\n"; + FragTrap none; + FragTrap clapy("Clapy"); + ClapTrap clapo("Clapo"); + + std::cout << "\n----------------------------\n" << std::endl; + + none.attack("Clapy"); + none.takeDamage(100); + none.attack("Clapy"); + none.beRepaired(10); + + std::cout << "\n----------------------------\n" << std::endl; + + clapy.attack("Clapo"); + clapo.takeDamage(0); + clapy.takeDamage(50); + clapy.beRepaired(5); + clapy.takeDamage(50); + + for (int i = 0; i < 100; i++) + clapy.attack("Clapo"); + + std::cout << "\n----------------------------\n" << std::endl; + + { + FragTrap clapy2(clapy); + FragTrap clapy3 = clapy; + + clapy2.attack("Clapo"); + clapy3.attack("Clapo"); + } + + std::cout << "\n----------------------------\n" << std::endl; + + { + FragTrap five("Fifi"); + + five.highFivesGuys(); + five.takeDamage(100); + five.highFivesGuys(); + + ClapTrap *six = new FragTrap("Fyfy"); + + delete six; + } + + std::cout << "\n----------------------------\n" << std::endl; + +} diff --git a/CPP04/ex00/Animal.cpp b/CPP04/ex00/Animal.cpp new file mode 100644 index 0000000..20b94bb --- /dev/null +++ b/CPP04/ex00/Animal.cpp @@ -0,0 +1,29 @@ +#include "Animal.hpp" + +Animal::Animal() { + std::cout << "Animal born" << std::endl; + this->type = "Animal"; +} + +Animal::Animal(const Animal &other) { + *this = other; +} + +Animal& Animal::operator=(const Animal &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +Animal::~Animal() { + std::cout << "Animal die" << std::endl; +} + +std::string Animal::getType() const { + return type; +} + +void Animal::makeSound() const { + std::cout << "Animal Sound" << std::endl; +} diff --git a/CPP04/ex00/Animal.hpp b/CPP04/ex00/Animal.hpp new file mode 100644 index 0000000..55ac518 --- /dev/null +++ b/CPP04/ex00/Animal.hpp @@ -0,0 +1,20 @@ +#ifndef ANIMAL_HPP +# define ANIMAL_HPP + +# include + +class Animal { + public: + Animal(); + virtual ~Animal(); + Animal(const Animal &other); + Animal& operator=(const Animal &other); + + virtual void makeSound() const; + std::string getType() const; + + protected: + std::string type; +}; + +#endif diff --git a/CPP04/ex00/Cat.cpp b/CPP04/ex00/Cat.cpp new file mode 100644 index 0000000..a3c7d70 --- /dev/null +++ b/CPP04/ex00/Cat.cpp @@ -0,0 +1,25 @@ +#include "Cat.hpp" + +Cat::Cat() { + std::cout << "Cat born" << std::endl; + this->type = "Cat"; +} + +Cat::Cat(const Cat &other) : Animal() { + *this = other; +} + +Cat& Cat::operator=(const Cat &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +Cat::~Cat() { + std::cout << "Cat die" << std::endl; +} + +void Cat::makeSound() const { + std::cout << "Miaou" << std::endl; +} diff --git a/CPP04/ex00/Cat.hpp b/CPP04/ex00/Cat.hpp new file mode 100644 index 0000000..04a516d --- /dev/null +++ b/CPP04/ex00/Cat.hpp @@ -0,0 +1,16 @@ +#ifndef CAT_HPP +# define CAT_HPP + +#include "Animal.hpp" + +class Cat : public Animal { + public: + Cat(); + ~Cat(); + Cat(const Cat &other); + Cat& operator=(const Cat &other); + + virtual void makeSound() const; +}; + +#endif diff --git a/CPP04/ex00/Dog.cpp b/CPP04/ex00/Dog.cpp new file mode 100644 index 0000000..f4d7cd3 --- /dev/null +++ b/CPP04/ex00/Dog.cpp @@ -0,0 +1,25 @@ +#include "Dog.hpp" + +Dog::Dog() { + std::cout << "Dog born" << std::endl; + this->type = "Dog"; +} + +Dog::Dog(const Dog &other) : Animal() { + *this = other; +} + +Dog& Dog::operator=(const Dog &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +Dog::~Dog() { + std::cout << "Dog die" << std::endl; +} + +void Dog::makeSound() const { + std::cout << "Waf" << std::endl; +} diff --git a/CPP04/ex00/Dog.hpp b/CPP04/ex00/Dog.hpp new file mode 100644 index 0000000..0102250 --- /dev/null +++ b/CPP04/ex00/Dog.hpp @@ -0,0 +1,16 @@ +#ifndef DOG_HPP +# define DOG_HPP + +#include "Animal.hpp" + +class Dog : public Animal { + public: + Dog(); + ~Dog(); + Dog(const Dog &other); + Dog& operator=(const Dog &other); + + virtual void makeSound() const; +}; + +#endif diff --git a/CPP04/ex00/Makefile b/CPP04/ex00/Makefile new file mode 100644 index 0000000..e361d75 --- /dev/null +++ b/CPP04/ex00/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Animal + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP04/ex00/WrongAnimal.cpp b/CPP04/ex00/WrongAnimal.cpp new file mode 100644 index 0000000..ed845b9 --- /dev/null +++ b/CPP04/ex00/WrongAnimal.cpp @@ -0,0 +1,29 @@ +#include "WrongAnimal.hpp" + +WrongAnimal::WrongAnimal() { + std::cout << "WrongAnimal born" << std::endl; + this->type = "WrongAnimal"; +} + +WrongAnimal::WrongAnimal(const WrongAnimal &other) { + *this = other; +} + +WrongAnimal& WrongAnimal::operator=(const WrongAnimal &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +WrongAnimal::~WrongAnimal() { + std::cout << "WrongAnimal die" << std::endl; +} + +std::string WrongAnimal::getType() const { + return type; +} + +void WrongAnimal::makeSound() const { + std::cout << "WrongAnimal Sound" << std::endl; +} diff --git a/CPP04/ex00/WrongAnimal.hpp b/CPP04/ex00/WrongAnimal.hpp new file mode 100644 index 0000000..2017dc8 --- /dev/null +++ b/CPP04/ex00/WrongAnimal.hpp @@ -0,0 +1,20 @@ +#ifndef WRONGANIMAL_HPP +# define WRONGANIMAL_HPP + +# include + +class WrongAnimal { + public: + WrongAnimal(); + virtual ~WrongAnimal(); + WrongAnimal(const WrongAnimal &other); + WrongAnimal& operator=(const WrongAnimal &other); + + void makeSound() const; + std::string getType() const; + + protected: + std::string type; +}; + +#endif diff --git a/CPP04/ex00/WrongCat.cpp b/CPP04/ex00/WrongCat.cpp new file mode 100644 index 0000000..a2616dc --- /dev/null +++ b/CPP04/ex00/WrongCat.cpp @@ -0,0 +1,25 @@ +#include "WrongCat.hpp" + +WrongCat::WrongCat() { + std::cout << "WrongCat born" << std::endl; + this->type = "WrongCat"; +} + +WrongCat::WrongCat(const WrongCat &other) : WrongAnimal() { + *this = other; +} + +WrongCat& WrongCat::operator=(const WrongCat &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +WrongCat::~WrongCat() { + std::cout << "WrongCat die" << std::endl; +} + +void WrongCat::makeSound() const { + std::cout << "Meuh" << std::endl; +} diff --git a/CPP04/ex00/WrongCat.hpp b/CPP04/ex00/WrongCat.hpp new file mode 100644 index 0000000..45cd22f --- /dev/null +++ b/CPP04/ex00/WrongCat.hpp @@ -0,0 +1,16 @@ +#ifndef WRONGCAT_HPP +# define WRONGCAT_HPP + +#include "WrongAnimal.hpp" + +class WrongCat : public WrongAnimal { + public: + WrongCat(); + ~WrongCat(); + WrongCat(const WrongCat &other); + WrongCat& operator=(const WrongCat &other); + + void makeSound() const; +}; + +#endif diff --git a/CPP04/ex00/main.cpp b/CPP04/ex00/main.cpp new file mode 100644 index 0000000..f6d8750 --- /dev/null +++ b/CPP04/ex00/main.cpp @@ -0,0 +1,59 @@ +#include "Animal.hpp" +#include "WrongAnimal.hpp" +#include "Cat.hpp" +#include "WrongCat.hpp" +#include "Dog.hpp" + +int main() { + + std::cout << "\n--Test0--\n" << std::endl; + { + const Animal* meta = new Animal(); + const Animal* dog = new Dog(); + const Animal* cat = new Cat(); + + std::cout << "\n"; + + std::cout << "animal: " + meta->getType() << std::endl; + std::cout << "dog: " + dog->getType() << std::endl; + std::cout << "cat: " + cat->getType() << std::endl; + std::cout << "dog Sound : "; + dog->makeSound(); + std::cout << "cat Sound : "; + cat->makeSound(); + std::cout << "animal Sound : "; + meta->makeSound(); + + std::cout << "\n"; + + delete meta; + delete dog; + delete cat; + } + + std::cout << "\n--Test1--\n" << std::endl; + + { + const WrongAnimal* wrongAnimal = new WrongAnimal(); + const WrongAnimal* wrongCat = new WrongCat(); + + std::cout << "\n"; + + std::cout << "WrongAnimal: " + wrongAnimal->getType() << std::endl; + std::cout << "WrongCat: " + wrongCat->getType() << std::endl; + + std::cout << "WrongAnimal Sound : "; + wrongAnimal->makeSound(); + std::cout << "WrongCat Sound : "; + wrongCat->makeSound(); + + std::cout << "\n"; + + delete wrongAnimal; + delete wrongCat; + } + + std::cout << "\n--End--\n" << std::endl; + + return (0); +} diff --git a/CPP04/ex01/Animal.cpp b/CPP04/ex01/Animal.cpp new file mode 100644 index 0000000..20b94bb --- /dev/null +++ b/CPP04/ex01/Animal.cpp @@ -0,0 +1,29 @@ +#include "Animal.hpp" + +Animal::Animal() { + std::cout << "Animal born" << std::endl; + this->type = "Animal"; +} + +Animal::Animal(const Animal &other) { + *this = other; +} + +Animal& Animal::operator=(const Animal &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +Animal::~Animal() { + std::cout << "Animal die" << std::endl; +} + +std::string Animal::getType() const { + return type; +} + +void Animal::makeSound() const { + std::cout << "Animal Sound" << std::endl; +} diff --git a/CPP04/ex01/Animal.hpp b/CPP04/ex01/Animal.hpp new file mode 100644 index 0000000..55ac518 --- /dev/null +++ b/CPP04/ex01/Animal.hpp @@ -0,0 +1,20 @@ +#ifndef ANIMAL_HPP +# define ANIMAL_HPP + +# include + +class Animal { + public: + Animal(); + virtual ~Animal(); + Animal(const Animal &other); + Animal& operator=(const Animal &other); + + virtual void makeSound() const; + std::string getType() const; + + protected: + std::string type; +}; + +#endif diff --git a/CPP04/ex01/Brain.cpp b/CPP04/ex01/Brain.cpp new file mode 100644 index 0000000..4c2133e --- /dev/null +++ b/CPP04/ex01/Brain.cpp @@ -0,0 +1,21 @@ +#include "Brain.hpp" + +Brain::Brain() { + std::cout << "Brain created" << std::endl; +} + +Brain::~Brain() { + std::cout << "Brain destroyed" << std::endl; +} + +Brain::Brain(const Brain &other) { + *this = other; +} + +Brain& Brain::operator=(const Brain &other) { + if (this != &other) { + for (int i = 0; i < 100; i++) + this->ideas[i] = other.ideas[i]; + } + return *this; +} diff --git a/CPP04/ex01/Brain.hpp b/CPP04/ex01/Brain.hpp new file mode 100644 index 0000000..b819349 --- /dev/null +++ b/CPP04/ex01/Brain.hpp @@ -0,0 +1,18 @@ +#ifndef BRAIN_HPP +# define BRAIN_HPP + +#include +#include + +class Brain { + public: + Brain(); + ~Brain(); + Brain(const Brain &other); + Brain& operator=(const Brain &other); + + private: + std::string ideas[100]; +}; + +#endif diff --git a/CPP04/ex01/Cat.cpp b/CPP04/ex01/Cat.cpp new file mode 100644 index 0000000..95ae22a --- /dev/null +++ b/CPP04/ex01/Cat.cpp @@ -0,0 +1,29 @@ +#include "Cat.hpp" + +Cat::Cat() : Animal() { + std::cout << "Cat born" << std::endl; + this->type = "Cat"; + this->brain = new Brain(); +} + +Cat::Cat(const Cat &other) : Animal() { + this->brain = new Brain(); + *this = other; +} + +Cat& Cat::operator=(const Cat &other) { + if (this != &other) { + this->type = other.type; + *this->brain = *other.brain; + } + return (*this); +} + +Cat::~Cat() { + std::cout << "Cat die" << std::endl; + delete this->brain; +} + +void Cat::makeSound() const { + std::cout << "Miaou" << std::endl; +} diff --git a/CPP04/ex01/Cat.hpp b/CPP04/ex01/Cat.hpp new file mode 100644 index 0000000..6bd7fcc --- /dev/null +++ b/CPP04/ex01/Cat.hpp @@ -0,0 +1,20 @@ +#ifndef CAT_HPP +# define CAT_HPP + +#include "Animal.hpp" +#include "Brain.hpp" + +class Cat : public Animal { + public: + Cat(); + ~Cat(); + Cat(const Cat &other); + Cat& operator=(const Cat &other); + + virtual void makeSound() const; + + private: + Brain *brain; +}; + +#endif diff --git a/CPP04/ex01/Dog.cpp b/CPP04/ex01/Dog.cpp new file mode 100644 index 0000000..915b16e --- /dev/null +++ b/CPP04/ex01/Dog.cpp @@ -0,0 +1,29 @@ +#include "Dog.hpp" + +Dog::Dog() : Animal() { + std::cout << "Dog born" << std::endl; + this->type = "Dog"; + this->brain = new Brain(); +} + +Dog::Dog(const Dog &other) : Animal() { + this->brain = new Brain(); + *this = other; +} + +Dog& Dog::operator=(const Dog &other) { + if (this != &other) { + this->type = other.type; + *this->brain = *other.brain; + } + return (*this); +} + +Dog::~Dog() { + std::cout << "Dog die" << std::endl; + delete this->brain; +} + +void Dog::makeSound() const { + std::cout << "Waf" << std::endl; +} diff --git a/CPP04/ex01/Dog.hpp b/CPP04/ex01/Dog.hpp new file mode 100644 index 0000000..1708a69 --- /dev/null +++ b/CPP04/ex01/Dog.hpp @@ -0,0 +1,20 @@ +#ifndef DOG_HPP +# define DOG_HPP + +#include "Animal.hpp" +#include "Brain.hpp" + +class Dog : public Animal { + public: + Dog(); + ~Dog(); + Dog(const Dog &other); + Dog& operator=(const Dog &other); + + virtual void makeSound() const; + + private: + Brain *brain; +}; + +#endif diff --git a/CPP04/ex01/Makefile b/CPP04/ex01/Makefile new file mode 100644 index 0000000..36a7ef9 --- /dev/null +++ b/CPP04/ex01/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Brain + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP04/ex01/WrongAnimal.cpp b/CPP04/ex01/WrongAnimal.cpp new file mode 100644 index 0000000..ed845b9 --- /dev/null +++ b/CPP04/ex01/WrongAnimal.cpp @@ -0,0 +1,29 @@ +#include "WrongAnimal.hpp" + +WrongAnimal::WrongAnimal() { + std::cout << "WrongAnimal born" << std::endl; + this->type = "WrongAnimal"; +} + +WrongAnimal::WrongAnimal(const WrongAnimal &other) { + *this = other; +} + +WrongAnimal& WrongAnimal::operator=(const WrongAnimal &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +WrongAnimal::~WrongAnimal() { + std::cout << "WrongAnimal die" << std::endl; +} + +std::string WrongAnimal::getType() const { + return type; +} + +void WrongAnimal::makeSound() const { + std::cout << "WrongAnimal Sound" << std::endl; +} diff --git a/CPP04/ex01/WrongAnimal.hpp b/CPP04/ex01/WrongAnimal.hpp new file mode 100644 index 0000000..2017dc8 --- /dev/null +++ b/CPP04/ex01/WrongAnimal.hpp @@ -0,0 +1,20 @@ +#ifndef WRONGANIMAL_HPP +# define WRONGANIMAL_HPP + +# include + +class WrongAnimal { + public: + WrongAnimal(); + virtual ~WrongAnimal(); + WrongAnimal(const WrongAnimal &other); + WrongAnimal& operator=(const WrongAnimal &other); + + void makeSound() const; + std::string getType() const; + + protected: + std::string type; +}; + +#endif diff --git a/CPP04/ex01/WrongCat.cpp b/CPP04/ex01/WrongCat.cpp new file mode 100644 index 0000000..a2616dc --- /dev/null +++ b/CPP04/ex01/WrongCat.cpp @@ -0,0 +1,25 @@ +#include "WrongCat.hpp" + +WrongCat::WrongCat() { + std::cout << "WrongCat born" << std::endl; + this->type = "WrongCat"; +} + +WrongCat::WrongCat(const WrongCat &other) : WrongAnimal() { + *this = other; +} + +WrongCat& WrongCat::operator=(const WrongCat &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +WrongCat::~WrongCat() { + std::cout << "WrongCat die" << std::endl; +} + +void WrongCat::makeSound() const { + std::cout << "Meuh" << std::endl; +} diff --git a/CPP04/ex01/WrongCat.hpp b/CPP04/ex01/WrongCat.hpp new file mode 100644 index 0000000..45cd22f --- /dev/null +++ b/CPP04/ex01/WrongCat.hpp @@ -0,0 +1,16 @@ +#ifndef WRONGCAT_HPP +# define WRONGCAT_HPP + +#include "WrongAnimal.hpp" + +class WrongCat : public WrongAnimal { + public: + WrongCat(); + ~WrongCat(); + WrongCat(const WrongCat &other); + WrongCat& operator=(const WrongCat &other); + + void makeSound() const; +}; + +#endif diff --git a/CPP04/ex01/main.cpp b/CPP04/ex01/main.cpp new file mode 100644 index 0000000..a225900 --- /dev/null +++ b/CPP04/ex01/main.cpp @@ -0,0 +1,33 @@ +#include "Animal.hpp" +#include "WrongAnimal.hpp" +#include "Cat.hpp" +#include "WrongCat.hpp" +#include "Dog.hpp" + +int main() { + + std::cout << "\n--Test0--\n" << std::endl; + { + Cat cat1; + { + Cat cat2 = cat1; + } + } + std::cout << "\n--Test1--\n" << std::endl; + { + Dog dog1; + { + Dog dog2(dog1); + dog1 = dog2; + dog2 = dog1; + } + } + std::cout << "\n--Test2--\n" << std::endl; + { + Animal *dogo = new Dog(); + delete dogo; + } + std::cout << "\n--End--\n" << std::endl; + + return (0); +} diff --git a/CPP04/ex02/Animal.cpp b/CPP04/ex02/Animal.cpp new file mode 100644 index 0000000..30fa334 --- /dev/null +++ b/CPP04/ex02/Animal.cpp @@ -0,0 +1,25 @@ +#include "Animal.hpp" + +Animal::Animal() { + std::cout << "Animal born" << std::endl; + this->type = "Animal"; +} + +Animal::Animal(const Animal &other) { + *this = other; +} + +Animal& Animal::operator=(const Animal &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +Animal::~Animal() { + std::cout << "Animal die" << std::endl; +} + +std::string Animal::getType() const { + return type; +} diff --git a/CPP04/ex02/Animal.hpp b/CPP04/ex02/Animal.hpp new file mode 100644 index 0000000..bd14943 --- /dev/null +++ b/CPP04/ex02/Animal.hpp @@ -0,0 +1,20 @@ +#ifndef ANIMAL_HPP +# define ANIMAL_HPP + +# include + +class Animal { + public: + Animal(); + virtual ~Animal(); + Animal(const Animal &other); + Animal& operator=(const Animal &other); + + virtual void makeSound() const = 0; + std::string getType() const; + + protected: + std::string type; +}; + +#endif diff --git a/CPP04/ex02/Brain.cpp b/CPP04/ex02/Brain.cpp new file mode 100644 index 0000000..bdc0ce7 --- /dev/null +++ b/CPP04/ex02/Brain.cpp @@ -0,0 +1,21 @@ +#include "Brain.hpp" + +Brain::Brain() { + std::cout << "Brain created" << std::endl; +} + +Brain::~Brain() { + std::cout << "Brain Destroyed" << std::endl; +} + +Brain::Brain(const Brain &other) { + *this = other; +} + +Brain& Brain::operator=(const Brain &other) { + if (this != &other) { + for (int i = 0; i < 100; i++) + this->ideas[i] = other.ideas[i]; + } + return *this; +} diff --git a/CPP04/ex02/Brain.hpp b/CPP04/ex02/Brain.hpp new file mode 100644 index 0000000..b819349 --- /dev/null +++ b/CPP04/ex02/Brain.hpp @@ -0,0 +1,18 @@ +#ifndef BRAIN_HPP +# define BRAIN_HPP + +#include +#include + +class Brain { + public: + Brain(); + ~Brain(); + Brain(const Brain &other); + Brain& operator=(const Brain &other); + + private: + std::string ideas[100]; +}; + +#endif diff --git a/CPP04/ex02/Cat.cpp b/CPP04/ex02/Cat.cpp new file mode 100644 index 0000000..95ae22a --- /dev/null +++ b/CPP04/ex02/Cat.cpp @@ -0,0 +1,29 @@ +#include "Cat.hpp" + +Cat::Cat() : Animal() { + std::cout << "Cat born" << std::endl; + this->type = "Cat"; + this->brain = new Brain(); +} + +Cat::Cat(const Cat &other) : Animal() { + this->brain = new Brain(); + *this = other; +} + +Cat& Cat::operator=(const Cat &other) { + if (this != &other) { + this->type = other.type; + *this->brain = *other.brain; + } + return (*this); +} + +Cat::~Cat() { + std::cout << "Cat die" << std::endl; + delete this->brain; +} + +void Cat::makeSound() const { + std::cout << "Miaou" << std::endl; +} diff --git a/CPP04/ex02/Cat.hpp b/CPP04/ex02/Cat.hpp new file mode 100644 index 0000000..6bd7fcc --- /dev/null +++ b/CPP04/ex02/Cat.hpp @@ -0,0 +1,20 @@ +#ifndef CAT_HPP +# define CAT_HPP + +#include "Animal.hpp" +#include "Brain.hpp" + +class Cat : public Animal { + public: + Cat(); + ~Cat(); + Cat(const Cat &other); + Cat& operator=(const Cat &other); + + virtual void makeSound() const; + + private: + Brain *brain; +}; + +#endif diff --git a/CPP04/ex02/Dog.cpp b/CPP04/ex02/Dog.cpp new file mode 100644 index 0000000..915b16e --- /dev/null +++ b/CPP04/ex02/Dog.cpp @@ -0,0 +1,29 @@ +#include "Dog.hpp" + +Dog::Dog() : Animal() { + std::cout << "Dog born" << std::endl; + this->type = "Dog"; + this->brain = new Brain(); +} + +Dog::Dog(const Dog &other) : Animal() { + this->brain = new Brain(); + *this = other; +} + +Dog& Dog::operator=(const Dog &other) { + if (this != &other) { + this->type = other.type; + *this->brain = *other.brain; + } + return (*this); +} + +Dog::~Dog() { + std::cout << "Dog die" << std::endl; + delete this->brain; +} + +void Dog::makeSound() const { + std::cout << "Waf" << std::endl; +} diff --git a/CPP04/ex02/Dog.hpp b/CPP04/ex02/Dog.hpp new file mode 100644 index 0000000..1708a69 --- /dev/null +++ b/CPP04/ex02/Dog.hpp @@ -0,0 +1,20 @@ +#ifndef DOG_HPP +# define DOG_HPP + +#include "Animal.hpp" +#include "Brain.hpp" + +class Dog : public Animal { + public: + Dog(); + ~Dog(); + Dog(const Dog &other); + Dog& operator=(const Dog &other); + + virtual void makeSound() const; + + private: + Brain *brain; +}; + +#endif diff --git a/CPP04/ex02/Makefile b/CPP04/ex02/Makefile new file mode 100644 index 0000000..d59f12c --- /dev/null +++ b/CPP04/ex02/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Abstract + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP04/ex02/WrongAnimal.cpp b/CPP04/ex02/WrongAnimal.cpp new file mode 100644 index 0000000..ed845b9 --- /dev/null +++ b/CPP04/ex02/WrongAnimal.cpp @@ -0,0 +1,29 @@ +#include "WrongAnimal.hpp" + +WrongAnimal::WrongAnimal() { + std::cout << "WrongAnimal born" << std::endl; + this->type = "WrongAnimal"; +} + +WrongAnimal::WrongAnimal(const WrongAnimal &other) { + *this = other; +} + +WrongAnimal& WrongAnimal::operator=(const WrongAnimal &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +WrongAnimal::~WrongAnimal() { + std::cout << "WrongAnimal die" << std::endl; +} + +std::string WrongAnimal::getType() const { + return type; +} + +void WrongAnimal::makeSound() const { + std::cout << "WrongAnimal Sound" << std::endl; +} diff --git a/CPP04/ex02/WrongAnimal.hpp b/CPP04/ex02/WrongAnimal.hpp new file mode 100644 index 0000000..2017dc8 --- /dev/null +++ b/CPP04/ex02/WrongAnimal.hpp @@ -0,0 +1,20 @@ +#ifndef WRONGANIMAL_HPP +# define WRONGANIMAL_HPP + +# include + +class WrongAnimal { + public: + WrongAnimal(); + virtual ~WrongAnimal(); + WrongAnimal(const WrongAnimal &other); + WrongAnimal& operator=(const WrongAnimal &other); + + void makeSound() const; + std::string getType() const; + + protected: + std::string type; +}; + +#endif diff --git a/CPP04/ex02/WrongCat.cpp b/CPP04/ex02/WrongCat.cpp new file mode 100644 index 0000000..a2616dc --- /dev/null +++ b/CPP04/ex02/WrongCat.cpp @@ -0,0 +1,25 @@ +#include "WrongCat.hpp" + +WrongCat::WrongCat() { + std::cout << "WrongCat born" << std::endl; + this->type = "WrongCat"; +} + +WrongCat::WrongCat(const WrongCat &other) : WrongAnimal() { + *this = other; +} + +WrongCat& WrongCat::operator=(const WrongCat &other) { + if (this != &other) { + this->type = other.type; + } + return (*this); +} + +WrongCat::~WrongCat() { + std::cout << "WrongCat die" << std::endl; +} + +void WrongCat::makeSound() const { + std::cout << "Meuh" << std::endl; +} diff --git a/CPP04/ex02/WrongCat.hpp b/CPP04/ex02/WrongCat.hpp new file mode 100644 index 0000000..45cd22f --- /dev/null +++ b/CPP04/ex02/WrongCat.hpp @@ -0,0 +1,16 @@ +#ifndef WRONGCAT_HPP +# define WRONGCAT_HPP + +#include "WrongAnimal.hpp" + +class WrongCat : public WrongAnimal { + public: + WrongCat(); + ~WrongCat(); + WrongCat(const WrongCat &other); + WrongCat& operator=(const WrongCat &other); + + void makeSound() const; +}; + +#endif diff --git a/CPP04/ex02/main.cpp b/CPP04/ex02/main.cpp new file mode 100644 index 0000000..6425679 --- /dev/null +++ b/CPP04/ex02/main.cpp @@ -0,0 +1,26 @@ +#include "Animal.hpp" +#include "WrongAnimal.hpp" +#include "Cat.hpp" +#include "WrongCat.hpp" +#include "Dog.hpp" + +int main() { + + std::cout << "\n--Test0--\n" << std::endl; + { + const Animal* cat1 = new Cat(); + Dog dogo; + cat1->makeSound(); + dogo.makeSound(); + delete cat1; + } + std::cout << "\n--Test1--\n" << std::endl; + { + //Animal animal; + + //animal.makeSound(); + } + std::cout << "\n--End--\n" << std::endl; + + return (0); +} diff --git a/CPP05/ex00/Bureaucrat.cpp b/CPP05/ex00/Bureaucrat.cpp new file mode 100644 index 0000000..200b017 --- /dev/null +++ b/CPP05/ex00/Bureaucrat.cpp @@ -0,0 +1,61 @@ +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat() : name("") { + this->grade = 150; +} + +Bureaucrat::Bureaucrat(std::string name, int grade) :name(name){ + if (grade > 150) + throw Bureaucrat::GradeTooLowException(); + else if (grade < 1) + throw Bureaucrat::GradeTooHighException(); + this->grade = grade; +} + +Bureaucrat::~Bureaucrat() { +} + +Bureaucrat::Bureaucrat(const Bureaucrat &other) : name(other.name) { + *this = other; +} + +Bureaucrat &Bureaucrat::operator=(const Bureaucrat &other) { + if (this != &other) { + this->grade = other.grade; + } + return (*this); +} + +std::string Bureaucrat::getName() const { + return this->name; +} + +int Bureaucrat::getGrade() const { + return this->grade; +} + +void Bureaucrat::increaseGrade() { + if (this->grade <= 1) + throw Bureaucrat::GradeTooHighException(); + this->grade--; +} + +void Bureaucrat::decreaseGrade() { + if (this->grade >= 150) + throw Bureaucrat::GradeTooLowException(); + this->grade++; +} + +std::ostream& operator<<( std::ostream& os, Bureaucrat const& crat ) { + return os << crat.getName() << ", bureaucrat grade " << crat.getGrade() << "." << std::endl; +} + + +char const* Bureaucrat::GradeTooHighException::what() const throw() { + return "Grade is too high"; +} + +char const* Bureaucrat::GradeTooLowException::what() const throw() { + return "Grade is too low"; +} + diff --git a/CPP05/ex00/Bureaucrat.hpp b/CPP05/ex00/Bureaucrat.hpp new file mode 100644 index 0000000..25277d1 --- /dev/null +++ b/CPP05/ex00/Bureaucrat.hpp @@ -0,0 +1,39 @@ +#ifndef BUREAUCRAT_HPP +# define BUREAUCRAT_HPP + +# include +# include + +class Bureaucrat { + public: + class GradeTooHighException : public std::exception { + public: + char const* what() const throw(); + }; + + class GradeTooLowException : public std::exception { + public: + char const* what() const throw(); + }; + + Bureaucrat(); + Bureaucrat(std::string name, int grade); + ~Bureaucrat(); + Bureaucrat(const Bureaucrat &other); + Bureaucrat &operator=(const Bureaucrat &other); + + std::string getName() const; + int getGrade() const; + void setName(std::string name); + + void increaseGrade(); + void decreaseGrade(); + + private: + const std::string name; + int grade; +}; + +std::ostream& operator<<(std::ostream& os, Bureaucrat const& crat); + +#endif diff --git a/CPP05/ex00/Makefile b/CPP05/ex00/Makefile new file mode 100644 index 0000000..a258c5c --- /dev/null +++ b/CPP05/ex00/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Bureaucrat + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP05/ex00/main.cpp b/CPP05/ex00/main.cpp new file mode 100644 index 0000000..dfceed1 --- /dev/null +++ b/CPP05/ex00/main.cpp @@ -0,0 +1,52 @@ +#include "Bureaucrat.hpp" + +int main() { + std::cout << "\n---Test---\n" << std::endl; + + try { + Bureaucrat toto("toto", 151); + } + catch (std::exception & e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n----------------\n" << std::endl; + + try { + Bureaucrat toto("toto", 0); + } + catch (std::exception & e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n----------------\n" << std::endl; + + try { + Bureaucrat toto("toto", -515); + } + catch (std::exception & e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n----------------\n" << std::endl; + + try { + Bureaucrat toto("toto", 5); + std::cout << toto << std::endl; + toto.decreaseGrade(); + std::cout << toto << std::endl; + toto.increaseGrade(); + toto.increaseGrade(); + toto.increaseGrade(); + toto.increaseGrade(); + toto.increaseGrade(); + std::cout << toto << std::endl; + toto.increaseGrade(); + std::cout << toto << std::endl; + } + catch (std::exception & e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n---End Test---\n" << std::endl; +} diff --git a/CPP05/ex01/Bureaucrat.cpp b/CPP05/ex01/Bureaucrat.cpp new file mode 100644 index 0000000..b0a59aa --- /dev/null +++ b/CPP05/ex01/Bureaucrat.cpp @@ -0,0 +1,74 @@ +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat() : name("") { + this->grade = 150; +} + +Bureaucrat::Bureaucrat(std::string name, int grade) :name(name){ + if (grade > 150) + throw Bureaucrat::GradeTooLowException(); + else if (grade < 1) + throw Bureaucrat::GradeTooHighException(); + this->grade = grade; +} + +Bureaucrat::~Bureaucrat() { +} + +Bureaucrat::Bureaucrat(const Bureaucrat &other) : name(other.name) { + *this = other; +} + +Bureaucrat &Bureaucrat::operator=(const Bureaucrat &other) { + if (this != &other) { + this->grade = other.grade; + } + return (*this); +} + +std::string Bureaucrat::getName() const { + return this->name; +} + +int Bureaucrat::getGrade() const { + return this->grade; +} + +void Bureaucrat::increaseGrade() { + if (this->grade <= 1) + throw Bureaucrat::GradeTooHighException(); + this->grade--; +} + +void Bureaucrat::decreaseGrade() { + if (this->grade >= 150) + throw Bureaucrat::GradeTooLowException(); + this->grade++; +} + +void Bureaucrat::signForm(Form &form) { + if (form.isSigned()) { + std::cout << name << " couldn't sign " << form.getName() << " because it's already signed" << std::endl; + return; + } + try { + form.beSigned(*this); + std::cout << name << " signed " << form.getName() << std::endl; + } + catch (std::exception & e) { + std::cout << name << " couldn't sign " << form.getName() << " because grade too low" << std::endl; + } +} + +std::ostream& operator<<( std::ostream& os, Bureaucrat const& crat ) { + return os << crat.getName() << ", bureaucrat grade " << crat.getGrade() << "." << std::endl; +} + +char const* Bureaucrat::GradeTooHighException::what() const throw() { + return "Grade is too high"; +} + +char const* Bureaucrat::GradeTooLowException::what() const throw() { + return "Grade is too low"; +} + diff --git a/CPP05/ex01/Bureaucrat.hpp b/CPP05/ex01/Bureaucrat.hpp new file mode 100644 index 0000000..4c80c7e --- /dev/null +++ b/CPP05/ex01/Bureaucrat.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include +#include +#include "Form.hpp" + +class Form; + +class Bureaucrat { + public: + class GradeTooHighException : public std::exception { + public: + char const* what() const throw(); + }; + + class GradeTooLowException : public std::exception { + public: + char const* what() const throw(); + }; + + Bureaucrat(); + Bureaucrat(std::string name, int grade); + ~Bureaucrat(); + Bureaucrat(const Bureaucrat &other); + Bureaucrat &operator=(const Bureaucrat &other); + + std::string getName() const; + int getGrade() const; + void setName(std::string name); + + void increaseGrade(); + void decreaseGrade(); + + void signForm(Form &form); + + private: + const std::string name; + int grade; +}; + +std::ostream& operator<<(std::ostream& os, Bureaucrat const& crat); diff --git a/CPP05/ex01/Form.cpp b/CPP05/ex01/Form.cpp new file mode 100644 index 0000000..3c29c14 --- /dev/null +++ b/CPP05/ex01/Form.cpp @@ -0,0 +1,61 @@ +#include "Form.hpp" + +Form::Form() : name(""), sign(false), grade(150), gradeExec(150) { +} + +Form::Form(std::string name, int grade, int gradeExec) + : name(name), sign(false), grade(grade), gradeExec(gradeExec) { + if (grade > 150 || gradeExec > 151) + throw Form::GradeTooLowException(); + if (grade < 1 || gradeExec < 1) + throw Form::GradeTooHighException(); +} + +Form::~Form() { +} + +Form::Form(const Form &form) : name(form.name), grade(form.grade), gradeExec(form.gradeExec) { + *this = form; +} + +Form &Form::operator=(const Form &form) { + if (this != &form) { + this->sign = form.sign; + } + return *this; +} + +std::string Form::getName() const { + return this->name; +} + +bool Form::isSigned() const { + return this->sign; +} + +int Form::getGrade() const { + return this->grade; +} + +int Form::getGradeExec() const { + return this->gradeExec; +} + +void Form::beSigned(Bureaucrat &crat) { + if (crat.getGrade() > this->grade) + throw Form::GradeTooLowException(); + this->sign = true; +} + +std::ostream& operator<<( std::ostream& os, Form const& form ) { + return os << "name:" << form.getName() << " sign:" << form.isSigned() + << " grade:" << form.getGrade() << " gradeExec:" << form.getGradeExec() << std::endl; +} + +char const* Form::GradeTooHighException::what() const throw() { + return "Grade is too high"; +} + +char const* Form::GradeTooLowException::what() const throw() { + return "Grade is too low"; +} diff --git a/CPP05/ex01/Form.hpp b/CPP05/ex01/Form.hpp new file mode 100644 index 0000000..7a25ea3 --- /dev/null +++ b/CPP05/ex01/Form.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "Bureaucrat.hpp" + +class Bureaucrat; + +class Form { + public: + class GradeTooHighException : public std::exception { + public: + char const* what() const throw(); + }; + + class GradeTooLowException : public std::exception { + public: + char const* what() const throw(); + }; + + Form(); + Form(std::string name, int grade, int gradeExec); + ~Form(); + Form(const Form &form); + Form &operator=(const Form &form); + + std::string getName() const; + bool isSigned() const; + int getGrade() const; + int getGradeExec() const; + + void beSigned(Bureaucrat &crat); + + private: + const std::string name; + bool sign; + const int grade; + const int gradeExec; +}; + +std::ostream& operator<<(std::ostream& os, Form const& form); diff --git a/CPP05/ex01/Makefile b/CPP05/ex01/Makefile new file mode 100644 index 0000000..a258c5c --- /dev/null +++ b/CPP05/ex01/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Bureaucrat + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP05/ex01/main.cpp b/CPP05/ex01/main.cpp new file mode 100644 index 0000000..8c383f8 --- /dev/null +++ b/CPP05/ex01/main.cpp @@ -0,0 +1,39 @@ +#include "Bureaucrat.hpp" +#include "Form.hpp" + +int main() { + std::cout << "\n---Test---\n" << std::endl; + + try { + Form form("toto", 151, 150); + } + catch (std::exception & e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n----------------\n" << std::endl; + + try { + Form form("toto", 1, 0); + } + catch (std::exception & e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n----------------\n" << std::endl; + + try { + Form form("fofo", 5, 4); + Bureaucrat toto("toto", 5); + Bureaucrat tata("tata", 6); + + tata.signForm(form); + toto.signForm(form); + toto.signForm(form); + } + catch (std::exception & e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n---End Test---\n" << std::endl; +} diff --git a/CPP05/ex02/AForm.cpp b/CPP05/ex02/AForm.cpp new file mode 100644 index 0000000..53a41c1 --- /dev/null +++ b/CPP05/ex02/AForm.cpp @@ -0,0 +1,74 @@ +#include "AForm.hpp" + +AForm::AForm() : name(""), sign(false), grade(150), gradeExec(150) { +} + +AForm::AForm(std::string name, std::string target, int grade, int gradeExec) + : name(name), target(target), sign(false), grade(grade), gradeExec(gradeExec) { + if (grade > 150 || gradeExec > 151) + throw AForm::GradeTooLowException(); + if (grade < 1 || gradeExec < 1) + throw AForm::GradeTooHighException(); +} + +AForm::~AForm() { +} + +AForm::AForm(const AForm &form) : name(form.name), grade(form.grade), gradeExec(form.gradeExec) { + *this = form; +} + +AForm &AForm::operator=(const AForm &form) { + if (this != &form) { + this->sign = form.sign; + this->target = form.target; + } + return *this; +} + +std::string AForm::getName() const { + return this->name; +} + +std::string AForm::getTarget() const { + return this->target; +} + +bool AForm::isSigned() const { + return this->sign; +} + +int AForm::getGrade() const { + return this->grade; +} + +int AForm::getGradeExec() const { + return this->gradeExec; +} + +void AForm::beSigned(Bureaucrat &crat) { + if (crat.getGrade() > this->grade) + throw AForm::GradeTooLowException(); + this->sign = true; +} + +void AForm::execute(const Bureaucrat &crat) const { + if (crat.getGrade() > this->gradeExec) + throw AForm::GradeTooLowException(); + //this->target = crat.getName(); + executeAction(); +} + + +std::ostream& operator<<( std::ostream& os, AForm const& form ) { + return os << "name:" << form.getName() << " sign:" << form.isSigned() + << " grade:" << form.getGrade() << " gradeExec:" << form.getGradeExec() << std::endl; +} + +char const* AForm::GradeTooHighException::what() const throw() { + return "Grade is too high"; +} + +char const* AForm::GradeTooLowException::what() const throw() { + return "Grade is too low"; +} diff --git a/CPP05/ex02/AForm.hpp b/CPP05/ex02/AForm.hpp new file mode 100644 index 0000000..0acb3c7 --- /dev/null +++ b/CPP05/ex02/AForm.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include "Bureaucrat.hpp" + +class Bureaucrat; + +class AForm { + public: + class GradeTooHighException : public std::exception { + public: + char const* what() const throw(); + }; + + class GradeTooLowException : public std::exception { + public: + char const* what() const throw(); + }; + + AForm(); + AForm(std::string name, std::string target, int grade, int gradeExec); + virtual ~AForm(); + AForm(const AForm &form); + AForm &operator=(const AForm &form); + + std::string getName() const; + std::string getTarget() const; + bool isSigned() const; + int getGrade() const; + int getGradeExec() const; + + void beSigned(Bureaucrat &crat); + void execute(const Bureaucrat &crat) const; + virtual void executeAction() const = 0; + + private: + const std::string name; + std::string target; + bool sign; + const int grade; + const int gradeExec; +}; + +std::ostream& operator<<(std::ostream& os, AForm const& form); diff --git a/CPP05/ex02/Bureaucrat.cpp b/CPP05/ex02/Bureaucrat.cpp new file mode 100644 index 0000000..a2406f8 --- /dev/null +++ b/CPP05/ex02/Bureaucrat.cpp @@ -0,0 +1,84 @@ +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat() : name("") { + this->grade = 150; +} + +Bureaucrat::Bureaucrat(std::string name, int grade) :name(name){ + if (grade > 150) + throw Bureaucrat::GradeTooLowException(); + else if (grade < 1) + throw Bureaucrat::GradeTooHighException(); + this->grade = grade; +} + +Bureaucrat::~Bureaucrat() { +} + +Bureaucrat::Bureaucrat(const Bureaucrat &other) : name(other.name) { + *this = other; +} + +Bureaucrat &Bureaucrat::operator=(const Bureaucrat &other) { + if (this != &other) { + this->grade = other.grade; + } + return (*this); +} + +std::string Bureaucrat::getName() const { + return this->name; +} + +int Bureaucrat::getGrade() const { + return this->grade; +} + +void Bureaucrat::increaseGrade() { + if (this->grade <= 1) + throw Bureaucrat::GradeTooHighException(); + this->grade--; +} + +void Bureaucrat::decreaseGrade() { + if (this->grade >= 150) + throw Bureaucrat::GradeTooLowException(); + this->grade++; +} + +void Bureaucrat::signForm(AForm &form) { + if (form.isSigned()) { + std::cout << name << " couldn't sign " << form.getName() << " because it's already signed" << std::endl; + return; + } + try { + form.beSigned(*this); + std::cout << name << " signed " << form.getName() << std::endl; + } + catch (std::exception & e) { + std::cout << name << " couldn't sign " << form.getName() << " because grade too low" << std::endl; + } +} + +void Bureaucrat::executeForm(const AForm &form) const{ + try { + std::cout << name << " executed " << form.getName() << std::endl; + form.execute(*this); + } + catch (std::exception & e) { + std::cout << name << " couldn't execute " << form.getName() << " because grade too low" << std::endl; + } +} + +std::ostream& operator<<( std::ostream& os, Bureaucrat const& crat ) { + return os << crat.getName() << ", bureaucrat grade " << crat.getGrade() << "." << std::endl; +} + +char const* Bureaucrat::GradeTooHighException::what() const throw() { + return "Grade is too high"; +} + +char const* Bureaucrat::GradeTooLowException::what() const throw() { + return "Grade is too low"; +} + diff --git a/CPP05/ex02/Bureaucrat.hpp b/CPP05/ex02/Bureaucrat.hpp new file mode 100644 index 0000000..a0c61f0 --- /dev/null +++ b/CPP05/ex02/Bureaucrat.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include "AForm.hpp" + +class AForm; + +class Bureaucrat { + public: + class GradeTooHighException : public std::exception { + public: + char const* what() const throw(); + }; + + class GradeTooLowException : public std::exception { + public: + char const* what() const throw(); + }; + + Bureaucrat(); + Bureaucrat(std::string name, int grade); + ~Bureaucrat(); + Bureaucrat(const Bureaucrat &other); + Bureaucrat &operator=(const Bureaucrat &other); + + std::string getName() const; + int getGrade() const; + void setName(std::string name); + + void increaseGrade(); + void decreaseGrade(); + + void signForm(AForm &form); + void executeForm(const AForm& form) const; + + private: + const std::string name; + int grade; +}; + +std::ostream& operator<<(std::ostream& os, Bureaucrat const& crat); diff --git a/CPP05/ex02/Makefile b/CPP05/ex02/Makefile new file mode 100644 index 0000000..a258c5c --- /dev/null +++ b/CPP05/ex02/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Bureaucrat + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP05/ex02/PresidentialPardonForm.cpp b/CPP05/ex02/PresidentialPardonForm.cpp new file mode 100644 index 0000000..6d21cc0 --- /dev/null +++ b/CPP05/ex02/PresidentialPardonForm.cpp @@ -0,0 +1,9 @@ +#include "PresidentialPardonForm.hpp" + +PresidentialPardonForm::PresidentialPardonForm() : AForm("", "", 25, 5) {} + +PresidentialPardonForm::PresidentialPardonForm(std::string target) : AForm("presidential" , target, 25, 5) {} + +void PresidentialPardonForm::executeAction() const { + std::cout << getName() << " has been pardoned by Zaphod Beeblebrox." << std::endl; +} diff --git a/CPP05/ex02/PresidentialPardonForm.hpp b/CPP05/ex02/PresidentialPardonForm.hpp new file mode 100644 index 0000000..c155086 --- /dev/null +++ b/CPP05/ex02/PresidentialPardonForm.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "AForm.hpp" + +class PresidentialPardonForm : public AForm { + public : + PresidentialPardonForm(); + PresidentialPardonForm(std::string name); + + void executeAction() const; +}; diff --git a/CPP05/ex02/RobotomyRequestForm.cpp b/CPP05/ex02/RobotomyRequestForm.cpp new file mode 100644 index 0000000..24979df --- /dev/null +++ b/CPP05/ex02/RobotomyRequestForm.cpp @@ -0,0 +1,13 @@ +#include "RobotomyRequestForm.hpp" +#include + +RobotomyRequestForm::RobotomyRequestForm() : AForm("", "", 72, 45) {} + +RobotomyRequestForm::RobotomyRequestForm(std::string target) : AForm("robotomy", target, 72, 45) {} + +void RobotomyRequestForm::executeAction() const { + if (std::rand() % 2) + std::cout << getTarget() << " has been robotomized!" << std::endl; + else + std::cout << "Robotomy failed." << std::endl; +} diff --git a/CPP05/ex02/RobotomyRequestForm.hpp b/CPP05/ex02/RobotomyRequestForm.hpp new file mode 100644 index 0000000..e15078b --- /dev/null +++ b/CPP05/ex02/RobotomyRequestForm.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "AForm.hpp" + +class RobotomyRequestForm : public AForm { + public : + RobotomyRequestForm(); + RobotomyRequestForm(std::string name); + + void executeAction() const; +}; diff --git a/CPP05/ex02/ShrubberyCreationForm.cpp b/CPP05/ex02/ShrubberyCreationForm.cpp new file mode 100644 index 0000000..b839541 --- /dev/null +++ b/CPP05/ex02/ShrubberyCreationForm.cpp @@ -0,0 +1,22 @@ +#include "ShrubberyCreationForm.hpp" +#include + +static const std::string tree = " ,@@@@@@@, \n" +" ,,,. ,@@@@@@/@@, .oo8888o. \n" +" ,&\%%&%&&%,@@@@@/@@@@@@,8888\\88/8o \n" +" ,%&\\%&&%&&%,@@@\\@@@/@@@88\\88888/88' \n" +" %&&%&%&/%&&%@@\\@@/ /@@@88888\\88888' \n" +" %&&%/ %&\%%&&@@\\ V /@@' `88\\8 `/88' \n" +" `&%\\ ` /%&' |.| \\ '|8' \n" +" |o| | | | | \n" +" |.| | | | | \n" +"jgs \\/ ._\\//_/__/ ,\\_ //__\\/. \\_//__/_ \n"; + +ShrubberyCreationForm::ShrubberyCreationForm() : AForm("", "", 145, 137) {} + +ShrubberyCreationForm::ShrubberyCreationForm(std::string target) : AForm("Shrubbery", target, 145, 137) {} + +void ShrubberyCreationForm::executeAction() const { + std::ofstream ofs ((getTarget() + "_shrubbery").c_str()); + ofs << tree; +} diff --git a/CPP05/ex02/ShrubberyCreationForm.hpp b/CPP05/ex02/ShrubberyCreationForm.hpp new file mode 100644 index 0000000..6129ec9 --- /dev/null +++ b/CPP05/ex02/ShrubberyCreationForm.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "AForm.hpp" + +class ShrubberyCreationForm : public AForm { + public : + ShrubberyCreationForm(); + ShrubberyCreationForm(std::string name); + + void executeAction() const; +}; diff --git a/CPP05/ex02/main.cpp b/CPP05/ex02/main.cpp new file mode 100644 index 0000000..50d5c53 --- /dev/null +++ b/CPP05/ex02/main.cpp @@ -0,0 +1,57 @@ +#include "Bureaucrat.hpp" +#include "AForm.hpp" +#include "ShrubberyCreationForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "PresidentialPardonForm.hpp" + +int main() { + + Bureaucrat tyty("tyty", 5); + Bureaucrat titi("titi", 25); + Bureaucrat toto("toto", 120); + Bureaucrat tata("tata", 150); + + std::cout << "\n---Test0---\n" << std::endl; + + try { + ShrubberyCreationForm shrube("toto"); + ShrubberyCreationForm shrube2 = shrube; + std::cout << "shrube2 = shrube" << std::endl; + std::cout << "shrube2's name: " << shrube2.getName() << std::endl; + + + toto.executeForm(shrube2); + tata.executeForm(shrube); + } + catch (std::exception &e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n---Test1---\n" << std::endl; + + try { + RobotomyRequestForm roboto("toto"); + + for (int i = 0; i < 10; i++) + tyty.executeForm(roboto); + toto.executeForm(roboto); + } + catch (std::exception &e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n---Test2---\n" << std::endl; + + try { + PresidentialPardonForm presi("tyty"); + tyty.executeForm(presi); + titi.executeForm(presi); + toto.executeForm(presi); + tata.executeForm(presi); + } + catch (std::exception &e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n---End Test---\n" << std::endl; +} diff --git a/CPP05/ex03/AForm.cpp b/CPP05/ex03/AForm.cpp new file mode 100644 index 0000000..8ac2704 --- /dev/null +++ b/CPP05/ex03/AForm.cpp @@ -0,0 +1,73 @@ +#include "AForm.hpp" + +AForm::AForm() : name(""), sign(false), grade(150), gradeExec(150) { +} + +AForm::AForm(std::string name, int grade, int gradeExec) + : name(name), sign(false), grade(grade), gradeExec(gradeExec) { + if (grade > 150 || gradeExec > 151) + throw AForm::GradeTooLowException(); + if (grade < 1 || gradeExec < 1) + throw AForm::GradeTooHighException(); +} + +AForm::~AForm() { +} + +AForm::AForm(const AForm &form) : name(form.name), grade(form.grade), gradeExec(form.gradeExec) { + *this = form; +} + +AForm &AForm::operator=(const AForm &form) { + if (this != &form) { + this->sign = form.sign; + } + return *this; +} + +std::string AForm::getName() const { + return this->name; +} + +std::string AForm::getTarget() const { + return this->target; +} + +bool AForm::isSigned() const { + return this->sign; +} + +int AForm::getGrade() const { + return this->grade; +} + +int AForm::getGradeExec() const { + return this->gradeExec; +} + +void AForm::beSigned(Bureaucrat &crat) { + if (crat.getGrade() > this->grade) + throw AForm::GradeTooLowException(); + this->sign = true; +} + +void AForm::execute(Bureaucrat &crat) { + if (crat.getGrade() > this->gradeExec) + throw AForm::GradeTooLowException(); + this->target = crat.getName(); + executeAction(); +} + + +std::ostream& operator<<( std::ostream& os, AForm const& form ) { + return os << "name:" << form.getName() << " sign:" << form.isSigned() + << " grade:" << form.getGrade() << " gradeExec:" << form.getGradeExec() << std::endl; +} + +char const* AForm::GradeTooHighException::what() const throw() { + return "Grade is too high"; +} + +char const* AForm::GradeTooLowException::what() const throw() { + return "Grade is too low"; +} diff --git a/CPP05/ex03/AForm.hpp b/CPP05/ex03/AForm.hpp new file mode 100644 index 0000000..9ff1490 --- /dev/null +++ b/CPP05/ex03/AForm.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include "Bureaucrat.hpp" + +class Bureaucrat; + +class AForm { + public: + class GradeTooHighException : public std::exception { + public: + char const* what() const throw(); + }; + + class GradeTooLowException : public std::exception { + public: + char const* what() const throw(); + }; + + AForm(); + AForm(std::string name, int grade, int gradeExec); + virtual ~AForm(); + AForm(const AForm &form); + AForm &operator=(const AForm &form); + + std::string getName() const; + std::string getTarget() const; + bool isSigned() const; + int getGrade() const; + int getGradeExec() const; + + void beSigned(Bureaucrat &crat); + void execute(Bureaucrat &crat); + virtual void executeAction() = 0; + + private: + const std::string name; + std::string target; + bool sign; + const int grade; + const int gradeExec; +}; + +std::ostream& operator<<(std::ostream& os, AForm const& form); diff --git a/CPP05/ex03/Bureaucrat.cpp b/CPP05/ex03/Bureaucrat.cpp new file mode 100644 index 0000000..cd42fff --- /dev/null +++ b/CPP05/ex03/Bureaucrat.cpp @@ -0,0 +1,84 @@ +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat() : name("") { + this->grade = 150; +} + +Bureaucrat::Bureaucrat(std::string name, int grade) :name(name){ + if (grade > 150) + throw Bureaucrat::GradeTooLowException(); + else if (grade < 1) + throw Bureaucrat::GradeTooHighException(); + this->grade = grade; +} + +Bureaucrat::~Bureaucrat() { +} + +Bureaucrat::Bureaucrat(const Bureaucrat &other) : name(other.name) { + *this = other; +} + +Bureaucrat &Bureaucrat::operator=(const Bureaucrat &other) { + if (this != &other) { + this->grade = other.grade; + } + return (*this); +} + +std::string Bureaucrat::getName() const { + return this->name; +} + +int Bureaucrat::getGrade() const { + return this->grade; +} + +void Bureaucrat::increaseGrade() { + if (this->grade <= 1) + throw Bureaucrat::GradeTooHighException(); + this->grade--; +} + +void Bureaucrat::decreaseGrade() { + if (this->grade >= 150) + throw Bureaucrat::GradeTooLowException(); + this->grade++; +} + +void Bureaucrat::signAForm(AForm &form) { + if (form.isSigned()) { + std::cout << name << " couldn't sign " << form.getName() << " because it's already signed" << std::endl; + return; + } + try { + form.beSigned(*this); + std::cout << name << " signed " << form.getName() << std::endl; + } + catch (std::exception & e) { + std::cout << name << " couldn't sign " << form.getName() << " because grade too low" << std::endl; + } +} + +void Bureaucrat::executeAForm(AForm &form) { + try { + std::cout << name << " executed " << form.getName() << std::endl; + form.execute(*this); + } + catch (std::exception & e) { + std::cout << name << " couldn't execute " << form.getName() << " because grade too low" << std::endl; + } +} + +std::ostream& operator<<( std::ostream& os, Bureaucrat const& crat ) { + return os << crat.getName() << ", bureaucrat grade " << crat.getGrade() << "." << std::endl; +} + +char const* Bureaucrat::GradeTooHighException::what() const throw() { + return "Grade is too high"; +} + +char const* Bureaucrat::GradeTooLowException::what() const throw() { + return "Grade is too low"; +} + diff --git a/CPP05/ex03/Bureaucrat.hpp b/CPP05/ex03/Bureaucrat.hpp new file mode 100644 index 0000000..9054c21 --- /dev/null +++ b/CPP05/ex03/Bureaucrat.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include "AForm.hpp" + +class AForm; + +class Bureaucrat { + public: + class GradeTooHighException : public std::exception { + public: + char const* what() const throw(); + }; + + class GradeTooLowException : public std::exception { + public: + char const* what() const throw(); + }; + + Bureaucrat(); + Bureaucrat(std::string name, int grade); + ~Bureaucrat(); + Bureaucrat(const Bureaucrat &other); + Bureaucrat &operator=(const Bureaucrat &other); + + std::string getName() const; + int getGrade() const; + void setName(std::string name); + + void increaseGrade(); + void decreaseGrade(); + + void signAForm(AForm &form); + void executeAForm(AForm& form); + + private: + const std::string name; + int grade; +}; + +std::ostream& operator<<(std::ostream& os, Bureaucrat const& crat); diff --git a/CPP05/ex03/Intern.cpp b/CPP05/ex03/Intern.cpp new file mode 100644 index 0000000..e86a32a --- /dev/null +++ b/CPP05/ex03/Intern.cpp @@ -0,0 +1,39 @@ +#include "Intern.hpp" + +Intern::Intern() {} + +Intern::~Intern() {} + +Intern::Intern(const Intern &intern) { + (void)intern; +} + +Intern &Intern::operator=(const Intern &intern) { + (void)intern; + return *this; +} + +AForm *Intern::makeAForm(const std::string &name, const std::string &target) { + AForm *form = NULL; + std::string forms[3] = {"shrubbery creation", "robotomy request", "presidential pardon"}; + + int i = 0; + for (; i < 4; i++) + if (forms[i] == name) + break; + switch (i) { + case 0: + form = new ShrubberyCreationAForm(target); + break; + case 1: + form = new RobotomyRequestAForm(target); + break; + case 2: + form = new PresidentialPardonAForm(target); + break; + default: + std::cout << "Error creation form" << std::endl; + return NULL; + } + return form; +} diff --git a/CPP05/ex03/Intern.hpp b/CPP05/ex03/Intern.hpp new file mode 100644 index 0000000..10ca1c5 --- /dev/null +++ b/CPP05/ex03/Intern.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "AForm.hpp" +#include "ShrubberyCreationForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "PresidentialPardonForm.hpp" + +class Intern { + public: + Intern(); + Intern(const Intern &intern); + ~Intern(); + Intern &operator=(const Intern &intern); + AForm *makeAForm(const std::string &name, const std::string &target); +}; diff --git a/CPP05/ex03/Makefile b/CPP05/ex03/Makefile new file mode 100644 index 0000000..a258c5c --- /dev/null +++ b/CPP05/ex03/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Bureaucrat + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP05/ex03/PresidentialPardonForm.cpp b/CPP05/ex03/PresidentialPardonForm.cpp new file mode 100644 index 0000000..b85dbdf --- /dev/null +++ b/CPP05/ex03/PresidentialPardonForm.cpp @@ -0,0 +1,9 @@ +#include "PresidentialPardonForm.hpp" + +PresidentialPardonAForm::PresidentialPardonAForm() : AForm("", 25, 5) {} + +PresidentialPardonAForm::PresidentialPardonAForm(std::string name) : AForm(name, 25, 5) {} + +void PresidentialPardonAForm::executeAction() { + std::cout << getName() << " has been pardoned by Zaphod Beeblebrox." << std::endl; +} diff --git a/CPP05/ex03/PresidentialPardonForm.hpp b/CPP05/ex03/PresidentialPardonForm.hpp new file mode 100644 index 0000000..f62159c --- /dev/null +++ b/CPP05/ex03/PresidentialPardonForm.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "AForm.hpp" + +class PresidentialPardonAForm : public AForm { + public : + PresidentialPardonAForm(); + PresidentialPardonAForm(std::string name); + + void executeAction(); +}; diff --git a/CPP05/ex03/RobotomyRequestForm.cpp b/CPP05/ex03/RobotomyRequestForm.cpp new file mode 100644 index 0000000..e3960ba --- /dev/null +++ b/CPP05/ex03/RobotomyRequestForm.cpp @@ -0,0 +1,13 @@ +#include "RobotomyRequestForm.hpp" +#include + +RobotomyRequestAForm::RobotomyRequestAForm() : AForm("", 72, 45) {} + +RobotomyRequestAForm::RobotomyRequestAForm(std::string name) : AForm(name, 72, 45) {} + +void RobotomyRequestAForm::executeAction() { + if (std::rand() % 2) + std::cout << getTarget() << " has been robotomized!" << std::endl; + else + std::cout << "Robotomy failed." << std::endl; +} diff --git a/CPP05/ex03/RobotomyRequestForm.hpp b/CPP05/ex03/RobotomyRequestForm.hpp new file mode 100644 index 0000000..5dbf9f0 --- /dev/null +++ b/CPP05/ex03/RobotomyRequestForm.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "AForm.hpp" + +class RobotomyRequestAForm : public AForm { + public : + RobotomyRequestAForm(); + RobotomyRequestAForm(std::string name); + + void executeAction(); +}; diff --git a/CPP05/ex03/ShrubberyCreationForm.cpp b/CPP05/ex03/ShrubberyCreationForm.cpp new file mode 100644 index 0000000..577e4a7 --- /dev/null +++ b/CPP05/ex03/ShrubberyCreationForm.cpp @@ -0,0 +1,22 @@ +#include "ShrubberyCreationForm.hpp" +#include + +static const std::string tree = " ,@@@@@@@, \n" +" ,,,. ,@@@@@@/@@, .oo8888o. \n" +" ,&\%%&%&&%,@@@@@/@@@@@@,8888\\88/8o \n" +" ,%&\\%&&%&&%,@@@\\@@@/@@@88\\88888/88' \n" +" %&&%&%&/%&&%@@\\@@/ /@@@88888\\88888' \n" +" %&&%/ %&\%%&&@@\\ V /@@' `88\\8 `/88' \n" +" `&%\\ ` /%&' |.| \\ '|8' \n" +" |o| | | | | \n" +" |.| | | | | \n" +"jgs \\/ ._\\//_/__/ ,\\_ //__\\/. \\_//__/_ \n"; + +ShrubberyCreationAForm::ShrubberyCreationAForm() : AForm("", 145, 137) {} + +ShrubberyCreationAForm::ShrubberyCreationAForm(std::string name) : AForm(name, 145, 137) {} + +void ShrubberyCreationAForm::executeAction() { + std::ofstream ofs ((getTarget() + "_shrubbery").c_str()); + ofs << tree; +} diff --git a/CPP05/ex03/ShrubberyCreationForm.hpp b/CPP05/ex03/ShrubberyCreationForm.hpp new file mode 100644 index 0000000..5d3f9bb --- /dev/null +++ b/CPP05/ex03/ShrubberyCreationForm.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "AForm.hpp" + +class ShrubberyCreationAForm : public AForm { + public : + ShrubberyCreationAForm(); + ShrubberyCreationAForm(std::string name); + + void executeAction(); +}; diff --git a/CPP05/ex03/main.cpp b/CPP05/ex03/main.cpp new file mode 100644 index 0000000..dbb332d --- /dev/null +++ b/CPP05/ex03/main.cpp @@ -0,0 +1,44 @@ +#include "Bureaucrat.hpp" +#include "AForm.hpp" +#include "ShrubberyCreationForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "PresidentialPardonForm.hpp" +#include "Intern.hpp" + +int main() { + + Bureaucrat tyty("tyty", 5); + Bureaucrat titi("titi", 45); + + std::cout << "\n---Test0---\n" << std::endl; + + try { + Intern cho; + AForm *formShrub; + AForm *formRoboto; + AForm *formPresi; + + formShrub = cho.makeAForm("shrubbery creation", "fifi"); + formRoboto = cho.makeAForm("robotomy request", "fifi"); + formPresi = cho.makeAForm("presidential pardon", "fifi"); + + titi.signAForm(*formShrub); + titi.signAForm(*formRoboto); + titi.signAForm(*formPresi); + tyty.signAForm(*formPresi); + + titi.executeAForm(*formShrub); + titi.executeAForm(*formRoboto); + titi.executeAForm(*formPresi); + tyty.executeAForm(*formPresi); + + delete formShrub; + delete formRoboto; + delete formPresi; + } + catch (std::exception &e) { + std::cout << e.what() << std::endl; + } + + std::cout << "\n---End Test---\n" << std::endl; +} diff --git a/CPP06/ex00/Makefile b/CPP06/ex00/Makefile new file mode 100644 index 0000000..361c76a --- /dev/null +++ b/CPP06/ex00/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = ScalarConverter + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP06/ex00/ScalarConverter.cpp b/CPP06/ex00/ScalarConverter.cpp new file mode 100644 index 0000000..017adc2 --- /dev/null +++ b/CPP06/ex00/ScalarConverter.cpp @@ -0,0 +1,150 @@ +#include "ScalarConverter.hpp" + +#include + +ScalarConverter::ScalarConverter() {} + +ScalarConverter::ScalarConverter(const ScalarConverter &sca) { + (void)sca; +} + +ScalarConverter::~ScalarConverter() {} + +ScalarConverter &ScalarConverter::operator=(const ScalarConverter &sca) { + (void) sca; + return *this; +} + +bool isInt(const std::string& str) { + for (std::size_t i = 0; i < str.length(); ++i) + if (!std::isdigit(str[i])) + return false; + return true; +} + +size_t string_occurence(const std::string &str, char c) { + int nbr = 0; + for (size_t i = 0; i < str.size() ; i++) + if (str[i] == c) + nbr++; + return nbr; +} + +void printNumber(double nbr, std::string str); +void printOther(std::string str); + +void printChar(int nbr); +void printChar(float nbr); +void printChar(double nbr); + +bool special(std::string str); +bool dot(std::string str); + +void ScalarConverter::convert(std::string str) { + + if (special(str)) + return ; + + if (dot(str)) + return; + + char* endPtrDouble; + double nbrDouble = std::strtod(str.c_str(), &endPtrDouble); + + char* endPtrFloat; + std::string str_reduce = str.substr(0, str.size() - 1); + std::strtof(str_reduce.c_str(), &endPtrFloat); + + if (isInt(str) + || (*endPtrFloat == '\0' && str.size() > 1 + && string_occurence(str, 'f') == 1 && + str[str.size() - 1] == 'f') + || (*endPtrDouble == '\0')) + printNumber(nbrDouble, str); + else + printOther(str); +} + +void printNumber(double nbr, std::string str) { + printChar(nbr); + long int numLong = std::strtol(str.c_str(), NULL, 10); + if (numLong > INT_MAX || numLong < INT_MIN) + std::cout << "int: impossible" << std::endl; + else + std::cout << "int: " << static_cast(nbr) << std::endl; + if (static_cast(nbr) == nbr) { + std::cout << "float: " << static_cast(nbr) << ".0f" << std::endl; + std::cout << "double: " << nbr << ".0" << std::endl; + } + else { + std::cout << "float: " << static_cast(nbr) << "f" << std::endl; + std::cout << "double: " << nbr << std::endl; + } +} + +void printOther(std::string str) { + if (str.size() == 1) + printNumber(static_cast(str[0]), str); + else { + std::cout << "char: impossible" << std::endl; + std::cout << "int: impossible" << std::endl; + std::cout << "float: impossible" << std::endl; + std::cout << "double: impossible" << std::endl; + } +} + +void printChar(int nbr) { + if (std::isprint(nbr) && nbr <= 127 && nbr >= 32) + std::cout << "char: '" << static_cast(nbr) << "'" << std::endl; + else + std::cout << "char: Non displayable" << std::endl; +} + +void printChar(double nbr) { + if (nbr > 127 || nbr < -127) + std::cout << "char: impossible" << std::endl; + else if (static_cast(nbr) == nbr) + printChar(static_cast(nbr)); + else + std::cout << "char: impossible" << std::endl; +} + +void printChar(float nbr) { + printChar(static_cast(nbr)); +} + +bool special(std::string str) { + if (str == "nan" || str == "nanf") { + std::cout << "char: impossible" << std::endl; + std::cout << "int: impossible" << std::endl; + std::cout << "float: nanf" << std::endl; + std::cout << "double: nan" << std::endl; + return true; + } + else if (str == "+inf" || str == "inf" || str == "+inff" || str == "inff") { + std::cout << "char: impossible" << std::endl; + std::cout << "int: impossible" << std::endl; + std::cout << "float: +inff" << std::endl; + std::cout << "double: +inf" << std::endl; + return true; + } + else if (str == "-inf" || str == "-inff") { + std::cout << "char: impossible" << std::endl; + std::cout << "int: impossible" << std::endl; + std::cout << "float: -inff" << std::endl; + std::cout << "double: -inf" << std::endl; + return true; + } + return false; +} + +bool dot(std::string str) { + if (str[str.size() - 1] == '.') { + std::cout << "char: impossible" << std::endl; + std::cout << "int: impossible" << std::endl; + std::cout << "float: impossible" << std::endl; + std::cout << "double: impossible" << std::endl; + return true; + } + return false; +} diff --git a/CPP06/ex00/ScalarConverter.hpp b/CPP06/ex00/ScalarConverter.hpp new file mode 100644 index 0000000..5c80a6d --- /dev/null +++ b/CPP06/ex00/ScalarConverter.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include +#include +#include + +class ScalarConverter { + private: + ScalarConverter(); + ScalarConverter(const ScalarConverter &sca); + ~ScalarConverter(); + ScalarConverter& operator=(const ScalarConverter &sca); + + public: + static void convert(std::string str); +}; diff --git a/CPP06/ex00/main.cpp b/CPP06/ex00/main.cpp new file mode 100644 index 0000000..44a5dbd --- /dev/null +++ b/CPP06/ex00/main.cpp @@ -0,0 +1,8 @@ +#include "ScalarConverter.hpp" + +int main(int argc, char **argv) { + if (argc <= 1) + return (0); + ScalarConverter::convert(argv[1]); + return (0); +} diff --git a/CPP06/ex01/Makefile b/CPP06/ex01/Makefile new file mode 100644 index 0000000..c6a8012 --- /dev/null +++ b/CPP06/ex01/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Serialization + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP06/ex01/Serializer.cpp b/CPP06/ex01/Serializer.cpp new file mode 100644 index 0000000..dcc5b4b --- /dev/null +++ b/CPP06/ex01/Serializer.cpp @@ -0,0 +1,23 @@ +#include "Serializer.hpp" + +Serializer::Serializer() {} + +Serializer::Serializer(const Serializer &seria) { + (void)seria; +} + +Serializer::~Serializer() {} + +Serializer &Serializer::operator=(const Serializer &seria) { + (void) seria; + return *this; +} + +uintptr_t Serializer::serialize(Data *ptr) { + return reinterpret_cast(ptr); +} + +Data* Serializer::deserialize(uintptr_t raw) { + Data* data = reinterpret_cast(raw); + return data; +} diff --git a/CPP06/ex01/Serializer.hpp b/CPP06/ex01/Serializer.hpp new file mode 100644 index 0000000..a9621e7 --- /dev/null +++ b/CPP06/ex01/Serializer.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +struct Data { + bool isOk; + int value; +}; + +class Serializer { + private: + Serializer(); + Serializer(const Serializer &seria); + ~Serializer(); + Serializer& operator=(const Serializer &seria); + + public: + static uintptr_t serialize(Data *ptr); + static Data *deserialize(uintptr_t raw); +}; diff --git a/CPP06/ex01/main.cpp b/CPP06/ex01/main.cpp new file mode 100644 index 0000000..0c893e6 --- /dev/null +++ b/CPP06/ex01/main.cpp @@ -0,0 +1,40 @@ +#include "Serializer.hpp" + +int main(void) { + + std::cout << "\n---Test0---\n" << std::endl; + + { + Data struct1; + Data struct2; + + struct1.isOk = false; + struct2.isOk = true; + std::cout << "struct1.isOk: " << std::boolalpha << struct1.isOk << std::endl; + std::cout << "struct2.isOk: " << std::boolalpha << struct2.isOk << std::endl; + + struct1.value = 5; + struct2.value = 37; + std::cout << "struct1.value: " << struct1.value << std::endl; + std::cout << "struct2.value: " << struct2.value << std::endl; + + std::cout<< "\n"; + + uintptr_t tmp1 = Serializer::serialize(&struct1); + uintptr_t tmp2 = Serializer::serialize(&struct2); + + std::cout << "uintptr_t tmp1: " << tmp1 << std::endl; + std::cout << "uintptr_t tmp2: " << tmp2 << std::endl; + + std::cout<< "\n"; + + Data newstruct1 = *Serializer::deserialize(tmp1); + Data newstruct2 = *Serializer::deserialize(tmp2); + std::cout << "newstruct1.isOk: " << std::boolalpha << newstruct1.isOk << std::endl; + std::cout << "newstruct2.isOk: " << std::boolalpha << newstruct2.isOk << std::endl; + std::cout << "newstruct1.value: " << newstruct1.value << std::endl; + std::cout << "newstruct2.value: " << newstruct2.value << std::endl; + } + + std::cout << "\n---EndTest---\n" << std::endl; +} diff --git a/CPP06/ex02/Base.cpp b/CPP06/ex02/Base.cpp new file mode 100644 index 0000000..7b77eca --- /dev/null +++ b/CPP06/ex02/Base.cpp @@ -0,0 +1,47 @@ +#include "Base.hpp" + +Base::~Base() {} + +Base *Base::generate() { + int i = rand() % 3; + switch (i) { + case 0: + return new A; + case 1: + return new B; + case 2: + return new C; + default: + return new A; + } +} + +void Base::identify(Base *p) { + if (dynamic_cast(p)) + std::cout << "A" << std::endl; + if (dynamic_cast(p)) + std::cout << "B" << std::endl; + if (dynamic_cast(p)) + std::cout << "C" << std::endl; +} + +void Base::identify(Base &p) { + try { + (void)dynamic_cast(p); + std::cout << "A" << std::endl; + } catch (std::exception& e) {} + try { + (void)dynamic_cast(p); + std::cout << "B" << std::endl; + } catch (std::exception& e) {} + try { + (void)dynamic_cast(p); + std::cout << "C" << std::endl; + } catch (std::exception& e) {} +} + +A::~A() {} + +B::~B() {} + +C::~C() {} diff --git a/CPP06/ex02/Base.hpp b/CPP06/ex02/Base.hpp new file mode 100644 index 0000000..5737d09 --- /dev/null +++ b/CPP06/ex02/Base.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include + +class Base { + public: + virtual ~Base(); + static Base *generate(); + static void identify(Base *p); + static void identify(Base &p); +}; + +class A : public Base { + public: + ~A(); +}; + +class B : public Base { + public: + ~B(); +}; + +class C : public Base { + public: + ~C(); +}; diff --git a/CPP06/ex02/Makefile b/CPP06/ex02/Makefile new file mode 100644 index 0000000..4a788dd --- /dev/null +++ b/CPP06/ex02/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Base + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP06/ex02/main.cpp b/CPP06/ex02/main.cpp new file mode 100644 index 0000000..b309bae --- /dev/null +++ b/CPP06/ex02/main.cpp @@ -0,0 +1,27 @@ +#include "Base.hpp" + +int main(void) { + + srand(time(NULL)); + + std::cout << "\n---Test0---\n" << std::endl; + + int nbr = 5; + for (int i = 0; i < nbr; i++) { + Base *base = Base::generate(); + Base::identify(base); + delete base; + } + + std::cout << "\n"; + + for (int i = 0; i < nbr; i++) { + Base &base = *Base::generate(); + Base::identify(base); + delete &base; + } + + std::cout << "\n---EndTest---\n" << std::endl; + + return (0); +} diff --git a/CPP07/ex00/Makefile b/CPP07/ex00/Makefile new file mode 100644 index 0000000..cb76499 --- /dev/null +++ b/CPP07/ex00/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = whatever + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP07/ex00/main.cpp b/CPP07/ex00/main.cpp new file mode 100644 index 0000000..2af39d8 --- /dev/null +++ b/CPP07/ex00/main.cpp @@ -0,0 +1,51 @@ +#include "whatever.hpp" +class Awesome +{ + public: + Awesome(void) : _n(0) {} + Awesome( int n ) : _n( n ) {} + Awesome & operator= (Awesome & a) { _n = a._n; return *this; } + bool operator==( Awesome const & rhs ) const { return (this->_n == rhs._n); } + bool operator!=( Awesome const & rhs ) const{ return (this->_n != rhs._n); } + bool operator>( Awesome const & rhs ) const { return (this->_n > rhs._n); } + bool operator<( Awesome const & rhs ) const { return (this->_n < rhs._n); } + bool operator>=( Awesome const & rhs ) const { return (this->_n >= rhs._n); } + bool operator<=( Awesome const & rhs ) const { return (this->_n <= rhs._n); } + int get_n() const { return _n; } + private: + int _n; +}; +std::ostream & operator<<(std::ostream & o, const Awesome &a) { o << a.get_n(); return o; } + +int main(void) +{ + std::cout << "\n---Test0---\n" << std::endl; + { + int a = 2; + int b = 3; + swap( a, b ); + std::cout << "a = " << a << ", b = " << b << std::endl; + std::cout << "min( a, b ) = " << min( a, b ) << std::endl; + std::cout << "max( a, b ) = " << max( a, b ) << std::endl; + std::string c = "chaine1"; + std::string d = "chaine2"; + swap(c, d); + std::cout << "c = " << c << ", d = " << d << std::endl; + std::cout << "min( c, d ) = " << min( c, d ) << std::endl; + std::cout << "max( c, d ) = " << max( c, d ) << std::endl; + } + + std::cout << "\n---Test1---\n" << std::endl; + + { + Awesome a(2), b(4); + std::cout << "a: " << a << " b: " << b << std::endl; + swap(a, b); + std::cout << "a: " << a << " b: " << b << std::endl; + std::cout << "max: " << max(a, b) << std::endl; + std::cout << "min: " << min(a, b) << std::endl; + } + + std::cout << "\n---EndTest---\n" << std::endl; + return (0); +} diff --git a/CPP07/ex00/whatever.hpp b/CPP07/ex00/whatever.hpp new file mode 100644 index 0000000..9c4af11 --- /dev/null +++ b/CPP07/ex00/whatever.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +template +void swap(T &one, T &two) { + T tmp = one; + one = two; + two = tmp; +} + +template +T min(T &one, T &two) { + return one < two ? one : two; +} + +template +T max(T &one, T &two) { + return one > two ? one : two; +} diff --git a/CPP07/ex01/Makefile b/CPP07/ex01/Makefile new file mode 100644 index 0000000..9724bcd --- /dev/null +++ b/CPP07/ex01/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Iter + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP07/ex01/iter.hpp b/CPP07/ex01/iter.hpp new file mode 100644 index 0000000..a048113 --- /dev/null +++ b/CPP07/ex01/iter.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +template +void iter(T *arr, size_t len, void(*f)(T&)) { + for (size_t i = 0; i < len; i++) + f(arr[i]); +} + +template +void print(T &t) { + std::cout << t << " "; +} + +template +void add(T &t) { + t++; +} diff --git a/CPP07/ex01/main.cpp b/CPP07/ex01/main.cpp new file mode 100644 index 0000000..79f7eeb --- /dev/null +++ b/CPP07/ex01/main.cpp @@ -0,0 +1,55 @@ +#include "iter.hpp" +class Awesome +{ + public: + Awesome( void ) : _n( 42 ) { return; } + int get( void ) const { return this->_n; } + private: + int _n; +}; +std::ostream & operator<<( std::ostream & o, Awesome const & rhs ) { o << rhs.get(); return o; } + +template< typename T > +void print( T const & x ) { std::cout << x << std::endl; return; } + +int main(void) { + + std::cout << "\n---Test0---\n" << std::endl; + { + int arr1[] = { 1, 2, 3, 4, 5 }; + std::cout << "arr1*: " << std::endl; + iter(arr1, 5, &print); + std::cout << "\narr1*: " << std::endl; + iter(arr1, 5, &add); + iter(arr1, 5, &print); + + float arr2[] = { 1.1f, 2.2f, 3.3f, 4.4f, 5.5f}; + std::cout << "\narr2: " << std::endl; + iter(arr2, 5, &print); + std::cout << "\narr2*: " << std::endl; + iter(arr2, 5, &add); + iter(arr2, 5, &print); + + char arr3[] = { 'a', 'b', 'c', 'd', 'e' }; + std::cout << "\narr3: " << std::endl; + iter(arr3, 5, &print); + std::cout << "\narr3*: " << std::endl; + iter(arr3, 5, &add); + iter(arr3, 5, &print); + + std::string arr4[] = { "one", "two", "three", "four", "five" }; + std::cout << "\narr4: " << std::endl; + iter(arr4, 5, &print); + } + + std::cout << "\n\n---Test1---\n" << std::endl; + { + int tab[] = { 0, 1, 2, 3, 4 }; + Awesome tab2[5]; + iter( tab, 5, print ); + iter( tab2, 5, print ); + } + std::cout << "\n\n---EndTest---\n" << std::endl; + + return 0; +} diff --git a/CPP07/ex02/Array.hpp b/CPP07/ex02/Array.hpp new file mode 100644 index 0000000..6c225d9 --- /dev/null +++ b/CPP07/ex02/Array.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include + +template +class Array { + public: + Array() : arr(new T[0]), len(0) {}; + Array(unsigned int len) : arr(new T[len]), len(len) {}; + Array(const Array &other) : arr(new T[other.size()]), len(other.size()) { + for (unsigned int i = 0; i < other.size(); i++) + arr[i] = other.arr[i]; + } + ~Array() {delete[] arr;} + Array &operator=(const Array &other) { + if (*this != &other) { + delete[] this->arr; + arr = new T[other.size()]; + len = other.size(); + for (unsigned int i = 0; i < other.size(); i++) + arr[i] = other.arr[i]; + } + return *this; + } + + T& operator[](unsigned int i) const { + return i >= len ? throw OutOfBoundException() : arr[i]; + } + + unsigned int size() const {return len;} + + class OutOfBoundException : public std::exception { + public: const char* what() const throw() { return "Index is out of bounds"; } + }; + + private: + T *arr; + unsigned int len; +}; diff --git a/CPP07/ex02/Makefile b/CPP07/ex02/Makefile new file mode 100644 index 0000000..6f6a780 --- /dev/null +++ b/CPP07/ex02/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Array + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP07/ex02/main.cpp b/CPP07/ex02/main.cpp new file mode 100644 index 0000000..aa2714c --- /dev/null +++ b/CPP07/ex02/main.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include "Array.hpp" + +int main(void) +{ + std::cout << "\n---Test0---\n" << std::endl; + { + Array numbers(750); + int* numbers_copy = new int[750]; + srand(time(NULL)); + for (int i = 0; i < 750; i++) { + const int value = rand(); + numbers[i] = value; + numbers_copy[i] = value; + } + + { + Array tmp = numbers; + Array test(tmp); + } + + for (int i = 0; i < 750; i++) { + if (numbers_copy[i] != numbers[i]) { + std::cerr << "Not same value" << std::endl; + return 1; + } + } + std::cout << "Same value !" << std::endl; + try { + numbers[-2] = 0; + } + catch(const std::exception& e) { + std::cerr << e.what() << '\n'; + } + try { + numbers[750] = 0; + } + catch(const std::exception& e) { + std::cerr << e.what() << '\n'; + } + + for (int i = 0; i < 750; i++) { + numbers[i] = rand(); + } + + delete [] numbers_copy; + } + + std::cout << "\n---EndTest---\n" << std::endl; + + return 0; +} diff --git a/CPP08/ex00/Makefile b/CPP08/ex00/Makefile new file mode 100644 index 0000000..5d99ada --- /dev/null +++ b/CPP08/ex00/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = easyfind + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP08/ex00/easyfind.hpp b/CPP08/ex00/easyfind.hpp new file mode 100644 index 0000000..f187f78 --- /dev/null +++ b/CPP08/ex00/easyfind.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include +#include +#include +#include + +template +void easyfind (T t, int toFind) { + if (std::find(t.begin(), t.end(), toFind) != t.end()) + std::cout << "It's found !" << std::endl; + else + std::cout << "It's not found !" << std::endl; + +} diff --git a/CPP08/ex00/main.cpp b/CPP08/ex00/main.cpp new file mode 100644 index 0000000..db47a24 --- /dev/null +++ b/CPP08/ex00/main.cpp @@ -0,0 +1,32 @@ +#include "easyfind.hpp" + +int main(void) { + + std::cout << "\n---Test0---\n" << std::endl; + + { + std::cout << "list: 2, 4, 6, 8, 10, 12, -1" << std::endl; + int tab[] = {2, 4, 6, 8, 10, 12, -1}; + + std::cout << "\n"; + + std::vector vec0(tab, tab + sizeof(tab) / sizeof(int)); + std::list list0(tab, tab + sizeof(tab) / sizeof(int)); + + std::cout << "test with vector on '2': "; + easyfind(vec0, 2); + std::cout << "test with vector on '21214': "; + easyfind(vec0, 21214); + + std::cout << "\n"; + + std::cout << "test with list on '2': "; + easyfind(list0, 2); + std::cout << "test with list on '21214': "; + easyfind(list0, 21214); + } + + std::cout << "\n---EndTest---\n" << std::endl; + + return 0; +} diff --git a/CPP08/ex01/Makefile b/CPP08/ex01/Makefile new file mode 100644 index 0000000..5314f8b --- /dev/null +++ b/CPP08/ex01/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = Span + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP08/ex01/Span.cpp b/CPP08/ex01/Span.cpp new file mode 100644 index 0000000..d3815b5 --- /dev/null +++ b/CPP08/ex01/Span.cpp @@ -0,0 +1,51 @@ +#include "Span.hpp" + +Span::Span() { + N = 0; +} + +Span::Span(unsigned int N) : N(N) { + +} + +Span::Span(const Span &span) { + *this = span; +} + +Span::~Span() { + +} + +Span &Span::operator=(const Span &span) { + if (this != &span) { + this->N = span.N; + this->list = span.list; + } + return *this; +} + +void Span::addNumber(int nbr) { + if (list.size() + 1 > N) + throw std::out_of_range("Out of Range"); + list.push_back(nbr); +} + +unsigned int Span::shortestSpan() const { + if (list.size() < 2) + throw std::exception(); + unsigned int min = longestSpan(); + for (std::list::const_iterator it0 = list.begin(); it0 != list.end(); it0++) { + for (std::list::const_iterator it1 = list.begin(); it1 != list.end(); it1++) { + if (it0 != it1) + if ((long)std::abs(*it0 - *it1) < (long)min) + min = std::abs(*it0 - *it1); + } + } + return min; +} + +unsigned int Span::longestSpan() const { + if (list.size() < 2) + throw std::exception(); + return (*std::max_element(list.begin(), list.end()) - *std::min_element(list.begin(), list.end())); +} diff --git a/CPP08/ex01/Span.hpp b/CPP08/ex01/Span.hpp new file mode 100644 index 0000000..1760422 --- /dev/null +++ b/CPP08/ex01/Span.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + + +class Span { + public: + Span(unsigned int N); + Span(const Span &span); + ~Span(); + Span &operator=(const Span &span); + + void addNumber(int nbr); + unsigned int shortestSpan() const; + unsigned int longestSpan() const; + private: + Span(); + unsigned int N; + std::list list; +}; diff --git a/CPP08/ex01/main.cpp b/CPP08/ex01/main.cpp new file mode 100644 index 0000000..92155b3 --- /dev/null +++ b/CPP08/ex01/main.cpp @@ -0,0 +1,62 @@ +#include "Span.hpp" + +int main(void) { + + std::cout << "\n---Test0---\n" << std::endl; + { + Span spa0(0); + + try { + spa0.addNumber(4); + } + catch (std::exception &e) { + std::cout << e.what() << std::endl; + } + } + + std::cout << "\n---Test1---\n" << std::endl; + { + Span spa(10); + + spa.addNumber(6); + spa.addNumber(3); + spa.addNumber(17); + spa.addNumber(9); + spa.addNumber(11); + std::cout << "spa: 6, 3, 17, 9, 11" << std::endl; + std::cout << spa.shortestSpan() << std::endl; + std::cout << spa.longestSpan() << std::endl; + } + + std::cout << "\n---Test2---\n" << std::endl; + { + Span spa(10); + + spa.addNumber(-5); + spa.addNumber(5); + + std::cout << "spa: -5, 5" << std::endl; + + std::cout << spa.shortestSpan() << std::endl; + std::cout << spa.longestSpan() << std::endl; + } + + + std::cout << "\n---Test3---\n" << std::endl; + { + Span spa(5); + srand(time(NULL)); + + for (int i = 0; i < 5; i++) { + int number = (rand() % 20) - 10; + std::cout << "spa[" << i << "]: " << number << ", "; + spa.addNumber(number); + } + std::cout << "\n"; + + std::cout << spa.shortestSpan() << std::endl; + std::cout << spa.longestSpan() << std::endl; + } + + std::cout << "\n---EndTest---\n" << std::endl; +} diff --git a/CPP08/ex02/Makefile b/CPP08/ex02/Makefile new file mode 100644 index 0000000..501c504 --- /dev/null +++ b/CPP08/ex02/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = MutantStack + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP08/ex02/MutantStack.hpp b/CPP08/ex02/MutantStack.hpp new file mode 100644 index 0000000..72127d2 --- /dev/null +++ b/CPP08/ex02/MutantStack.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include +#include + +template > +class MutantStack : public std::stack { + public: + MutantStack() {}; + MutantStack(const MutantStack &mut) { *this = mut; } + ~MutantStack() {}; + MutantStack &operator=(const MutantStack &mut) { + std::stack::operator=(mut); + return *this; + } + + typedef typename Container::iterator iterator; + + iterator begin() { return this->c.begin(); } + iterator end() { return this->c.end(); } +}; diff --git a/CPP08/ex02/main.cpp b/CPP08/ex02/main.cpp new file mode 100644 index 0000000..b1833f0 --- /dev/null +++ b/CPP08/ex02/main.cpp @@ -0,0 +1,53 @@ +#include "MutantStack.hpp" + +#include +#include + +int main(void) { + + std::cout << "\n---Test0---\n" << std::endl; + + { + MutantStack mstack; + mstack.push(5); + mstack.push(17); + std::cout << mstack.top() << std::endl; + mstack.pop(); + std::cout << mstack.size() << std::endl; + mstack.push(3); + mstack.push(5); + mstack.push(737); + mstack.push(0); + MutantStack::iterator it = mstack.begin(); + MutantStack::iterator ite = mstack.end(); + ++it; + --it; + while (it != ite) + { + std::cout << *it << ", "; + ++it; + } + } + + std::cout << "\n\n---Test1---\n" << std::endl; + + { + MutantStack mstack; + srand(time(NULL)); + for (int i = 0; i < 20; i++) + mstack.push((rand() % 200) - 100); + if (find(mstack.begin(), mstack.end(), 0) != mstack.end()) + std::cout << "There is 0 in the stack" << std::endl; + else + std::cout << "There isn't 0 in the stack" << std::endl; + MutantStack::iterator it = mstack.begin(); + for (int i = 0; i < 20; i++) { + std::cout << *it << ", "; + it++; + } + } + + std::cout << "\n\n---EndTest---\n" << std::endl; + + return 0; +} diff --git a/CPP09/ex00/BitcoinExchange.cpp b/CPP09/ex00/BitcoinExchange.cpp new file mode 100644 index 0000000..a7fd3c0 --- /dev/null +++ b/CPP09/ex00/BitcoinExchange.cpp @@ -0,0 +1,235 @@ +#include "BitcoinExchange.hpp" + +void isDate(std::string date); + +BitcoinExchange::BitcoinExchange() { + std::ifstream data("data.csv"); + + if (data.is_open()) { + std::string s; + int i = 0; + while (std::getline(data, s)) { + if (i == 0 && s != "date,exchange_rate") { + std::cout << "Error: Data need to start with \"date,exchange_rate\"" << std::endl; + throw std::exception(); + } + else if (i > 0) { + try { + std::string date = s.substr(0, s.find(",")); + if (date.size() < 10 || date.size() > 10) { + std::cout << "Error: date invalid"; + throw std::exception(); + } + else + isDate(date); + char *endPrice; + double price = std::strtof(s.substr(s.find(",") + 1 , s.size()).c_str(), &endPrice); + if (price < 0) { + std::cout << "Error: price negatif"; + throw std::exception(); + } + else + if (i != 0 && *endPrice == '\0') + mapBitcoin.insert(std::make_pair(date, price)); + } + catch (std::exception &e) { + std::cout << " in data" << std::endl; + throw std::exception(); + } + } + i++; + } + data.close(); + + if (mapBitcoin.size() == 0) { + std::cout << "Data file empty." << std::endl; + throw std::exception(); + } + } + else { + std::cout << "Error data file." << std::endl; + throw std::exception(); + } +} + +BitcoinExchange::~BitcoinExchange() { + +} + +BitcoinExchange::BitcoinExchange(const BitcoinExchange &bit) { + *this = bit; +} + +BitcoinExchange &BitcoinExchange::operator=(const BitcoinExchange &bit) { + if (this != &bit) { + this->mapBitcoin = bit.mapBitcoin; + } + return *this; +} + +// if the month finish by 31 return true else return false +bool finishMonth(int month) { + if (month == 1 || month == 3 || month == 5 || month == 7 + || month == 8 || month == 10 || month == 12) + return true; + return false; +} + +bool isLeapYear(int year) { + return (((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)); +} + +void isDate(std::string date) { + int year = std::atoi(date.substr(0, 4).c_str()); + int month = std::atoi(date.substr(5, 7).c_str()); + int day = std::atoi(date.substr(8, 10).c_str()); + bool leapYear = isLeapYear(year); + + if (month < 1 || month > 12) { + std::cout << "Error: Bad Month"; + throw std::exception(); + } + if ( (day < 1) || + (month == 2 && ((day > 28 && !leapYear) || (day > 29 && leapYear))) || + (finishMonth(month) && day > 31) || + (!finishMonth(month) && day > 30) + ) { + std::cout << "Error: Bad Day"; + throw std::exception(); + } + if (year < 2009 || (year == 2009 && month == 1 && day < 2)) { + std::cout << "Error: Too old date"; + throw std::exception(); + } +} + +double getValue(std::string value) { + char* endPtr; + double newValue = std::strtod(value.c_str(), &endPtr); + + if (*endPtr != '\0') { + std::cout << "Error: Bad value"; + throw std::exception(); + } + + if (newValue > 1000) { + std::cout << "Error: Too High"; + throw std::exception(); + } + + if (newValue < 0) { + std::cout << "Error: Negatif Number"; + throw std::exception(); + } + + return newValue; +} + +void verification(std::string s) { + int nbr = 0; + for (size_t i = 0; i < s.size() && nbr <= 1; i++) + if (s[i] == '|') + nbr++; + if (nbr > 1) { + std::cout << "Error: There are too many '|' in the line"; + throw std::exception(); + } + else if (nbr == 0) { + std::cout << "Error: There aren't '|' in the line"; + throw std::exception(); + } + if (s.substr(0, s.find(" ")).size() != 10) { + std::cout << "Error: Bad date"; + throw std::exception(); + } + if (s.substr(s.find("|") + 1, s.size()).size() <= 0) { + std::cout << "Error: Bad value"; + throw std::exception(); + } +} + +// True if d1 is older or equal than d2 +bool olderDate(std::string d1, std::string d2) { + int year1 = std::atoi(d1.substr(0, 4).c_str()); + int month1 = std::atoi(d1.substr(5, 7).c_str()); + int day1 = std::atoi(d1.substr(8, 10).c_str()); + + int year2 = std::atoi(d2.substr(0, 4).c_str()); + int month2 = std::atoi(d2.substr(5, 7).c_str()); + int day2 = std::atoi(d2.substr(8, 10).c_str()); + + if (year1 == year2) { + if (month1 == month2) { + if (day1 == day2) { + return true; + } + else + return (day1 < day2); + } + else + return (month1 < month2); + } + else + return (year1 < year2); +} + +void BitcoinExchange::printBitcoinValue(std::string date, double value) { + + std::map::iterator it; + std::string dateMap; + double valueMap; + double lastValueMap = 0; + for (it = mapBitcoin.begin(); it != mapBitcoin.end(); ++it) { + dateMap = it->first; + valueMap = it->second; + + if (dateMap == date) + break; + else if (olderDate(date, dateMap)) { + valueMap = lastValueMap; + break; + } + lastValueMap = valueMap; + } + std::cout << date << " => " << value << " = " << value * valueMap << std::endl; +} + +void BitcoinExchange::read(const std::string &file) { + std::ifstream input(file.c_str()); + + int i = 0; + if (input.is_open()) { + std::string s; + while (std::getline(input, s)) { + if (i == 0) + { + if (s == "date | value") + std::cout << "date | value" << std::endl; + else { + std::cout << "Error: File need to start with \"date | value\"" << std::endl; + return ; + } + } + else { + try { + verification(s); + std::string date = s.substr(0, s.find("|") - 1); + isDate(s.substr(0, s.find("|") - 1)); + double value = getValue(s.substr(s.find("|") + 1, s.size())); + + printBitcoinValue(date, value); + } + catch (std::exception &e) { + std::cout << " << Your input: " << s << std::endl; + } + } + i++; + } + if (i == 0) + std::cout << "Error: Empty file" << std::endl; + } + else { + std::cout << "Error input file." << std::endl; + throw std::exception(); + } +} diff --git a/CPP09/ex00/BitcoinExchange.hpp b/CPP09/ex00/BitcoinExchange.hpp new file mode 100644 index 0000000..adb9f62 --- /dev/null +++ b/CPP09/ex00/BitcoinExchange.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +class BitcoinExchange { + public: + BitcoinExchange(); + ~BitcoinExchange(); + BitcoinExchange(const BitcoinExchange &bit); + BitcoinExchange &operator=(const BitcoinExchange &bit); + + void read(const std::string &file); + private: + std::map mapBitcoin; + + void printBitcoinValue(std::string date, double value); +}; diff --git a/CPP09/ex00/Makefile b/CPP09/ex00/Makefile new file mode 100644 index 0000000..c72c0c6 --- /dev/null +++ b/CPP09/ex00/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = btc + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP09/ex00/main.cpp b/CPP09/ex00/main.cpp new file mode 100644 index 0000000..6df1821 --- /dev/null +++ b/CPP09/ex00/main.cpp @@ -0,0 +1,18 @@ +#include "BitcoinExchange.hpp" + +int main(int argc, char **argv) { + if (argc != 2) { + std::cout << "Error number argument" << std::endl; + return 1; + } + + try { + BitcoinExchange btc; + btc.read(argv[1]); + } + catch (std::exception &e) { + (void) e; + } + + return 0; +} diff --git a/CPP09/ex01/Makefile b/CPP09/ex01/Makefile new file mode 100644 index 0000000..a26e852 --- /dev/null +++ b/CPP09/ex01/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = RPN + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP09/ex01/main.cpp b/CPP09/ex01/main.cpp new file mode 100644 index 0000000..cc14d56 --- /dev/null +++ b/CPP09/ex01/main.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#include + +void superPop(std::stack&stck, double *first, double *second) { + *second = stck.top(); + stck.pop(); + *first = stck.top(); + stck.pop(); +} + +void addition(std::stack &stck) { + double nbr1, nbr2; + superPop(stck, &nbr1, &nbr2); + + stck.push(nbr1 + nbr2); +} + +void subtraction(std::stack &stck) { + double nbr1, nbr2; + superPop(stck, &nbr1, &nbr2); + + stck.push(nbr1 - nbr2); +} + +void multiplication(std::stack &stck) { + double nbr1, nbr2; + superPop(stck, &nbr1, &nbr2); + + stck.push(nbr1 * nbr2); +} + +void division(std::stack &stck) { + double nbr1, nbr2; + superPop(stck, &nbr1, &nbr2); + + if (nbr1 == 0 || nbr2 == 0) { + std::cout << "Error: Can't divise by 0" << std::endl; + throw std::exception(); + } + + stck.push(nbr1 / nbr2); +} + +int main(int argc, char **argv) { + + if (argc != 2) { + std::cout << "Error: Number of argument is wrong" << std::endl; + return 1; + } + + std::stack stck; + std::string cal(argv[1]); + bool spaced = false; + + for (size_t i = 0; i < cal.size(); i++) { + char c = cal[i]; + if (spaced && c != ' ') { + std::cout << "Error: Only one character by character" << std::endl; + return 1; + } + else if (!spaced) { + if (std::isdigit(c)) + stck.push(std::atoi(&c)); + else if (stck.size() <= 1) { + std::cout << "Error: Too much operator" << std::endl; + return 1; + } + else if (c == '+') + addition(stck); + else if (c == '-') + subtraction(stck); + else if (c == '*') + multiplication(stck); + else if (c == '/') { + try { + division(stck); + } + catch (std::exception &e) { + return 1; + } + } + else { + std::cout << "Error: Bad Input '" << c << "'" << std::endl; + return 1; + } + } + spaced = !spaced; + } + double result = stck.top(); + stck.pop(); + if (!stck.empty()) { + std::cout << "Error" << std::endl; + return 1; + } + std::cout << result << std::endl; + return 0; +} diff --git a/CPP09/ex02/Makefile b/CPP09/ex02/Makefile new file mode 100644 index 0000000..e3315ab --- /dev/null +++ b/CPP09/ex02/Makefile @@ -0,0 +1,129 @@ +SRCS = $(shell find . -name "*.cpp") +OBJS = ${SRCS:.cpp=.o} +CXX = c++ +CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g +NAME = PmergeMe + +all: ${NAME} + +${NAME}: ${OBJS} + ${CXX} -o ${NAME} ${OBJS} ${UTILS} + +clean: + rm -f ${OBJS} + +fclean: + rm -f ${OBJS} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re coffee bozo + +coffee: + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___...(-------)-....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " (" + @echo " ) (" + @echo " ___..(.------)--....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + @sleep 0.3 + @clear + @echo "" + @echo " ( ) " + @echo " ) (" + @echo " ___)...----)----....___" + @echo ' .-"" ) ( ""-.' + @echo " .-''''|-._ ( ) _.-|" + @echo ' / .--.| `""---...........---""` |' + @echo " / / | |" + @echo " | | | |" + @echo " \ \ | |" + @echo " '\ '\ | |" + @echo " '\ '| |" + @echo " _/ /\ /" + @echo " (__/ \ /" + @echo ' _..---""` \ /`""---.._' + @echo " .-' \ / '-." + @echo ": '-.__ __.-' :" + @echo ': ) ""---...---"" ( :' + @echo "\'._ '"--...___...--"' _.'" + @echo ' \""--..__ __..--""/' + @echo " '._ """----.....______.....----""" _.'" + @echo ' ""--..,,_____ _____,,..--"""''' + @echo ' """------"""' + make coffee + +bozo : + @wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif + @xdg-open bozo.gif + @@sleep 2.13 + @pkill eog + @rm bozo.gif diff --git a/CPP09/ex02/main.cpp b/CPP09/ex02/main.cpp new file mode 100644 index 0000000..54c73b7 --- /dev/null +++ b/CPP09/ex02/main.cpp @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void fillDequeVector(int argc, char **argv, std::deque &deq, std::vector &vec) { + char *endPtr; + + for (int i = 1; i < argc; i++) { + long int nbr = std::strtol(argv[i], &endPtr, 10); + if (*endPtr != '\0' || nbr > INT_MAX || nbr < INT_MIN) { + std::cout << "Error: Bad value: " << argv[i] << std::endl; + throw std::exception(); + } + deq.push_back(nbr); + vec.push_back(nbr); + } +} + +template +void binarySearchInsert(T &t, int value) { + int start = 0; + int end = t.size() - 1; + if (t[end] < value) { + t.insert(t.end(), value); + return ; + } + while (true) { + int mid = start - (start - end) / 2; + int cur_value = t[mid]; + if (cur_value == value || end - start <= 1) { + + if (cur_value < value) + t.insert(t.begin() + mid + 1, value); + else + t.insert(t.begin() + mid, value); + + return ; + } + else if (cur_value < value) + start = mid; + else if (cur_value > value) + end = mid; + } +} + +template +void mergeInsertSort(T &t) { + + unsigned int size = t.size(); + + int min[size / 2]; + int all[size]; + + for (unsigned int i = 0; i < size; i++) + all[i] = t[i]; + t.clear(); + + for (unsigned int i = 0; i + 1 < size; i+=2) { + int maximun = std::max(all[i], all[i + 1]); + int minimun = std::min(all[i], all[i + 1]); + t.push_back(maximun); + int index = i / 2; + min[index] = minimun; + } + + std::sort(t.begin(), t.end()); + + for (unsigned int i = 0; i < size / 2; i++) + binarySearchInsert(t, min[i]); + + if (t.size() % 2 == 1) + binarySearchInsert(t, all[size - 1]); + +} + +int main(int argc, char **argv) { + + if (argc <= 2) { + std::cout << "Not enought arguments" << std::endl; + return 1; + } + + std::deque deq; + std::vector vec; + try { + fillDequeVector(argc, argv, deq, vec); + } + catch (std::exception &e) { + return 1; + } + + std::cout << "Before: "; + for (size_t i = 0; i < deq.size(); i++) { + std::cout << deq[i] << " "; + } + std::cout << "\n"; + + clock_t clockDeq = clock(); + mergeInsertSort(deq); + clockDeq = clock() - clockDeq; + + std::cout << "After: "; + for (size_t i = 0; i < deq.size(); i++) { + std::cout << deq[i] << " "; + } + + + std::cout << "\n"; + + clock_t clockVec = clock(); + mergeInsertSort(vec); + clockVec = clock() - clockVec; + + std::cout << "Time to process a range of " << argc - 1 << " elements with std::deque : " << ((double)clockDeq)/ CLOCKS_PER_SEC * 1000.0 << " ms" << std::endl; + std::cout << "Time to process a range of " << argc - 1 << " elements with std::vector : " << ((double)clockVec)/ CLOCKS_PER_SEC * 1000.0 << " ms" << std::endl; + return 0; + +}