├── cpp_00 ├── ex00 │ ├── Makefile │ └── megaphone.cpp └── ex01 │ ├── Contact.class.cpp │ ├── Contact.class.hpp │ ├── Makefile │ ├── PhoneBook.class.cpp │ ├── PhoneBook.class.hpp │ └── main.cpp ├── cpp_01 ├── c01.pdf ├── ex00 │ ├── Makefile │ ├── Zombie.cpp │ ├── Zombie.hpp │ ├── main.cpp │ ├── newZombie.cpp │ └── randomChump.cpp ├── ex01 │ ├── Makefile │ ├── Zombie.cpp │ ├── Zombie.hpp │ ├── main.cpp │ └── zombieHorde.cpp ├── ex02 │ ├── Makefile │ └── main.cpp ├── ex03 │ ├── HumanA.cpp │ ├── HumanA.hpp │ ├── HumanB.cpp │ ├── HumanB.hpp │ ├── Makefile │ ├── Weapon.cpp │ ├── Weapon.hpp │ └── main.cpp ├── ex04 │ ├── Makefile │ ├── file │ ├── main.cpp │ └── main.hpp └── ex05 │ ├── Harl.cpp │ ├── Harl.hpp │ ├── Makefile │ └── main.cpp ├── cpp_02 ├── cpp_02.pdf ├── ex00 │ ├── Fixed.cpp │ ├── Fixed.hpp │ ├── Makefile │ └── main.cpp ├── ex01 │ ├── Fixed.cpp │ ├── Fixed.hpp │ ├── Makefile │ └── main.cpp └── ex02 │ ├── Fixed.cpp │ ├── Fixed.hpp │ ├── Makefile │ └── main.cpp ├── cpp_03 ├── cpp_03.pdf ├── ex00 │ ├── ClapTrap.cpp │ ├── ClapTrap.hpp │ ├── Makefile │ └── main.cpp ├── ex01 │ ├── ClapTrap.cpp │ ├── ClapTrap.hpp │ ├── Makefile │ ├── ScavTrap.cpp │ ├── ScavTrap.hpp │ └── main.cpp └── ex02 │ ├── ClapTrap.cpp │ ├── ClapTrap.hpp │ ├── FragTrap.cpp │ ├── FragTrap.hpp │ ├── Makefile │ ├── ScavTrap.cpp │ ├── ScavTrap.hpp │ └── main.cpp ├── cpp_04 ├── cpp_04.pdf ├── ex00 │ ├── Animal.cpp │ ├── Animal.hpp │ ├── Cat.cpp │ ├── Cat.hpp │ ├── Dog.cpp │ ├── Dog.hpp │ ├── Makefile │ ├── WrongAnimal.cpp │ ├── WrongAnimal.hpp │ ├── WrongCat.cpp │ ├── WrongCat.hpp │ └── main.cpp ├── ex01 │ ├── Animal.cpp │ ├── Animal.hpp │ ├── Animal.o │ ├── Brain.cpp │ ├── Brain.hpp │ ├── Cat.cpp │ ├── Cat.hpp │ ├── Cat.o │ ├── Dog.cpp │ ├── Dog.hpp │ ├── Dog.o │ ├── Makefile │ ├── main.cpp │ └── main.o └── ex02 │ ├── Animal.cpp │ ├── Animal.hpp │ ├── Brain.cpp │ ├── Brain.hpp │ ├── Cat.cpp │ ├── Cat.hpp │ ├── Dog.cpp │ ├── Dog.hpp │ ├── Makefile │ └── main.cpp ├── cpp_05 ├── cpp_05.pdf ├── ex00 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Makefile │ └── main.cpp ├── ex01 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Form.cpp │ ├── Form.hpp │ ├── Makefile │ └── main.cpp ├── ex02 │ ├── AForm.cpp │ ├── AForm.hpp │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Makefile │ ├── PresidentialPardonForm.cpp │ ├── PresidentialPardonForm.hpp │ ├── RobotomyRequestForm.cpp │ ├── RobotomyRequestForm.hpp │ ├── ShrubberyCreationForm.cpp │ ├── ShrubberyCreationForm.hpp │ └── main.cpp └── ex03 │ ├── AForm.cpp │ ├── AForm.hpp │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Intern.cpp │ ├── Intern.hpp │ ├── Makefile │ ├── PresidentialPardonForm.cpp │ ├── PresidentialPardonForm.hpp │ ├── RobotomyRequestForm.cpp │ ├── RobotomyRequestForm.hpp │ ├── ShrubberyCreationForm.cpp │ ├── ShrubberyCreationForm.hpp │ └── main.cpp ├── cpp_06 ├── Readme ├── cpp_06.pdf ├── ex00 │ ├── Convert.cpp │ ├── Convert.hpp │ ├── Makefile │ └── main.cpp ├── ex01 │ ├── Makefile │ ├── Serialize.cpp │ ├── Serialize.hpp │ └── main.cpp └── ex02 │ ├── A.cpp │ ├── A.hpp │ ├── B.cpp │ ├── B.hpp │ ├── Base.cpp │ ├── Base.hpp │ ├── C.cpp │ ├── C.hpp │ ├── Makefile │ ├── helper.cpp │ ├── helper.hpp │ └── main.cpp ├── cpp_07 ├── cpp_07.pdf ├── ex00 │ ├── Makefile │ ├── main.cpp │ └── whatever.hpp ├── ex01 │ ├── Makefile │ ├── iter │ ├── iter.hpp │ ├── main.cpp │ └── main.o ├── ex02 │ ├── Array.hpp │ ├── Array.tpp │ ├── Makefile │ └── main.cpp └── main.cpp └── cpp_08 ├── cpp_08.pdf ├── ex00 ├── Makefile ├── easyfind.hpp └── main.cpp ├── ex01 ├── Makefile ├── Span.cpp ├── Span.hpp └── main.cpp └── ex02 ├── Makefile ├── MutantStack.hpp └── main.cpp /cpp_00/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/11/13 14:31:48 by namohamm #+# #+# # 9 | # Updated: 2022/11/25 16:36:26 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = megaphone 14 | 15 | SRCS = megaphone.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(NAME) 24 | 25 | $(NAME): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(NAME) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | fclean: clean 32 | rm -f $(NAME) 33 | 34 | re: fclean all 35 | 36 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_00/ex00/megaphone.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* megaphone.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/13 14:26:32 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/25 16:02:02 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char **argv) 16 | { 17 | int i = 1; 18 | int j = 0; 19 | if (argc == 1) 20 | std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *"; 21 | while (i < argc) 22 | { 23 | while (argv[i][j]) 24 | { 25 | std::cout << (char)toupper(argv[i][j]); 26 | j++; 27 | } 28 | i++; 29 | j = 0; 30 | } 31 | std::cout << std::endl; 32 | return 0; 33 | } -------------------------------------------------------------------------------- /cpp_00/ex01/Contact.class.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Contact.class.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/20 12:48:56 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/21 13:50:28 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CONTACT_CLASS_HPP 14 | # define CONTACT_CLASS_HPP 15 | 16 | # include 17 | 18 | class Contact { 19 | private: 20 | std::string _firstName; 21 | std::string _lastName; 22 | std::string _nickname; 23 | long int _phoneNumber; 24 | std::string _darkestSecret; 25 | public: 26 | Contact(void); 27 | ~Contact(void); 28 | void setFirstName(void); 29 | void setLastName(void); 30 | void setNickname(void); 31 | void setPhoneNumber(void); 32 | void setDarkestSecret(void); 33 | std::string getFirstName(void); 34 | std::string getLastName(void); 35 | std::string getNickname(void); 36 | long int getPhoneNumber(void); 37 | std::string getDarkestSecret(void); 38 | void printContact(void); 39 | }; 40 | 41 | #endif -------------------------------------------------------------------------------- /cpp_00/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/11/13 14:31:48 by namohamm #+# #+# # 9 | # Updated: 2022/11/25 16:11:19 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = phonebook 14 | 15 | SRCS = PhoneBook.class.cpp Contact.class.cpp main.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | all: $(NAME) 22 | 23 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 24 | 25 | $(NAME): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(NAME) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | nass: $(NAME) clean 32 | 33 | fclean: clean 34 | rm -f $(NAME) 35 | 36 | re: fclean all 37 | 38 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_00/ex01/PhoneBook.class.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PhoneBook.class.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/20 13:00:40 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/25 16:35:05 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PHONEBOOK_CLASS_HPP 14 | # define PHONEBOOK_CLASS_HPP 15 | 16 | # include 17 | # include 18 | # include "Contact.class.hpp" 19 | 20 | class PhoneBook { 21 | private: 22 | Contact _contacts[8]; 23 | int _index; 24 | int _maxIndex; 25 | public: 26 | PhoneBook(void); 27 | ~PhoneBook(void); 28 | void addContact(Contact contact); 29 | void searchContact(void); 30 | void printContacts(void); 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /cpp_00/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/20 13:49:55 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/21 14:48:49 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "PhoneBook.class.hpp" 14 | 15 | int main(void) { 16 | PhoneBook phoneBook; 17 | std::string input; 18 | Contact contact; 19 | 20 | while (1) { 21 | std::cout << "+-------------------------------------------+" << std::endl; 22 | std::cout << "| Commands: ADD, SEARCH, EXIT |" << std::endl; 23 | std::cout << "+-------------------------------------------+" << std::endl; 24 | std::cout << "Enter a Command: "; 25 | if (!std::getline(std::cin, input)) 26 | break ; 27 | if (input == "EXIT") { 28 | break ; 29 | } else if (input == "ADD") { 30 | contact.setFirstName(); 31 | contact.setLastName(); 32 | contact.setNickname(); 33 | contact.setPhoneNumber(); 34 | contact.setDarkestSecret(); 35 | phoneBook.addContact(contact); 36 | } else if (input == "SEARCH") { 37 | phoneBook.searchContact(); 38 | } 39 | } 40 | return (0); 41 | } -------------------------------------------------------------------------------- /cpp_01/c01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_01/c01.pdf -------------------------------------------------------------------------------- /cpp_01/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/11/25 16:57:48 by namohamm #+# #+# # 9 | # Updated: 2022/11/28 11:50:58 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = brainz 14 | 15 | SRCS = main.cpp Zombie.cpp newZombie.cpp randomChump.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(NAME) 24 | 25 | $(NAME): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(NAME) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | nass: $(NAME) clean 32 | 33 | fclean: clean 34 | rm -f $(NAME) 35 | 36 | re: fclean all 37 | 38 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_01/ex00/Zombie.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Zombie.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/25 17:04:02 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/28 12:47:46 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Zombie.hpp" 14 | 15 | Zombie::Zombie( void ){ 16 | return; 17 | } 18 | 19 | Zombie::~Zombie( void ){ 20 | std::cout << this->_name << " has been destroyed" << std::endl; 21 | return ; 22 | } 23 | 24 | void Zombie::setName(std::string name) { 25 | this->_name = name; 26 | return ; 27 | } 28 | void Zombie::announce(void){ 29 | std::cout << this->_name << ": BraiiiiiiinnnzzzZ..." << std::endl; 30 | } -------------------------------------------------------------------------------- /cpp_01/ex00/Zombie.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Zombie.class.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/25 17:02:04 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/28 11:50:03 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ZOMBIE_CLASS_HPP 14 | # define ZOMBIE_CLASS_HPP 15 | 16 | #include 17 | 18 | class Zombie 19 | { 20 | private: 21 | std::string _name; 22 | public: 23 | Zombie( void ); 24 | ~Zombie( void ); 25 | void announce( void ); 26 | void setName( std::string name ); 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /cpp_01/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/25 17:18:02 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/01 10:47:50 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Zombie.hpp" 14 | 15 | Zombie *newZombie( std::string name ); 16 | void randomChump( std::string name ); 17 | 18 | int main(void) 19 | { 20 | Zombie *zombie; 21 | zombie = newZombie("newNass"); 22 | randomChump("randomNass"); 23 | delete zombie; 24 | return (0); 25 | } -------------------------------------------------------------------------------- /cpp_01/ex00/newZombie.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* newZombie.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 11:25:20 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/28 12:47:54 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Zombie.hpp" 14 | 15 | Zombie *newZombie( std::string name ) { 16 | Zombie *zombie = new Zombie(); 17 | zombie->setName(name); 18 | return (zombie); 19 | } 20 | -------------------------------------------------------------------------------- /cpp_01/ex00/randomChump.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* randomChump.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 11:27:18 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/28 12:48:01 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Zombie.hpp" 14 | 15 | void randomChump( std::string name ) { 16 | Zombie zombie = Zombie(); 17 | zombie.setName(name); 18 | zombie.announce(); 19 | } -------------------------------------------------------------------------------- /cpp_01/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/11/28 11:45:18 by namohamm #+# #+# # 9 | # Updated: 2022/11/28 13:26:31 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = horde 14 | 15 | SRCS = main.cpp Zombie.cpp zombieHorde.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(NAME) 24 | 25 | $(NAME): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(NAME) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | nass: $(NAME) clean 32 | 33 | fclean: clean 34 | rm -f $(NAME) 35 | 36 | re: fclean all 37 | 38 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_01/ex01/Zombie.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Zombie.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 11:55:48 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/01 10:46:42 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Zombie.hpp" 14 | 15 | Zombie::Zombie( void ) { 16 | std::cout << "Zombie created" << std::endl; 17 | return ; 18 | } 19 | 20 | Zombie::~Zombie( void ) { 21 | std::cout << "Zombie " << this->_name << " has been destroyed." << std::endl; 22 | return ; 23 | } 24 | 25 | 26 | void Zombie::setName( std::string name ) { 27 | this->_name = name; 28 | return ; 29 | } 30 | 31 | void Zombie::announce(void){ 32 | std::cout << this->_name << ": BraiiiiiiinnnzzzZ..." << std::endl; 33 | } -------------------------------------------------------------------------------- /cpp_01/ex01/Zombie.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Zombie.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 11:55:20 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/01 10:46:58 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ZOMBIE_HPP 14 | # define ZOMBIE_HPP 15 | 16 | # include 17 | 18 | class Zombie 19 | { 20 | private: 21 | std::string _name; 22 | public: 23 | Zombie( void ); 24 | ~Zombie( void ); 25 | void setName( std::string name ); 26 | void announce( void ); 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /cpp_01/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 12:54:01 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/01 10:47:36 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Zombie.hpp" 14 | 15 | Zombie* zombieHorde( int N, std::string name ); 16 | 17 | int main( void ) 18 | { 19 | Zombie* horde = zombieHorde(10, "Bob"); 20 | delete[] horde; 21 | return (0); 22 | } -------------------------------------------------------------------------------- /cpp_01/ex01/zombieHorde.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* zombieHorde.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 11:54:33 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/01 10:47:16 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Zombie.hpp" 14 | 15 | Zombie* zombieHorde( int N, std::string name ) 16 | { 17 | Zombie* horde = new Zombie[N]; 18 | for (int i = 0; i < N; i++) { 19 | horde[i].setName(name); 20 | horde[i].announce(); 21 | } 22 | return (horde); 23 | } -------------------------------------------------------------------------------- /cpp_01/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/11/28 13:27:52 by namohamm #+# #+# # 9 | # Updated: 2022/11/28 13:28:36 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = hi 14 | 15 | SRCS = main.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(NAME) 24 | 25 | $(NAME): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(NAME) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | nass: $(NAME) clean 32 | 33 | fclean: clean 34 | rm -f $(NAME) 35 | 36 | re: fclean all 37 | 38 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_01/ex02/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 13:28:43 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/28 13:38:32 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main( void ) { 16 | std::string str = "HI THIS IS BRAIN"; 17 | std::string* stringPTR = &str; 18 | std::string &stringREF = str; 19 | 20 | std::cout << "Memory addresses:" << std::endl; 21 | std::cout << " String: " << &str << std::endl; 22 | std::cout << " StringPTR: " << stringPTR << std::endl; 23 | std::cout << " StringREF: " << &stringREF << std::endl; 24 | 25 | std::cout << "String values:" << std::endl; 26 | std::cout << " String: " << str << std::endl; 27 | std::cout << " StringPTR: " << *stringPTR << std::endl; 28 | std::cout << " StringREF: " << stringREF << std::endl; 29 | 30 | return (0); 31 | } -------------------------------------------------------------------------------- /cpp_01/ex03/HumanA.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanA.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 16:15:40 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/29 11:02:11 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "HumanA.hpp" 14 | 15 | HumanA::HumanA( std::string name, Weapon &weapon) : _name(name), _weapon(weapon) { 16 | } 17 | 18 | HumanA::~HumanA( void ) { 19 | return ; 20 | } 21 | 22 | void HumanA::attack( void ) { 23 | std::cout << this->_name << " attacks with his " << this->_weapon.getType() << std::endl; 24 | return ; 25 | } -------------------------------------------------------------------------------- /cpp_01/ex03/HumanA.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanA.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 13:50:46 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/29 10:59:44 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HUMANA_HPP 14 | # define HUMANA_HPP 15 | 16 | # include 17 | # include "Weapon.hpp" 18 | 19 | class HumanA { 20 | private: 21 | std::string _name; 22 | Weapon &_weapon; 23 | public: 24 | HumanA(std::string name, Weapon &weapon); 25 | ~HumanA( void ); 26 | void attack( void ); 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /cpp_01/ex03/HumanB.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanB.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 16:25:50 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/01 11:01:00 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "HumanB.hpp" 14 | 15 | HumanB::HumanB( std::string name ) : _name(name), _weapon(NULL) { 16 | return ; 17 | } 18 | 19 | HumanB::~HumanB( void ) { 20 | return ; 21 | } 22 | 23 | void HumanB::attack( void ) { 24 | if (this->_weapon != NULL) { 25 | std::cout << this->_name << " attacks with his " << this->_weapon->getType() << std::endl; 26 | } else { 27 | std::cout << this->_name << " attacks with his fists" << std::endl; 28 | } 29 | return ; 30 | } 31 | 32 | void HumanB::setWeapon(Weapon &weapon) { 33 | this->_weapon = &weapon; 34 | return ; 35 | } -------------------------------------------------------------------------------- /cpp_01/ex03/HumanB.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanB.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 16:10:23 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/29 11:03:38 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HUMANB_HPP 14 | # define HUMANB_HPP 15 | 16 | # include 17 | # include "Weapon.hpp" 18 | 19 | class HumanB { 20 | private: 21 | std::string _name; 22 | Weapon *_weapon; 23 | public: 24 | HumanB(std::string name); 25 | ~HumanB( void ); 26 | void attack( void ); 27 | void setWeapon(Weapon &weapon); 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /cpp_01/ex03/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/11/28 13:44:09 by namohamm #+# #+# # 9 | # Updated: 2022/11/29 11:06:41 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = violence 14 | 15 | SRCS = main.cpp Weapon.cpp HumanA.cpp HumanB.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(NAME) 24 | 25 | $(NAME): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(NAME) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | nass: $(NAME) clean 32 | 33 | fclean: clean 34 | rm -f $(NAME) 35 | 36 | re: fclean all 37 | 38 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_01/ex03/Weapon.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Weapon.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 16:19:19 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/29 10:38:33 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Weapon.hpp" 14 | 15 | Weapon::Weapon( std::string type ) { 16 | this->_type = type; 17 | return ; 18 | } 19 | 20 | Weapon::~Weapon( void ) { 21 | return ; 22 | } 23 | 24 | std::string const &Weapon::getType(void) { 25 | return (this->_type); 26 | } 27 | 28 | void Weapon::setType(std::string type) { 29 | this->_type = type; 30 | return ; 31 | } -------------------------------------------------------------------------------- /cpp_01/ex03/Weapon.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Weapon.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 13:48:13 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/29 10:38:41 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef WEAPON_HPP 14 | # define WEAPON_HPP 15 | 16 | #include 17 | 18 | class Weapon { 19 | private: 20 | std::string _type; 21 | public: 22 | Weapon( std::string type ); 23 | ~Weapon( void ); 24 | std::string const &getType(void); 25 | void setType(std::string type); 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /cpp_01/ex03/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/28 13:44:52 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/06 10:12:56 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Weapon.hpp" 14 | #include "HumanA.hpp" 15 | #include "HumanB.hpp" 16 | 17 | int main() 18 | { 19 | { 20 | Weapon club = Weapon("crude spiked club"); 21 | 22 | HumanA bob("Bob", club); 23 | bob.attack(); 24 | club.setType("some other type of club"); 25 | bob.attack(); 26 | } 27 | { 28 | Weapon club = Weapon("crude spiked club"); 29 | 30 | HumanB jim("Jim"); 31 | jim.setWeapon(club); 32 | jim.attack(); 33 | club.setType("some other type of club"); 34 | jim.attack(); 35 | } 36 | return 0; 37 | } -------------------------------------------------------------------------------- /cpp_01/ex04/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/11/29 11:12:45 by namohamm #+# #+# # 9 | # Updated: 2022/11/29 11:14:15 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = replace 14 | 15 | SRCS = main.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(NAME) 24 | 25 | $(NAME): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(NAME) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | nass: $(NAME) clean 32 | 33 | fclean: clean 34 | rm -f $(NAME) 35 | 36 | re: fclean all 37 | 38 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_01/ex04/file: -------------------------------------------------------------------------------- 1 | okay how hello-hello-how-are_hello-you are you ? I added hello Nass S1 hello S2 2 | I think a hello is something that is very important to say to someone hello is the key of happy life hello hello hello -------------------------------------------------------------------------------- /cpp_01/ex04/main.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/29 11:52:52 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/29 11:54:09 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef MAIN_HPP 14 | # define MAIN_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | 21 | #endif -------------------------------------------------------------------------------- /cpp_01/ex05/Harl.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Harl.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/01 09:20:18 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/01 10:18:16 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HARL_HPP 14 | # define HARL_HPP 15 | 16 | /* 17 | ** What is an Orthodox Canonical Class? 18 | ** well, it's a class that has 4 functions: 19 | ** 1- Default Constructor 20 | ** 2- Copy Constructor 21 | ** 3- Assignment Operator 22 | ** 4- Destructor 23 | */ 24 | 25 | # include 26 | 27 | class Harl { 28 | private: 29 | void debug( void ); 30 | void info( void ); 31 | void warning( void ); 32 | void error( void ); 33 | public: 34 | Harl( void ); // default constructor 35 | ~Harl( void ); // destructor 36 | Harl( Harl const & src ); // copy constructor 37 | Harl & operator=( Harl const & rhs ); // assignment operator 38 | void complain( std::string level ); // member function 39 | }; 40 | 41 | #endif -------------------------------------------------------------------------------- /cpp_01/ex05/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/01 09:18:19 by namohamm #+# #+# # 9 | # Updated: 2022/12/01 09:46:02 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = harl 14 | 15 | SRCS = main.cpp Harl.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CXXFLAGS = -Wall -Wextra -Werror 22 | 23 | $(Name): $(OBJS) 24 | $(CXX) $(CXXFLAGS) $(OBJS) -o $(Name) 25 | 26 | all: $(Name) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | fclean: clean 32 | rm -f $(Name) 33 | 34 | re: fclean all 35 | 36 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_01/ex05/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/01 09:44:45 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/06 09:58:28 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Harl.hpp" 14 | 15 | int main( void ){ 16 | Harl harl; 17 | 18 | std::cout << std::endl; 19 | harl.complain("DEBUG"); 20 | std::cout << std::endl; 21 | harl.complain("INFO"); 22 | std::cout << std::endl; 23 | harl.complain("WARNING"); 24 | std::cout << std::endl; 25 | harl.complain("ERROR"); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /cpp_02/cpp_02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_02/cpp_02.pdf -------------------------------------------------------------------------------- /cpp_02/ex00/Fixed.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Fixed.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/29 19:45:21 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/30 21:22:23 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Fixed.hpp" 14 | 15 | Fixed::Fixed() : _fixedPointValue(0) { 16 | std::cout << "Default constructor called" << std::endl; 17 | } 18 | 19 | Fixed::Fixed(const Fixed ©) { 20 | std::cout << "Copy constructor called" << std::endl; 21 | *this = copy; 22 | } 23 | 24 | Fixed::~Fixed() { 25 | std::cout << "Destructor called" << std::endl; 26 | } 27 | 28 | Fixed& Fixed::operator=(const Fixed &rhs) { 29 | std::cout << "Copy assignation operator called" << std::endl; 30 | this->_fixedPointValue = rhs.getRawBits(); 31 | return *this; 32 | } 33 | 34 | 35 | int Fixed::getRawBits(void) const { 36 | std::cout << "getRawBits member function called" << std::endl; 37 | return this->_fixedPointValue; 38 | } 39 | 40 | void Fixed::setRawBits(int const raw) { 41 | this->_fixedPointValue = raw; 42 | } -------------------------------------------------------------------------------- /cpp_02/ex00/Fixed.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Fixed.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/29 19:43:21 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/29 19:55:51 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FIXED_HPP 14 | # define FIXED_HPP 15 | 16 | # include 17 | 18 | class Fixed 19 | { 20 | private: 21 | int _fixedPointValue; 22 | static const int _fractionalBits = 8; 23 | public: 24 | Fixed(); 25 | Fixed(const Fixed ©); 26 | ~Fixed(); 27 | Fixed& operator=(const Fixed &rhs); 28 | int getRawBits(void) const; 29 | void setRawBits(int const raw); 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /cpp_02/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/11/29 19:38:31 by namohamm #+# #+# # 9 | # Updated: 2022/11/29 19:51:22 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = fixed_1 14 | 15 | SRCS = main.cpp Fixed.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = clang++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | nass: clean 32 | rm -f $(Name) 33 | 34 | fclean: clean 35 | rm -f $(Name) 36 | 37 | re: fclean all 38 | 39 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_02/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/29 19:48:56 by namohamm #+# #+# */ 9 | /* Updated: 2022/11/29 19:49:35 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Fixed.hpp" 14 | 15 | int main( void ) { 16 | Fixed a; 17 | Fixed b(a); 18 | Fixed c; 19 | 20 | c = b; 21 | 22 | std::cout << a.getRawBits() << std::endl; 23 | std::cout << b.getRawBits() << std::endl; 24 | std::cout << c.getRawBits() << std::endl; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /cpp_02/ex01/Fixed.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Fixed.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/29 23:53:31 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/03 06:35:06 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FIXED_HPP 14 | # define FIXED_HPP 15 | 16 | # include 17 | 18 | class Fixed 19 | { 20 | private: 21 | int _fixedPointValue; 22 | static const int _fractionalBits = 8; 23 | public: 24 | Fixed(); 25 | Fixed(const Fixed ©); 26 | ~Fixed(); 27 | Fixed& operator=(const Fixed &rhs); 28 | int getRawBits(void) const; 29 | void setRawBits(int const raw); 30 | Fixed(const int value); 31 | Fixed(const float value); 32 | float toFloat(void) const; 33 | int toInt(void) const; 34 | }; 35 | 36 | std::ostream& operator<<(std::ostream &out, const Fixed &rhs); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /cpp_02/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/11/29 21:06:32 by namohamm #+# #+# # 9 | # Updated: 2022/12/07 14:10:48 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = fixed_2 14 | 15 | SRCS = main.cpp Fixed.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = clang++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g3 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | nass: clean 32 | rm -f $(Name) 33 | 34 | fclean: clean 35 | rm -f $(Name) 36 | 37 | re: fclean all 38 | 39 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_02/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/11/29 23:49:27 by namohamm #+# #+# */ 9 | 10 | /* Updated: 2022/12/01 11:45:17 by namohamm ### ########.fr */ 11 | /* */ 12 | /* ************************************************************************** */ 13 | 14 | #include "Fixed.hpp" 15 | #include 16 | #include 17 | #include 18 | int main ( void ) { 19 | 20 | Fixed a; 21 | Fixed const b( 10 ); 22 | Fixed const c( 42.42f ); 23 | Fixed const d( b ); 24 | 25 | a = Fixed( 1234.4321f ); 26 | std::cout << "a is " << a << std::endl; 27 | std::cout << "b is " << b << std::endl; 28 | std::cout << "c is " << c << std::endl; 29 | std::cout << "d is " << d << std::endl; 30 | std::cout << "a is " << a.toInt() << " as integer" << std::endl; 31 | std::cout << "b is " << b.toInt() << " as integer" << std::endl; 32 | std::cout << "c is " << c.toInt() << " as integer" << std::endl; 33 | std::cout << "d is " << d.toInt() << " as integer" << std::endl; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /cpp_02/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/03 12:20:58 by namohamm #+# #+# # 9 | # Updated: 2022/12/03 12:21:16 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = fixed_3 14 | 15 | SRCS = main.cpp Fixed.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = clang++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | nass: clean 32 | rm -f $(Name) 33 | 34 | fclean: clean 35 | rm -f $(Name) 36 | 37 | re: fclean all 38 | 39 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_02/ex02/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/03 12:21:41 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/03 12:34:40 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Fixed.hpp" 14 | 15 | int main(void) { 16 | Fixed a; 17 | Fixed b(Fixed(5.05f) * Fixed(2)); 18 | 19 | std::cout << a << std::endl; 20 | std::cout << ++a << std::endl; 21 | std::cout << a << std::endl; 22 | std::cout << a++ << std::endl; 23 | std::cout << a << std::endl; 24 | 25 | std::cout << b << std::endl; 26 | 27 | std::cout << Fixed::max(a, b) << std::endl; 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /cpp_03/cpp_03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_03/cpp_03.pdf -------------------------------------------------------------------------------- /cpp_03/ex00/ClapTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ClapTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/01 14:59:47 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/09 10:44:30 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CLAPTRAP_HPP 14 | # define CLAPTRAP_HPP 15 | 16 | # include 17 | 18 | class ClapTrap { 19 | private: 20 | std::string _name; 21 | int _hitPoints; 22 | int _energyPoints; 23 | int _attackDamage; 24 | public: 25 | ClapTrap(); 26 | ClapTrap( std::string name ); 27 | ClapTrap( ClapTrap const & rhs ); 28 | ClapTrap & operator=( ClapTrap const & rhs ); 29 | ~ClapTrap(); 30 | void attack( std::string const & target ); 31 | void takeDamage( unsigned int amount ); 32 | void beRepaired( unsigned int amount ); 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /cpp_03/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/01 14:40:52 by namohamm #+# #+# # 9 | # Updated: 2022/12/09 10:41:04 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = claptrap 14 | 15 | SRCS = main.cpp ClapTrap.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | 41 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_03/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/01 21:28:49 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/09 10:45:56 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ClapTrap.hpp" 14 | 15 | int main(void) { 16 | ClapTrap clapTrap("ClapTrap"); 17 | std::cout << "------------------"<< std::endl; 18 | clapTrap.attack("Enemy"); 19 | clapTrap.takeDamage(9); 20 | clapTrap.beRepaired(8); 21 | std::cout << "------------------"<< std::endl; 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /cpp_03/ex01/ClapTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ClapTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/01 14:59:47 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/04 17:23:51 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CLAPTRAP_HPP 14 | # define CLAPTRAP_HPP 15 | 16 | # include 17 | 18 | class ClapTrap { 19 | protected: 20 | std::string _name; 21 | int _hitPoints; 22 | int _energyPoints; 23 | int _attackDamage; 24 | public: 25 | ClapTrap(); 26 | ClapTrap( std::string name ); 27 | ClapTrap( ClapTrap const& rhs ); 28 | ClapTrap& operator=( ClapTrap const& rhs ); 29 | ~ClapTrap(); 30 | void attack( std::string const& target ); 31 | void takeDamage( unsigned int amount ); 32 | void beRepaired( unsigned int amount ); 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /cpp_03/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/01 14:40:52 by namohamm #+# #+# # 9 | # Updated: 2022/12/09 10:47:29 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = scravtrap 14 | 15 | SRCS = main.cpp ClapTrap.cpp ScavTrap.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | 41 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_03/ex01/ScavTrap.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ScavTrap.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 13:09:53 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/04 13:12:28 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ScavTrap.hpp" 14 | 15 | ScavTrap::ScavTrap() : ClapTrap() { 16 | std::cout << "ScavTrap Default Constructor Called" << std::endl; 17 | } 18 | 19 | ScavTrap::ScavTrap( std::string name ) : ClapTrap(name) { 20 | std::cout << "ScavTrap Constructor Called" << std::endl; 21 | if (!this->_name.length()) { 22 | this->_name = "Default"; 23 | } 24 | } 25 | 26 | ScavTrap::ScavTrap( ScavTrap const & rhs ) { 27 | std::cout << "ScavTrap Copy Constructor Called" << std::endl; 28 | *this = rhs; 29 | } 30 | 31 | ScavTrap & ScavTrap::operator=( ScavTrap const & rhs ) { 32 | std::cout << "ScavTrap Assignation Operator Called" << std::endl; 33 | if (this != &rhs) { 34 | this->_name = rhs._name; 35 | this->_hitPoints = rhs._hitPoints; 36 | this->_energyPoints = rhs._energyPoints; 37 | this->_attackDamage = rhs._attackDamage; 38 | } 39 | return *this; 40 | } 41 | 42 | ScavTrap::~ScavTrap() { 43 | std::cout << "ScavTrap Destructor Called" << std::endl; 44 | } 45 | 46 | void ScavTrap::guardGate() { 47 | std::cout << "ScavTrap " << this->_name << " has entered Gate keeper mode" << std::endl; 48 | } 49 | -------------------------------------------------------------------------------- /cpp_03/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/01 21:28:49 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/04 17:27:22 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ClapTrap.hpp" 14 | #include "ScavTrap.hpp" 15 | 16 | int main(void) { 17 | ClapTrap clapTrap("ClapTrap"); 18 | ScavTrap scavTrap("ScavTrap"); 19 | std::cout << "------------------"<< std::endl; 20 | clapTrap.attack("Enemy"); 21 | clapTrap.takeDamage(10); 22 | clapTrap.beRepaired(5); 23 | std::cout << "------------------"<< std::endl; 24 | scavTrap.attack("Enemy"); 25 | scavTrap.takeDamage(10); 26 | scavTrap.beRepaired(5); 27 | scavTrap.guardGate(); 28 | std::cout << "------------------"<< std::endl; 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /cpp_03/ex02/ClapTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ClapTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/01 14:59:47 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/01 21:44:50 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CLAPTRAP_HPP 14 | # define CLAPTRAP_HPP 15 | 16 | # include 17 | 18 | class ClapTrap { 19 | protected: 20 | std::string _name; 21 | int _hitPoints; 22 | int _energyPoints; 23 | int _attackDamage; 24 | public: 25 | ClapTrap(); 26 | ClapTrap( std::string name ); 27 | ClapTrap( ClapTrap const & rhs ); 28 | ClapTrap & operator=( ClapTrap const & rhs ); 29 | ~ClapTrap(); 30 | void attack( std::string const & target ); 31 | void takeDamage( unsigned int amount ); 32 | void beRepaired( unsigned int amount ); 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /cpp_03/ex02/FragTrap.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* FragTrap.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 14:25:40 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/09 10:59:09 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "FragTrap.hpp" 14 | 15 | FragTrap::FragTrap(void) : ClapTrap() { 16 | std::cout << "FragTrap Default Constructor Called" << std::endl; 17 | } 18 | 19 | FragTrap::FragTrap(std::string name) : ClapTrap(name) { 20 | std::cout << "FragTrap Name Constructor Called" << std::endl; 21 | } 22 | 23 | FragTrap::FragTrap(FragTrap const & rhs) : ClapTrap(rhs) { 24 | std::cout << "FragTrap Copy Constructor Called" << std::endl; 25 | *this = rhs; 26 | } 27 | 28 | FragTrap::~FragTrap(void) { 29 | std::cout << "FragTrap Destructor Called" << std::endl; 30 | } 31 | 32 | FragTrap & FragTrap::operator=(FragTrap const & rhs) { 33 | std::cout << "FragTrap Assignation Operator Called" << std::endl; 34 | if (this != &rhs) { 35 | this->_name = rhs._name; 36 | this->_hitPoints = rhs._hitPoints; 37 | this->_energyPoints = rhs._energyPoints; 38 | this->_attackDamage = rhs._attackDamage; 39 | } 40 | return *this; 41 | } 42 | 43 | void FragTrap::highFivesGuys(void) { 44 | std::cout << "FragTrap " << this->_name << " gives high fives to everyone" << std::endl; 45 | } 46 | -------------------------------------------------------------------------------- /cpp_03/ex02/FragTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* FragTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 14:23:21 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/04 17:09:04 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FRAGTRAP_HPP 14 | # define FRAGTRAP_HPP 15 | 16 | # include 17 | # include "ClapTrap.hpp" 18 | 19 | // FragTrap Class inherits from ClapTrap Class 20 | class FragTrap : public ClapTrap { 21 | public: 22 | FragTrap(void); 23 | FragTrap(std::string name); 24 | FragTrap(FragTrap const& src); 25 | ~FragTrap(void); 26 | FragTrap& operator=(FragTrap const& rhs); 27 | void highFivesGuys(void); 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /cpp_03/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/01 14:40:52 by namohamm #+# #+# # 9 | # Updated: 2022/12/09 10:52:50 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = fragtrap 14 | 15 | SRCS = main.cpp ClapTrap.cpp ScavTrap.cpp FragTrap.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | 41 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_03/ex02/ScavTrap.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ScavTrap.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 13:09:53 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/04 17:09:19 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ScavTrap.hpp" 14 | 15 | ScavTrap::ScavTrap() : ClapTrap() { 16 | std::cout << "ScavTrap Default Constructor Called" << std::endl; 17 | } 18 | 19 | ScavTrap::ScavTrap( std::string name ) : ClapTrap(name) { 20 | std::cout << "ScavTrap Constructor Called" << std::endl; 21 | if (!this->_name.length()) { 22 | this->_name = "Default"; 23 | } 24 | } 25 | 26 | ScavTrap::ScavTrap( ScavTrap const & rhs ) { 27 | std::cout << "ScavTrap Copy Constructor Called" << std::endl; 28 | *this = rhs; 29 | } 30 | 31 | ScavTrap & ScavTrap::operator=( ScavTrap const & rhs ) { 32 | std::cout << "ScavTrap Assignation Operator Called" << std::endl; 33 | if (this != &rhs) { 34 | this->_name = rhs._name; 35 | this->_hitPoints = rhs._hitPoints; 36 | this->_energyPoints = rhs._energyPoints; 37 | this->_attackDamage = rhs._attackDamage; 38 | } 39 | return *this; 40 | } 41 | 42 | ScavTrap::~ScavTrap() { 43 | std::cout << "ScavTrap Destructor Called" << std::endl; 44 | } 45 | 46 | void ScavTrap::guardGate() { 47 | std::cout << "ScavTrap " << this->_name << " has entered Gate keeper mode" << std::endl; 48 | } 49 | -------------------------------------------------------------------------------- /cpp_03/ex02/ScavTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ScavTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/02 00:28:27 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/04 17:09:06 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SCAVTRAP_HPP 14 | # define SCAVTRAP_HPP 15 | 16 | # include 17 | # include "ClapTrap.hpp" 18 | 19 | // SravTrap inherits from ClapTrap 20 | // its constructor and destructor and attack will print a 21 | // different message than the ones in ClapTrap 22 | 23 | /* 24 | ** What is inheritance? 25 | ** Inheritance is a way to reuse code. It allows you to create a new class 26 | ** that reuses (inherits) all the properties and behaviors of an existing class. 27 | ** The class whose properties and behaviors are inherited is called the base class. 28 | ** The class that inherits the properties and behaviors of the base class is called 29 | ** the derived class. 30 | ** the derived class can add its own properties and behaviors in addition to the 31 | ** inherited ones. 32 | ** The derived class can also override the behavior of the base class. 33 | ** Here the syntax: 34 | ** class DerivedClassName : access BaseClassName { 35 | ** // body of the derived class 36 | ** } 37 | ** access can be public, protected or private 38 | ** access specifies the access level for the base class members in the derived class 39 | */ 40 | 41 | class ScavTrap : public ClapTrap { 42 | public: 43 | ScavTrap(); 44 | ScavTrap( std::string name ); 45 | ScavTrap( ScavTrap const& rhs ); 46 | ~ScavTrap(); 47 | ScavTrap& operator=( ScavTrap const& rhs ); 48 | void guardGate(); 49 | }; 50 | 51 | #endif -------------------------------------------------------------------------------- /cpp_03/ex02/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/01 21:28:49 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/09 10:59:44 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ClapTrap.hpp" 14 | #include "ScavTrap.hpp" 15 | #include "FragTrap.hpp" 16 | 17 | int main(void) { 18 | ClapTrap clapTrap("ClapTrap"); 19 | ScavTrap scavTrap("ScavTrap"); 20 | FragTrap fragTrap("FragTrap"); 21 | std::cout << "------------------"<< std::endl; 22 | clapTrap.attack("Enemy"); 23 | clapTrap.takeDamage(10); 24 | clapTrap.beRepaired(5); 25 | std::cout << "------------------"<< std::endl; 26 | scavTrap.attack("Enemy"); 27 | scavTrap.takeDamage(10); 28 | scavTrap.beRepaired(5); 29 | scavTrap.guardGate(); 30 | std::cout << "------------------"<< std::endl; 31 | fragTrap.attack("Enemy"); 32 | fragTrap.takeDamage(10); 33 | fragTrap.beRepaired(5); 34 | fragTrap.highFivesGuys(); 35 | std::cout << "------------------"<< std::endl; 36 | return 0; 37 | } -------------------------------------------------------------------------------- /cpp_04/cpp_04.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_04/cpp_04.pdf -------------------------------------------------------------------------------- /cpp_04/ex00/Animal.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:11:53 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 10:45:59 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Animal.hpp" 14 | 15 | Animal::Animal(): _type() { 16 | std::cout << "Animal Default Constructor Called" << std::endl; 17 | this->_type = "Animal"; 18 | } 19 | 20 | Animal::Animal( Animal const& rhs ) { 21 | std::cout << "Animal Copy Constructor Called" << std::endl; 22 | *this = rhs; 23 | } 24 | 25 | Animal::~Animal() { 26 | std::cout << "Animal Destructor Called" << std::endl; 27 | } 28 | 29 | Animal& Animal::operator=(Animal const& rhs) { 30 | std::cout << "Animal Assignation Operator Called" << std::endl; 31 | if (this != &rhs) 32 | this->_type = rhs._type; 33 | return *this; 34 | } 35 | 36 | std::string Animal::getType() const { 37 | return this->_type; 38 | } 39 | 40 | void Animal::makeSound() const { 41 | std::cout << "Animal Sound!" << std::endl; 42 | } -------------------------------------------------------------------------------- /cpp_04/ex00/Animal.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 17:47:22 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 10:40:27 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ANIMAL_HPP 14 | # define ANIMAL_HPP 15 | 16 | # include 17 | 18 | class Animal 19 | { 20 | protected: 21 | std::string _type; 22 | public: 23 | Animal(); 24 | Animal( Animal const& rhs ); 25 | virtual ~Animal(); 26 | Animal& operator=(Animal const& rhs); 27 | virtual void makeSound() const; 28 | std::string getType() const; 29 | }; 30 | 31 | #endif -------------------------------------------------------------------------------- /cpp_04/ex00/Cat.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:21:08 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/09 18:07:52 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Cat.hpp" 14 | 15 | Cat::Cat(): Animal() { 16 | std::cout << "Cat Default Constructor Called" << std::endl; 17 | this->_type = "Cat"; 18 | } 19 | 20 | Cat::Cat( Cat const& rhs ) { 21 | std::cout << "Cat Copy Constructor Called" << std::endl; 22 | *this = rhs; 23 | } 24 | 25 | Cat::~Cat() { 26 | std::cout << "Cat Destructor Called" << std::endl; 27 | } 28 | 29 | Cat& Cat::operator=(Cat const& rhs) { 30 | std::cout << "Cat Assignation Operator Called" << std::endl; 31 | if (this != &rhs) 32 | this->_type = rhs._type; 33 | return *this; 34 | } 35 | 36 | void Cat::makeSound() const { 37 | std::cout << "Meow meow!" << std::endl; 38 | } -------------------------------------------------------------------------------- /cpp_04/ex00/Cat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:21:44 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/09 18:07:11 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CAT_HPP 14 | # define CAT_HPP 15 | 16 | # include "Animal.hpp" 17 | 18 | class Cat : public Animal { 19 | public: 20 | Cat(); 21 | Cat( Cat const& rhs ); 22 | ~Cat(); 23 | Cat& operator=(Cat const& rhs); 24 | void makeSound() const; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /cpp_04/ex00/Dog.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:19:34 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/09 14:29:36 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Dog.hpp" 14 | 15 | Dog::Dog(): Animal() { 16 | std::cout << "Dog Default Constructor Called" << std::endl; 17 | this->_type = "Dog"; 18 | } 19 | 20 | Dog::Dog( Dog const& rhs ) { 21 | std::cout << "Dog Copy Constructor Called" << std::endl; 22 | *this = rhs; 23 | } 24 | 25 | Dog::~Dog() { 26 | std::cout << "Dog Destructor Called" << std::endl; 27 | } 28 | 29 | Dog& Dog::operator=(Dog const& rhs) { 30 | std::cout << "Dog Assignation Operator Called" << std::endl; 31 | if (this != &rhs) 32 | this->_type = rhs._type; 33 | return *this; 34 | } 35 | 36 | void Dog::makeSound() const { 37 | std::cout << "Woof woof!" << std::endl; 38 | } -------------------------------------------------------------------------------- /cpp_04/ex00/Dog.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:14:57 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/09 14:00:35 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DOG_HPP 14 | # define DOG_HPP 15 | 16 | # include "Animal.hpp" 17 | 18 | class Dog : public Animal { 19 | public: 20 | Dog(); 21 | Dog( Dog const& rhs ); 22 | ~Dog(); 23 | Dog& operator=(Dog const& rhs); 24 | void makeSound() const; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /cpp_04/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/04 17:45:18 by namohamm #+# #+# # 9 | # Updated: 2022/12/11 10:36:59 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = animal 14 | 15 | SRCS = main.cpp Animal.cpp Dog.cpp Cat.cpp WrongAnimal.cpp WrongCat.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | 41 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_04/ex00/WrongAnimal.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* WrongAnimal.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/05 22:43:52 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 12:03:05 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "WrongAnimal.hpp" 14 | 15 | WrongAnimal::WrongAnimal() { 16 | std::cout << "WrongAnimal constructor called" << std::endl; 17 | this->_type = "WrongAnimal"; 18 | } 19 | 20 | WrongAnimal::WrongAnimal( WrongAnimal const& rhs ) { 21 | std::cout << "WrongAnimal copy constructor called" << std::endl; 22 | *this = rhs; 23 | } 24 | 25 | WrongAnimal::~WrongAnimal() { 26 | std::cout << "WrongAnimal destructor called" << std::endl; 27 | } 28 | 29 | WrongAnimal& WrongAnimal::operator=(WrongAnimal const& rhs) { 30 | std::cout << "WrongAnimal assignation operator called" << std::endl; 31 | if (this != &rhs) 32 | this->_type = rhs._type; 33 | return *this; 34 | } 35 | 36 | std::string WrongAnimal::getType() const { 37 | return this->_type; 38 | } 39 | 40 | void WrongAnimal::makeSound() const { 41 | std::cout << "WrongAnimal sound!" << std::endl; 42 | } 43 | -------------------------------------------------------------------------------- /cpp_04/ex00/WrongAnimal.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* WrongAnimal.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/05 22:40:01 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 12:03:38 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef WRONGANIMAL_HPP 14 | # define WRONGANIMAL_HPP 15 | 16 | #include 17 | 18 | class WrongAnimal { 19 | protected: 20 | std::string _type; 21 | public: 22 | WrongAnimal(); 23 | WrongAnimal( WrongAnimal const& rhs ); 24 | ~WrongAnimal(); 25 | WrongAnimal& operator=(WrongAnimal const& rhs); 26 | std::string getType() const; 27 | void makeSound() const; 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /cpp_04/ex00/WrongCat.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* WrongCat.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/05 22:45:37 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 12:03:19 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "WrongCat.hpp" 14 | 15 | WrongCat::WrongCat() { 16 | std::cout << "WrongCat constructor called" << std::endl; 17 | this->_type = "WrongCat"; 18 | } 19 | 20 | WrongCat::WrongCat( WrongCat const& rhs ) { 21 | std::cout << "WrongCat copy constructor called" << std::endl; 22 | *this = rhs; 23 | } 24 | 25 | WrongCat::~WrongCat() { 26 | std::cout << "WrongCat destructor called" << std::endl; 27 | } 28 | 29 | WrongCat& WrongCat::operator=(WrongCat const& rhs) { 30 | std::cout << "WrongCat assignation operator called" << std::endl; 31 | if (this != &rhs) 32 | this->_type = rhs._type; 33 | return *this; 34 | } 35 | 36 | void WrongCat::makeSound() const { 37 | std::cout << "WrongCat sound!" << std::endl; 38 | } -------------------------------------------------------------------------------- /cpp_04/ex00/WrongCat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* WrongCat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/05 22:42:46 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 12:03:30 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef WRONGCAT_HPP 14 | # define WRONGCAT_HPP 15 | 16 | # include "WrongAnimal.hpp" 17 | 18 | class WrongCat : public WrongAnimal { 19 | public: 20 | WrongCat(); 21 | WrongCat( WrongCat const& rhs ); 22 | ~WrongCat(); 23 | WrongCat& operator=(WrongCat const& rhs); 24 | void makeSound() const; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /cpp_04/ex01/Animal.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:11:53 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 12:00:58 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Animal.hpp" 14 | 15 | Animal::Animal(): _type() { 16 | std::cout << "Animal Default Constructor Called" << std::endl; 17 | this->_type = "Animal"; 18 | } 19 | 20 | Animal::Animal( Animal const& rhs ) { 21 | std::cout << "Animal Copy Constructor Called" << std::endl; 22 | *this = rhs; 23 | } 24 | 25 | Animal::~Animal() { 26 | std::cout << "Animal Destructor Called" << std::endl; 27 | } 28 | 29 | Animal& Animal::operator=(Animal const& rhs) { 30 | std::cout << "Animal Assignation Operator Called" << std::endl; 31 | if (this != &rhs) 32 | this->_type = rhs._type; 33 | return *this; 34 | } 35 | 36 | std::string Animal::getType() const { 37 | return this->_type; 38 | } 39 | 40 | void Animal::makeSound() const { 41 | std::cout << "Animal Sound!" << std::endl; 42 | } -------------------------------------------------------------------------------- /cpp_04/ex01/Animal.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 17:47:22 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 12:02:35 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ANIMAL_HPP 14 | # define ANIMAL_HPP 15 | 16 | # include 17 | 18 | class Animal 19 | { 20 | protected: 21 | std::string _type; 22 | public: 23 | Animal(); 24 | Animal( Animal const& rhs ); 25 | virtual ~Animal(); 26 | Animal& operator=(Animal const& rhs); 27 | virtual void makeSound() const; 28 | std::string getType() const; 29 | }; 30 | 31 | #endif -------------------------------------------------------------------------------- /cpp_04/ex01/Animal.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_04/ex01/Animal.o -------------------------------------------------------------------------------- /cpp_04/ex01/Brain.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Brain.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/06 16:09:48 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 16:09:47 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Brain.hpp" 14 | #include 15 | 16 | std::string random_idea() { 17 | std::string idea[5] = {"Play ", "Eat", "Jump", "Sleep", "Think"}; 18 | return idea[rand() % 5]; 19 | } 20 | Brain::Brain() { 21 | std::cout << "Brain Default Constructor Called" << std::endl; 22 | for (int i = 0; i < 100; i++) 23 | this->_ideas[i] = random_idea(); 24 | } 25 | 26 | Brain::Brain( Brain const& rhs ) { 27 | std::cout << "Brain Copy Constructor Called" << std::endl; 28 | *this = rhs; 29 | } 30 | 31 | Brain::~Brain() { 32 | std::cout << "Brain Destructor Called" << std::endl; 33 | } 34 | 35 | Brain& Brain::operator=(Brain const& rhs) { 36 | std::cout << "Brain Assignation Operator Called" << std::endl; 37 | if (this != &rhs) { 38 | for (int i = 0; i < 100; i++) 39 | this->_ideas[i] = rhs._ideas[i]; 40 | } 41 | return *this; 42 | } 43 | 44 | void Brain::getIdeas() const { 45 | for (int i = 0; i < 5; i++) 46 | std::cout << this->_ideas[i] << std::endl; 47 | } 48 | 49 | void Brain::changeIdeas() { 50 | for (int i = 0; i < 100; i++) 51 | this->_ideas[i] = "Another ideas"; 52 | } 53 | 54 | std::string *Brain::getIdeaas() { 55 | return this->_ideas; 56 | } 57 | 58 | void Brain::setIdeas(std::string *ideas) { 59 | for (int i = 0; i < 100; i++) 60 | this->_ideas[i] = ideas[i]; 61 | } -------------------------------------------------------------------------------- /cpp_04/ex01/Brain.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Brain.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/05 23:36:01 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 14:54:44 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef BRAIN_HPP 14 | # define BRAIN_HPP 15 | 16 | # include 17 | 18 | class Brain 19 | { 20 | private: 21 | std::string _ideas[100]; 22 | public: 23 | Brain(); 24 | Brain(Brain const &rhs); 25 | ~Brain(); 26 | Brain& operator=(Brain const &rhs); 27 | std::string identify() const; 28 | void getIdeas() const; 29 | void setIdeas(std::string *ideas); 30 | std::string *getIdeaas(); 31 | void changeIdeas(); 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /cpp_04/ex01/Cat.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:21:08 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 15:55:57 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Cat.hpp" 14 | 15 | Cat::Cat(): Animal() { 16 | std::cout << "Cat Default Constructor Called" << std::endl; 17 | this->_type = "Cat"; 18 | this->_brain = new Brain(); 19 | } 20 | 21 | Cat::Cat( Cat const& rhs ): Animal(rhs) { 22 | std::cout << "Cat Copy Constructor Called" << std::endl; 23 | *this = rhs; 24 | } 25 | 26 | Cat::~Cat() { 27 | delete this->_brain; 28 | std::cout << "Cat Destructor Called" << std::endl; 29 | } 30 | 31 | Cat& Cat::operator=(Cat const& rhs) { 32 | std::cout << "Cat Assignation Operator Called" << std::endl; 33 | if (this != &rhs) { 34 | this->_type = rhs._type; 35 | if (this->_brain) 36 | delete this->_brain; 37 | this->_brain = new Brain(); 38 | this->_brain->setIdeas(rhs._brain->getIdeaas()); 39 | 40 | } 41 | return *this; 42 | } 43 | 44 | void Cat::makeSound() const { 45 | std::cout << "Meow meow!" << std::endl; 46 | } 47 | 48 | Brain *Cat::getbrain() const { 49 | return this->_brain; 50 | } -------------------------------------------------------------------------------- /cpp_04/ex01/Cat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:21:44 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 15:55:44 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CAT_HPP 14 | # define CAT_HPP 15 | 16 | # include "Animal.hpp" 17 | # include "Brain.hpp" 18 | 19 | class Cat : public Animal { 20 | private: 21 | Brain* _brain; 22 | public: 23 | Cat(); 24 | Cat( Cat const& rhs ); 25 | ~Cat(); 26 | Cat& operator=(Cat const& rhs); 27 | void makeSound() const; 28 | Brain *getbrain() const; 29 | }; 30 | 31 | #endif -------------------------------------------------------------------------------- /cpp_04/ex01/Cat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_04/ex01/Cat.o -------------------------------------------------------------------------------- /cpp_04/ex01/Dog.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:19:34 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 15:59:48 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Dog.hpp" 14 | 15 | Dog::Dog(): Animal() { 16 | std::cout << "Dog Default Constructor Called" << std::endl; 17 | this->_type = "Dog"; 18 | this->_brain = new Brain(); 19 | } 20 | 21 | Dog::Dog( Dog const& rhs ): Animal(rhs) { 22 | std::cout << "Dog Copy Constructor Called" << std::endl; 23 | *this = rhs; 24 | } 25 | 26 | Dog::~Dog() { 27 | delete this->_brain; 28 | std::cout << "Dog Destructor Called" << std::endl; 29 | } 30 | 31 | Dog& Dog::operator=(Dog const& rhs) { 32 | std::cout << "Dog Assignation Operator Called" << std::endl; 33 | if (this != &rhs) { 34 | this->_type = rhs._type; 35 | if (this->_brain) 36 | delete this->_brain; 37 | this->_brain = new Brain(); 38 | this->_brain->setIdeas(rhs._brain->getIdeaas()); 39 | 40 | } 41 | return *this; 42 | } 43 | 44 | void Dog::makeSound() const { 45 | std::cout << "Woof woof!" << std::endl; 46 | } 47 | 48 | Brain *Dog::getbrain() const { 49 | return this->_brain; 50 | } -------------------------------------------------------------------------------- /cpp_04/ex01/Dog.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:14:57 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 16:09:51 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DOG_HPP 14 | # define DOG_HPP 15 | 16 | # include "Animal.hpp" 17 | # include "Brain.hpp" 18 | 19 | class Dog : public Animal { 20 | private: 21 | Brain* _brain; 22 | public: 23 | Dog(); 24 | Dog( Dog const& rhs ); 25 | ~Dog(); 26 | Dog& operator=(Dog const& rhs); 27 | void makeSound() const; 28 | Brain *getbrain() const; 29 | }; 30 | 31 | #endif -------------------------------------------------------------------------------- /cpp_04/ex01/Dog.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_04/ex01/Dog.o -------------------------------------------------------------------------------- /cpp_04/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/04 17:45:18 by namohamm #+# #+# # 9 | # Updated: 2022/12/11 13:19:09 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = brain 14 | 15 | SRCS = main.cpp Animal.cpp Dog.cpp Cat.cpp Brain.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -g3 -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | 41 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_04/ex01/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_04/ex01/main.o -------------------------------------------------------------------------------- /cpp_04/ex02/Animal.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:11:53 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 12:00:58 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Animal.hpp" 14 | 15 | Animal::Animal(): _type() { 16 | std::cout << "Animal Default Constructor Called" << std::endl; 17 | this->_type = "Animal"; 18 | } 19 | 20 | Animal::Animal( Animal const& rhs ) { 21 | std::cout << "Animal Copy Constructor Called" << std::endl; 22 | *this = rhs; 23 | } 24 | 25 | Animal::~Animal() { 26 | std::cout << "Animal Destructor Called" << std::endl; 27 | } 28 | 29 | Animal& Animal::operator=(Animal const& rhs) { 30 | std::cout << "Animal Assignation Operator Called" << std::endl; 31 | if (this != &rhs) 32 | this->_type = rhs._type; 33 | return *this; 34 | } 35 | 36 | std::string Animal::getType() const { 37 | return this->_type; 38 | } 39 | 40 | void Animal::makeSound() const { 41 | std::cout << "Animal Sound!" << std::endl; 42 | } -------------------------------------------------------------------------------- /cpp_04/ex02/Animal.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 17:47:22 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 16:11:23 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ANIMAL_HPP 14 | # define ANIMAL_HPP 15 | 16 | # include 17 | 18 | class Animal 19 | { 20 | protected: 21 | std::string _type; 22 | public: 23 | Animal(); 24 | Animal( Animal const& rhs ); 25 | virtual ~Animal(); 26 | Animal& operator=(Animal const& rhs); 27 | virtual void makeSound() const = 0; 28 | std::string getType() const; 29 | }; 30 | 31 | #endif -------------------------------------------------------------------------------- /cpp_04/ex02/Brain.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Brain.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/06 16:09:48 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 16:09:47 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Brain.hpp" 14 | #include 15 | 16 | std::string random_idea() { 17 | std::string idea[5] = {"Play ", "Eat", "Jump", "Sleep", "Think"}; 18 | return idea[rand() % 5]; 19 | } 20 | Brain::Brain() { 21 | std::cout << "Brain Default Constructor Called" << std::endl; 22 | for (int i = 0; i < 100; i++) 23 | this->_ideas[i] = random_idea(); 24 | } 25 | 26 | Brain::Brain( Brain const& rhs ) { 27 | std::cout << "Brain Copy Constructor Called" << std::endl; 28 | *this = rhs; 29 | } 30 | 31 | Brain::~Brain() { 32 | std::cout << "Brain Destructor Called" << std::endl; 33 | } 34 | 35 | Brain& Brain::operator=(Brain const& rhs) { 36 | std::cout << "Brain Assignation Operator Called" << std::endl; 37 | if (this != &rhs) { 38 | for (int i = 0; i < 100; i++) 39 | this->_ideas[i] = rhs._ideas[i]; 40 | } 41 | return *this; 42 | } 43 | 44 | void Brain::getIdeas() const { 45 | for (int i = 0; i < 5; i++) 46 | std::cout << this->_ideas[i] << std::endl; 47 | } 48 | 49 | void Brain::changeIdeas() { 50 | for (int i = 0; i < 100; i++) 51 | this->_ideas[i] = "Another ideas"; 52 | } 53 | 54 | std::string *Brain::getIdeaas() { 55 | return this->_ideas; 56 | } 57 | 58 | void Brain::setIdeas(std::string *ideas) { 59 | for (int i = 0; i < 100; i++) 60 | this->_ideas[i] = ideas[i]; 61 | } -------------------------------------------------------------------------------- /cpp_04/ex02/Brain.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Brain.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/05 23:36:01 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 14:54:44 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef BRAIN_HPP 14 | # define BRAIN_HPP 15 | 16 | # include 17 | 18 | class Brain 19 | { 20 | private: 21 | std::string _ideas[100]; 22 | public: 23 | Brain(); 24 | Brain(Brain const &rhs); 25 | ~Brain(); 26 | Brain& operator=(Brain const &rhs); 27 | std::string identify() const; 28 | void getIdeas() const; 29 | void setIdeas(std::string *ideas); 30 | std::string *getIdeaas(); 31 | void changeIdeas(); 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /cpp_04/ex02/Cat.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:21:08 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 15:55:57 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Cat.hpp" 14 | 15 | Cat::Cat(): Animal() { 16 | std::cout << "Cat Default Constructor Called" << std::endl; 17 | this->_type = "Cat"; 18 | this->_brain = new Brain(); 19 | } 20 | 21 | Cat::Cat( Cat const& rhs ): Animal(rhs) { 22 | std::cout << "Cat Copy Constructor Called" << std::endl; 23 | *this = rhs; 24 | } 25 | 26 | Cat::~Cat() { 27 | delete this->_brain; 28 | std::cout << "Cat Destructor Called" << std::endl; 29 | } 30 | 31 | Cat& Cat::operator=(Cat const& rhs) { 32 | std::cout << "Cat Assignation Operator Called" << std::endl; 33 | if (this != &rhs) { 34 | this->_type = rhs._type; 35 | if (this->_brain) 36 | delete this->_brain; 37 | this->_brain = new Brain(); 38 | this->_brain->setIdeas(rhs._brain->getIdeaas()); 39 | 40 | } 41 | return *this; 42 | } 43 | 44 | void Cat::makeSound() const { 45 | std::cout << "Meow meow!" << std::endl; 46 | } 47 | 48 | Brain *Cat::getbrain() const { 49 | return this->_brain; 50 | } -------------------------------------------------------------------------------- /cpp_04/ex02/Cat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:21:44 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 15:55:44 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CAT_HPP 14 | # define CAT_HPP 15 | 16 | # include "Animal.hpp" 17 | # include "Brain.hpp" 18 | 19 | class Cat : public Animal { 20 | private: 21 | Brain* _brain; 22 | public: 23 | Cat(); 24 | Cat( Cat const& rhs ); 25 | ~Cat(); 26 | Cat& operator=(Cat const& rhs); 27 | void makeSound() const; 28 | Brain *getbrain() const; 29 | }; 30 | 31 | #endif -------------------------------------------------------------------------------- /cpp_04/ex02/Dog.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:19:34 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 15:59:48 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Dog.hpp" 14 | 15 | Dog::Dog(): Animal() { 16 | std::cout << "Dog Default Constructor Called" << std::endl; 17 | this->_type = "Dog"; 18 | this->_brain = new Brain(); 19 | } 20 | 21 | Dog::Dog( Dog const& rhs ): Animal(rhs) { 22 | std::cout << "Dog Copy Constructor Called" << std::endl; 23 | *this = rhs; 24 | } 25 | 26 | Dog::~Dog() { 27 | delete this->_brain; 28 | std::cout << "Dog Destructor Called" << std::endl; 29 | } 30 | 31 | Dog& Dog::operator=(Dog const& rhs) { 32 | std::cout << "Dog Assignation Operator Called" << std::endl; 33 | if (this != &rhs) { 34 | this->_type = rhs._type; 35 | if (this->_brain) 36 | delete this->_brain; 37 | this->_brain = new Brain(); 38 | this->_brain->setIdeas(rhs._brain->getIdeaas()); 39 | 40 | } 41 | return *this; 42 | } 43 | 44 | void Dog::makeSound() const { 45 | std::cout << "Woof woof!" << std::endl; 46 | } 47 | 48 | Brain *Dog::getbrain() const { 49 | return this->_brain; 50 | } -------------------------------------------------------------------------------- /cpp_04/ex02/Dog.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/04 18:14:57 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/11 16:09:51 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DOG_HPP 14 | # define DOG_HPP 15 | 16 | # include "Animal.hpp" 17 | # include "Brain.hpp" 18 | 19 | class Dog : public Animal { 20 | private: 21 | Brain* _brain; 22 | public: 23 | Dog(); 24 | Dog( Dog const& rhs ); 25 | ~Dog(); 26 | Dog& operator=(Dog const& rhs); 27 | void makeSound() const; 28 | Brain *getbrain() const; 29 | }; 30 | 31 | #endif -------------------------------------------------------------------------------- /cpp_04/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/04 17:45:18 by namohamm #+# #+# # 9 | # Updated: 2022/12/11 16:14:15 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = abstract 14 | 15 | SRCS = main.cpp Animal.cpp Dog.cpp Cat.cpp Brain.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -g3 -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | 41 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_05/cpp_05.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_05/cpp_05.pdf -------------------------------------------------------------------------------- /cpp_05/ex00/Bureaucrat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Bureaucrat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/07 15:51:55 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/12 12:10:09 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef BUREAUCRAT_HPP 14 | # define BUREAUCRAT_HPP 15 | 16 | # include 17 | 18 | class Bureaucrat 19 | { 20 | private: 21 | std::string const _name; 22 | int _grade; 23 | Bureaucrat(); 24 | class GradeTooHighException : public std::exception 25 | { 26 | public: 27 | const char* what() const throw(); 28 | }; 29 | class GradeTooLowException : public std::exception 30 | { 31 | public: 32 | const char* what() const throw(); 33 | }; 34 | public: 35 | Bureaucrat(std::string name, int grade); 36 | Bureaucrat(Bureaucrat const ©); 37 | ~Bureaucrat(); 38 | Bureaucrat &operator=(Bureaucrat const &rhs); 39 | std::string getName() const; 40 | int getGrade() const; 41 | void incrementGrade(); 42 | void decrementGrade(); 43 | }; 44 | 45 | std::ostream &operator<<(std::ostream &out, Bureaucrat const &rhs); 46 | 47 | #endif -------------------------------------------------------------------------------- /cpp_05/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/07 15:49:09 by namohamm #+# #+# # 9 | # Updated: 2022/12/10 15:42:13 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = bureaucrat 14 | 15 | SRCS = main.cpp Bureaucrat.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_05/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/07 15:57:50 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 14:09:25 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Bureaucrat.hpp" 14 | 15 | int main() 16 | { 17 | /*-------------------------*/ 18 | Bureaucrat b("Bob", 5); 19 | std::cout << b << std::endl; 20 | b.incrementGrade(); 21 | std::cout << b << std::endl; 22 | b.decrementGrade(); 23 | std::cout << b << std::endl; 24 | /*-------------------------*/ 25 | // try and catch 26 | try 27 | { 28 | Bureaucrat b("Nass", -8); 29 | std::cout << b << std::endl; 30 | } 31 | catch (std::exception &e) 32 | { 33 | std::cerr << e.what() << std::endl; 34 | } 35 | /*-------------------------*/ 36 | return 0; 37 | } -------------------------------------------------------------------------------- /cpp_05/ex01/Bureaucrat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Bureaucrat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/07 15:51:55 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/12 14:33:42 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef BUREAUCRAT_HPP 14 | # define BUREAUCRAT_HPP 15 | 16 | # include 17 | # include "Form.hpp" 18 | class Form; 19 | 20 | class Bureaucrat 21 | { 22 | private: 23 | std::string const _name; 24 | int _grade; 25 | Bureaucrat(); 26 | class GradeTooHighException : public std::exception 27 | { 28 | public: 29 | const char* what() const throw(); 30 | }; 31 | class GradeTooLowException : public std::exception 32 | { 33 | public: 34 | const char* what() const throw(); 35 | }; 36 | public: 37 | Bureaucrat(std::string name, int grade); 38 | Bureaucrat(Bureaucrat const ©); 39 | ~Bureaucrat(); 40 | Bureaucrat &operator=(Bureaucrat const &rhs); 41 | std::string getName() const; 42 | int getGrade() const; 43 | void incrementGrade(); 44 | void decrementGrade(); 45 | void signForm(Form &form); 46 | }; 47 | 48 | std::ostream &operator<<(std::ostream &out, Bureaucrat const &rhs); 49 | 50 | #endif -------------------------------------------------------------------------------- /cpp_05/ex01/Form.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Form.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/12 14:11:57 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/12 22:14:25 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FORM_HPP 14 | # define FORM_HPP 15 | 16 | # include 17 | # include "Bureaucrat.hpp" 18 | class Bureaucrat; 19 | 20 | class Form 21 | { 22 | private: 23 | std::string const _name; 24 | bool _signed; 25 | int const _gradeToSign; 26 | int const _gradeToExecute; 27 | Form(); 28 | class GradeTooHighException : public std::exception 29 | { 30 | public: 31 | const char* what() const throw(); 32 | }; 33 | class GradeTooLowException : public std::exception 34 | { 35 | public: 36 | const char* what() const throw(); 37 | }; 38 | public: 39 | Form(std::string name, int gradeToSign, int gradeToExecute); 40 | Form(Form const &rhs); 41 | ~Form(); 42 | Form &operator=(Form const &rhs); 43 | std::string getName() const; 44 | bool getSigned() const; 45 | int getGradeToSign() const; 46 | int getGradeToExecute() const; 47 | void beSigned(Bureaucrat const &rhs); 48 | }; 49 | 50 | std::ostream &operator<<(std::ostream &out, Form const &rhs); 51 | 52 | #endif -------------------------------------------------------------------------------- /cpp_05/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/07 15:49:09 by namohamm #+# #+# # 9 | # Updated: 2022/12/12 22:16:08 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = form 14 | 15 | SRCS = main.cpp Bureaucrat.cpp Form.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_05/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/07 15:57:50 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/13 09:35:13 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Bureaucrat.hpp" 14 | 15 | int main() { 16 | Bureaucrat bureaucrat_1("Nass", 3); 17 | Bureaucrat bureaucrat_2("Ssan", 75); 18 | std::cout << bureaucrat_1 << std::endl; 19 | std::cout << bureaucrat_2 << std::endl; 20 | /*-----------------------------------*/ 21 | Form form_1("Form_1", 5, 10); 22 | std::cout << form_1 << std::endl; 23 | /*-----------------------------------*/ 24 | try { 25 | Form form_2("Form_1", 8996, 10); 26 | } 27 | catch (std::exception &e) { 28 | std::cerr << e.what() << std::endl; 29 | } 30 | /*-----------------------------------*/ 31 | try { 32 | bureaucrat_1.signForm(form_1); 33 | } 34 | catch (std::exception &e) { 35 | std::cerr << e.what() << std::endl; 36 | } 37 | /*-----------------------------------*/ 38 | std::cout << form_1 << std::endl; 39 | /*-----------------------------------*/ 40 | try { 41 | bureaucrat_2.signForm(form_1); 42 | } 43 | catch (std::exception &e) { 44 | std::cerr << e.what() << std::endl; 45 | } 46 | /*-----------------------------------*/ 47 | std::cout << form_1 << std::endl; 48 | return 0; 49 | } -------------------------------------------------------------------------------- /cpp_05/ex02/AForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* AForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/12 14:11:57 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 16:19:57 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef AFORM_HPP 14 | # define AFORM_HPP 15 | 16 | # include 17 | # include "Bureaucrat.hpp" 18 | class Bureaucrat; 19 | 20 | class AForm 21 | { 22 | private: 23 | std::string const _name; 24 | bool _signed; 25 | int const _gradeToSign; 26 | int const _gradeToExecute; 27 | AForm(); 28 | protected: 29 | class GradeTooHighException : public std::exception 30 | { 31 | public: 32 | const char* what() const throw(); 33 | }; 34 | class GradeTooLowException : public std::exception 35 | { 36 | public: 37 | const char* what() const throw(); 38 | }; 39 | public: 40 | AForm(std::string name, int gradeToSign, int gradeToExecute); 41 | AForm(AForm const &rhs); 42 | virtual ~AForm(); 43 | AForm &operator=(AForm const &rhs); 44 | virtual std::string getName() const; 45 | bool getSigned() const; 46 | int getGradeToSign() const; 47 | int getGradeToExecute() const; 48 | void beSigned(Bureaucrat const &rhs); 49 | virtual void execute(Bureaucrat const &executor) const = 0; 50 | }; 51 | 52 | std::ostream &operator<<(std::ostream &out, AForm const &rhs); 53 | 54 | #endif -------------------------------------------------------------------------------- /cpp_05/ex02/Bureaucrat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Bureaucrat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/07 15:51:55 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/12 14:33:42 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef BUREAUCRAT_HPP 14 | # define BUREAUCRAT_HPP 15 | 16 | # include 17 | # include "AForm.hpp" 18 | class AForm; 19 | 20 | class Bureaucrat 21 | { 22 | private: 23 | std::string const _name; 24 | int _grade; 25 | Bureaucrat(); 26 | class GradeTooHighException : public std::exception 27 | { 28 | public: 29 | const char* what() const throw(); 30 | }; 31 | class GradeTooLowException : public std::exception 32 | { 33 | public: 34 | const char* what() const throw(); 35 | }; 36 | public: 37 | Bureaucrat(std::string name, int grade); 38 | Bureaucrat(Bureaucrat const ©); 39 | ~Bureaucrat(); 40 | Bureaucrat &operator=(Bureaucrat const &rhs); 41 | std::string getName() const; 42 | int getGrade() const; 43 | void incrementGrade(); 44 | void decrementGrade(); 45 | void signAForm(AForm &form); 46 | void executeForm(AForm const &form); 47 | }; 48 | 49 | std::ostream &operator<<(std::ostream &out, Bureaucrat const &rhs); 50 | 51 | #endif -------------------------------------------------------------------------------- /cpp_05/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/07 15:49:09 by namohamm #+# #+# # 9 | # Updated: 2022/12/15 17:24:35 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = form28 14 | 15 | SRCS = main.cpp Bureaucrat.cpp AForm.cpp PresidentialPardonForm.cpp \ 16 | RobotomyRequestForm.cpp ShrubberyCreationForm.cpp 17 | 18 | OBJS = $(SRCS:.cpp=.o) 19 | 20 | CXX = c++ 21 | 22 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 23 | 24 | all: $(Name) 25 | 26 | $(Name): $(OBJS) 27 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 28 | @printf "\033c" 29 | 30 | clean: 31 | rm -f $(OBJS) 32 | 33 | nass: clean 34 | rm -f $(Name) 35 | 36 | fclean: clean 37 | rm -f $(Name) 38 | 39 | re: fclean all 40 | 41 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_05/ex02/PresidentialPardonForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PresidentialPardonForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/14 00:59:01 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 17:18:10 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PRESIDENTIALPARDONFORM_HPP 14 | # define PRESIDENTIALPARDONFORM_HPP 15 | 16 | # include 17 | # include "AForm.hpp" 18 | 19 | class PresidentialPardonForm : public AForm 20 | { 21 | private: 22 | std::string const _target; 23 | public: 24 | PresidentialPardonForm(std::string target); 25 | PresidentialPardonForm(PresidentialPardonForm const &rhs); 26 | ~PresidentialPardonForm(); 27 | PresidentialPardonForm &operator=(PresidentialPardonForm const &rhs); 28 | std::string getTarget() const; 29 | void execute(Bureaucrat const &executor) const; 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /cpp_05/ex02/RobotomyRequestForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* RobotomyRequestForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/13 23:54:08 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 17:18:49 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ROBOTOMYREQUESTFORM_HPP 14 | # define ROBOTOMYREQUESTFORM_HPP 15 | 16 | # include 17 | # include 18 | # include "AForm.hpp" 19 | 20 | class RobotomyRequestForm : public AForm 21 | { 22 | private: 23 | std::string const _target; 24 | void robotomizeTarget(); 25 | public: 26 | RobotomyRequestForm(std::string target); 27 | RobotomyRequestForm(RobotomyRequestForm const &rhs); 28 | ~RobotomyRequestForm(); 29 | RobotomyRequestForm &operator=(RobotomyRequestForm const &rhs); 30 | std::string getTarget() const; 31 | void execute(Bureaucrat const &executor) const; 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /cpp_05/ex02/ShrubberyCreationForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ShrubberyCreationForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/13 12:56:00 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 15:55:31 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SHRUBBERYCREATIONFORM_HPP 14 | # define SHRUBBERYCREATIONFORM_HPP 15 | 16 | # include 17 | # include 18 | # include "AForm.hpp" 19 | 20 | class ShrubberyCreationForm: public AForm 21 | { 22 | private: 23 | std::string const _target; 24 | void creationTarget() const; 25 | class FileNotOpenException : public std::exception 26 | { 27 | public: 28 | virtual const char *what() const throw(); 29 | }; 30 | public: 31 | ShrubberyCreationForm(std::string target); 32 | ShrubberyCreationForm(ShrubberyCreationForm const &rhs); 33 | ~ShrubberyCreationForm(); 34 | ShrubberyCreationForm &operator=(ShrubberyCreationForm const &rhs); 35 | std::string getTarget() const; 36 | void execute(Bureaucrat const &executor) const; 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /cpp_05/ex03/AForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* AForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/12 14:11:57 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 16:19:57 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef AFORM_HPP 14 | # define AFORM_HPP 15 | 16 | # include 17 | # include "Bureaucrat.hpp" 18 | class Bureaucrat; 19 | 20 | class AForm 21 | { 22 | private: 23 | std::string const _name; 24 | bool _signed; 25 | int const _gradeToSign; 26 | int const _gradeToExecute; 27 | AForm(); 28 | protected: 29 | class GradeTooHighException : public std::exception 30 | { 31 | public: 32 | const char* what() const throw(); 33 | }; 34 | class GradeTooLowException : public std::exception 35 | { 36 | public: 37 | const char* what() const throw(); 38 | }; 39 | public: 40 | AForm(std::string name, int gradeToSign, int gradeToExecute); 41 | AForm(AForm const &rhs); 42 | virtual ~AForm(); 43 | AForm &operator=(AForm const &rhs); 44 | virtual std::string getName() const; 45 | bool getSigned() const; 46 | int getGradeToSign() const; 47 | int getGradeToExecute() const; 48 | void beSigned(Bureaucrat const &rhs); 49 | virtual void execute(Bureaucrat const &executor) const = 0; 50 | }; 51 | 52 | std::ostream &operator<<(std::ostream &out, AForm const &rhs); 53 | 54 | #endif -------------------------------------------------------------------------------- /cpp_05/ex03/Bureaucrat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Bureaucrat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/07 15:51:55 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/12 14:33:42 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef BUREAUCRAT_HPP 14 | # define BUREAUCRAT_HPP 15 | 16 | # include 17 | # include "AForm.hpp" 18 | class AForm; 19 | 20 | class Bureaucrat 21 | { 22 | private: 23 | std::string const _name; 24 | int _grade; 25 | Bureaucrat(); 26 | class GradeTooHighException : public std::exception 27 | { 28 | public: 29 | const char* what() const throw(); 30 | }; 31 | class GradeTooLowException : public std::exception 32 | { 33 | public: 34 | const char* what() const throw(); 35 | }; 36 | public: 37 | Bureaucrat(std::string name, int grade); 38 | Bureaucrat(Bureaucrat const ©); 39 | ~Bureaucrat(); 40 | Bureaucrat &operator=(Bureaucrat const &rhs); 41 | std::string getName() const; 42 | int getGrade() const; 43 | void incrementGrade(); 44 | void decrementGrade(); 45 | void signAForm(AForm &form); 46 | void executeForm(AForm const &form); 47 | }; 48 | 49 | std::ostream &operator<<(std::ostream &out, Bureaucrat const &rhs); 50 | 51 | #endif -------------------------------------------------------------------------------- /cpp_05/ex03/Intern.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Intern.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/14 13:25:29 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/14 14:15:41 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef INTERN_HPP 14 | # define INTERN_HPP 15 | 16 | # include 17 | # include 18 | # include "AForm.hpp" 19 | # include "PresidentialPardonForm.hpp" 20 | # include "RobotomyRequestForm.hpp" 21 | # include "ShrubberyCreationForm.hpp" 22 | 23 | class Intern 24 | { 25 | public: 26 | Intern(); 27 | Intern(Intern const &rhs); 28 | ~Intern(); 29 | Intern &operator=(Intern const &rhs); 30 | AForm *makeForm(std::string const &name, std::string const &target); 31 | class FormNotFoundException : public std::exception 32 | { 33 | public: 34 | virtual const char *what() const throw(); 35 | }; 36 | }; 37 | 38 | #endif -------------------------------------------------------------------------------- /cpp_05/ex03/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/07 15:49:09 by namohamm #+# #+# # 9 | # Updated: 2022/12/14 14:00:20 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = intern 14 | 15 | SRCS = main.cpp Bureaucrat.cpp AForm.cpp PresidentialPardonForm.cpp \ 16 | RobotomyRequestForm.cpp ShrubberyCreationForm.cpp Intern.cpp 17 | 18 | OBJS = $(SRCS:.cpp=.o) 19 | 20 | CXX = c++ 21 | 22 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 23 | 24 | all: $(Name) 25 | 26 | $(Name): $(OBJS) 27 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 28 | @printf "\033c" 29 | 30 | clean: 31 | rm -f $(OBJS) 32 | 33 | nass: clean 34 | rm -f $(Name) 35 | 36 | fclean: clean 37 | rm -f $(Name) 38 | 39 | re: fclean all 40 | 41 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_05/ex03/PresidentialPardonForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PresidentialPardonForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/14 00:59:01 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 17:18:10 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef PRESIDENTIALPARDONFORM_HPP 14 | # define PRESIDENTIALPARDONFORM_HPP 15 | 16 | # include 17 | # include "AForm.hpp" 18 | 19 | class PresidentialPardonForm : public AForm 20 | { 21 | private: 22 | std::string const _target; 23 | public: 24 | PresidentialPardonForm(std::string target); 25 | PresidentialPardonForm(PresidentialPardonForm const &rhs); 26 | ~PresidentialPardonForm(); 27 | PresidentialPardonForm &operator=(PresidentialPardonForm const &rhs); 28 | std::string getTarget() const; 29 | void execute(Bureaucrat const &executor) const; 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /cpp_05/ex03/RobotomyRequestForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* RobotomyRequestForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/13 23:54:08 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 16:53:58 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ROBOTOMYREQUESTFORM_HPP 14 | # define ROBOTOMYREQUESTFORM_HPP 15 | 16 | # include 17 | # include 18 | # include "AForm.hpp" 19 | 20 | class RobotomyRequestForm : public AForm 21 | { 22 | private: 23 | std::string const _target; 24 | void robotomizeTarget(); 25 | public: 26 | RobotomyRequestForm(std::string target); 27 | RobotomyRequestForm(RobotomyRequestForm const &rhs); 28 | ~RobotomyRequestForm(); 29 | RobotomyRequestForm &operator=(RobotomyRequestForm const &rhs); 30 | std::string getTarget() const; 31 | void execute(Bureaucrat const &executor) const; 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /cpp_05/ex03/ShrubberyCreationForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ShrubberyCreationForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/13 12:56:00 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 15:55:31 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SHRUBBERYCREATIONFORM_HPP 14 | # define SHRUBBERYCREATIONFORM_HPP 15 | 16 | # include 17 | # include 18 | # include "AForm.hpp" 19 | 20 | class ShrubberyCreationForm: public AForm 21 | { 22 | private: 23 | std::string const _target; 24 | void creationTarget() const; 25 | class FileNotOpenException : public std::exception 26 | { 27 | public: 28 | virtual const char *what() const throw(); 29 | }; 30 | public: 31 | ShrubberyCreationForm(std::string target); 32 | ShrubberyCreationForm(ShrubberyCreationForm const &rhs); 33 | ~ShrubberyCreationForm(); 34 | ShrubberyCreationForm &operator=(ShrubberyCreationForm const &rhs); 35 | std::string getTarget() const; 36 | void execute(Bureaucrat const &executor) const; 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /cpp_05/ex03/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/07 15:57:50 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 17:14:50 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "AForm.hpp" 14 | #include "ShrubberyCreationForm.hpp" 15 | #include "RobotomyRequestForm.hpp" 16 | #include "PresidentialPardonForm.hpp" 17 | #include "Intern.hpp" 18 | 19 | void tryCatch(Bureaucrat &b, Intern &i, std::string formName, std::string formTarget) { 20 | std::cout << std::endl; 21 | try { 22 | if (formName.empty() || formTarget.empty()) { 23 | throw std::invalid_argument("Invalid parameters"); 24 | } 25 | AForm *f = i.makeForm(formName, formTarget); 26 | std::cout << *f; 27 | b.signAForm(*f); 28 | b.executeForm(*f); 29 | delete f; 30 | } 31 | catch (std::exception &e) { 32 | std::cerr << e.what() << std::endl; 33 | } 34 | } 35 | 36 | int main() { 37 | std::cout <<"Intern::makeForm() Tests"<< std::endl; 38 | Bureaucrat b1("Martin", 1); 39 | Bureaucrat b150("Luna", 150); 40 | Intern i; 41 | 42 | tryCatch(b150, i, "Shrubbery Creation", "Limelight"); 43 | tryCatch(b150, i, "Robotomy Request", "Bob"); 44 | tryCatch(b150, i, "Presidential Pardon", "Claire"); 45 | tryCatch(b150, i, "Hogwarts Enrollment", "Dumbledore"); 46 | 47 | tryCatch(b1, i, "Shrubbery Creation", "Limelight"); 48 | tryCatch(b1, i, "Robotomy Request", "Bob"); 49 | tryCatch(b1, i, "Presidential Pardon", "Claire"); 50 | tryCatch(b1, i, "Hogwarts Enrollment", "Dumbledore"); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /cpp_06/Readme: -------------------------------------------------------------------------------- 1 | In C++, static_cast is a type conversion operator that allows you to convert a 2 | value from one type to another, provided that the two types are compatible. 3 | It is used to explicitly convert one type to another and is typically used 4 | when you want to convert a value to a related type, such as when you want to 5 | convert a base class to a derived class or when you want to convert a float to 6 | an int. 7 | 8 | 9 | const_cast is a C++ operator that allows you to change the const or volatile 10 | qualification of a variable. This means you can remove the const or volatile 11 | qualifier from a variable, or add it back if it has been removed. 12 | 13 | 14 | For example, you might use reinterpret_cast to treat a pointer to an integer 15 | as a pointer to a float, or to treat an integer as a pointer to a structure. 16 | This can be useful when working with low-level data structures or when trying 17 | to perform bitwise operations on values that are not naturally compatible. -------------------------------------------------------------------------------- /cpp_06/cpp_06.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_06/cpp_06.pdf -------------------------------------------------------------------------------- /cpp_06/ex00/Convert.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Convert.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/14 22:46:56 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 21:58:47 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CONVERT_HPP 14 | # define CONVERT_HPP 15 | 16 | # include 17 | # include 18 | 19 | class Convert 20 | { 21 | private: 22 | std::string _str; 23 | char _char; 24 | int _int; 25 | float _float; 26 | double _double; 27 | public: 28 | Convert(); 29 | Convert(Convert const &rhs); 30 | ~Convert(); 31 | Convert &operator=(Convert const &rhs); 32 | Convert(std::string const &str); 33 | void convertToChar(); 34 | void convertToInt(); 35 | void convertToFloat(); 36 | void convertToDouble(); 37 | void convert(); 38 | }; 39 | 40 | #endif -------------------------------------------------------------------------------- /cpp_06/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/14 22:44:58 by namohamm #+# #+# # 9 | # Updated: 2022/12/14 22:46:02 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = convert 14 | 15 | SRCS = main.cpp Convert.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_06/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/14 23:10:55 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/18 18:53:20 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Convert.hpp" 14 | 15 | // is_num 16 | bool is_num(std::string str) 17 | { 18 | if ((str.find_first_not_of("0123456789") == std::string::npos) 19 | || (str.find_first_not_of("-0123456789") == std::string::npos && str[0] == '-')) 20 | return (true); 21 | return (false); 22 | } 23 | 24 | // is_float 25 | bool is_float(std::string str) 26 | { 27 | if ((str.find_first_not_of("0123456789.") == std::string::npos) 28 | || (str.find_first_not_of("-0123456789.") == std::string::npos && str[0] == '-')) 29 | return (true); 30 | return (false); 31 | } 32 | 33 | // is_char 34 | bool is_char(std::string str) 35 | { 36 | if (str.length() == 1) 37 | return (true); 38 | return (false); 39 | } 40 | 41 | // not_convertable 42 | bool not_convertable(std::string str) 43 | { 44 | if (is_num(str) || is_float(str) || is_char(str)) 45 | return (false); 46 | return (true); 47 | } 48 | 49 | int main(int argc, char **argv) 50 | { 51 | if (argc != 2) 52 | { 53 | std::cout << "Error: Invalid number of arguments" << std::endl; 54 | return (1); 55 | } 56 | // check if argument is convertable or not empty 57 | if (not_convertable(argv[1]) || argv[1][0] == '\0') 58 | { 59 | std::cout << "Error: Invalid argument" << std::endl; 60 | return (1); 61 | } 62 | Convert convert(argv[1]); 63 | convert.convert(); 64 | return (0); 65 | } -------------------------------------------------------------------------------- /cpp_06/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/15 01:20:37 by namohamm #+# #+# # 9 | # Updated: 2022/12/18 15:12:29 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = serialize 14 | 15 | SRCS = main.cpp Serialize.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | # CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | CPPFLAGS = -std=c++11 -Wall -Wextra -Werror 23 | 24 | all: $(Name) 25 | 26 | $(Name): $(OBJS) 27 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 28 | @printf "\033c" 29 | 30 | clean: 31 | rm -f $(OBJS) 32 | 33 | nass: clean 34 | rm -f $(Name) 35 | 36 | fclean: clean 37 | rm -f $(Name) 38 | 39 | re: fclean all 40 | 41 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_06/ex01/Serialize.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Serialize.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 01:44:34 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 01:45:21 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Serialize.hpp" 14 | 15 | uintptr_t serialize(Data *ptr) { 16 | return (reinterpret_cast(ptr)); 17 | } 18 | 19 | Data *deserialize(uintptr_t raw) { 20 | return (reinterpret_cast(raw)); 21 | } 22 | -------------------------------------------------------------------------------- /cpp_06/ex01/Serialize.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Serialize.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 01:21:27 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/18 15:07:30 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SERIALIZE_HPP 14 | # define SERIALIZE_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | # include 22 | # include 23 | 24 | struct Data 25 | { 26 | std::string s; 27 | int n; 28 | }; 29 | 30 | uintptr_t serialize(Data *ptr); 31 | Data *deserialize(uintptr_t raw); 32 | 33 | #endif -------------------------------------------------------------------------------- /cpp_06/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 01:45:42 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/18 15:13:07 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Serialize.hpp" 14 | 15 | int main() { 16 | Data data; 17 | data.s = "hello"; 18 | 19 | // Serialize the pointer to data 20 | uintptr_t serialized = serialize(&data); 21 | 22 | // Deserialize the serialized pointer 23 | Data* deserialized = deserialize(serialized); 24 | 25 | // Ensure the deserialized pointer is equal to the original pointer 26 | if (deserialized == &data) { 27 | std::cout << "Success!" << std::endl; 28 | } else { 29 | std::cout << "Failed!" << std::endl; 30 | } 31 | 32 | std::cout << "s: " << deserialized->s << std::endl; 33 | 34 | return 0; 35 | } 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /cpp_06/ex02/A.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_06/ex02/A.cpp -------------------------------------------------------------------------------- /cpp_06/ex02/A.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* A.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 22:38:41 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 22:39:34 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef A_HPP 14 | # define A_HPP 15 | 16 | # include "Base.hpp" 17 | 18 | class A : public Base { 19 | }; 20 | 21 | #endif -------------------------------------------------------------------------------- /cpp_06/ex02/B.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_06/ex02/B.cpp -------------------------------------------------------------------------------- /cpp_06/ex02/B.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* B.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 22:39:57 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 22:40:12 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef B_HPP 14 | # define B_HPP 15 | 16 | # include "Base.hpp" 17 | 18 | class B : public Base { 19 | }; 20 | 21 | #endif -------------------------------------------------------------------------------- /cpp_06/ex02/Base.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Base.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 22:37:57 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 22:43:38 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Base.hpp" 14 | 15 | Base::~Base() {} 16 | -------------------------------------------------------------------------------- /cpp_06/ex02/Base.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Base.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 22:22:42 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 22:41:53 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef BASE_HPP 14 | # define BASE_HPP 15 | 16 | class Base 17 | { 18 | public: 19 | virtual ~Base(); 20 | }; 21 | 22 | Base * generate(void); 23 | 24 | #endif -------------------------------------------------------------------------------- /cpp_06/ex02/C.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_06/ex02/C.cpp -------------------------------------------------------------------------------- /cpp_06/ex02/C.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* C.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 22:40:19 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 22:40:40 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef C_HPP 14 | # define C_HPP 15 | 16 | # include "Base.hpp" 17 | 18 | class C : public Base { 19 | }; 20 | 21 | #endif -------------------------------------------------------------------------------- /cpp_06/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/15 22:19:03 by namohamm #+# #+# # 9 | # Updated: 2022/12/15 22:54:01 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = real_type 14 | 15 | SRCS = main.cpp Base.cpp A.cpp B.cpp C.cpp helper.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_06/ex02/helper.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* helper.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 22:43:43 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 23:07:49 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "helper.hpp" 14 | 15 | Base * generate(void) 16 | { 17 | int random = rand() % 3; 18 | if (random == 0) 19 | return new A; 20 | else if (random == 1) 21 | return new B; 22 | else 23 | return new C; 24 | } 25 | 26 | void identify(Base * p) 27 | { 28 | if (dynamic_cast(p)) 29 | std::cout << "A" << std::endl; 30 | else if (dynamic_cast(p)) 31 | std::cout << "B" << std::endl; 32 | else if (dynamic_cast(p)) 33 | std::cout << "C" << std::endl; 34 | } 35 | 36 | void identify(Base & p) 37 | { 38 | try 39 | { 40 | A &a = dynamic_cast(p); 41 | (void)a; 42 | std::cout << "A" << std::endl; 43 | } 44 | catch (std::exception &e) 45 | { 46 | try 47 | { 48 | B &b = dynamic_cast(p); 49 | (void)b; 50 | std::cout << "B" << std::endl; 51 | } 52 | catch (std::exception &e) 53 | { 54 | try 55 | { 56 | C &c = dynamic_cast(p); 57 | (void)c; 58 | std::cout << "C" << std::endl; 59 | } 60 | catch (std::exception &e) 61 | { 62 | std::cout << "Not A, B or C" << std::endl; 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /cpp_06/ex02/helper.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* helper.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 22:45:27 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 22:50:06 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HELPER_HPP 14 | # define HELPER_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | 20 | # include "Base.hpp" 21 | # include "A.hpp" 22 | # include "B.hpp" 23 | # include "C.hpp" 24 | 25 | Base * generate(void); 26 | void identify(Base * p); 27 | void identify(Base & p); 28 | 29 | #endif -------------------------------------------------------------------------------- /cpp_06/ex02/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 22:55:06 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/18 22:40:42 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "helper.hpp" 14 | 15 | int main() 16 | { 17 | srand(time(NULL)); 18 | Base *base = generate(); 19 | identify(base); 20 | identify(*base); 21 | return (0); 22 | } -------------------------------------------------------------------------------- /cpp_07/cpp_07.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_07/cpp_07.pdf -------------------------------------------------------------------------------- /cpp_07/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/15 23:23:48 by namohamm #+# #+# # 9 | # Updated: 2022/12/15 23:30:00 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = start 14 | 15 | SRCS = main.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_07/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 23:28:36 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/16 10:53:49 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "whatever.hpp" 14 | #include 15 | 16 | int main( void ) { 17 | int a = 2; 18 | int b = 3; 19 | ::swap( a, b ); 20 | std::cout << "a = " << a << ", b = " << b << std::endl; 21 | std::cout << "min( a, b ) = " << ::min( a, b ) << std::endl; 22 | std::cout << "max( a, b ) = " << ::max( a, b ) << std::endl; 23 | std::string c = "chaine1"; 24 | std::string d = "chaine2"; 25 | ::swap(c, d); 26 | std::cout << "c = " << c << ", d = " << d << std::endl; 27 | std::cout << "min( c, d ) = " << ::min( c, d ) << std::endl; 28 | std::cout << "max( c, d ) = " << ::max( c, d ) << std::endl; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /cpp_07/ex00/whatever.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* whatever.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 23:26:12 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 23:26:54 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef WHATEVER_HPP 14 | # define WHATEVER_HPP 15 | 16 | template 17 | void swap(T &a, T &b) 18 | { 19 | T tmp = a; 20 | a = b; 21 | b = tmp; 22 | } 23 | 24 | template 25 | T min(T &a, T &b) 26 | { 27 | return (a < b ? a : b); 28 | } 29 | 30 | template 31 | T max(T &a, T &b) 32 | { 33 | return (a > b ? a : b); 34 | } 35 | 36 | #endif -------------------------------------------------------------------------------- /cpp_07/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/16 10:56:55 by namohamm #+# #+# # 9 | # Updated: 2022/12/16 11:03:48 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = iter 14 | 15 | SRCS = main.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_07/ex01/iter: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_07/ex01/iter -------------------------------------------------------------------------------- /cpp_07/ex01/iter.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* iter.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/16 10:59:48 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/16 11:02:14 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ITER_HPP 14 | # define ITER_HPP 15 | 16 | template 17 | void iter(T *array, int length, void (*f)(T const &)) 18 | { 19 | for (int i = 0; i < length; i++) 20 | f(array[i]); 21 | } 22 | 23 | #endif -------------------------------------------------------------------------------- /cpp_07/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/16 11:02:18 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/16 11:17:44 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "iter.hpp" 15 | 16 | 17 | void print(int const &x) 18 | { 19 | std::cout << x << std::endl; 20 | } 21 | 22 | int main() 23 | { 24 | int array[5] = {1, 2, 3, 4, 5}; 25 | iter(array, 5, print); 26 | return (0); 27 | } -------------------------------------------------------------------------------- /cpp_07/ex01/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_07/ex01/main.o -------------------------------------------------------------------------------- /cpp_07/ex02/Array.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Array.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/20 15:26:36 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/20 15:27:59 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ARRAY_HPP 14 | # define ARRAY_HPP 15 | 16 | # include 17 | # include 18 | 19 | template 20 | class Array 21 | { 22 | private: 23 | T* _array; 24 | unsigned int _size; 25 | public: 26 | Array(); 27 | Array(unsigned int n); 28 | Array(Array const &src); 29 | ~Array(); 30 | Array &operator=(Array const &rhs); 31 | T &operator[](unsigned int i); 32 | unsigned int size() const; 33 | }; 34 | 35 | # include "Array.tpp" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /cpp_07/ex02/Array.tpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Array.tpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/20 15:29:41 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/20 16:48:04 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef ARRAY_TPP 14 | # define ARRAY_TPP 15 | 16 | # include "Array.hpp" 17 | 18 | template 19 | Array::Array() : _array(new T[0]), _size(0) { 20 | } 21 | 22 | template 23 | Array::Array(unsigned int n) : _array(new T[n]), _size(n) { 24 | } 25 | 26 | template 27 | Array::Array(Array const &src) { 28 | *this = src; 29 | } 30 | 31 | template 32 | Array::~Array() { 33 | delete [] _array; 34 | } 35 | 36 | template 37 | Array &Array::operator=(Array const &rhs) { 38 | if (this != &rhs) { 39 | _size = rhs._size; 40 | _array = new T[_size]; 41 | for (unsigned int i = 0; i < _size; i++) { 42 | _array[i] = rhs._array[i]; 43 | } 44 | } 45 | return *this; 46 | } 47 | 48 | template 49 | T &Array::operator[](unsigned int i) { 50 | if (i >= _size) { 51 | throw std::runtime_error("Index out of bounds"); 52 | } 53 | return _array[i]; 54 | } 55 | 56 | template 57 | unsigned int Array::size() const { 58 | return _size; 59 | } 60 | 61 | #endif -------------------------------------------------------------------------------- /cpp_07/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/16 11:19:04 by namohamm #+# #+# # 9 | # Updated: 2022/12/20 15:23:14 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = array 14 | 15 | SRCS = main.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_07/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/15 23:22:03 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/15 23:31:08 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | // #include 15 | 16 | // #define MAX_VAL 750 17 | // int main(int, char**) 18 | // { 19 | // Array numbers(MAX_VAL); 20 | // int* mirror = new int[MAX_VAL]; 21 | // srand(time(NULL)); 22 | // for (int i = 0; i < MAX_VAL; i++) 23 | // { 24 | // const int value = rand(); 25 | // numbers[i] = value; 26 | // mirror[i] = value; 27 | // } 28 | // //SCOPE 29 | // { 30 | // Array tmp = numbers; 31 | // Array test(tmp); 32 | // } 33 | 34 | // for (int i = 0; i < MAX_VAL; i++) 35 | // { 36 | // if (mirror[i] != numbers[i]) 37 | // { 38 | // std::cerr << "didn't save the same value!!" << std::endl; 39 | // return 1; 40 | // } 41 | // } 42 | // try 43 | // { 44 | // numbers[-2] = 0; 45 | // } 46 | // catch(const std::exception& e) 47 | // { 48 | // std::cerr << e.what() << '\n'; 49 | // } 50 | // try 51 | // { 52 | // numbers[MAX_VAL] = 0; 53 | // } 54 | // catch(const std::exception& e) 55 | // { 56 | // std::cerr << e.what() << '\n'; 57 | // } 58 | 59 | // for (int i = 0; i < MAX_VAL; i++) 60 | // { 61 | // numbers[i] = rand(); 62 | // } 63 | // delete [] mirror;// 64 | // return 0; 65 | // } -------------------------------------------------------------------------------- /cpp_08/cpp_08.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nass42/CPP_MODULES/3357f6ba6e0d28786c6b5c439e6621b8ec0e8d54/cpp_08/cpp_08.pdf -------------------------------------------------------------------------------- /cpp_08/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/19 22:10:09 by namohamm #+# #+# # 9 | # Updated: 2022/12/19 22:12:41 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = easyfind 14 | 15 | SRCS = main.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_08/ex00/easyfind.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* easyfind.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/19 22:16:57 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/19 22:28:49 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef EASYFIND_HPP 14 | # define EASYFIND_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | 20 | template 21 | int easyfind(T &container, int n) 22 | { 23 | typename T::iterator it = std::find(container.begin(), container.end(), n); 24 | if (it == container.end()) 25 | throw std::runtime_error("Element not found"); 26 | return *it; 27 | } 28 | 29 | #endif -------------------------------------------------------------------------------- /cpp_08/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/19 22:20:49 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/19 22:39:05 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "easyfind.hpp" 14 | 15 | int main() 16 | { 17 | std::vector v; 18 | v.push_back(1); 19 | v.push_back(2); 20 | v.push_back(3); 21 | v.push_back(4); 22 | v.push_back(5); 23 | try 24 | { 25 | std::cout << easyfind(v, 5) << std::endl; 26 | std::cout << easyfind(v, 11) << std::endl; 27 | } 28 | catch (std::exception &e) 29 | { 30 | std::cerr << e.what() << std::endl; 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /cpp_08/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/19 22:42:21 by namohamm #+# #+# # 9 | # Updated: 2022/12/19 22:42:41 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = span 14 | 15 | SRCS = main.cpp Span.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_08/ex01/Span.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Span.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/19 22:43:04 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/20 00:06:17 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SPAN_HPP 14 | # define SPAN_HPP 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | 21 | 22 | class Span 23 | { 24 | private: 25 | Span(void); 26 | std::vector _vec; 27 | unsigned int _N; 28 | public: 29 | Span(unsigned int N); 30 | Span(Span const & src); 31 | ~Span(void); 32 | 33 | Span & operator=(Span const & rhs); 34 | 35 | void addNumber(int n); 36 | int shortestSpan(void); 37 | int longestSpan(void); 38 | 39 | void addNumbers(int n, int m); 40 | 41 | class SpanFullException : public std::exception 42 | { 43 | public: 44 | virtual const char* what() const throw(); 45 | }; 46 | 47 | class SpanEmptyException : public std::exception 48 | { 49 | virtual const char* what() const throw(); 50 | }; 51 | 52 | }; 53 | 54 | #endif -------------------------------------------------------------------------------- /cpp_08/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: namohamm +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/12/20 00:16:44 by namohamm #+# #+# # 9 | # Updated: 2022/12/24 11:50:39 by namohamm ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | Name = mutantstack 14 | 15 | SRCS = main.cpp 16 | 17 | OBJS = $(SRCS:.cpp=.o) 18 | 19 | CXX = c++ 20 | 21 | CPPFLAGS = -std=c++98 -Wall -Wextra -Werror 22 | 23 | all: $(Name) 24 | 25 | $(Name): $(OBJS) 26 | $(CXX) $(CPPFLAGS) $(OBJS) -o $(Name) 27 | @printf "\033c" 28 | 29 | clean: 30 | rm -f $(OBJS) 31 | 32 | nass: clean 33 | rm -f $(Name) 34 | 35 | fclean: clean 36 | rm -f $(Name) 37 | 38 | re: fclean all 39 | 40 | .PHONY: all clean fclean re -------------------------------------------------------------------------------- /cpp_08/ex02/MutantStack.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* MutantStack.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/24 02:30:26 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/24 14:46:16 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef MUTANTSTACK_HPP 14 | # define MUTANTSTACK_HPP 15 | 16 | #include 17 | #include 18 | 19 | template 20 | class MutantStack : public std::stack 21 | { 22 | public: 23 | MutantStack() : std::stack() {} 24 | // MutantStack(MutantStack const &src) : std::stack(src) {} 25 | ~MutantStack() {} 26 | // MutantStack &operator=(MutantStack const &rhs) 27 | // { 28 | // if (this != &rhs) 29 | // std::stack::operator=(rhs); 30 | // return (*this); 31 | // } 32 | typedef typename std::stack::container_type::iterator iterator; 33 | iterator begin() { return (std::stack::c.begin()); } 34 | iterator end() { return (std::stack::c.end()); } 35 | }; 36 | #endif -------------------------------------------------------------------------------- /cpp_08/ex02/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: namohamm +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/12/24 11:48:44 by namohamm #+# #+# */ 9 | /* Updated: 2022/12/24 14:51:59 by namohamm ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "MutantStack.hpp" 14 | 15 | int main() 16 | { 17 | MutantStack mstack; 18 | mstack.push(5); 19 | mstack.push(17); 20 | std::cout << mstack.top() << std::endl; 21 | std::cout << "------------------" << std::endl; 22 | mstack.pop(); 23 | std::cout << mstack.size() << std::endl; 24 | std::cout << "------------------" << std::endl; 25 | mstack.push(3); 26 | mstack.push(5); 27 | mstack.push(737); 28 | //[...] 29 | mstack.push(0); 30 | MutantStack::iterator it = mstack.begin(); 31 | MutantStack::iterator ite = mstack.end(); 32 | ++it; 33 | --it; 34 | std::cout << "------------------" << std::endl; 35 | while (it != ite) 36 | { 37 | std::cout << *it << std::endl; 38 | ++it; 39 | } 40 | std::cout << "------------------" << std::endl; 41 | std::stack s(mstack); 42 | MutantStack t(mstack); 43 | mstack.pop(); 44 | mstack.pop(); 45 | mstack.pop(); 46 | mstack.pop(); 47 | mstack.pop(); 48 | std::cout << mstack.size() << std::endl; 49 | std::cout << t.size() << std::endl; 50 | MutantStack::iterator et = t.begin(); 51 | MutantStack::iterator ete = t.end(); 52 | std::cout << "------------------" << std::endl; 53 | while (et != ete) 54 | { 55 | std::cout << *et << std::endl; 56 | et++; 57 | } 58 | std::cout << "------------------" << std::endl; 59 | return 0; 60 | } --------------------------------------------------------------------------------