├── .gitignore ├── CPP_Module_00 ├── en.subject.pdf ├── ex00 │ ├── Makefile │ └── megaphone.cpp ├── ex01 │ ├── Contact.cpp │ ├── Contact.hpp │ ├── Makefile │ ├── PhoneBook.cpp │ ├── PhoneBook.hpp │ └── main.cpp └── ex02 │ ├── Account.cpp │ ├── Account.hpp │ ├── Makefile │ └── tests.cpp ├── CPP_Module_01 ├── en.subject.pdf ├── ex00 │ ├── Pony.cpp │ ├── Pony.hpp │ └── main.cpp ├── ex01 │ └── ex01.cpp ├── ex02 │ ├── Zombie.cpp │ ├── Zombie.hpp │ ├── ZombieEvent.cpp │ ├── ZombieEvent.hpp │ └── main.cpp ├── ex03 │ ├── Zombie.cpp │ ├── Zombie.hpp │ ├── ZombieHorde.cpp │ ├── ZombieHorde.hpp │ └── main.cpp ├── ex04 │ └── ex04.cpp ├── ex05 │ ├── Brain.cpp │ ├── Brain.hpp │ ├── Human.cpp │ ├── Human.hpp │ └── main.cpp ├── ex06 │ ├── HumanA.cpp │ ├── HumanA.hpp │ ├── HumanB.cpp │ ├── HumanB.hpp │ ├── Weapon.cpp │ ├── Weapon.hpp │ └── main.cpp ├── ex07 │ ├── Makefile │ ├── main.cpp │ ├── test-case │ ├── test-empty │ └── test-sample ├── ex08 │ ├── Human.cpp │ ├── Human.hpp │ └── main.cpp └── ex09 │ ├── Logger.cpp │ ├── Logger.hpp │ ├── logfile │ └── main.cpp ├── CPP_Module_02 ├── en.subject.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 └── ex03 │ ├── Fixed.cpp │ ├── Fixed.hpp │ ├── Makefile │ ├── Point.cpp │ ├── Point.hpp │ ├── bsp.cpp │ └── main.cpp ├── CPP_Module_03 ├── en.subject.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 └── ex03 │ ├── ClapTrap.cpp │ ├── ClapTrap.hpp │ ├── DiamondTrap.cpp │ ├── DiamondTrap.hpp │ ├── FragTrap.cpp │ ├── FragTrap.hpp │ ├── Makefile │ ├── ScavTrap.cpp │ ├── ScavTrap.hpp │ └── main.cpp ├── CPP_Module_04 ├── en.subject.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 │ ├── Brain.cpp │ ├── Brain.hpp │ ├── Cat.cpp │ ├── Cat.hpp │ ├── Dog.cpp │ ├── Dog.hpp │ ├── Makefile │ └── main.cpp ├── ex02 │ ├── Animal.cpp │ ├── Animal.hpp │ ├── Brain.cpp │ ├── Brain.hpp │ ├── Cat.cpp │ ├── Cat.hpp │ ├── Dog.cpp │ ├── Dog.hpp │ ├── Makefile │ └── main.cpp └── ex04 │ ├── AMateria.cpp │ ├── AMateria.hpp │ ├── Character.cpp │ ├── Character.hpp │ ├── Cure.cpp │ ├── Cure.hpp │ ├── ICharacter.hpp │ ├── IMateriaSource.hpp │ ├── Ice.cpp │ ├── Ice.hpp │ ├── Makefile │ ├── MateriaSource.cpp │ ├── MateriaSource.hpp │ └── main.cpp ├── CPP_Module_05 ├── en.subject.pdf ├── ex00 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Makefile │ └── main.cpp ├── ex01 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Form.cpp │ ├── Form.hpp │ ├── Makefile │ └── main.cpp ├── ex02 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Form.cpp │ ├── Form.hpp │ ├── Makefile │ ├── PresidentialPardonForm.cpp │ ├── PresidentialPardonForm.hpp │ ├── RobotomyRequestForm.cpp │ ├── RobotomyRequestForm.hpp │ ├── ShrubberyCreationForm.cpp │ ├── ShrubberyCreationForm.hpp │ └── main.cpp └── ex03 │ ├── Bureaucrat.cpp │ ├── Bureaucrat.hpp │ ├── Form.cpp │ ├── Form.hpp │ ├── Intern.cpp │ ├── Intern.hpp │ ├── Makefile │ ├── PresidentialPardonForm.cpp │ ├── PresidentialPardonForm.hpp │ ├── RobotomyRequestForm.cpp │ ├── RobotomyRequestForm.hpp │ ├── ShrubberyCreationForm.cpp │ ├── ShrubberyCreationForm.hpp │ └── main.cpp ├── CPP_Module_06 ├── en.subject.pdf ├── ex00 │ ├── Interpreter.cpp │ ├── Interpreter.hpp │ ├── Makefile │ └── main.cpp ├── ex01 │ ├── Data.hpp │ ├── Makefile │ └── main.cpp └── ex02 │ ├── A.cpp │ ├── A.hpp │ ├── B.cpp │ ├── B.hpp │ ├── Base.cpp │ ├── Base.hpp │ ├── C.cpp │ ├── C.hpp │ ├── Makefile │ └── main.cpp ├── CPP_Module_07 ├── en.subject.pdf ├── ex00 │ ├── Makefile │ ├── main.cpp │ └── whatever.hpp ├── ex01 │ ├── Makefile │ ├── iter.hpp │ └── main.cpp └── ex02 │ ├── Array.hpp │ ├── Makefile │ └── main.cpp ├── CPP_Module_08 ├── en.subject.pdf ├── ex00 │ ├── Makefile │ ├── easyfind.hpp │ └── main.cpp ├── ex01 │ ├── Makefile │ ├── Span.cpp │ ├── Span.hpp │ └── main.cpp └── ex02 │ ├── Makefile │ ├── MutantStack.hpp │ └── main.cpp └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.out 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /CPP_Module_00/en.subject.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_00/en.subject.pdf -------------------------------------------------------------------------------- /CPP_Module_00/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/15 21:07:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/15 21:10:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = megaphone 14 | 15 | SRCS = megaphone.cpp 16 | OBJS = ${SRCS:.cpp=.o} 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_00/ex00/megaphone.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* megaphone.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/15 21:11:15 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/15 21:11:17 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void toUpper(char **str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while ((*str)[i]) 21 | { 22 | if ((*str)[i] >= 'a' && (*str)[i] <= 'z') 23 | (*str)[i] -= 32; 24 | i++; 25 | } 26 | } 27 | 28 | int main(int argc, char **argv) 29 | { 30 | int i; 31 | 32 | if (argc == 1) 33 | std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *" << std::endl; 34 | else 35 | { 36 | i = 1; 37 | while (argv[i]) 38 | { 39 | toUpper(&argv[i]); 40 | std::cout << argv[i]; 41 | i++; 42 | } 43 | std::cout << "\n"; 44 | } 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /CPP_Module_00/ex01/Contact.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Contact.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/15 23:14:15 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/15 23:15:17 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | class Contact { 18 | private: 19 | std::string firstname; 20 | std::string lastname; 21 | std::string nickname; 22 | std::string secret; 23 | std::string number; 24 | public: 25 | const std::string& get_firstname(void) const; 26 | const std::string& get_lastname(void) const; 27 | const std::string& get_nickname(void) const; 28 | const std::string& get_secret(void) const; 29 | const std::string& get_number(void) const; 30 | void set_firstname(std::string firstname); 31 | void set_lastname(std::string lastname); 32 | void set_nickname(std::string nickname); 33 | void set_secret(std::string secret); 34 | void set_number(std::string number); 35 | }; 36 | -------------------------------------------------------------------------------- /CPP_Module_00/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/15 21:53:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/15 21:53:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = phonebook 14 | 15 | SRCS = Contact.cpp PhoneBook.cpp main.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_00/ex01/PhoneBook.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PhoneBook.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/16 00:04:15 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/16 00:05:17 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Contact.hpp" 16 | #include 17 | 18 | class PhoneBook { 19 | private: 20 | Contact contacts[8]; 21 | int size; 22 | int index; 23 | public: 24 | PhoneBook() : size (0), index (0) {} 25 | int get_size(void) const; 26 | void add_contact(std::string data[5]); 27 | void display_contact(int i) const; 28 | void display_phonebook(void) const; 29 | }; 30 | -------------------------------------------------------------------------------- /CPP_Module_00/ex02/Account.hpp: -------------------------------------------------------------------------------- 1 | // ************************************************************************** // 2 | // // 3 | // Account.class.cpp for GlobalBanksters United // 4 | // Created on : Thu Nov 20 19:43:15 1989 // 5 | // Last update : Wed Jan 04 14:54:06 1992 // 6 | // Made by : Brad "Buddy" McLane // 7 | // // 8 | // ************************************************************************** // 9 | 10 | // ************************************************************************** // 11 | // Account Class // 12 | // ************************************************************************** // 13 | 14 | #pragma once 15 | 16 | class Account { 17 | 18 | public: 19 | 20 | typedef Account t; 21 | 22 | static int getNbAccounts( void ); 23 | static int getTotalAmount( void ); 24 | static int getNbDeposits( void ); 25 | static int getNbWithdrawals( void ); 26 | static void displayAccountsInfos( void ); 27 | 28 | Account( int initial_deposit ); 29 | ~Account( void ); 30 | 31 | void makeDeposit( int deposit ); 32 | bool makeWithdrawal( int withdrawal ); 33 | int checkAmount( void ) const; 34 | void displayStatus( void ) const; 35 | 36 | 37 | private: 38 | 39 | static int _nbAccounts; 40 | static int _totalAmount; 41 | static int _totalNbDeposits; 42 | static int _totalNbWithdrawals; 43 | 44 | static void _displayTimestamp( void ); 45 | 46 | int _accountIndex; 47 | int _amount; 48 | int _nbDeposits; 49 | int _nbWithdrawals; 50 | 51 | Account( void ); 52 | }; 53 | -------------------------------------------------------------------------------- /CPP_Module_00/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/16 18:26:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/16 18:27:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = bankjob 14 | 15 | SRCS = Account.cpp tests.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_01/en.subject.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_01/en.subject.pdf -------------------------------------------------------------------------------- /CPP_Module_01/ex00/Pony.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Pony.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/16 22:42:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/16 22:44:18 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class Pony { 19 | private: 20 | std::string name; 21 | std::string origin; 22 | int age; 23 | bool magical; 24 | public: 25 | Pony(std::string name, std::string origin, int age); 26 | 27 | const std::string& getName(void) const; 28 | const std::string& getOrigin(void) const; 29 | int getAge(void) const; 30 | bool isMagical(void) const; 31 | 32 | void setName(std::string name); 33 | void setOrigin(std::string origin); 34 | void setAge(int age); 35 | 36 | void run(void) const; 37 | void eat(void) const; 38 | void speak(void) const; 39 | }; 40 | -------------------------------------------------------------------------------- /CPP_Module_01/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/16 23:40:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/16 23:41:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Pony.hpp" 14 | 15 | void ponyOnTheHeap(void) 16 | { 17 | Pony *heapPony; 18 | 19 | heapPony = new Pony("Jack", "Iceland", 7); 20 | delete heapPony; 21 | } 22 | 23 | void ponyOnTheStack(void) 24 | { 25 | Pony stackPony("Arthur", "Sweeden", 4); 26 | } 27 | 28 | int main(void) 29 | { 30 | ponyOnTheHeap(); 31 | ponyOnTheStack(); 32 | } 33 | -------------------------------------------------------------------------------- /CPP_Module_01/ex01/ex01.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ex01.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/16 23:49:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/16 23:50:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void memoryLeak() 14 | { 15 | std::string* panther = new std::string("String panther"); 16 | std::cout << *panther << std::endl; 17 | delete panther; 18 | } 19 | -------------------------------------------------------------------------------- /CPP_Module_01/ex02/Zombie.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Zombie.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/16 01:06:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/16 01:08:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Zombie.hpp" 14 | 15 | Zombie::Zombie(std::string name, std::string type) 16 | : name(name), type(type) 17 | { 18 | announce(); 19 | } 20 | 21 | Zombie::Zombie() {} 22 | 23 | Zombie::~Zombie() 24 | { 25 | std::cout << this->name << " died!" << std::endl; 26 | } 27 | 28 | const std::string& Zombie::getName() const 29 | { 30 | return (this->name); 31 | } 32 | 33 | const std::string& Zombie::getType() const 34 | { 35 | return (this->type); 36 | } 37 | 38 | void Zombie::setName(std::string name) 39 | { 40 | this->name = name; 41 | } 42 | 43 | void Zombie::setType(std::string type) 44 | { 45 | this->type = type; 46 | } 47 | 48 | void Zombie::announce() const 49 | { 50 | std::cout << "<" << this->name << " "; 51 | std::cout << "(" << this->type << ")>"; 52 | std::cout << " Braiiiiiiinnnssss..." << std::endl; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /CPP_Module_01/ex02/Zombie.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Zombie.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/16 00:58:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/16 00:59:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class Zombie { 19 | private: 20 | std::string name; 21 | std::string type; 22 | public: 23 | Zombie(std::string name, std::string type); 24 | Zombie(void); 25 | ~Zombie(void); 26 | 27 | const std::string& getName(void) const; 28 | const std::string& getType(void) const; 29 | void setName(std::string name); 30 | void setType(std::string type); 31 | 32 | void announce(void) const; 33 | }; 34 | -------------------------------------------------------------------------------- /CPP_Module_01/ex02/ZombieEvent.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ZombieEvent.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/19 16:27:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/19 16:27:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ZombieEvent.hpp" 14 | 15 | std::string ZombieEvent::namepool[7] = {"Alfred", "Richardo", "Leonardo", "Adam", "Charles", "Dominic", "Ferdinand"}; 16 | 17 | Zombie *ZombieEvent::newZombie(std::string name) const 18 | { 19 | return (new Zombie(name, this->type)); 20 | } 21 | 22 | Zombie *ZombieEvent::randomChump(void) const 23 | { 24 | std::string name; 25 | 26 | name = namepool[rand() % 7]; 27 | return (new Zombie(name, this->type)); 28 | } 29 | 30 | void ZombieEvent::setZombieType(std::string type) 31 | { 32 | this->type = type; 33 | } 34 | -------------------------------------------------------------------------------- /CPP_Module_01/ex02/ZombieEvent.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ZombieEvent.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/19 16:05:17 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/19 16:06:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Zombie.hpp" 16 | #include 17 | 18 | class ZombieEvent { 19 | private: 20 | std::string type; 21 | static std::string namepool[7]; 22 | public: 23 | Zombie *newZombie(std::string name) const; 24 | Zombie *randomChump(void) const; 25 | void setZombieType(std::string type); 26 | }; 27 | -------------------------------------------------------------------------------- /CPP_Module_01/ex03/Zombie.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Zombie.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/16 01:06:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/16 01:08:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Zombie.hpp" 14 | 15 | 16 | Zombie::Zombie(std::string name, std::string type) 17 | : name(name), type(type) 18 | { 19 | announce(); 20 | } 21 | 22 | Zombie::Zombie() {} 23 | 24 | Zombie::~Zombie() 25 | { 26 | std::cout << this->name << " died!" << std::endl; 27 | } 28 | 29 | const std::string& Zombie::getName() const 30 | { 31 | return (this->name); 32 | } 33 | 34 | const std::string& Zombie::getType() const 35 | { 36 | return (this->type); 37 | } 38 | 39 | void Zombie::setName(std::string name) 40 | { 41 | this->name = name; 42 | } 43 | 44 | void Zombie::setType(std::string type) 45 | { 46 | this->type = type; 47 | } 48 | 49 | void Zombie::announce() const 50 | { 51 | std::cout << "<" << this->name << " "; 52 | std::cout << "(" << this->type << ")>"; 53 | std::cout << " Braiiiiiiinnnssss..." << std::endl; 54 | } 55 | -------------------------------------------------------------------------------- /CPP_Module_01/ex03/Zombie.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Zombie.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/16 00:58:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/16 00:59:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class Zombie { 19 | private: 20 | std::string name; 21 | std::string type; 22 | public: 23 | Zombie(std::string name, std::string type); 24 | Zombie(void); 25 | ~Zombie(void); 26 | 27 | const std::string& getName(void) const; 28 | const std::string& getType(void) const; 29 | void setName(std::string name); 30 | void setType(std::string type); 31 | 32 | void announce(void) const; 33 | }; 34 | -------------------------------------------------------------------------------- /CPP_Module_01/ex03/ZombieHorde.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ZombieHorde.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 12:46:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 00:46:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ZombieHorde.hpp" 14 | 15 | std::string ZombieHorde::namepool[7] = {"Alfred", "Richardo", "Leonardo", "Adam", "Charles", "Dominic", "Ferdinand"}; 16 | std::string ZombieHorde::typepool[7] = {"Walker", "Deadhead", "Stalker", "Bitter", "Rotter", "Wasted", "Infected"}; 17 | 18 | ZombieHorde::ZombieHorde(int N) 19 | { 20 | int i; 21 | 22 | i = 0; 23 | srand(time(NULL)); 24 | this->zombies = new Zombie[N]; 25 | while (i < N) 26 | { 27 | this->zombies[i].setName(this->namepool[rand() % 7]); 28 | this->zombies[i].setType(this->typepool[rand() % 7]); 29 | i++; 30 | } 31 | this->size = N; 32 | } 33 | 34 | ZombieHorde::~ZombieHorde() 35 | { 36 | delete[] this->zombies; 37 | } 38 | 39 | void ZombieHorde::announce() const 40 | { 41 | int i; 42 | 43 | i = 0; 44 | while (i < this->size) 45 | { 46 | this->zombies[i].announce(); 47 | i++; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /CPP_Module_01/ex03/ZombieHorde.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ZombieHorde.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 12:30:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 12:31:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Zombie.hpp" 16 | #include 17 | 18 | class ZombieHorde { 19 | private: 20 | static std::string namepool[7]; 21 | static std::string typepool[7]; 22 | Zombie *zombies; 23 | int size; 24 | public: 25 | ZombieHorde(int N); 26 | ~ZombieHorde(void); 27 | 28 | void announce(void) const; 29 | }; 30 | -------------------------------------------------------------------------------- /CPP_Module_01/ex03/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 14:46:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 14:48:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ZombieHorde.hpp" 14 | 15 | int main() 16 | { 17 | ZombieHorde horde(4); 18 | 19 | std::cout << "I just created 4 zombies!!!\n" << std::endl; 20 | std::cout << "Let's make them announce themselves\n" << std::endl; 21 | 22 | horde.announce(); 23 | std::cout << "\nNow everyone dies\n" << std::endl; 24 | } 25 | -------------------------------------------------------------------------------- /CPP_Module_01/ex04/ex04.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 21:47:27 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 21:48:44 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main() 16 | { 17 | std::string str; 18 | std::string *str_ptr; 19 | std::string &str_ref = str; 20 | 21 | str = "HI THIS IS BRAIN"; 22 | str_ptr = &str; 23 | std::cout << "String pointer: " << *str_ptr << std::endl; 24 | std::cout << "String reference: " << str_ref << std::endl; 25 | } 26 | -------------------------------------------------------------------------------- /CPP_Module_01/ex05/Brain.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Brain.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 22:13:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 22:14:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Brain.hpp" 14 | 15 | Brain::Brain() 16 | { 17 | neurons = 0; 18 | } 19 | 20 | Brain::Brain(unsigned long n) : neurons(n) {} 21 | 22 | unsigned long Brain::get_neurons() const 23 | { 24 | return (this->neurons); 25 | } 26 | 27 | void Brain::set_neurons(unsigned long n) 28 | { 29 | this->neurons = n; 30 | } 31 | 32 | std::string Brain::identify() const 33 | { 34 | std::stringstream ptr_address; 35 | 36 | ptr_address << this; 37 | return (ptr_address.str()); 38 | } 39 | -------------------------------------------------------------------------------- /CPP_Module_01/ex05/Brain.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Brain.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 21:57:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 21:58:32 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | class Brain { 20 | private: 21 | unsigned long neurons; 22 | public: 23 | Brain(); 24 | Brain(unsigned long n); 25 | 26 | unsigned long get_neurons(void) const; 27 | std::string identify(void) const; 28 | void set_neurons(unsigned long n); 29 | }; 30 | -------------------------------------------------------------------------------- /CPP_Module_01/ex05/Human.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Human.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 22:27:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 22:27:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Human.hpp" 14 | 15 | const Brain& Human::getBrain() const 16 | { 17 | return (this->brain); 18 | } 19 | 20 | std::string Human::identify() const 21 | { 22 | return (this->brain.identify()); 23 | } 24 | -------------------------------------------------------------------------------- /CPP_Module_01/ex05/Human.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Human.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 22:23:11 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 22:25:40 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Brain.hpp" 16 | 17 | class Human { 18 | private: 19 | Brain brain; 20 | public: 21 | const Brain& getBrain(void) const; 22 | std::string identify(void) const; 23 | }; 24 | -------------------------------------------------------------------------------- /CPP_Module_01/ex05/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 22:30:32 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 22:31:41 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Human.hpp" 14 | 15 | int main() 16 | { 17 | Human bob; 18 | 19 | std::cout << bob.identify() << std::endl; 20 | std::cout << bob.getBrain().identify() << std::endl; 21 | } 22 | -------------------------------------------------------------------------------- /CPP_Module_01/ex06/HumanA.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanA.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 00:13:15 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 00:14:26 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "HumanA.hpp" 14 | 15 | HumanA::HumanA(std::string name, Weapon& weapon) : name(name), weapon(weapon) {} 16 | 17 | void HumanA::attack() const 18 | { 19 | std::cout << this->name << " attacks with his " << this->weapon.getType() << std::endl; 20 | } 21 | -------------------------------------------------------------------------------- /CPP_Module_01/ex06/HumanA.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanA.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 00:09:15 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 00:10:26 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Weapon.hpp" 16 | #include 17 | #include 18 | 19 | class HumanA { 20 | private: 21 | std::string name; 22 | Weapon &weapon; 23 | public: 24 | HumanA(std::string name, Weapon& weapon); 25 | 26 | void attack(void) const; 27 | }; 28 | -------------------------------------------------------------------------------- /CPP_Module_01/ex06/HumanB.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanB.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 00:21:15 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 00:22:26 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "HumanB.hpp" 14 | 15 | HumanB::HumanB(std::string name) : name(name) {} 16 | 17 | void HumanB::setWeapon(Weapon *weapon) 18 | { 19 | this->weapon = weapon; 20 | } 21 | 22 | void HumanB::attack(void) const 23 | { 24 | std::cout << this->name << " attacks with his " << this->weapon->getType() << std::endl; 25 | } 26 | -------------------------------------------------------------------------------- /CPP_Module_01/ex06/HumanB.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* HumanB.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 00:17:15 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 00:18:26 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Weapon.hpp" 16 | #include 17 | #include 18 | 19 | class HumanB { 20 | private: 21 | std::string name; 22 | Weapon *weapon; 23 | public: 24 | HumanB(std::string name); 25 | 26 | void setWeapon(Weapon *weapon); 27 | void attack(void) const; 28 | }; 29 | -------------------------------------------------------------------------------- /CPP_Module_01/ex06/Weapon.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Weapon.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 00:05:15 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 00:06:26 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Weapon.hpp" 14 | 15 | Weapon::Weapon(std::string type) : type(type) {} 16 | 17 | const std::string& Weapon::getType() const 18 | { 19 | return (this->type); 20 | } 21 | 22 | void Weapon::setType(std::string type) 23 | { 24 | this->type = type; 25 | } 26 | -------------------------------------------------------------------------------- /CPP_Module_01/ex06/Weapon.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Weapon.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 23:10:15 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 23:11:26 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | class Weapon { 18 | private: 19 | std::string type; 20 | public: 21 | Weapon(std::string type); 22 | 23 | const std::string& getType(void) const; 24 | void setType(std::string type); 25 | }; 26 | -------------------------------------------------------------------------------- /CPP_Module_01/ex06/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/20 00:25:45 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/20 00:25:56 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "HumanA.hpp" 14 | #include "HumanB.hpp" 15 | 16 | int main() 17 | { 18 | { 19 | Weapon club = Weapon("crude spiked club"); 20 | HumanA bob("Bob", club); 21 | bob.attack(); 22 | club.setType("some other type of club"); 23 | bob.attack(); 24 | } 25 | { 26 | Weapon club = Weapon("crude spiked club"); 27 | HumanB jim("Jim"); 28 | jim.setWeapon(&club); 29 | jim.attack(); 30 | club.setType("some other type of club"); 31 | jim.attack(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CPP_Module_01/ex07/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/20 00:51:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/20 00:53:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = replace 14 | 15 | SRCS = main.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_01/ex07/test-case: -------------------------------------------------------------------------------- 1 | Donald Ervin Knuth 2 | DONALD Ervin Knuth 3 | DONALD ERVIN Knuth 4 | DONALD ERVIN KNUTH 5 | DONALD Ervin Knuth 6 | donald ervin knuth 7 | dOnAlD ErVin knUtH 8 | -------------------------------------------------------------------------------- /CPP_Module_01/ex07/test-empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_01/ex07/test-empty -------------------------------------------------------------------------------- /CPP_Module_01/ex07/test-sample: -------------------------------------------------------------------------------- 1 | Hello James. 2 | How are you doing James? 3 | Would you like some tea James? 4 | Are you a bit blue James? 5 | -------------------------------------------------------------------------------- /CPP_Module_01/ex08/Human.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Human.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/21 23:25:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/21 23:26:18 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | # include 16 | # include 17 | 18 | class Human { 19 | private: 20 | void meleeAttack(std::string const& target); 21 | void rangedAttack(std::string const& target); 22 | void intimidatingShout(std::string const& target); 23 | public: 24 | void action(std::string const& action_name, std::string const& target); 25 | }; 26 | -------------------------------------------------------------------------------- /CPP_Module_01/ex08/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/22 13:47:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/22 13:48:18 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Human.hpp" 14 | 15 | int main() 16 | { 17 | Human h; 18 | 19 | std::cout<< "Attack by function pointers" << std::endl; 20 | 21 | h.action("meleeAttack", "Dragon"); 22 | h.action("rangedAttack", "Dragon"); 23 | h.action("intimidatingShout", "Dragon"); 24 | } 25 | -------------------------------------------------------------------------------- /CPP_Module_01/ex09/Logger.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Logger.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/22 14:59:23 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/22 15:02:10 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | class Logger { 21 | private: 22 | std::string logFile; 23 | 24 | void logToConsole(std::string const& log) const; 25 | void logToFile(std::string const& log) const; 26 | std::string makeLogEntry(std::string const& message) const; 27 | public: 28 | Logger(std::string logFile); 29 | 30 | void log(std::string const& dest, std::string const& message) const; 31 | }; 32 | -------------------------------------------------------------------------------- /CPP_Module_01/ex09/logfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_01/ex09/logfile -------------------------------------------------------------------------------- /CPP_Module_01/ex09/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/22 15:43:31 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/22 15:45:14 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Logger.hpp" 14 | 15 | int main() 16 | { 17 | Logger logger("logfile"); 18 | 19 | logger.log("console", "First Log!"); 20 | logger.log("file", "Logging into the file!"); 21 | logger.log("file", "Second line of the logfile!"); 22 | logger.log("console", "Last Log!"); 23 | } 24 | -------------------------------------------------------------------------------- /CPP_Module_02/en.subject.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_02/en.subject.pdf -------------------------------------------------------------------------------- /CPP_Module_02/ex00/Fixed.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Fixed.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/22 20:10:23 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/22 19:11:10 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Fixed.hpp" 14 | 15 | Fixed::Fixed() 16 | { 17 | std::cout << "Default constructor called" << std::endl; 18 | this->value = 0; 19 | } 20 | 21 | Fixed::Fixed(const Fixed& other) 22 | { 23 | std::cout << "Copy constructor called" << std::endl; 24 | *this = other; 25 | } 26 | 27 | Fixed::~Fixed() 28 | { 29 | std::cout << "Destructor called" << std::endl; 30 | } 31 | 32 | Fixed& Fixed::operator=(const Fixed& other) 33 | { 34 | std::cout << "Assignation operator called" << std::endl; 35 | this->setRawBits(other.getRawBits()); 36 | return (*this); 37 | } 38 | 39 | int Fixed::getRawBits() const 40 | { 41 | std::cout << "getRawBits member function called" << std::endl; 42 | return (this->value); 43 | } 44 | 45 | void Fixed::setRawBits(const int raw) 46 | { 47 | this->value = raw; 48 | } 49 | -------------------------------------------------------------------------------- /CPP_Module_02/ex00/Fixed.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Fixed.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/22 19:06:23 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/22 19:11:10 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | class Fixed { 18 | private: 19 | int value; 20 | static const int fractBits = 8; 21 | public: 22 | Fixed(void); 23 | Fixed(const Fixed& other); 24 | ~Fixed(void); 25 | 26 | Fixed& operator=(const Fixed& other); 27 | int getRawBits(void) const; 28 | void setRawBits(const int raw); 29 | }; 30 | -------------------------------------------------------------------------------- /CPP_Module_02/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/22 20:27:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/22 21:29:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = fixed 14 | 15 | SRCS = main.cpp Fixed.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_02/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/22 19:24:23 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/22 19:25:10 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Fixed.hpp" 14 | 15 | int main( void ) 16 | { 17 | Fixed a; 18 | Fixed b( a ); 19 | Fixed c; 20 | 21 | c = b; 22 | 23 | std::cout << a.getRawBits() << std::endl; 24 | std::cout << b.getRawBits() << std::endl; 25 | std::cout << c.getRawBits() << std::endl; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /CPP_Module_02/ex01/Fixed.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Fixed.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/22 20:44:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/22 20:49:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class Fixed { 19 | private: 20 | int value; 21 | static const int fractBits = 8; 22 | public: 23 | Fixed(void); 24 | Fixed(const Fixed& other); 25 | Fixed(const float val); 26 | Fixed(const int val); 27 | ~Fixed(void); 28 | 29 | Fixed& operator=(const Fixed& other); 30 | int getRawBits(void) const; 31 | void setRawBits(const int raw); 32 | 33 | int toInt(void) const; 34 | float toFloat(void) const; 35 | }; 36 | 37 | std::ostream& operator<<(std::ostream& out, const Fixed& fixed); 38 | -------------------------------------------------------------------------------- /CPP_Module_02/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/22 20:27:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/22 21:29:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = fixed 14 | 15 | SRCS = main.cpp Fixed.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_02/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/22 22:00:23 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/22 22:01:10 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Fixed.hpp" 14 | 15 | int main( void ) 16 | { 17 | Fixed a; 18 | Fixed const b( 10 ); 19 | Fixed const c( 42.42f ); 20 | Fixed const d( b ); 21 | 22 | a = Fixed( 1234.4321f ); 23 | 24 | std::cout << "a is " << a << std::endl; 25 | std::cout << "b is " << b << std::endl; 26 | std::cout << "c is " << c << std::endl; 27 | std::cout << "d is " << d << std::endl; 28 | 29 | std::cout << "a is " << a.toInt() << " as integer" << std::endl; 30 | std::cout << "b is " << b.toInt() << " as integer" << std::endl; 31 | std::cout << "c is " << c.toInt() << " as integer" << std::endl; 32 | std::cout << "d is " << d.toInt() << " as integer" << std::endl; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /CPP_Module_02/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/23 23:47:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/23 23:49:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = fixed 14 | 15 | SRCS = main.cpp Fixed.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_02/ex02/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/23 23:34:23 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/23 23:37:10 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Fixed.hpp" 14 | 15 | int main( void ) 16 | { 17 | Fixed a; 18 | Fixed const b( Fixed( 5.05f ) * Fixed( 2 ) ); 19 | 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 | std::cout << a << std::endl; 25 | 26 | std::cout << b << std::endl; 27 | 28 | std::cout << Fixed::max( a, b ) << std::endl; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /CPP_Module_02/ex03/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/23 23:47:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/23 23:49:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = fixed 14 | 15 | SRCS = main.cpp Fixed.cpp Point.cpp bsp.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_02/ex03/Point.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Point.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/24 00:38:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/24 22:40:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Point.hpp" 14 | 15 | Point::Point(void) : x(Fixed(0)), y(Fixed(0)) { } 16 | 17 | Point::Point(const float x, const float y) 18 | : x(Fixed(x)), y(Fixed(y)) 19 | { } 20 | 21 | Point::Point(const Point& other) 22 | { 23 | *this = other; // overloaded = 24 | } 25 | 26 | Point::~Point() 27 | { 28 | 29 | } 30 | 31 | Point& Point::operator=(const Point&) 32 | { 33 | return (*this); 34 | } 35 | 36 | const Fixed& Point::getX(void) const 37 | { 38 | return (this->x); 39 | } 40 | 41 | const Fixed& Point::getY(void) const 42 | { 43 | return (this->y); 44 | } 45 | -------------------------------------------------------------------------------- /CPP_Module_02/ex03/Point.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Point.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/24 00:16:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/24 00:18:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Fixed.hpp" 16 | 17 | class Point { 18 | private: 19 | const Fixed x; 20 | const Fixed y; 21 | public: 22 | Point(void); 23 | Point(const Point&); 24 | Point(const float x, const float y); 25 | ~Point(); 26 | 27 | Point& operator=(const Point& other); 28 | 29 | const Fixed& getX(void) const; 30 | const Fixed& getY(void) const; 31 | }; 32 | -------------------------------------------------------------------------------- /CPP_Module_02/ex03/bsp.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* bsp.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/24 19:51:23 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/24 19:53:10 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Point.hpp" 14 | 15 | float area(const Point& a, const Point& b, const Point& c) 16 | { 17 | float x1, y1; 18 | float x2, y2; 19 | float x3, y3; 20 | 21 | x1 = a.getX().toFloat(); 22 | y1 = a.getY().toFloat(); 23 | x2 = b.getX().toFloat(); 24 | y2 = b.getY().toFloat(); 25 | x3 = c.getX().toFloat(); 26 | y3 = c.getY().toFloat(); 27 | 28 | return abs((x1*(y2-y3) + x2*(y3-y1)+ x3*(y1-y2))/2.0); 29 | } 30 | 31 | bool bsp(const Point& a, const Point& b, const Point& c, const Point& point) 32 | { 33 | /* Calculate area of triangle ABC */ 34 | float A = area(a, b, c); 35 | 36 | /* Calculate area of triangle PBC */ 37 | float A1 = area(point, b, c); 38 | 39 | /* Calculate area of triangle APC */ 40 | float A2 = area(a, point, c); 41 | 42 | /* Calculate area of triangle ABP */ 43 | float A3 = area(a, b, point); 44 | 45 | /* Check if sum of A1, A2 and A3 is same as A */ 46 | return (A == A1 + A2 + A3); 47 | } 48 | -------------------------------------------------------------------------------- /CPP_Module_03/en.subject.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_03/en.subject.pdf -------------------------------------------------------------------------------- /CPP_Module_03/ex00/ClapTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ClapTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/24 21:55:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/24 23:01:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class ClapTrap { 19 | private: 20 | std::string name; 21 | unsigned int hitPoints; 22 | unsigned int energyPoints; 23 | unsigned int attackDamage; 24 | public: 25 | ClapTrap(void); 26 | ClapTrap(const ClapTrap& other); 27 | ClapTrap(std::string name); 28 | ~ClapTrap(void); 29 | 30 | ClapTrap& operator=(const ClapTrap& other); 31 | 32 | const std::string& getName(void) const; 33 | unsigned int getHitPoints(void) const; 34 | unsigned int getEnergyPoints(void) const; 35 | unsigned int getAttackDamage(void) const; 36 | void setName(const std::string& name); 37 | void setHitPoints(unsigned int hitPoints); 38 | void setEnergyPoints(unsigned int energyPoints); 39 | void setAttackDamage(unsigned int damage); 40 | 41 | void attack(const std::string& target); 42 | void takeDamage(unsigned int amount); 43 | void beRepaired(unsigned int amount); 44 | }; 45 | -------------------------------------------------------------------------------- /CPP_Module_03/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/25 13:40:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/25 13:43:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = claptrap 14 | 15 | SRCS = main.cpp ClapTrap.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | 39 | -------------------------------------------------------------------------------- /CPP_Module_03/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/25 13:43:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/25 13:45:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ClapTrap.hpp" 14 | 15 | int main() 16 | { 17 | ClapTrap Jack("Jack"); 18 | 19 | /* Info */ 20 | Jack.setAttackDamage(2); 21 | std::cout << "\n---------- ClapTrap Jack ----------" << std::endl; 22 | std::cout << "Hitpoints: " << Jack.getHitPoints() << " "; 23 | std::cout << "Energy: " << Jack.getEnergyPoints() << " "; 24 | std::cout << "Attack Damage: " << Jack.getAttackDamage() << " "; 25 | std::cout << " Status: Active" << std::endl; 26 | 27 | /* Test */ 28 | std::cout << "\nStart attacking...\n" << std::endl; 29 | 30 | Jack.attack("Sharks"); 31 | Jack.attack("Pirates"); 32 | Jack.takeDamage(3); 33 | Jack.takeDamage(4); 34 | Jack.beRepaired(10); 35 | Jack.attack("Dragon"); 36 | Jack.attack("Spirits"); 37 | Jack.attack("Lions"); 38 | Jack.attack("Kings"); 39 | 40 | std::cout << "\nFights are over..." << std::endl; 41 | } 42 | -------------------------------------------------------------------------------- /CPP_Module_03/ex01/ClapTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ClapTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/24 21:55:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/24 23:01:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class ClapTrap { 19 | protected: 20 | std::string name; 21 | unsigned int hitPoints; 22 | unsigned int energyPoints; 23 | unsigned int attackDamage; 24 | public: 25 | ClapTrap(void); 26 | ClapTrap(const ClapTrap& other); 27 | ClapTrap(std::string name); 28 | ~ClapTrap(void); 29 | 30 | ClapTrap& operator=(const ClapTrap& other); 31 | 32 | const std::string& getName(void) const; 33 | unsigned int getHitPoints(void) const; 34 | unsigned int getEnergyPoints(void) const; 35 | unsigned int getAttackDamage(void) const; 36 | void setName(const std::string& name); 37 | void setHitPoints(unsigned int hitPoints); 38 | void setEnergyPoints(unsigned int energyPoints); 39 | void setAttackDamage(unsigned int damage); 40 | 41 | void attack(const std::string& target); 42 | void takeDamage(unsigned int amount); 43 | void beRepaired(unsigned int amount); 44 | }; 45 | -------------------------------------------------------------------------------- /CPP_Module_03/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/25 13:40:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/25 13:43:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = scavtrap 14 | 15 | SRCS = main.cpp ClapTrap.cpp ScavTrap.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | 39 | -------------------------------------------------------------------------------- /CPP_Module_03/ex01/ScavTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* ::: :::::::: */ 3 | /* ScavTrap.hpp :+: :+: :+: */ 4 | /* +:+ +:+ +:+ */ 5 | /* By: shovsepy +#+ +:+ +#+ */ 6 | /* +#+#+#+#+#+ +#+ */ 7 | /* Created: 2022/01/25 15:47:18 by shovsepy #+# #+# */ 8 | /* Updated: 2022/01/25 15:50:53 by shovsepy ### ########.fr */ 9 | /* */ 10 | /* ************************************************************************** */ 11 | 12 | #pragma once 13 | 14 | #include "ClapTrap.hpp" 15 | 16 | class ScavTrap : public ClapTrap { 17 | public: 18 | ScavTrap(const std::string& name); 19 | ScavTrap(const ScavTrap& other); 20 | ScavTrap(void); 21 | ~ScavTrap(void); 22 | 23 | using ClapTrap::operator=; 24 | void attack(const std::string& target); 25 | void guardGate(void) const; 26 | }; 27 | -------------------------------------------------------------------------------- /CPP_Module_03/ex02/ClapTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ClapTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/24 21:55:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/24 23:01:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class ClapTrap { 19 | protected: 20 | std::string name; 21 | unsigned int hitPoints; 22 | unsigned int energyPoints; 23 | unsigned int attackDamage; 24 | public: 25 | ClapTrap(void); 26 | ClapTrap(const ClapTrap& other); 27 | ClapTrap(std::string name); 28 | ~ClapTrap(void); 29 | 30 | ClapTrap& operator=(const ClapTrap& other); 31 | 32 | const std::string& getName(void) const; 33 | unsigned int getHitPoints(void) const; 34 | unsigned int getEnergyPoints(void) const; 35 | unsigned int getAttackDamage(void) const; 36 | void setName(const std::string& name); 37 | void setHitPoints(unsigned int hitPoints); 38 | void setEnergyPoints(unsigned int energyPoints); 39 | void setAttackDamage(unsigned int damage); 40 | 41 | void attack(const std::string& target); 42 | void takeDamage(unsigned int amount); 43 | void beRepaired(unsigned int amount); 44 | }; 45 | -------------------------------------------------------------------------------- /CPP_Module_03/ex02/FragTrap.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* ::: :::::::: */ 3 | /* FragTrap.cpp :+: :+: :+: */ 4 | /* +:+ +:+ +:+ */ 5 | /* By: shovsepy +#+ +:+ +#+ */ 6 | /* +#+#+#+#+#+ +#+ */ 7 | /* Created: 2022/01/25 19:55:18 by shovsepy #+# #+# */ 8 | /* Updated: 2022/01/25 20:01:53 by shovsepy ### ########.fr */ 9 | /* */ 10 | /* ************************************************************************** */ 11 | 12 | #include "FragTrap.hpp" 13 | 14 | FragTrap::FragTrap(void) : ClapTrap() 15 | { 16 | std::cout << "FragTrap default constructor has been called!" << std::endl; 17 | } 18 | 19 | FragTrap::FragTrap(const std::string& name) : ClapTrap(name) 20 | { 21 | std::cout << "name << "> Status: Created" << std::endl; 22 | } 23 | 24 | FragTrap::FragTrap(const FragTrap& other) : ClapTrap(other) 25 | { 26 | std::cout << " Status: Cloned" << std::endl; 27 | } 28 | 29 | FragTrap::~FragTrap(void) 30 | { 31 | std::cout << "name << "> Status: Dead" << std::endl; 32 | } 33 | 34 | void FragTrap::highFivesGuys(void) const 35 | { 36 | std::cout << "name << "> High Five Guys! Status: Friendly" << std::endl; 37 | } 38 | -------------------------------------------------------------------------------- /CPP_Module_03/ex02/FragTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* ::: :::::::: */ 3 | /* FragTrap.hpp :+: :+: :+: */ 4 | /* +:+ +:+ +:+ */ 5 | /* By: shovsepy +#+ +:+ +#+ */ 6 | /* +#+#+#+#+#+ +#+ */ 7 | /* Created: 2022/01/25 19:49:18 by shovsepy #+# #+# */ 8 | /* Updated: 2022/01/25 19:57:53 by shovsepy ### ########.fr */ 9 | /* */ 10 | /* ************************************************************************** */ 11 | 12 | #pragma once 13 | 14 | #include "ClapTrap.hpp" 15 | 16 | class FragTrap : public ClapTrap { 17 | public: 18 | FragTrap(const std::string& name); 19 | FragTrap(const FragTrap& other); 20 | FragTrap(void); 21 | ~FragTrap(void); 22 | 23 | using ClapTrap::operator=; 24 | void highFivesGuys(void) const; 25 | }; 26 | -------------------------------------------------------------------------------- /CPP_Module_03/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/25 13:40:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/25 13:43:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = fragtrap 14 | 15 | SRCS = main.cpp ClapTrap.cpp ScavTrap.cpp FragTrap.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | 39 | -------------------------------------------------------------------------------- /CPP_Module_03/ex02/ScavTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* ::: :::::::: */ 3 | /* ScavTrap.hpp :+: :+: :+: */ 4 | /* +:+ +:+ +:+ */ 5 | /* By: shovsepy +#+ +:+ +#+ */ 6 | /* +#+#+#+#+#+ +#+ */ 7 | /* Created: 2022/01/25 15:47:18 by shovsepy #+# #+# */ 8 | /* Updated: 2022/01/25 15:50:53 by shovsepy ### ########.fr */ 9 | /* */ 10 | /* ************************************************************************** */ 11 | 12 | #pragma once 13 | 14 | #include "ClapTrap.hpp" 15 | 16 | class ScavTrap : public ClapTrap { 17 | public: 18 | ScavTrap(const std::string& name); 19 | ScavTrap(const ScavTrap& other); 20 | ScavTrap(void); 21 | ~ScavTrap(void); 22 | 23 | using ClapTrap::operator=; 24 | void attack(const std::string& target); 25 | void guardGate(void) const; 26 | }; 27 | -------------------------------------------------------------------------------- /CPP_Module_03/ex02/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/25 20:03:14 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/25 20:10:34 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "FragTrap.hpp" 14 | 15 | int main() 16 | { 17 | FragTrap temp("Daniel"); 18 | FragTrap Daniel("No name"); 19 | 20 | /* Assignment check */ 21 | temp.setEnergyPoints(8); 22 | Daniel = temp; 23 | 24 | /* Info */ 25 | std::cout << "\n---------- FragTrap Daniel ----------" << std::endl; 26 | std::cout << "Hitpoints: " << Daniel.getHitPoints() << " "; 27 | std::cout << "Energy: " << Daniel.getEnergyPoints() << " "; 28 | std::cout << "Attack Damage: " << Daniel.getAttackDamage() << " "; 29 | std::cout << "Status: Active" << std::endl; 30 | 31 | /* Test */ 32 | std::cout << "\nStart attacking...\n" << std::endl; 33 | 34 | Daniel.attack("Sharks"); 35 | Daniel.attack("Pirates"); 36 | Daniel.takeDamage(3); 37 | Daniel.takeDamage(14); 38 | Daniel.beRepaired(10); 39 | Daniel.attack("Dragon"); 40 | Daniel.attack("Spirits"); 41 | Daniel.attack("Kings"); 42 | 43 | std::cout << "\nFights are over...\n" << std::endl; 44 | } 45 | -------------------------------------------------------------------------------- /CPP_Module_03/ex03/ClapTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ClapTrap.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/24 21:55:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/24 23:01:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class ClapTrap { 19 | protected: 20 | std::string name; 21 | unsigned int hitPoints; 22 | unsigned int energyPoints; 23 | unsigned int attackDamage; 24 | public: 25 | ClapTrap(void); 26 | ClapTrap(const ClapTrap& other); 27 | ClapTrap(std::string name); 28 | ~ClapTrap(void); 29 | 30 | ClapTrap& operator=(const ClapTrap& other); 31 | 32 | const std::string& getName(void) const; 33 | unsigned int getHitPoints(void) const; 34 | unsigned int getEnergyPoints(void) const; 35 | unsigned int getAttackDamage(void) const; 36 | void setName(const std::string& name); 37 | void setHitPoints(unsigned int hitPoints); 38 | void setEnergyPoints(unsigned int energyPoints); 39 | void setAttackDamage(unsigned int damage); 40 | 41 | void attack(const std::string& target); 42 | void takeDamage(unsigned int amount); 43 | void beRepaired(unsigned int amount); 44 | }; 45 | -------------------------------------------------------------------------------- /CPP_Module_03/ex03/DiamondTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* ::: :::::::: */ 3 | /* DiamondTrap.hpp :+: :+: :+: */ 4 | /* +:+ +:+ +:+ */ 5 | /* By: shovsepy +#+ +:+ +#+ */ 6 | /* +#+#+#+#+#+ +#+ */ 7 | /* Created: 2022/01/25 21:04:18 by shovsepy #+# #+# */ 8 | /* Updated: 2022/01/25 15:10:53 by shovsepy ### ########.fr */ 9 | /* */ 10 | /* ************************************************************************** */ 11 | 12 | #pragma once 13 | 14 | #include "ScavTrap.hpp" 15 | #include "FragTrap.hpp" 16 | 17 | class DiamondTrap : public ScavTrap, public FragTrap { 18 | private: 19 | std::string name; 20 | public: 21 | DiamondTrap(const std::string& name); 22 | DiamondTrap(const DiamondTrap& other); 23 | DiamondTrap(void); 24 | ~DiamondTrap(void); 25 | 26 | using ClapTrap::operator=; 27 | using ScavTrap::attack; 28 | void whoAmI(void); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /CPP_Module_03/ex03/FragTrap.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* ::: :::::::: */ 3 | /* FragTrap.cpp :+: :+: :+: */ 4 | /* +:+ +:+ +:+ */ 5 | /* By: shovsepy +#+ +:+ +#+ */ 6 | /* +#+#+#+#+#+ +#+ */ 7 | /* Created: 2022/01/25 19:55:18 by shovsepy #+# #+# */ 8 | /* Updated: 2022/01/25 20:01:53 by shovsepy ### ########.fr */ 9 | /* */ 10 | /* ************************************************************************** */ 11 | 12 | #include "FragTrap.hpp" 13 | 14 | FragTrap::FragTrap(void) : ClapTrap() 15 | { 16 | std::cout << "FragTrap default constructor has been called!" << std::endl; 17 | } 18 | 19 | FragTrap::FragTrap(const std::string& name) : ClapTrap(name) 20 | { 21 | std::cout << "name << "> Status: Created" << std::endl; 22 | this->hitPoints = 100; 23 | this->energyPoints = 100; 24 | this->attackDamage = 30; 25 | } 26 | 27 | FragTrap::FragTrap(const FragTrap& other) : ClapTrap(other) 28 | { 29 | std::cout << " Status: Cloned" << std::endl; 30 | this->hitPoints = 100; 31 | this->energyPoints = 100; 32 | this->attackDamage = 30; 33 | } 34 | 35 | FragTrap::~FragTrap(void) 36 | { 37 | std::cout << "name << "> Status: Dead" << std::endl; 38 | } 39 | 40 | void FragTrap::highFivesGuys(void) const 41 | { 42 | std::cout << "name << "> High Five Guys! Status: Friendly" << std::endl; 43 | } 44 | -------------------------------------------------------------------------------- /CPP_Module_03/ex03/FragTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* ::: :::::::: */ 3 | /* FragTrap.hpp :+: :+: :+: */ 4 | /* +:+ +:+ +:+ */ 5 | /* By: shovsepy +#+ +:+ +#+ */ 6 | /* +#+#+#+#+#+ +#+ */ 7 | /* Created: 2022/01/25 19:49:18 by shovsepy #+# #+# */ 8 | /* Updated: 2022/01/25 19:57:53 by shovsepy ### ########.fr */ 9 | /* */ 10 | /* ************************************************************************** */ 11 | 12 | #pragma once 13 | 14 | #include "ClapTrap.hpp" 15 | 16 | class FragTrap : virtual public ClapTrap { 17 | public: 18 | FragTrap(const std::string& name); 19 | FragTrap(const FragTrap& other); 20 | FragTrap(void); 21 | ~FragTrap(void); 22 | 23 | using ClapTrap::operator=; 24 | void highFivesGuys(void) const; 25 | }; 26 | -------------------------------------------------------------------------------- /CPP_Module_03/ex03/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/25 22:07:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/25 22:09:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = diamond 14 | 15 | SRCS = main.cpp ClapTrap.cpp ScavTrap.cpp FragTrap.cpp DiamondTrap.cpp 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | 39 | -------------------------------------------------------------------------------- /CPP_Module_03/ex03/ScavTrap.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* ::: :::::::: */ 3 | /* ScavTrap.hpp :+: :+: :+: */ 4 | /* +:+ +:+ +:+ */ 5 | /* By: shovsepy +#+ +:+ +#+ */ 6 | /* +#+#+#+#+#+ +#+ */ 7 | /* Created: 2022/01/25 15:47:18 by shovsepy #+# #+# */ 8 | /* Updated: 2022/01/25 15:50:53 by shovsepy ### ########.fr */ 9 | /* */ 10 | /* ************************************************************************** */ 11 | 12 | #pragma once 13 | 14 | #include "ClapTrap.hpp" 15 | 16 | class ScavTrap : virtual public ClapTrap { 17 | public: 18 | ScavTrap(const std::string& name); 19 | ScavTrap(const ScavTrap& other); 20 | ScavTrap(void); 21 | ~ScavTrap(void); 22 | 23 | using ClapTrap::operator=; 24 | void attack(const std::string& target); 25 | void guardGate(void) const; 26 | }; 27 | -------------------------------------------------------------------------------- /CPP_Module_03/ex03/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/25 20:03:14 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/25 20:10:34 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "DiamondTrap.hpp" 14 | 15 | int main() 16 | { 17 | DiamondTrap Diamond("Daniel"); 18 | 19 | Diamond.attack("Pirates"); 20 | Diamond.attack("Kings"); 21 | Diamond.attack("Lions"); 22 | Diamond.beRepaired(10); 23 | Diamond.takeDamage(100); 24 | Diamond.guardGate(); 25 | Diamond.highFivesGuys(); 26 | Diamond.whoAmI(); 27 | } 28 | -------------------------------------------------------------------------------- /CPP_Module_04/en.subject.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_04/en.subject.pdf -------------------------------------------------------------------------------- /CPP_Module_04/ex00/Animal.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 15:23:27 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 15:27:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Animal.hpp" 14 | 15 | Animal::Animal(void) 16 | { 17 | std::cout << "Default Constructor of Animal" << std::endl; 18 | } 19 | 20 | Animal::Animal(const std::string& type) 21 | { 22 | std::cout << "Type constructor of Animal" << std::endl; 23 | this->type = type; 24 | } 25 | 26 | Animal::Animal(const Animal& other) 27 | { 28 | std::cout << "Copy-Constructor of Animal" << std::endl; 29 | *this = other; 30 | } 31 | 32 | Animal::~Animal(void) 33 | { 34 | std::cout << "Destructor of Animal" << std::endl; 35 | } 36 | 37 | Animal& Animal::operator=(const Animal& other) 38 | { 39 | this->type = other.getType(); 40 | 41 | return (*this); 42 | } 43 | 44 | const std::string& Animal::getType(void) const 45 | { 46 | return (this->type); 47 | } 48 | 49 | void Animal::setType(const std::string& type) 50 | { 51 | this->type = type; 52 | } 53 | 54 | void Animal::makeSound(void) const 55 | { 56 | std::cout << "* Animal Sound!!! *" << std::endl; 57 | } 58 | -------------------------------------------------------------------------------- /CPP_Module_04/ex00/Animal.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 15:08:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 15:12:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class Animal { 19 | protected: 20 | std::string type; 21 | Animal(const std::string& type); 22 | public: 23 | Animal(void); 24 | Animal(const Animal& other); 25 | virtual ~Animal(void); 26 | 27 | Animal& operator=(const Animal& other); 28 | const std::string& getType(void) const; 29 | void setType(const std::string& type); 30 | virtual void makeSound(void) const; 31 | }; 32 | -------------------------------------------------------------------------------- /CPP_Module_04/ex00/Cat.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:24:27 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 16:26:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Cat.hpp" 14 | 15 | Cat::Cat(void) : Animal("Cat") 16 | { 17 | std::cout << "Default constructor of " << this->type << std::endl; 18 | } 19 | 20 | Cat::Cat(const Cat&) : Animal("Cat") 21 | { 22 | std::cout << "Copy-Constructor of " << this->type << std::endl; 23 | } 24 | 25 | Cat::~Cat(void) 26 | { 27 | std::cout << this->type << " has been destroyed" << std::endl; 28 | } 29 | 30 | void Cat::makeSound(void) const 31 | { 32 | std::cout << "* Meow! *" << std::endl; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /CPP_Module_04/ex00/Cat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:22:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 16:23:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Animal.hpp" 16 | 17 | class Cat : public Animal { 18 | public: 19 | Cat(void); 20 | Cat(const Cat&); 21 | ~Cat(); 22 | 23 | using Animal::operator=; 24 | void makeSound(void) const; 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /CPP_Module_04/ex00/Dog.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:11:27 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 16:14:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Dog.hpp" 14 | 15 | Dog::Dog(void) : Animal("Dog") 16 | { 17 | std::cout << "Default constructor of " << this->type << std::endl; 18 | } 19 | 20 | Dog::Dog(const Dog&) : Animal("Dog") 21 | { 22 | std::cout << "Copy-Constructor of " << this->type << std::endl; 23 | } 24 | 25 | Dog::~Dog(void) 26 | { 27 | std::cout << this->type << " has been destroyed" << std::endl; 28 | } 29 | 30 | void Dog::makeSound(void) const 31 | { 32 | std::cout << "* Barking! *" << std::endl; 33 | } 34 | -------------------------------------------------------------------------------- /CPP_Module_04/ex00/Dog.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:02:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 16:10:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Animal.hpp" 16 | 17 | class Dog : public Animal { 18 | public: 19 | Dog(void); 20 | Dog(const Dog&); 21 | ~Dog(); 22 | 23 | using Animal::operator=; 24 | void makeSound(void) const; 25 | }; 26 | -------------------------------------------------------------------------------- /CPP_Module_04/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/27 14:50:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/27 14:55:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = animals 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_04/ex00/WrongAnimal.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* WrongAnimal.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:49:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 16:53:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class WrongAnimal { 19 | protected: 20 | std::string type; 21 | WrongAnimal(const std::string& type); 22 | public: 23 | WrongAnimal(void); 24 | WrongAnimal(const WrongAnimal& other); 25 | virtual ~WrongAnimal(void); 26 | 27 | WrongAnimal& operator=(const WrongAnimal& other); 28 | const std::string& getType(void) const; 29 | void setType(const std::string& type); 30 | void makeSound(void) const; 31 | }; 32 | -------------------------------------------------------------------------------- /CPP_Module_04/ex00/WrongCat.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* WrongCat.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 17:09:27 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 17:10:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "WrongCat.hpp" 14 | 15 | WrongCat::WrongCat(void) : WrongAnimal("WrongCat") 16 | { 17 | std::cout << "Default constructor of " << this->type << std::endl; 18 | } 19 | 20 | WrongCat::WrongCat(const WrongCat&) : WrongAnimal("WrongCat") 21 | { 22 | std::cout << "Copy-Constructor of " << this->type << std::endl; 23 | } 24 | 25 | WrongCat::~WrongCat(void) 26 | { 27 | std::cout << this->type << " has been destroyed" << std::endl; 28 | } 29 | 30 | void WrongCat::makeSound(void) const 31 | { 32 | std::cout << "* WrongCat Meow *" << std::endl; 33 | } 34 | -------------------------------------------------------------------------------- /CPP_Module_04/ex00/WrongCat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* WrongCat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 17:02:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 17:05:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "WrongAnimal.hpp" 16 | 17 | class WrongCat : public WrongAnimal { 18 | public: 19 | WrongCat(void); 20 | WrongCat(const WrongCat&); 21 | ~WrongCat(); 22 | 23 | using WrongAnimal::operator=; 24 | void makeSound(void) const; 25 | }; 26 | -------------------------------------------------------------------------------- /CPP_Module_04/ex01/Animal.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 15:23:27 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 15:27:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Animal.hpp" 14 | 15 | Animal::Animal(void) 16 | { 17 | std::cout << "Default Constructor of Animal" << std::endl; 18 | } 19 | 20 | Animal::Animal(const std::string& type) 21 | { 22 | std::cout << "Type constructor of Animal" << std::endl; 23 | this->type = type; 24 | } 25 | 26 | Animal::Animal(const Animal& other) 27 | { 28 | std::cout << "Copy-Constructor of Animal" << std::endl; 29 | *this = other; 30 | } 31 | 32 | Animal::~Animal(void) 33 | { 34 | std::cout << "Destructor of Animal" << std::endl; 35 | } 36 | 37 | Animal& Animal::operator=(const Animal& other) 38 | { 39 | this->type = other.getType(); 40 | 41 | return (*this); 42 | } 43 | 44 | const std::string& Animal::getType(void) const 45 | { 46 | return (this->type); 47 | } 48 | 49 | void Animal::setType(const std::string& type) 50 | { 51 | this->type = type; 52 | } 53 | 54 | void Animal::makeSound(void) const 55 | { 56 | std::cout << "* Animal Sound!!! *" << std::endl; 57 | } 58 | -------------------------------------------------------------------------------- /CPP_Module_04/ex01/Animal.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 15:08:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 15:12:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include "Brain.hpp" 18 | 19 | class Animal { 20 | protected: 21 | std::string type; 22 | Animal(const std::string& type); 23 | public: 24 | Animal(void); 25 | Animal(const Animal& other); 26 | virtual ~Animal(void); 27 | 28 | virtual Animal& operator=(const Animal& other); 29 | const std::string& getType(void) const; 30 | void setType(const std::string& type); 31 | virtual void makeSound(void) const; 32 | virtual Brain *getBrain(void) const = 0; 33 | }; 34 | -------------------------------------------------------------------------------- /CPP_Module_04/ex01/Brain.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* brain.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 19:51:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 20:01:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Brain.hpp" 14 | 15 | Brain::Brain(void) 16 | { 17 | std::cout << "Default constructor of Brain" << std::endl; 18 | size = 0; 19 | } 20 | 21 | Brain::Brain(const Brain& other) 22 | { 23 | std::cout << "Copy-Constructor of Brain" << std::endl; 24 | *this = other; 25 | } 26 | 27 | Brain::~Brain(void) 28 | { 29 | std::cout << "Destructor of Brain" << std::endl; 30 | } 31 | 32 | Brain& Brain::operator=(const Brain& other) 33 | { 34 | for (int i = 0; i < 100; i++) 35 | this->ideas[i] = other.ideas[i]; 36 | this->size = other.size; 37 | return (*this); 38 | } 39 | 40 | const std::string& Brain::getIdea(unsigned int index) const 41 | { 42 | return (this->ideas[index]); 43 | } 44 | 45 | void Brain::addIdea(std::string idea) 46 | { 47 | if (size == 100) 48 | return; 49 | this->ideas[size++] = idea; 50 | } 51 | -------------------------------------------------------------------------------- /CPP_Module_04/ex01/Brain.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Brain.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 19:32:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 19:34:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class Brain { 19 | private: 20 | std::string ideas[100]; 21 | unsigned int size; 22 | public: 23 | Brain(void); 24 | Brain(const Brain& other); 25 | ~Brain(void); 26 | 27 | Brain& operator=(const Brain& other); 28 | void addIdea(std::string idea); 29 | const std::string& getIdea(unsigned int index) const; 30 | }; 31 | -------------------------------------------------------------------------------- /CPP_Module_04/ex01/Cat.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:24:27 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 16:26:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Cat.hpp" 14 | 15 | Cat::Cat(void) : Animal("Cat") 16 | { 17 | std::cout << "Default constructor of " << this->type << std::endl; 18 | this->brain = new Brain; 19 | } 20 | 21 | Cat::Cat(const Cat& other) : Animal("Cat") 22 | { 23 | std::cout << "Copy-Constructor of " << this->type << std::endl; 24 | *this = other; 25 | } 26 | 27 | Cat::~Cat(void) 28 | { 29 | std::cout << this->type << " has been destroyed" << std::endl; 30 | delete this->brain; 31 | } 32 | 33 | Animal& Cat::operator=(const Animal& other) 34 | { 35 | const Cat *pOther; 36 | 37 | pOther= dynamic_cast(&other); 38 | if (pOther) 39 | { 40 | this->type = pOther->type; 41 | *this->brain = *pOther->brain; 42 | } 43 | 44 | return (*this); 45 | } 46 | 47 | void Cat::makeSound(void) const 48 | { 49 | std::cout << "* Meow! *" << std::endl; 50 | } 51 | 52 | Brain* Cat::getBrain(void) const 53 | { 54 | return (this->brain); 55 | } 56 | -------------------------------------------------------------------------------- /CPP_Module_04/ex01/Cat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:22:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 19:29:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Animal.hpp" 16 | #include "Brain.hpp" 17 | 18 | class Cat : public Animal { 19 | private: 20 | Brain *brain; 21 | public: 22 | Cat(void); 23 | Cat(const Cat& other); 24 | ~Cat(); 25 | 26 | Animal& operator=(const Animal& other); 27 | void makeSound(void) const; 28 | Brain *getBrain(void) const; 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /CPP_Module_04/ex01/Dog.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:11:27 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 16:14:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Dog.hpp" 14 | 15 | Dog::Dog(void) : Animal("Dog") 16 | { 17 | std::cout << "Default constructor of " << this->type << std::endl; 18 | this->brain = new Brain; 19 | } 20 | 21 | Dog::Dog(const Dog& other) : Animal("Dog") 22 | { 23 | std::cout << "Copy-Constructor of " << this->type << std::endl; 24 | *this = other; 25 | } 26 | 27 | Dog::~Dog(void) 28 | { 29 | std::cout << this->type << " has been destroyed" << std::endl; 30 | delete this->brain; 31 | } 32 | 33 | Animal& Dog::operator=(const Animal& other) 34 | { 35 | const Dog *pOther; 36 | 37 | pOther = dynamic_cast(&other); 38 | if(pOther) 39 | { 40 | this->type = pOther->type; 41 | *this->brain = *pOther->brain; 42 | } 43 | 44 | return (*this); 45 | } 46 | 47 | void Dog::makeSound(void) const 48 | { 49 | std::cout << "* Barking! *" << std::endl; 50 | } 51 | 52 | Brain* Dog::getBrain(void) const 53 | { 54 | return (this->brain); 55 | } 56 | -------------------------------------------------------------------------------- /CPP_Module_04/ex01/Dog.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:02:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 16:10:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Animal.hpp" 16 | #include "Brain.hpp" 17 | 18 | class Dog : public Animal { 19 | private: 20 | Brain *brain; 21 | public: 22 | Dog(void); 23 | Dog(const Dog& other); 24 | ~Dog(); 25 | 26 | Animal& operator=(const Animal& other); 27 | void makeSound(void) const; 28 | Brain *getBrain(void) const; 29 | }; 30 | -------------------------------------------------------------------------------- /CPP_Module_04/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/27 14:50:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/27 14:55:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = animals 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_04/ex02/Animal.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 23:41:27 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 23:43:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Animal.hpp" 14 | 15 | Animal::~Animal(void) 16 | { 17 | std::cout << "Destructor of Animal" << std::endl; 18 | } 19 | 20 | const std::string& Animal::getType(void) const 21 | { 22 | return (this->type); 23 | } 24 | 25 | void Animal::setType(const std::string& type) 26 | { 27 | this->type = type; 28 | } 29 | -------------------------------------------------------------------------------- /CPP_Module_04/ex02/Animal.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Animal.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 23:39:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 23:41:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include "Brain.hpp" 18 | 19 | class Animal { 20 | protected: 21 | std::string type; 22 | public: 23 | virtual ~Animal(void); 24 | 25 | virtual Animal& operator=(const Animal& other) = 0; 26 | const std::string& getType(void) const; 27 | void setType(const std::string& type); 28 | virtual void makeSound(void) const = 0; 29 | virtual Brain *getBrain(void) const = 0; 30 | }; 31 | -------------------------------------------------------------------------------- /CPP_Module_04/ex02/Brain.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* brain.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 19:51:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 20:01:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Brain.hpp" 14 | 15 | Brain::Brain(void) 16 | { 17 | std::cout << "Default constructor of Brain" << std::endl; 18 | size = 0; 19 | } 20 | 21 | Brain::Brain(const Brain& other) 22 | { 23 | std::cout << "Copy-Constructor of Brain" << std::endl; 24 | *this = other; 25 | } 26 | 27 | Brain::~Brain(void) 28 | { 29 | std::cout << "Destructor of Brain" << std::endl; 30 | } 31 | 32 | Brain& Brain::operator=(const Brain& other) 33 | { 34 | for (int i = 0; i < 100; i++) 35 | this->ideas[i] = other.ideas[i]; 36 | this->size = other.size; 37 | return (*this); 38 | } 39 | 40 | const std::string& Brain::getIdea(unsigned int index) const 41 | { 42 | return (this->ideas[index]); 43 | } 44 | 45 | void Brain::addIdea(std::string idea) 46 | { 47 | if (size == 100) 48 | return; 49 | this->ideas[size++] = idea; 50 | } 51 | -------------------------------------------------------------------------------- /CPP_Module_04/ex02/Brain.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Brain.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 19:32:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 19:34:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | 18 | class Brain { 19 | private: 20 | std::string ideas[100]; 21 | unsigned int size; 22 | public: 23 | Brain(void); 24 | Brain(const Brain& other); 25 | ~Brain(void); 26 | 27 | Brain& operator=(const Brain& other); 28 | void addIdea(std::string idea); 29 | const std::string& getIdea(unsigned int index) const; 30 | }; 31 | -------------------------------------------------------------------------------- /CPP_Module_04/ex02/Cat.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cat.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:22:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 19:29:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Animal.hpp" 16 | #include "Brain.hpp" 17 | 18 | class Cat : public Animal { 19 | private: 20 | Brain *brain; 21 | public: 22 | Cat(void); 23 | Cat(const Cat& other); 24 | ~Cat(); 25 | 26 | Cat& operator=(const Cat& other); 27 | Animal& operator=(const Animal& other); 28 | void makeSound(void) const; 29 | Brain *getBrain(void) const; 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /CPP_Module_04/ex02/Dog.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Dog.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/27 16:02:18 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/27 16:10:53 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Animal.hpp" 16 | #include "Brain.hpp" 17 | 18 | class Dog : public Animal { 19 | private: 20 | Brain *brain; 21 | public: 22 | Dog(void); 23 | Dog(const Dog& other); 24 | ~Dog(); 25 | 26 | Dog& operator=(const Dog& other); 27 | Animal& operator=(const Animal& other); 28 | void makeSound(void) const; 29 | Brain *getBrain(void) const; 30 | }; 31 | -------------------------------------------------------------------------------- /CPP_Module_04/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/27 14:50:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/27 14:55:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = animals 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/AMateria.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* AMateria.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/28 01:28:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/28 01:32:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "AMateria.hpp" 14 | 15 | AMateria::AMateria(const std::string& type) : type(type) {} 16 | 17 | AMateria::~AMateria(void) {} 18 | 19 | const std::string& AMateria::getType(void) const 20 | { 21 | return (this->type); 22 | } 23 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/AMateria.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* AMateria.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/28 01:20:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/28 01:26:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "ICharacter.hpp" 16 | #include 17 | #include 18 | 19 | class ICharacter; 20 | 21 | class AMateria { 22 | protected: 23 | std::string type; 24 | public: 25 | AMateria(const std::string& type); 26 | virtual ~AMateria(void); 27 | 28 | virtual const std::string& getType(void) const; 29 | virtual AMateria* clone() const = 0; 30 | virtual void use(ICharacter& target) = 0; 31 | }; 32 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/Character.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Character.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/28 02:08:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/28 02:12:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "ICharacter.hpp" 16 | #include "AMateria.hpp" 17 | 18 | class Character : public ICharacter { 19 | private: 20 | std::string name; 21 | AMateria *inventory[4]; 22 | int size; 23 | public: 24 | Character(const std::string& name); 25 | Character(const Character& other); 26 | ~Character(void); 27 | 28 | Character& operator=(const Character& otehr); 29 | const std::string& getName(void) const; 30 | void equip(AMateria *m); 31 | void unequip(int idx); 32 | void use(int idx, ICharacter& target); 33 | }; 34 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/Cure.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cure.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/28 01:55:11 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/28 01:58:25 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Cure.hpp" 14 | 15 | Cure::Cure(void) : AMateria("cure") {} 16 | 17 | Cure::Cure(const Cure& other) : AMateria("cure") 18 | { 19 | *this = other; 20 | } 21 | 22 | Cure::~Cure(void) {} 23 | 24 | Cure& Cure::operator=(const Cure& other) 25 | { 26 | this->type = other.type; 27 | return (*this); 28 | } 29 | 30 | AMateria* Cure::clone() const 31 | { 32 | return (new Cure(*this)); 33 | } 34 | 35 | void Cure::use(ICharacter& target) 36 | { 37 | std::cout << "* heals " << target.getName() << "'s wounds *" << std::endl; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/Cure.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Cure.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/28 01:50:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/28 01:53:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "AMateria.hpp" 16 | 17 | class Cure : public AMateria { 18 | public: 19 | Cure(void); 20 | Cure(const Cure& other); 21 | ~Cure(void); 22 | 23 | Cure& operator=(const Cure& other); 24 | AMateria* clone() const; 25 | void use(ICharacter& target); 26 | }; 27 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/ICharacter.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ICharacter.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/28 01:59:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/28 02:03:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "AMateria.hpp" 16 | #include 17 | #include 18 | 19 | class AMateria; 20 | 21 | class ICharacter { 22 | public: 23 | virtual ~ICharacter() {} 24 | virtual const std::string& getName() const = 0; 25 | virtual void equip(AMateria* m) = 0; 26 | virtual void unequip(int idx) = 0; 27 | virtual void use(int idx, ICharacter& target) = 0; 28 | }; 29 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/IMateriaSource.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* IMateriaSource.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/28 15:35:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/28 15:37:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "AMateria.hpp" 16 | 17 | class IMateriaSource { 18 | public: 19 | virtual ~IMateriaSource() {} 20 | virtual void learnMateria(AMateria*) = 0; 21 | virtual AMateria* createMateria(const std::string& type) = 0; 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/Ice.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Ice.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/28 01:43:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/28 01:47:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Ice.hpp" 14 | 15 | Ice::Ice(void) : AMateria("ice") {} 16 | 17 | Ice::Ice(const Ice& other) : AMateria("ice") 18 | { 19 | *this = other; 20 | } 21 | 22 | Ice::~Ice(void) {} 23 | 24 | Ice& Ice::operator=(const Ice& other) 25 | { 26 | this->type = other.type; 27 | return (*this); 28 | } 29 | 30 | AMateria* Ice::clone() const 31 | { 32 | return (new Ice(*this)); 33 | } 34 | 35 | void Ice::use(ICharacter& target) 36 | { 37 | std::cout << "* shoots an ice bolt at " << target.getName() << " *" << std::endl; 38 | } 39 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/Ice.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Ice.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/28 01:37:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/28 01:42:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "AMateria.hpp" 16 | 17 | class Ice : public AMateria { 18 | public: 19 | Ice(void); 20 | Ice(const Ice& other); 21 | ~Ice(void); 22 | 23 | Ice& operator=(const Ice& other); 24 | AMateria* clone() const; 25 | void use(ICharacter& target); 26 | }; 27 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/28 15:43:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/28 15:51:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = materia 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/MateriaSource.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* MateriaSource.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/28 15:35:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/28 15:37:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "IMateriaSource.hpp" 16 | #include "AMateria.hpp" 17 | 18 | class MateriaSource: public IMateriaSource { 19 | private: 20 | AMateria *materias[4]; 21 | int size; 22 | public: 23 | MateriaSource(void); 24 | MateriaSource(const MateriaSource& other); 25 | ~MateriaSource(void); 26 | 27 | MateriaSource &operator=(const MateriaSource& other); 28 | 29 | virtual void learnMateria(AMateria *m); 30 | virtual AMateria *createMateria(const std::string& type); 31 | void printMaterias(void) const; 32 | }; 33 | -------------------------------------------------------------------------------- /CPP_Module_04/ex04/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 14:52:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/29 14:55:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "MateriaSource.hpp" 14 | #include "Character.hpp" 15 | #include "Ice.hpp" 16 | #include "Cure.hpp" 17 | 18 | int main() 19 | { 20 | IMateriaSource* src = new MateriaSource(); 21 | src->learnMateria(new Ice()); 22 | src->learnMateria(new Cure()); 23 | 24 | ICharacter* me = new Character("me"); 25 | 26 | AMateria* tmp; 27 | tmp = src->createMateria("ice"); 28 | me->equip(tmp); 29 | tmp = src->createMateria("cure"); 30 | me->equip(tmp); 31 | 32 | ICharacter* bob = new Character("bob"); 33 | 34 | me->use(0, *bob); 35 | me->use(1, *bob); 36 | 37 | delete bob; 38 | delete me; 39 | delete src; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /CPP_Module_05/en.subject.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_05/en.subject.pdf -------------------------------------------------------------------------------- /CPP_Module_05/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/29 15:47:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/29 15:51:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = bureaucrat 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_05/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/29 19:10:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/29 19:11:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = forms 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_05/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/29 19:10:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/29 19:11:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = forms 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_05/ex02/PresidentialPardonForm.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PresidentialPardonForm.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/30 02:06:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/30 02:10:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "PresidentialPardonForm.hpp" 14 | 15 | PresidentialPardonForm::PresidentialPardonForm(void) 16 | : Form("PresidentialPardonForm", 25, 5), target("") {} 17 | 18 | PresidentialPardonForm::PresidentialPardonForm(const std::string& target) 19 | : Form("PresidentialPardonForm", 25, 5), target(target) {} 20 | 21 | PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm& other) 22 | : Form("PresidentialPardonForm", 25, 5), target(other.getTarget()) 23 | {} 24 | 25 | PresidentialPardonForm::~PresidentialPardonForm(void) {} 26 | 27 | const std::string& PresidentialPardonForm::getTarget(void) const 28 | { 29 | return (this->target); 30 | } 31 | 32 | void PresidentialPardonForm::execute(const Bureaucrat& executor) const 33 | { 34 | this->checkExecutability(executor); 35 | std::cout << this->target << " has been pardoned by Zafod Beeblebrox." << std::endl; 36 | } 37 | -------------------------------------------------------------------------------- /CPP_Module_05/ex02/PresidentialPardonForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PresidentialPardonForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/30 02:01:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/30 02:05:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Form.hpp" 16 | 17 | class PresidentialPardonForm : public Form { 18 | private: 19 | const std::string target; 20 | 21 | PresidentialPardonForm(void); 22 | public: 23 | PresidentialPardonForm(const std::string& target); 24 | PresidentialPardonForm(const PresidentialPardonForm& other); 25 | ~PresidentialPardonForm(void); 26 | 27 | using Form::operator=; 28 | const std::string& getTarget(void) const; 29 | void execute(const Bureaucrat& executor) const; 30 | }; 31 | -------------------------------------------------------------------------------- /CPP_Module_05/ex02/RobotomyRequestForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* RobotomyRequstForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/30 01:42:38 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/30 01:45:55 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Form.hpp" 16 | 17 | class RobotomyRequestForm : public Form { 18 | private: 19 | const std::string target; 20 | 21 | RobotomyRequestForm(void); 22 | public: 23 | RobotomyRequestForm(const std::string& target); 24 | RobotomyRequestForm(const RobotomyRequestForm& other); 25 | ~RobotomyRequestForm(void); 26 | 27 | RobotomyRequestForm& operator=(const RobotomyRequestForm& other); 28 | const std::string& getTarget(void) const; 29 | virtual void execute(const Bureaucrat& executor) const; 30 | }; 31 | -------------------------------------------------------------------------------- /CPP_Module_05/ex02/ShrubberyCreationForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ShrubberyCreationForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 23:52:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/29 23:59:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Form.hpp" 16 | #include 17 | 18 | class ShrubberyCreationForm : public Form { 19 | private: 20 | const std::string target; 21 | 22 | ShrubberyCreationForm(void); 23 | public: 24 | ShrubberyCreationForm(const std::string& target); 25 | ShrubberyCreationForm(const ShrubberyCreationForm& other); 26 | ~ShrubberyCreationForm(void); 27 | 28 | using Form::operator=; 29 | const std::string& getTarget(void) const; 30 | void execute(const Bureaucrat& executor) const; 31 | }; 32 | -------------------------------------------------------------------------------- /CPP_Module_05/ex03/Intern.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Intern.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/30 13:25:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/30 13:30:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "ShrubberyCreationForm.hpp" 16 | #include "RobotomyRequestForm.hpp" 17 | #include "PresidentialPardonForm.hpp" 18 | 19 | class Intern { 20 | private: 21 | typedef struct s_form 22 | { 23 | std::string type; 24 | Form *form; 25 | } t_form; 26 | public: 27 | Intern(void); 28 | Intern(const Intern& other); 29 | ~Intern(void); 30 | 31 | Intern& operator=(const Intern& other); 32 | Form *makeForm(const std::string& formName, const std::string& target) const; 33 | }; 34 | -------------------------------------------------------------------------------- /CPP_Module_05/ex03/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/01/29 19:10:05 by shovsepy #+# #+# # 9 | # Updated: 2022/01/29 19:11:44 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = intern 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_05/ex03/PresidentialPardonForm.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PresidentialPardonForm.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/30 02:06:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/30 02:10:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "PresidentialPardonForm.hpp" 14 | 15 | PresidentialPardonForm::PresidentialPardonForm(void) 16 | : Form("PresidentialPardonForm", 25, 5), target("") {} 17 | 18 | PresidentialPardonForm::PresidentialPardonForm(const std::string& target) 19 | : Form("PresidentialPardonForm", 25, 5), target(target) {} 20 | 21 | PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm& other) 22 | : Form("PresidentialPardonForm", 25, 5), target(other.getTarget()) 23 | {} 24 | 25 | PresidentialPardonForm::~PresidentialPardonForm(void) {} 26 | 27 | const std::string& PresidentialPardonForm::getTarget(void) const 28 | { 29 | return (this->target); 30 | } 31 | 32 | void PresidentialPardonForm::execute(const Bureaucrat& executor) const 33 | { 34 | this->checkExecutability(executor); 35 | std::cout << this->target << " has been pardoned by Zafod Beeblebrox." << std::endl; 36 | } 37 | -------------------------------------------------------------------------------- /CPP_Module_05/ex03/PresidentialPardonForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* PresidentialPardonForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/30 02:01:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/30 02:05:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Form.hpp" 16 | 17 | class PresidentialPardonForm : public Form { 18 | private: 19 | const std::string target; 20 | 21 | PresidentialPardonForm(void); 22 | public: 23 | PresidentialPardonForm(const std::string& target); 24 | PresidentialPardonForm(const PresidentialPardonForm& other); 25 | ~PresidentialPardonForm(void); 26 | 27 | using Form::operator=; 28 | const std::string& getTarget(void) const; 29 | void execute(const Bureaucrat& executor) const; 30 | }; 31 | -------------------------------------------------------------------------------- /CPP_Module_05/ex03/RobotomyRequestForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* RobotomyRequstForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/30 01:42:38 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/30 01:45:55 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Form.hpp" 16 | 17 | class RobotomyRequestForm : public Form { 18 | private: 19 | const std::string target; 20 | 21 | RobotomyRequestForm(void); 22 | public: 23 | RobotomyRequestForm(const std::string& target); 24 | RobotomyRequestForm(const RobotomyRequestForm& other); 25 | ~RobotomyRequestForm(void); 26 | 27 | RobotomyRequestForm& operator=(const RobotomyRequestForm& other); 28 | const std::string& getTarget(void) const; 29 | virtual void execute(const Bureaucrat& executor) const; 30 | }; 31 | -------------------------------------------------------------------------------- /CPP_Module_05/ex03/ShrubberyCreationForm.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ShrubberyCreationForm.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/29 23:52:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/29 23:59:35 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Form.hpp" 16 | #include 17 | 18 | class ShrubberyCreationForm : public Form { 19 | private: 20 | const std::string target; 21 | 22 | ShrubberyCreationForm(void); 23 | public: 24 | ShrubberyCreationForm(const std::string& target); 25 | ShrubberyCreationForm(const ShrubberyCreationForm& other); 26 | ~ShrubberyCreationForm(void); 27 | 28 | using Form::operator=; 29 | const std::string& getTarget(void) const; 30 | void execute(const Bureaucrat& executor) const; 31 | }; 32 | -------------------------------------------------------------------------------- /CPP_Module_05/ex03/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/01/30 13:52:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/01/30 13:58:21 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Intern.hpp" 14 | 15 | int main() 16 | { 17 | Intern intern; 18 | Form *f; 19 | 20 | f = intern.makeForm("shrubbery creation", "28C"); 21 | std::cout << *f << std::endl; 22 | std::cout << std::endl; 23 | 24 | 25 | f = intern.makeForm("robotomy request", "28B"); 26 | std::cout << *f << std::endl; 27 | std::cout << std::endl; 28 | 29 | f = intern.makeForm("presidential pardon", "28A"); 30 | std::cout << *f << std::endl; 31 | std::cout << std::endl; 32 | 33 | f = intern.makeForm("undefined", "0U"); 34 | delete f; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /CPP_Module_06/en.subject.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_06/en.subject.pdf -------------------------------------------------------------------------------- /CPP_Module_06/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/02/01 14:08:15 by shovsepy #+# #+# # 9 | # Updated: 2022/02/01 14:10:24 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = convert 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_06/ex00/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/04 18:57:55 by shovsepy #+# #+# */ 9 | /* Updated: 2022/04/05 17:07:58 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "Interpreter.hpp" 15 | 16 | int main(int argc, char const *argv[]) 17 | { 18 | if (argc != 2) 19 | std::cout << "convert: bad arguments!" << std::endl; 20 | else 21 | { 22 | Interpreter p(argv[1]); 23 | std::cout << p << std::endl; 24 | } 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /CPP_Module_06/ex01/Data.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Data.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 18:33:17 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 18:35:29 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | typedef struct s_Data 18 | { 19 | std::string data; 20 | } Data; 21 | -------------------------------------------------------------------------------- /CPP_Module_06/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/02/01 18:31:15 by shovsepy #+# #+# # 9 | # Updated: 2022/02/01 18:32:24 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = serialization 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_06/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 19:21:17 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 19:25:29 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include "Data.hpp" 16 | 17 | uintptr_t serialize(Data *ptr) 18 | { 19 | return (reinterpret_cast(ptr)); 20 | } 21 | 22 | Data *deserialize(uintptr_t raw) 23 | { 24 | return (reinterpret_cast(raw)); 25 | } 26 | 27 | int main() 28 | { 29 | Data *ptr; 30 | Data *new_ptr; 31 | uintptr_t raw; 32 | 33 | ptr = new Data; 34 | ptr->data = "Dummy Data!"; 35 | 36 | raw = serialize(ptr); 37 | new_ptr = deserialize(raw); 38 | 39 | std::cout << "Data of ptr: " << ptr->data << std::endl; 40 | std::cout << "Data of new_ptr: " << new_ptr->data << std::endl; 41 | 42 | delete ptr; 43 | } 44 | -------------------------------------------------------------------------------- /CPP_Module_06/ex02/A.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* A.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 19:45:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 19:47:38 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "A.hpp" 14 | 15 | A::A(void) {} 16 | 17 | A::A(const A& other) { *this = other; } 18 | 19 | A::~A(void) {} 20 | 21 | A& A::operator=(const A&) { return (*this); } 22 | -------------------------------------------------------------------------------- /CPP_Module_06/ex02/A.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* A.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 19:43:54 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 19:45:18 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Base.hpp" 16 | 17 | class A : public Base { 18 | public: 19 | A(void); 20 | A(const A& other); 21 | ~A(void); 22 | 23 | A& operator=(const A&); 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /CPP_Module_06/ex02/B.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* B.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 19:45:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 19:47:38 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "B.hpp" 14 | 15 | B::B(void) {} 16 | 17 | B::B(const B& other) { *this = other; } 18 | 19 | B::~B(void) {} 20 | 21 | B& B::operator=(const B&) { return (*this); } 22 | 23 | -------------------------------------------------------------------------------- /CPP_Module_06/ex02/B.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* B.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 19:45:54 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 19:48:18 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Base.hpp" 16 | 17 | class B : public Base { 18 | public: 19 | B(void); 20 | B(const B& other); 21 | ~B(void); 22 | 23 | B& operator=(const B&); 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /CPP_Module_06/ex02/Base.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Base.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 19:42:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 19:43:38 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "Base.hpp" 14 | 15 | Base::~Base(void) {} 16 | -------------------------------------------------------------------------------- /CPP_Module_06/ex02/Base.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Base.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 19:40:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 19:42:38 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | class Base { 16 | public: 17 | virtual ~Base(void); 18 | }; 19 | -------------------------------------------------------------------------------- /CPP_Module_06/ex02/C.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* C.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 19:50:24 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 19:51:38 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "C.hpp" 14 | 15 | C::C(void) {} 16 | 17 | C::C(const C& other) { *this = other; } 18 | 19 | C::~C(void) {} 20 | 21 | C& C::operator=(const C&) { return (*this); } 22 | 23 | -------------------------------------------------------------------------------- /CPP_Module_06/ex02/C.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* C.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 19:48:54 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 19:49:18 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include "Base.hpp" 16 | 17 | class C : public Base { 18 | public: 19 | C(void); 20 | C(const C& other); 21 | ~C(void); 22 | 23 | C& operator=(const C&); 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /CPP_Module_06/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/02/01 19:54:15 by shovsepy #+# #+# # 9 | # Updated: 2022/02/01 18:56:24 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = identify 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_07/en.subject.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_07/en.subject.pdf -------------------------------------------------------------------------------- /CPP_Module_07/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/02/01 21:38:04 by shovsepy #+# #+# # 9 | # Updated: 2022/02/01 21:40:25 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = whatever 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_07/ex00/whatever.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* whatever.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 21:21:14 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 21:27:27 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | template 16 | void swap(T& a, T& b) 17 | { 18 | T tmp; 19 | 20 | tmp = a; 21 | a = b; 22 | b = tmp; 23 | } 24 | 25 | template 26 | const T& min(T& a, T& b) 27 | { 28 | return (a < b ? a : b); 29 | } 30 | 31 | template 32 | const T& max(T& a, T& b) 33 | { 34 | return (a > b ? a : b); 35 | } 36 | -------------------------------------------------------------------------------- /CPP_Module_07/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/02/01 21:45:04 by shovsepy #+# #+# # 9 | # Updated: 2022/02/01 21:46:25 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = iter 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_07/ex01/iter.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* iter.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 21:46:14 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 21:50:27 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | template 18 | void iter(T *arr, size_t len, void (*func)(T&)) 19 | { 20 | for (size_t i = 0; i < len; i++) 21 | { 22 | func(arr[i]); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CPP_Module_07/ex01/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/01 21:54:14 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/01 21:59:27 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "iter.hpp" 14 | #include 15 | #include 16 | #include 17 | 18 | template 19 | void display(T& elem) 20 | { 21 | std::cout << "Variable's value is: " << elem << std::endl; 22 | } 23 | 24 | void setRandomValue(int& number) 25 | { 26 | number = rand() % 100; 27 | } 28 | 29 | int main() 30 | { 31 | int intArray[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 32 | 33 | srand(time(NULL)); 34 | 35 | std::cout << "Displaying int Array\n" << std::endl; 36 | iter(intArray, 10, &display); 37 | 38 | std::cout << "\nSetting each value to random integer" << std::endl; 39 | iter(intArray, 10, &setRandomValue); 40 | 41 | std::cout << "\nDisplaying int Array with random values\n" << std::endl; 42 | ::iter(intArray, 10, &display); 43 | 44 | return (0); 45 | } 46 | -------------------------------------------------------------------------------- /CPP_Module_07/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/02/01 21:45:04 by shovsepy #+# #+# # 9 | # Updated: 2022/02/01 21:46:25 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = array 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_08/en.subject.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/42YerevanProjects/cpp_modules/f2edfe2fb3a12a7e86c1ff1e563f17c0487c649e/CPP_Module_08/en.subject.pdf -------------------------------------------------------------------------------- /CPP_Module_08/ex00/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/02/05 15:51:04 by shovsepy #+# #+# # 9 | # Updated: 2022/02/05 15:52:25 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = easyfind 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_08/ex00/easyfind.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* easyfind.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/05 15:45:14 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/05 15:50:27 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | template 18 | typename T::iterator easyfind(T& container, int val) 19 | { 20 | return (std::find(container.begin(), container.end(), val)); 21 | } 22 | -------------------------------------------------------------------------------- /CPP_Module_08/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/02/05 19:12:04 by shovsepy #+# #+# # 9 | # Updated: 2022/02/05 19:15:25 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = span 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_08/ex01/Span.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* Span.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/05 18:13:14 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/05 18:18:27 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | class Span { 22 | private: 23 | std::vector storage; 24 | unsigned int N; 25 | public: 26 | Span(void); 27 | Span(unsigned int N); 28 | Span(const Span& other); 29 | ~Span(void); 30 | 31 | Span& operator=(const Span& other); 32 | int size(void) const; 33 | int capacity(void) const; 34 | void addNumber(int n); 35 | int shortestSpan(void) const; 36 | int longestSpan(void) const; 37 | 38 | template 39 | void addNumber(It begin, It end) 40 | { 41 | while (begin != end) 42 | { 43 | this->addNumber(*begin); 44 | begin++; 45 | } 46 | } 47 | }; 48 | 49 | std::ostream& operator<<(std::ostream& out, const Span& instance); 50 | -------------------------------------------------------------------------------- /CPP_Module_08/ex02/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: shovsepy +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/02/05 20:16:04 by shovsepy #+# #+# # 9 | # Updated: 2022/02/05 20:17:25 by shovsepy ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | NAME = mutant 14 | 15 | SRCS = $(wildcard *.cpp) 16 | OBJS = $(SRCS:.cpp=.o) 17 | 18 | CC = c++ 19 | CFLAGS = -Wall -Wextra -Werror -std=c++98 20 | 21 | all: $(NAME) 22 | 23 | .cpp.o: 24 | $(CC) $(CFLAGS) -c $< -o $(<:.cpp=.o) 25 | 26 | $(NAME): $(OBJS) 27 | $(CC) $(OBJS) $(CFLAGS) -o $(NAME) 28 | 29 | clean: 30 | @$(RM) $(OBJS) 31 | 32 | fclean: clean 33 | @$(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /CPP_Module_08/ex02/MutantStack.hpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* MutantStack.hpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/05 20:05:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/05 20:10:27 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #pragma once 14 | 15 | #include 16 | 17 | template 18 | class MutantStack : public std::stack { 19 | public: 20 | typedef typename std::stack::container_type::iterator iterator; 21 | iterator begin() { return this->c.begin(); }; 22 | iterator end() { return this->c.end(); }; 23 | }; 24 | -------------------------------------------------------------------------------- /CPP_Module_08/ex02/main.cpp: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.cpp :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shovsepy +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/02/05 20:12:08 by shovsepy #+# #+# */ 9 | /* Updated: 2022/02/05 20:15:27 by shovsepy ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "MutantStack.hpp" 14 | #include 15 | 16 | int main() 17 | { 18 | MutantStack mstack; 19 | 20 | mstack.push(5); 21 | mstack.push(17); 22 | 23 | std::cout << mstack.top() << std::endl; 24 | 25 | mstack.pop(); 26 | 27 | std::cout << mstack.size() << std::endl; 28 | 29 | mstack.push(3); 30 | mstack.push(5); 31 | mstack.push(737); 32 | 33 | //[...] 34 | 35 | mstack.push(0); 36 | 37 | MutantStack::iterator it = mstack.begin(); 38 | MutantStack::iterator ite = mstack.end(); 39 | 40 | ++it; 41 | --it; 42 | 43 | while (it != ite) 44 | { 45 | std::cout << *it << std::endl; 46 | ++it; 47 | } 48 | 49 | std::stack s(mstack); 50 | return (0); 51 | } 52 | --------------------------------------------------------------------------------