diff --git a/cpp00/ex_00/megaphone.cpp b/cpp00/ex_00/megaphone.cpp deleted file mode 100644 index ea39dca..0000000 --- a/cpp00/ex_00/megaphone.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -int main(int ac, char **av) { - std::string tmp; - if (ac < 2) { - std::cout << "* SILENCE I WISH NOT TO BE HORNY ANYMORE *" << std::endl; - return 1; - } - for (int i=1; av[i] != '\0'; i++) { - tmp = av[i]; - for (int j=0; av[i][j] != '\0'; j++) { - if (tmp.at(j) >= 'a' && tmp.at(j) <= 'z') { - std::cout << (char)std::toupper(tmp.at(j)); - } - else - std::cout << tmp.at(j); - if (av[i][j + 1] == '\0') - std::cout << ' '; - } - } - std::cout << std::endl; -} diff --git a/cpp00/ex_01/PhoneBook.cpp b/cpp00/ex_01/PhoneBook.cpp deleted file mode 100644 index 65aa4e7..0000000 --- a/cpp00/ex_01/PhoneBook.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "PhoneBook.hpp" - -extern phonebook book; - -int take_input() { - int input; - std::cin.clear(); - std::cin >> input; - if (std::cin.fail()) - { - std::cin.clear(); - std::cin.ignore(std::numeric_limits::max(), '\n'); - std::cout << " Wrong input. " << std::endl; - return (-1); - } - return (input); -} - -std::string take_string() { -b: - std::string input; - std::cin.clear(); - fflush(stdin); - std::getline(std::cin, input); - if (std::cin.fail()) { - std::cout << std::endl; - std::cout << " Input fail " << std::endl; - goto b; - } - return (input); -} - -int console_log(){ - std::cout << "+------------------------------------------------------+" << std::endl - << "| Name | Lastname | Nickname | P Number | Secret |" << std::endl - << "+------------------------------------------------------+" << std::endl; - return 0; -} - -int print_short_cnt(int i) { - if(i < 8) - { - if (book.cnt[i].get_name().length() > 10) {std::cout << '|' << std::right << std::setw(9) << book.cnt[i].get_name().substr(0, 9) << '.';} - else {std::cout << '|' << std::right << std::setw(10) << book.cnt[i].get_name();} - if (book.cnt[i].get_lastname().length() > 10) {std::cout << '|' << std::right << std::setw(9) << book.cnt[i].get_lastname().substr(0, 9) << '.';} - else {std::cout << '|' << std::right << std::setw(10) << book.cnt[i].get_lastname();} - if (book.cnt[i].get_nickname().length() > 10) {std::cout << '|' << std::right << std::setw(9) << book.cnt[i].get_nickname().substr(0, 9) << '.';} - else {std::cout << '|' << std::right << std::setw(10) << book.cnt[i].get_nickname();} - if (book.cnt[i].get_pnumber().length() > 10) {std::cout << '|' << std::right << std::setw(9) << book.cnt[i].get_pnumber().substr(0, 9) << '.';} - else {std::cout << '|' << std::right << std::setw(10) << book.cnt[i].get_pnumber();} - if (book.cnt[i].get_secret().length() > 10) {std::cout << '|' << std::right << std::setw(9) << book.cnt[i].get_secret().substr(0, 9) << '.';} - else {std::cout << '|' << std::right << std::setw(10) << book.cnt[i].get_secret();} - std::cout << '|' << ' ' << i << std::endl<< "+------------------------------------------------------+" << std::endl; - } - return 1; -} - -int print_long_cnt(int i) { - if (book.cnt[i].get_name().length()) { - std::cout << "Name: " << book.cnt[i].get_name() << std::endl - << "Lastname: " << book.cnt[i].get_lastname() << std::endl - << "Nickname: " << book.cnt[i].get_nickname() << std::endl - << "Phone Number: " << book.cnt[i].get_pnumber() << std::endl - << "Secred: " << book.cnt[i].get_secret() << std::endl; - } else { - std::cout << " Apsent contact. " << std::endl; - } - return 0; -} - -int phonebook::search() { - console_log(); - for (int i=0; book.cnt[i].get_name().length(); i++) { - print_short_cnt(i); - } - std::cout << " + [ YOU WANNA SEE MORE THING?, GIMME NUMBER ] + " << std::endl; - print_long_cnt(take_input()); - return (1); -} - -int phonebook::add() { -a: - try { - std::cout << std::endl; - std::cout << "Name: " ; - if (!this->cnt[idx % 8].set_name(take_string())) {goto a;} - std::cout << "Lastname: " ; this->cnt[idx % 8].set_lastname(take_string()); - std::cout << "Nickname: " ; this->cnt[idx % 8].set_nickname(take_string()); - std::cout << "Phone Number: "; this->cnt[idx % 8].set_pnumber(take_string()); - std::cout << "Secred: " ; this->cnt[idx % 8].set_secret(take_string()); - this->idx += 1; - - } - catch(const std::exception& e) { - std::cerr << e.what() << std::endl; - } - return (0); -} - -std::string contact::get_name() {return (this->name);} -std::string contact::get_lastname() {return (this->lastname);} -std::string contact::get_nickname() {return (this->nickname);} -std::string contact::get_pnumber() {return (this->pnumber);} -std::string contact::get_secret() {return (this->secret);} - -int contact::set_name(std::string _name) { - if (_name.empty()){ - std::cout << " Input is cant be empty. "; return (0);} - this->name = _name; - return (1); -} -void contact::set_lastname(std::string _lastname) {this->lastname = _lastname;} -void contact::set_nickname(std::string _nickname) {this->nickname = _nickname;} -void contact::set_pnumber(std::string _pnumber) {this->pnumber = _pnumber;} -void contact::set_secret(std::string _secret) {this->secret = _secret;} \ No newline at end of file diff --git a/cpp00/ex_01/PhoneBook.hpp b/cpp00/ex_01/PhoneBook.hpp deleted file mode 100644 index 2bc8fcf..0000000 --- a/cpp00/ex_01/PhoneBook.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef PHONEBOOK_CPP -#define PHONEBOOK_CPP - -#include -#include -#include - -//CLASS - -class contact { -public: - //name - std::string get_name(); - int set_name(std::string); - //surname - void set_lastname(std::string); - std::string get_lastname(); - //nickname - std::string get_nickname(); - void set_nickname(std::string); - //p_number - std::string get_pnumber(); - void set_pnumber(std::string); - //secret - std::string get_secret(); - void set_secret(std::string); -private: - std::string name; - std::string lastname; - std::string nickname; - std::string pnumber; - std::string secret; -}; - -class phonebook { -public: - int add(); - int search(); - - contact cnt[8]; - int idx; -}; - -// FUNCTION - -int take_input(); - -#endif \ No newline at end of file diff --git a/cpp00/ex_01/main.cpp b/cpp00/ex_01/main.cpp deleted file mode 100644 index d336f31..0000000 --- a/cpp00/ex_01/main.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "PhoneBook.hpp" - -phonebook book; -int main(void) { - std::string input; - while (true) { -a: - std::cout << std::endl - << "+-------------------------------------------------------+" << std::endl - << "| 1 : Add | 2 : Search | 3 : Exit | Maybe More |" << std::endl - << "+-------------------------------------------------------+" << std::endl; - switch (take_input()) - { - case -1: - goto a; - case 1: - book.add(); - goto a; - case 2: - book.search(); - break; - case 3: - exit(3); - case 31: - std::cout << "RICKROLLED"; - goto a; - default: - goto a; - break; - } - } - return (0); -} diff --git a/cpp00/ex_02/Account.cpp b/cpp00/ex_02/Account.cpp deleted file mode 100644 index 24f0fea..0000000 --- a/cpp00/ex_02/Account.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "Account.hpp" - - -int Account::_nbAccounts = 0; -int Account::_totalAmount = 0; -int Account::_totalNbDeposits = 0; -int Account::_totalNbWithdrawals = 0; - -int Account::getNbAccounts() {return _nbAccounts;} -int Account::getTotalAmount() {return _totalAmount;} -int Account::getNbDeposits() {return _totalNbDeposits;} -int Account::getNbWithdrawals() {return _totalNbWithdrawals;} - -int Account::checkAmount(void) const {return _amount;} - -void Account::_displayTimestamp(void) -{ - time_t now; - - now = time(NULL); - std::cout << std::put_time(localtime(&now), "[%Y%m%d_%H%M%S] "); -} - -Account::Account(int init_deposit) { - _displayTimestamp(); - this->_accountIndex = this->_nbAccounts; - this->_nbAccounts++; - this->_totalAmount += init_deposit; - this->_amount = init_deposit; - std::cout << " index:" << this->_accountIndex << ";amount:" << this->_amount << ";created" << std::endl; -} -Account::~Account() { - _displayTimestamp(); - std::cout << " index:" << this->_accountIndex << ";amount:" << this->_amount << ";closed" << std::endl; -} - -void Account::makeDeposit(int deposit) { - this->_totalAmount += deposit; - this->_totalNbDeposits++; - this->_nbDeposits++; - _displayTimestamp(); - std::cout << " index:" << this->_accountIndex << ";p_amount:" << this->_amount << ";deposit:" << deposit << ";amount:"; - this->_amount += deposit; - std::cout << this->_amount << ";nb_deposits:" << this->_nbDeposits << std::endl; -} -bool Account::makeWithdrawal(int withdraw) { - _displayTimestamp(); - std::cout << " index:" << this->_accountIndex << ";p_amount:" << this->_amount; - if (this->_amount - withdraw > 0) { - this->_amount -= withdraw; - this->_totalAmount -= withdraw; - this->_totalNbWithdrawals++; this->_nbWithdrawals++; - std::cout << ";withdrawal:" << withdraw << ";amount:" << this->_amount << ";nb_withdrawals:" << this->_nbWithdrawals << std::endl; - return true; - } else { - std::cout << ";withdrawal:refused" << std::endl; - return false; - } -} -void Account::displayStatus(void) const { - _displayTimestamp(); - std::cout << " accounts:" << _accountIndex << ";total:" << _amount - << ";deposits:" << _nbDeposits << ";withdrawals:" << _nbWithdrawals - << std::endl; -} -void Account::displayAccountsInfos(void) { - _displayTimestamp(); - std::cout << " accounts:" << _nbAccounts << ";total:" << _totalAmount - << ";deposits:" << _totalNbDeposits << ";withdrawals:" << _totalNbWithdrawals - << std::endl; -} diff --git a/cpp00/ex_02/Account.hpp b/cpp00/ex_02/Account.hpp deleted file mode 100644 index c8c9a04..0000000 --- a/cpp00/ex_02/Account.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// ************************************************************************** // -// // -// Account.hpp for GlobalBanksters United // -// Created on : Thu Nov 20 19:43:15 1989 // -// Last update : Wed Jan 04 14:54:06 1992 // -// Made by : Brad "Buddy" McLane // -// // -// ************************************************************************** // - - -#pragma once -#ifndef __ACCOUNT_H__ -#define __ACCOUNT_H__ - -#include -#include -#include -#include -#include -#include - -// ************************************************************************** // -// Account Class // -// ************************************************************************** // - -class Account { -public: - - typedef Account t; - - static int getNbAccounts(void); - static int getTotalAmount(void); - static int getNbDeposits(void); - static int getNbWithdrawals(void); - static void displayAccountsInfos(void); - - Account( int initial_deposit ); - ~Account( void ); - - void makeDeposit( int deposit ); - bool makeWithdrawal( int withdrawal ); - int checkAmount( void ) const; - void displayStatus( void ) const; - - -private: - - static int _nbAccounts; - static int _totalAmount; - static int _totalNbDeposits; - static int _totalNbWithdrawals; - - static void _displayTimestamp( void ); - - int _accountIndex; - int _amount; - int _nbDeposits; - int _nbWithdrawals; - - Account( void ); - -}; - - - -// ************************************************************************** // -// vim: set ts=4 sw=4 tw=80 noexpandtab: // -// -*- indent-tabs-mode:t; -*- -// -*- mode: c++-mode; -*- -// -*- fill-column: 75; comment-column: 75; -*- -// ************************************************************************** // - - -#endif /* __ACCOUNT_H__ */ \ No newline at end of file diff --git a/cpp00/ex_02/tests.cpp b/cpp00/ex_02/tests.cpp deleted file mode 100644 index 816987a..0000000 --- a/cpp00/ex_02/tests.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// ************************************************************************** // -// // -// tests.cpp for GlobalBanksters United // -// Created on : Thu Nov 20 23:45:02 1989 // -// Last update : Wed Jan 04 09:23:52 1992 // -// Made by : Brad "Buddy" McLane // -// // -// ************************************************************************** // - -#include -#include -#include -#include "Account.hpp" - - -int main( void ) { - - typedef std::vector accounts_t; - typedef std::vector ints_t; - typedef std::pair acc_int_t; - - int const amounts[] = { 42, 54, 957, 432, 1234, 0, 754, 16576 }; - size_t const amounts_size( sizeof(amounts) / sizeof(int) ); - accounts_t accounts( amounts, amounts + amounts_size ); - accounts_t::iterator acc_begin = accounts.begin(); - accounts_t::iterator acc_end = accounts.end(); - - int const d[] = { 5, 765, 564, 2, 87, 23, 9, 20 }; - size_t const d_size( sizeof(d) / sizeof(int) ); - ints_t deposits( d, d + d_size ); - ints_t::iterator dep_begin = deposits.begin(); - ints_t::iterator dep_end = deposits.end(); - - int const w[] = { 321, 34, 657, 4, 76, 275, 657, 7654 }; - size_t const w_size( sizeof(w) / sizeof(int) ); - ints_t withdrawals( w, w + w_size ); - ints_t::iterator wit_begin = withdrawals.begin(); - ints_t::iterator wit_end = withdrawals.end(); - - Account::displayAccountsInfos(); - std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) ); - - for ( acc_int_t it( acc_begin, dep_begin ); - it.first != acc_end && it.second != dep_end; - ++(it.first), ++(it.second) ) { - - (*(it.first)).makeDeposit( *(it.second) ); - } - - Account::displayAccountsInfos(); - std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) ); - - for ( acc_int_t it( acc_begin, wit_begin ); - it.first != acc_end && it.second != wit_end; - ++(it.first), ++(it.second) ) { - - (*(it.first)).makeWithdrawal( *(it.second) ); - } - - Account::displayAccountsInfos(); - std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) ); - - return 0; -} - - -// ************************************************************************** // -// vim: set ts=4 sw=4 tw=80 noexpandtab: // -// -*- indent-tabs-mode:t; -*- -// -*- mode: c++-mode; -*- -// -*- fill-column: 75; comment-column: 75; -*- -// ************************************************************************** // \ No newline at end of file diff --git a/cpp01/ex00/Makefile b/cpp01/ex00/Makefile deleted file mode 100644 index 9dc5503..0000000 --- a/cpp01/ex00/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = zombie0 -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp01/ex00/Zombie.cpp b/cpp01/ex00/Zombie.cpp deleted file mode 100644 index f2c0c3f..0000000 --- a/cpp01/ex00/Zombie.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "Zombie.hpp" - -void zombie::announce (void) { - std::cout << this->get_name() << ": BraiiiiiiinnnzzzZ..." << std::endl; -} - -std::string zombie::get_name(void) { - return(this->Name); -} - -void zombie::set_name(std::string _name) { - this->Name = _name; -} - -zombie::zombie() {} - -zombie::zombie(std::string _Name) { - set_name(_Name); -} - -zombie::~zombie() {} \ No newline at end of file diff --git a/cpp01/ex00/Zombie.hpp b/cpp01/ex00/Zombie.hpp deleted file mode 100644 index d4b4c3e..0000000 --- a/cpp01/ex00/Zombie.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include -#include - -class zombie { - public: - void announce( void ); - void set_name(std::string); - std::string get_name(void); - zombie(); - zombie(std::string _Name); - ~zombie(); - - private: - std::string Name; -}; - - zombie* newZombie( std::string name ); - void randomChump( std::string name ); - diff --git a/cpp01/ex00/main.cpp b/cpp01/ex00/main.cpp deleted file mode 100644 index 7b9a2c8..0000000 --- a/cpp01/ex00/main.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "Zombie.hpp" - -void runZombie(void) -{ - zombie asd("Crazy"); - asd.announce(); - zombie* foo = newZombie("Foo"); - randomChump("Flash"); - delete foo; -} - -int main() -{ - runZombie(); -} \ No newline at end of file diff --git a/cpp01/ex00/newZombie.cpp b/cpp01/ex00/newZombie.cpp deleted file mode 100644 index d781a86..0000000 --- a/cpp01/ex00/newZombie.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "Zombie.hpp" - -zombie* newZombie( std::string name ) -{ - zombie* nzombie = new zombie(name); - nzombie->announce(); - return(nzombie); -} \ No newline at end of file diff --git a/cpp01/ex00/randomChump.cpp b/cpp01/ex00/randomChump.cpp deleted file mode 100644 index 94f9394..0000000 --- a/cpp01/ex00/randomChump.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "Zombie.hpp" - -void randomChump( std::string name ) -{ - zombie random(name); - random.announce(); -} \ No newline at end of file diff --git a/cpp01/ex01/Makefile b/cpp01/ex01/Makefile deleted file mode 100644 index aee3f65..0000000 --- a/cpp01/ex01/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = zombie1 -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp01/ex01/Zombie.cpp b/cpp01/ex01/Zombie.cpp deleted file mode 100644 index f5200da..0000000 --- a/cpp01/ex01/Zombie.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Zombie.hpp" - -void zombie::announce(void) const { - std::cout << this->Name << ": BraiiiiiiinnnzzzZ..." << std::endl; -} - -zombie::zombie(){}; - -zombie::zombie(std::string name) : Name(name) {} \ No newline at end of file diff --git a/cpp01/ex01/Zombie.hpp b/cpp01/ex01/Zombie.hpp deleted file mode 100644 index f9e98e0..0000000 --- a/cpp01/ex01/Zombie.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include - -class zombie { - public: - zombie(); - zombie(std::string name); - void announce( void ) const; - - private: - mutable std::string Name; -}; - - void start_horde(void); - zombie* zombieHorde( int N, std::string name ); \ No newline at end of file diff --git a/cpp01/ex01/main.cpp b/cpp01/ex01/main.cpp deleted file mode 100644 index d5ac0b4..0000000 --- a/cpp01/ex01/main.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "Zombie.hpp" - -void start_horde(void) -{ - int N = 5; - std::string name = "ZombieHorde"; - zombie* horde = zombieHorde(N, name); - for (int i = 0; i < N; i++) { - horde[i].announce(); - } - delete[] horde; -} - -int main() -{ - start_horde(); -} \ No newline at end of file diff --git a/cpp01/ex01/zombie1 b/cpp01/ex01/zombie1 deleted file mode 100755 index 27f19da..0000000 Binary files a/cpp01/ex01/zombie1 and /dev/null differ diff --git a/cpp01/ex01/zombieHorde.cpp b/cpp01/ex01/zombieHorde.cpp deleted file mode 100644 index 8d7b28d..0000000 --- a/cpp01/ex01/zombieHorde.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Zombie.hpp" - -zombie* zombieHorde(int N, std::string name) -{ - zombie* horde = new zombie[N]; - for (int i = 0; i < N; i++){ - new(&horde[i]) zombie(name); - } - return horde; -} \ No newline at end of file diff --git a/cpp01/ex02/Makefile b/cpp01/ex02/Makefile deleted file mode 100644 index d812322..0000000 --- a/cpp01/ex02/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = zombie2 -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp01/ex02/main.cpp b/cpp01/ex02/main.cpp deleted file mode 100644 index 6b243d5..0000000 --- a/cpp01/ex02/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int main(void) { - std::string brain = "HI THIS IS BRAIN"; - std::string *stringPTR = &brain; - std::string &stringREF = brain; - - std::cout << "Str memory adress: " << &brain << "\nstringPTR memory adress: " << &stringPTR << "\nstringREF memory adress: " << &stringREF << std::endl; - std::cout << "\nStr: " << brain << "\nstringPTR: " << *stringPTR << "\nstringREF: " << stringREF << std::endl; -} \ No newline at end of file diff --git a/cpp01/ex02/zombie2 b/cpp01/ex02/zombie2 deleted file mode 100755 index 2df87cc..0000000 Binary files a/cpp01/ex02/zombie2 and /dev/null differ diff --git a/cpp01/ex03/Makefile b/cpp01/ex03/Makefile deleted file mode 100644 index d812322..0000000 --- a/cpp01/ex03/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = zombie2 -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp01/ex03/humanA.cpp b/cpp01/ex03/humanA.cpp deleted file mode 100644 index 3706afd..0000000 --- a/cpp01/ex03/humanA.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "humanA.hpp" - -humanA::humanA(std::string name, weapon& weapon): _name(name), _weapon(weapon) {} -humanA::~humanA() {} - -void humanA::attack(void) const { - std::cout << this->_name << " attacks with their " << this->_weapon.getType() << std::endl; -} diff --git a/cpp01/ex03/humanA.hpp b/cpp01/ex03/humanA.hpp deleted file mode 100644 index 9cf7fe4..0000000 --- a/cpp01/ex03/humanA.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "weapon.hpp" - -class humanA { -public: - std::string _name; - weapon& _weapon; - humanA(std::string name, weapon& weapon); - ~humanA(); - void attack(void) const; -}; \ No newline at end of file diff --git a/cpp01/ex03/humanB.cpp b/cpp01/ex03/humanB.cpp deleted file mode 100644 index ab811e4..0000000 --- a/cpp01/ex03/humanB.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "humanB.hpp" - -humanB::humanB(std::string name): _name(name) {} -humanB::~humanB() {} - -void humanB::attack(void) const { - std::cout << this->_name << " attacks with their " << this->_weapon->getType() << std::endl; -} - -void humanB::setWeapon(weapon& weapon) { - this->_weapon = &weapon; -} \ No newline at end of file diff --git a/cpp01/ex03/humanB.hpp b/cpp01/ex03/humanB.hpp deleted file mode 100644 index 2f7406b..0000000 --- a/cpp01/ex03/humanB.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "weapon.hpp" - -class humanB { -public: - std::string _name; - weapon* _weapon; - humanB(std::string name); - ~humanB(); - void setWeapon(weapon& weapon); - void attack(void) const; -}; \ No newline at end of file diff --git a/cpp01/ex03/main.cpp b/cpp01/ex03/main.cpp deleted file mode 100644 index 1c8af45..0000000 --- a/cpp01/ex03/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "humanA.hpp" -#include "humanB.hpp" - -void runWar(void) -{ - { - weapon m4 = weapon("m4"); - humanA bob("Officer Bob", m4); - bob.attack(); - m4.setType("modified m4"); - bob.attack(); - } - { - weapon glock19 = weapon("glock19"); - humanB jamal("OG Jamal"); - jamal.setWeapon(glock19); - jamal.attack(); - glock19.setType("Gold glock19"); - jamal.attack(); - } -} - -int main(void) { - runWar(); -} \ No newline at end of file diff --git a/cpp01/ex03/weapon.cpp b/cpp01/ex03/weapon.cpp deleted file mode 100644 index 0e17a4a..0000000 --- a/cpp01/ex03/weapon.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "weapon.hpp" - -weapon::weapon(std::string type): _type(type) {} -weapon::~weapon(void) {} - -std::string weapon::getType(void) const {return this->_type;} - -void weapon::setType(std::string type) {this->_type = type;} diff --git a/cpp01/ex03/weapon.hpp b/cpp01/ex03/weapon.hpp deleted file mode 100644 index 88ea9dc..0000000 --- a/cpp01/ex03/weapon.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include - -class weapon { -private: - std::string _type; -public: - weapon(std::string type); - ~weapon(); - std::string getType(void) const; - void setType(std::string type); -}; \ No newline at end of file diff --git a/cpp01/ex03/zombie2 b/cpp01/ex03/zombie2 deleted file mode 100755 index 42d94b3..0000000 Binary files a/cpp01/ex03/zombie2 and /dev/null differ diff --git a/cpp01/ex04/Makefile b/cpp01/ex04/Makefile deleted file mode 100644 index 019f23e..0000000 --- a/cpp01/ex04/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = replace -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp01/ex04/main.cpp b/cpp01/ex04/main.cpp deleted file mode 100644 index 5909caf..0000000 --- a/cpp01/ex04/main.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "replace.hpp" - -int main(int ac, char **av) { - if (ac == 4) { - std::string filename(av[1]), s1(av[2]), s2(av[3]), line, buff; - std::ifstream file(filename); - filename.append(".replace"); - std::ofstream donut(filename, std::fstream::out | std::fstream::trunc); - if (file.is_open()) { - while (getline(file, buff)) { - donut << replace(buff, s1, s2) << std::endl; - } - file.close(); - } - donut.close(); - } else { - std::cout << "wrong arguement" << std::endl; - } -} diff --git a/cpp01/ex04/replace b/cpp01/ex04/replace deleted file mode 100755 index 71a63ef..0000000 Binary files a/cpp01/ex04/replace and /dev/null differ diff --git a/cpp01/ex04/replace.hpp b/cpp01/ex04/replace.hpp deleted file mode 100644 index 47ee751..0000000 --- a/cpp01/ex04/replace.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include -#include -#include - -std::string replace(std::string line, std::string s1, std::string s2); diff --git a/cpp01/ex04/test b/cpp01/ex04/test deleted file mode 100644 index 75e59b7..0000000 --- a/cpp01/ex04/test +++ /dev/null @@ -1 +0,0 @@ -gsadjhfkgjdfsgkhdfsaghjkaaaaaaa diff --git a/cpp01/ex04/test.replace b/cpp01/ex04/test.replace deleted file mode 100644 index 47a9f24..0000000 --- a/cpp01/ex04/test.replace +++ /dev/null @@ -1 +0,0 @@ -gsbndjhfkgjdfsgkhdfsbnghjkbnbnbnbnbnbnbn diff --git a/cpp01/ex04/utils.cpp b/cpp01/ex04/utils.cpp deleted file mode 100644 index 4541c63..0000000 --- a/cpp01/ex04/utils.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "replace.hpp" - -std::string replace(std::string line, std::string s1, std::string s2) { - size_t pos = 0; - while ((pos = line.find(s1, pos)) != std::string::npos) { - line.erase(pos, s1.length()); - line.insert(pos, s2); - pos += s2.length(); - } - return line; -} \ No newline at end of file diff --git a/cpp01/ex05/Harl b/cpp01/ex05/Harl deleted file mode 100755 index 7700c2b..0000000 Binary files a/cpp01/ex05/Harl and /dev/null differ diff --git a/cpp01/ex05/Makefile b/cpp01/ex05/Makefile deleted file mode 100644 index 773af62..0000000 --- a/cpp01/ex05/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = Harl -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp01/ex05/harl.cpp b/cpp01/ex05/harl.cpp deleted file mode 100644 index 31a4a45..0000000 --- a/cpp01/ex05/harl.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "harl.hpp" - -void harl::complain(std::string level) -{ - harl b; - void (harl::*function[4])(void) = - { - &harl::debug, - &harl::info, - &harl::warning, - &harl::error - }; - std::string a[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; - int i = 0; - for (; level.compare(a[i]) && i < 4; i++) - { - } - return ((i == 4) ? (void)(NULL) : (b.*function[i])()); -} - -void harl::debug (void) -{ - std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!" << std::endl; -} -void harl::info (void) -{ - std::cout << "I cannot believe adding extra bacon costs more money. You didn’t put enough bacon in my burger! If you did, I wouldn’t be asking for more!" << std::endl; -} -void harl::warning (void) -{ - std::cout << "I think I deserve to have some extra bacon for free. I’ve been coming for years whereas you started working here since last month." << std::endl; -} -void harl::error (void) -{ - std::cout << "This is unacceptable! I want to speak to the manager now." << std::endl; -} diff --git a/cpp01/ex05/harl.hpp b/cpp01/ex05/harl.hpp deleted file mode 100644 index 3b08f74..0000000 --- a/cpp01/ex05/harl.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include -#include - -class harl { -public: - std::string _level; - void complain(std::string level); -private: - void debug(void); - void info(void); - void warning(void); - void error(void); -}; \ No newline at end of file diff --git a/cpp01/ex05/main.cpp b/cpp01/ex05/main.cpp deleted file mode 100644 index bce98e9..0000000 --- a/cpp01/ex05/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "harl.hpp" - -int main(int ac,char** av) -{ - if(ac == 2) - { - harl True; - std::string level(av[1]); - True.complain(level); - } - return(0); -} \ No newline at end of file diff --git a/cpp01/ex06/Harl b/cpp01/ex06/Harl deleted file mode 100755 index 413bf7c..0000000 Binary files a/cpp01/ex06/Harl and /dev/null differ diff --git a/cpp01/ex06/Makefile b/cpp01/ex06/Makefile deleted file mode 100644 index 773af62..0000000 --- a/cpp01/ex06/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = Harl -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp01/ex06/harl.cpp b/cpp01/ex06/harl.cpp deleted file mode 100644 index 3d12719..0000000 --- a/cpp01/ex06/harl.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "harl.hpp" - -void harl::complain(std::string level) { - this->_level = level; - switch (level.at(0)) - { - case 'd': - std::cout << "[debug]" << std::endl; - this->debug(); - case 'i': - std::cout << "[info]" << std::endl; - this->info(); - case 'w': - std::cout << "[warning]" << std::endl; - this->warning(); - case 'e': - std::cout << "[error]" << std::endl; - this->error(); - break; - default: - std::cout << "wrong input"; - break; - } - -} - -void harl::debug(void) { - - std::cout << "7XL-çift peynirli-üçlü turşu-özel-ketçaplı burgerime fazladan domuz pastırması yemeyi seviyorum. Gerçekten seviyorum!" << std::endl; -} - -void harl::info(void) { - std::cout << "Ekstra domuz pastırması eklemenin daha fazla paraya mal olduğuna inanamıyorum. Burgerime yeterince pastırma koymadınız! Yapsaydınız, daha fazlasını istemezdim!" << std::endl; -} - -void harl::warning(void) { - std::cout << "Bence bedavaya fazladan pastırma yemeyi hak ediyorum. Ben yıllardır geliyorum, sen geçen aydan beri burada çalışmaya başladın.!" << std::endl; -} - -void harl::error(void) { - std::cout << "Bu kabul edilemez! Şimdi müdürle konuşmak istiyorum." << std::endl; -} \ No newline at end of file diff --git a/cpp01/ex06/harl.hpp b/cpp01/ex06/harl.hpp deleted file mode 100644 index 3b08f74..0000000 --- a/cpp01/ex06/harl.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include -#include - -class harl { -public: - std::string _level; - void complain(std::string level); -private: - void debug(void); - void info(void); - void warning(void); - void error(void); -}; \ No newline at end of file diff --git a/cpp01/ex06/main.cpp b/cpp01/ex06/main.cpp deleted file mode 100644 index b0b0ca7..0000000 --- a/cpp01/ex06/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "harl.hpp" - -int main(int ac, char **av) { - if (ac == 2) { - std::string level(av[1]); - harl check; - check.complain(level); - } -} \ No newline at end of file diff --git a/cpp02/ex00/Makefile b/cpp02/ex00/Makefile deleted file mode 100644 index dd76f36..0000000 --- a/cpp02/ex00/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -NAME = fixed -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all diff --git a/cpp02/ex00/fixed b/cpp02/ex00/fixed deleted file mode 100755 index 4a95d09..0000000 Binary files a/cpp02/ex00/fixed and /dev/null differ diff --git a/cpp02/ex00/fixed.cpp b/cpp02/ex00/fixed.cpp deleted file mode 100644 index 191556f..0000000 --- a/cpp02/ex00/fixed.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "fixed.hpp" - -fixed::fixed() { - this->raw_bits = 0; - std::cout << "default constructer called" << std::endl; -} - -fixed::fixed(fixed ©) { - std::cout << "copy constructer called" << std::endl; - this->raw_bits = copy.getRawBits(); -} - -fixed& fixed::operator=(const fixed& c) { - std::cout << "copy assignment operator called" << std::endl; - this->raw_bits = c.getRawBits(); - return *this; -} - -fixed::~fixed() { - std::cout << "deconstructer called" << std::endl; -} - -int fixed::getRawBits(void) const { - std::cout << "getRawBits member func called" << std::endl; - return raw_bits; -} - -void fixed::setRawBits(int const raw) { - std::cout << "setRawBits member func called" << std::endl; - this->raw_bits = raw; -} diff --git a/cpp02/ex00/fixed.hpp b/cpp02/ex00/fixed.hpp deleted file mode 100644 index 04d32f3..0000000 --- a/cpp02/ex00/fixed.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include -#include -#include - -class fixed { -private: - int raw_bits; - static const int fractional = 8; -public: - fixed(); - fixed(fixed ©); - fixed& operator=(const fixed& copy); - ~fixed(); - int getRawBits(void) const; - void setRawBits(int const raw); -}; diff --git a/cpp02/ex00/main.cpp b/cpp02/ex00/main.cpp deleted file mode 100644 index 4b63bed..0000000 --- a/cpp02/ex00/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "fixed.hpp" - -int main(int argc, char **argv) { - fixed a; - fixed b( a ); - fixed c; - c = b; - std::cout << a.getRawBits() << std::endl; - std::cout << b.getRawBits() << std::endl; - std::cout << c.getRawBits() << std::endl; - return 0; -} diff --git a/cpp02/ex01/Makefile b/cpp02/ex01/Makefile deleted file mode 100644 index dd76f36..0000000 --- a/cpp02/ex01/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -NAME = fixed -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all diff --git a/cpp02/ex01/fixed b/cpp02/ex01/fixed deleted file mode 100755 index 8828e76..0000000 Binary files a/cpp02/ex01/fixed and /dev/null differ diff --git a/cpp02/ex01/fixed.cpp b/cpp02/ex01/fixed.cpp deleted file mode 100644 index eca04ef..0000000 --- a/cpp02/ex01/fixed.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "fixed.hpp" - -fixed::fixed() { - std::cout << "default constructer called" << std::endl; - this->setRawBits(0); -} - -fixed::fixed(const int raw) { - std::cout << "Int constructor called" << std::endl; - this->setRawBits(raw << this->fractional); -} - -fixed::fixed(const float raw) { - std::cout << "float consturcter called" << std::endl; - this->setRawBits(std::roundf(raw * (1 << this->fractional))); -} - -fixed::fixed(fixed const ©) { - std::cout << "copy constructer called" << std::endl; - *this = copy; -} - -fixed& fixed::operator=(const fixed& c) { - std::cout << "copy assignment operator called" << std::endl; - this->setRawBits(c.getRawBits()); - return *this; -} - -std::ostream& operator<<(std::ostream &out, const fixed ©) { - out << (copy.getRawBits() / pow(2, 8)); - return out; -} - -fixed::~fixed() { - std::cout << "deconstructer called" << std::endl; -} - -int fixed::getRawBits(void) const { - return raw_bits; -} - -void fixed::setRawBits(int const raw) { - this->raw_bits = raw; -} - -int fixed::toInt(void) const { - int temp = this->getRawBits() / (1 << this->fractional); - return temp; -} - -float fixed::toFloat(void) const { - float temp = this->getRawBits() * (1 << this->fractional); - return temp; -} \ No newline at end of file diff --git a/cpp02/ex01/fixed.hpp b/cpp02/ex01/fixed.hpp deleted file mode 100644 index 98b66da..0000000 --- a/cpp02/ex01/fixed.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -class fixed { -private: - int raw_bits; - static const int fractional = 8; -public: - fixed(); - fixed(const int raw); - fixed(const float raw); - fixed(fixed const ©); - ~fixed(); - fixed& operator=(const fixed&); - int getRawBits(void) const; - void setRawBits(int const raw); - int toInt(void) const ; - float toFloat(void) const; -}; - -std::ostream& operator<<(std::ostream &out, const fixed ©); diff --git a/cpp02/ex01/main.cpp b/cpp02/ex01/main.cpp deleted file mode 100644 index 170a8aa..0000000 --- a/cpp02/ex01/main.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "fixed.hpp" - -int main(int argc, char **argv) { - fixed a; - fixed const b(10); - fixed const c(42.42f); - fixed const d(b); - a = fixed(1234.4321f); - std::cout << "a is " << a << std::endl; - std::cout << "b is " << b << std::endl; - std::cout << "c is " << c << std::endl; - std::cout << "d is " << d << std::endl; - std::cout << "a is " << a.toInt() << " as integer" << std::endl; - std::cout << "b is " << b.toInt() << " as integer" << std::endl; - std::cout << "c is " << c.toInt() << " as integer" << std::endl; - std::cout << "d is " << d.toInt() << " as integer" << std::endl; - return 0; -} diff --git a/cpp02/ex02/Makefile b/cpp02/ex02/Makefile deleted file mode 100644 index 2283953..0000000 --- a/cpp02/ex02/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -NAME = fixed -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -all: $(OBJECT) - @$(CC) $(FLAG) $(OBJECT) -o $(NAME) - @$(MAKE) clean - -clean: - @rm -rf $(OBJECT) - -fclean: clean - @rm -rf $(NAME) - -re: fclean all diff --git a/cpp02/ex02/fixed b/cpp02/ex02/fixed deleted file mode 100755 index 0893e5f..0000000 Binary files a/cpp02/ex02/fixed and /dev/null differ diff --git a/cpp02/ex02/fixed.cpp b/cpp02/ex02/fixed.cpp deleted file mode 100644 index 069ca0e..0000000 --- a/cpp02/ex02/fixed.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "fixed.hpp" - -fixed::fixed() : raw_bits(0) -{} - -fixed::fixed(const fixed& copy) : raw_bits(copy.getRawBits()) -{} - -fixed::fixed(const int nbr) : raw_bits(nbr << fractional) -{} - -fixed::fixed(const float nbr) : raw_bits(roundf(nbr * (1 << fractional))) -{} - -fixed& fixed::operator=(const fixed& nbr){ - if(this != &nbr) - raw_bits = nbr.getRawBits(); - return(*this); -} - -fixed::~fixed() -{} - -//gettr settr -int fixed::getRawBits(void) const {return(this->raw_bits);} -void fixed::setRawBits(int const nbr){this->raw_bits = nbr;} - -//toint tofloat -float fixed::toFloat(void) const -{return((float)getRawBits() / (1 << fractional));} - -int fixed::toInt() const -{return (getRawBits() >> fractional);} - -std::ostream & operator<<(std::ostream &o, const fixed &f) -{ - o << f.toFloat(); - return o; -} - -//comparison operators -bool fixed::operator>(const fixed &n) const -{return(this->raw_bits > n.getRawBits());} - -bool fixed::operator<(const fixed &n) const -{return(this->raw_bits < n.getRawBits());} - -bool fixed::operator>=(const fixed &n) const -{return(this->raw_bits >= n.getRawBits());} - -bool fixed::operator<=(const fixed &n) const -{return(this->raw_bits <= n.getRawBits());} - -bool fixed::operator==(const fixed& n) const -{return(this->raw_bits == n.getRawBits());} - -bool fixed::operator!=(const fixed& n) const -{return(this->raw_bits != n.getRawBits());} - -//arithmetic operators -fixed fixed::operator+(const fixed& n) const -{return(fixed(this->toFloat() + n.toFloat()));} - -fixed fixed::operator-(const fixed& n) const -{return(fixed(this->toFloat() - n.toFloat()));} - -fixed fixed::operator*(const fixed& n) const -{return(fixed(this->toFloat() * n.toFloat()));} - -fixed fixed::operator/(const fixed& n) const -{return(fixed(this->toFloat() / n.toFloat()));} - -//min max -const fixed& fixed::min(const fixed &a, const fixed &b) -{ - return(a.getRawBits() < b.getRawBits()) ? a : b; -} - -const fixed& fixed::max(const fixed &a, const fixed &b) -{ - return(a.getRawBits() > b.getRawBits()) ? a : b; -} -//++ -- -fixed &fixed::operator++(void) -{ - this->raw_bits++; - return(*this); -} -//++a -fixed fixed::operator++(int) -{ - fixed a(this->toFloat()); - this->raw_bits++; - return(a); -} -//a++ -fixed &fixed::operator--(void) -{ - this->raw_bits--; - return(*this); -} - -fixed fixed::operator--(int) -{ - fixed a(this->toFloat()); - this->raw_bits--; - return(a); -} \ No newline at end of file diff --git a/cpp02/ex02/fixed.hpp b/cpp02/ex02/fixed.hpp deleted file mode 100644 index d5771c4..0000000 --- a/cpp02/ex02/fixed.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -class fixed { -private: - int raw_bits; - static const int fractional = 8; -public: - fixed(); - fixed(const fixed&); - fixed(const int); - fixed(const float); - ~fixed(); - - //comparison operators - bool operator>(const fixed&) const; - bool operator<(const fixed&) const; - bool operator>=(const fixed&) const; - bool operator<=(const fixed&) const; - bool operator==(const fixed&) const; - bool operator!=(const fixed&) const; - - //arithmetic operators - fixed operator+(const fixed&) const; - fixed operator-(const fixed&)const; - fixed operator*(const fixed&)const; - fixed operator/(const fixed&)const; - - //assignment operator - fixed& operator=(const fixed&); - - //min max - static const fixed& min(const fixed &, const fixed &); - static const fixed& max(const fixed &, const fixed &); - - //++ -- - fixed &operator++(void); - fixed operator++(int); - fixed &operator--(void); - fixed operator--(int); - - - - - int getRawBits(void) const; - void setRawBits(int const); - - float toFloat(void) const; - int toInt(void) const; -}; - -std::ostream& operator<<(std::ostream &out, const fixed ©); diff --git a/cpp02/ex02/main.cpp b/cpp02/ex02/main.cpp deleted file mode 100644 index 7177fa8..0000000 --- a/cpp02/ex02/main.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "fixed.hpp" - -int main(int argc, char **argv) { - fixed a; - fixed const b( fixed( 5.05f ) * fixed( 2 ) ); - std::cout << a << std::endl; - std::cout << ++a << std::endl; - std::cout << a << std::endl; - std::cout << a++ << std::endl; - std::cout << a << std::endl; - std::cout << b << std::endl; - std::cout << fixed::max( a, b ) << std::endl; -return 0; -} diff --git a/cpp03/.DS_Store b/cpp03/.DS_Store deleted file mode 100644 index 3b6eb34..0000000 Binary files a/cpp03/.DS_Store and /dev/null differ diff --git a/cpp03/READMEcpp03.md b/cpp03/READMEcpp03.md deleted file mode 100644 index d1c0157..0000000 --- a/cpp03/READMEcpp03.md +++ /dev/null @@ -1,12 +0,0 @@ -# cpp-modules -c power point module - -public mode - - public become a public and protected a become protected - - public olanlar her yerden erisilebilir -protected mode - - public and protected become a protected - - kendi clasi ve derived claslardan erisilebilir -private mode - - public and protected become a private - - sadece kendi clasindan erisilebilirsss diff --git a/cpp03/en.cpp03subject.pdf b/cpp03/en.cpp03subject.pdf deleted file mode 100644 index 1c8043f..0000000 Binary files a/cpp03/en.cpp03subject.pdf and /dev/null differ diff --git a/cpp03/ex00/ClapTrap.cpp b/cpp03/ex00/ClapTrap.cpp deleted file mode 100644 index bb6eb85..0000000 --- a/cpp03/ex00/ClapTrap.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "ClapTrap.hpp" - -ClapTrap::ClapTrap(std::string _name): name(_name), hp(10), stamina(10), ad(0) { - std::cout << "ClapTrap asignment constructor called" << std::endl; -} - -ClapTrap::ClapTrap(): hp(10), stamina(10), ad(0), name("ClapTrap") { - std::cout << "ClapTrap default constructer called" << std::endl; -} - -ClapTrap::ClapTrap(ClapTrap& c) { - *this = c; - std::cout << "ClapTrap copy constructor called" << std::endl; -} - -ClapTrap& ClapTrap::operator=(ClapTrap& c) { - std::cout << "ClapTrap copy asignment operator called" << std::endl; - this->name = c.name; - this->hp = c.hp; - this->stamina = c.stamina; - this->ad = c.ad; - return *this; -} - -ClapTrap::~ClapTrap() { - std::cout << "ClapTrap deconstructor called" << std::endl; -} - -void ClapTrap::attack(const std::string& target) { - if (this->stamina > 0 && this->getHP() > 0) { - std::cout << this->getName() << " has given " << this->ad << " damage to " << target << std::endl; - this->stamina -= 1; - } -} - -void ClapTrap::takeDamage(unsigned int amount) { - if (this->stamina > 0 && this->getHP() > 0) { - std::cout << this->getName() << " was take " << amount << " damage" << std::endl; - this->hp -= amount; - this->stamina -= 1; - if (this->getHP() < 0) - std::cout << this->getName() << " is died" << std::endl; - } -} - -void ClapTrap::beRepaired(unsigned int amount) { - if (this->stamina > 0 && this->getHP() > 0) { - this->hp += amount; - std::cout << this->getName() << " is " << amount << " hp repaired" << std::endl; - this->stamina -= 1; - } -} - -std::string ClapTrap::getName(void) const {return this->name;} -int ClapTrap::getHP(void) const {return this->hp;} -int ClapTrap::getStamina(void) const {return this->stamina;} -int ClapTrap::getAD(void) const {return this->ad;} - -void ClapTrap::setName(std::string _name) {this->name = _name;} -void ClapTrap::setHP(int _hp) {this->hp = _hp;} -void ClapTrap::setStamina(int _stamina) {this->stamina = _stamina;} -void ClapTrap::setAD(int _ad) {this->ad = _ad;} - -std::ostream& operator<<(std::ostream& o, ClapTrap& c) { - o << "Name: " << c.getName() << " HP: " << c.getHP() << " Stamina: " << c.getStamina() << " AD: " << c.getAD(); - return o; -} diff --git a/cpp03/ex00/ClapTrap.hpp b/cpp03/ex00/ClapTrap.hpp deleted file mode 100644 index 188670a..0000000 --- a/cpp03/ex00/ClapTrap.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include -#include - -class ClapTrap { -private: - std::string name; - int hp; - int stamina; - int ad; -public: - ClapTrap(); - ClapTrap(std::string name); - ClapTrap(ClapTrap& c); - ~ClapTrap(); - - ClapTrap& operator=(ClapTrap& c); - - std::string getName(void) const ; - int getHP(void) const ; - int getStamina(void) const ; - int getAD(void) const ; - - void setName(std::string); - void setHP(int _hp); - void setStamina(int _stamina); - void setAD(int _ad); - - void attack(const std::string& target); - void takeDamage(unsigned int amount); - void beRepaired(unsigned int amount); -}; - -std::ostream& operator<<(std::ostream& o, ClapTrap& c); \ No newline at end of file diff --git a/cpp03/ex00/Makefile b/cpp03/ex00/Makefile deleted file mode 100644 index a1fac1c..0000000 --- a/cpp03/ex00/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = claptrap -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp03/ex00/main.cpp b/cpp03/ex00/main.cpp deleted file mode 100644 index 90c99f3..0000000 --- a/cpp03/ex00/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "ClapTrap.hpp" - -int main() { - ClapTrap n("clap"); - std::cout << n << std::endl; - n.attack("aaa"); - n.beRepaired(20); - n.takeDamage(4); - n.attack("bb"); -} diff --git a/cpp03/ex01/ClapTrap.cpp b/cpp03/ex01/ClapTrap.cpp deleted file mode 100644 index bb6eb85..0000000 --- a/cpp03/ex01/ClapTrap.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "ClapTrap.hpp" - -ClapTrap::ClapTrap(std::string _name): name(_name), hp(10), stamina(10), ad(0) { - std::cout << "ClapTrap asignment constructor called" << std::endl; -} - -ClapTrap::ClapTrap(): hp(10), stamina(10), ad(0), name("ClapTrap") { - std::cout << "ClapTrap default constructer called" << std::endl; -} - -ClapTrap::ClapTrap(ClapTrap& c) { - *this = c; - std::cout << "ClapTrap copy constructor called" << std::endl; -} - -ClapTrap& ClapTrap::operator=(ClapTrap& c) { - std::cout << "ClapTrap copy asignment operator called" << std::endl; - this->name = c.name; - this->hp = c.hp; - this->stamina = c.stamina; - this->ad = c.ad; - return *this; -} - -ClapTrap::~ClapTrap() { - std::cout << "ClapTrap deconstructor called" << std::endl; -} - -void ClapTrap::attack(const std::string& target) { - if (this->stamina > 0 && this->getHP() > 0) { - std::cout << this->getName() << " has given " << this->ad << " damage to " << target << std::endl; - this->stamina -= 1; - } -} - -void ClapTrap::takeDamage(unsigned int amount) { - if (this->stamina > 0 && this->getHP() > 0) { - std::cout << this->getName() << " was take " << amount << " damage" << std::endl; - this->hp -= amount; - this->stamina -= 1; - if (this->getHP() < 0) - std::cout << this->getName() << " is died" << std::endl; - } -} - -void ClapTrap::beRepaired(unsigned int amount) { - if (this->stamina > 0 && this->getHP() > 0) { - this->hp += amount; - std::cout << this->getName() << " is " << amount << " hp repaired" << std::endl; - this->stamina -= 1; - } -} - -std::string ClapTrap::getName(void) const {return this->name;} -int ClapTrap::getHP(void) const {return this->hp;} -int ClapTrap::getStamina(void) const {return this->stamina;} -int ClapTrap::getAD(void) const {return this->ad;} - -void ClapTrap::setName(std::string _name) {this->name = _name;} -void ClapTrap::setHP(int _hp) {this->hp = _hp;} -void ClapTrap::setStamina(int _stamina) {this->stamina = _stamina;} -void ClapTrap::setAD(int _ad) {this->ad = _ad;} - -std::ostream& operator<<(std::ostream& o, ClapTrap& c) { - o << "Name: " << c.getName() << " HP: " << c.getHP() << " Stamina: " << c.getStamina() << " AD: " << c.getAD(); - return o; -} diff --git a/cpp03/ex01/ClapTrap.hpp b/cpp03/ex01/ClapTrap.hpp deleted file mode 100644 index 8ce4040..0000000 --- a/cpp03/ex01/ClapTrap.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -class ClapTrap { -protected: - std::string name; - int hp; - int stamina; - int ad; -public: - ClapTrap(); - ClapTrap(std::string name); - ClapTrap(ClapTrap& c); - ~ClapTrap(); - - ClapTrap& operator=(ClapTrap& c); - - std::string getName(void) const ; - int getHP(void) const ; - int getStamina(void) const ; - int getAD(void) const ; - - void setName(std::string); - void setHP(int _hp); - void setStamina(int _stamina); - void setAD(int _ad); - - void attack(const std::string& target); - void takeDamage(unsigned int amount); - void beRepaired(unsigned int amount); -}; diff --git a/cpp03/ex01/Makefile b/cpp03/ex01/Makefile deleted file mode 100644 index 9090ae6..0000000 --- a/cpp03/ex01/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = scavtrap -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp03/ex01/ScavTrap.cpp b/cpp03/ex01/ScavTrap.cpp deleted file mode 100644 index 432b4c8..0000000 --- a/cpp03/ex01/ScavTrap.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "ScavTrap.hpp" - -ScavTrap::ScavTrap() { - std::cout << "ScavTrap default constructor" << std::endl; - this->setAD(30); - this->setHP(100); - this->setStamina(100); - this->setName("ScavTrap"); -} - -ScavTrap::ScavTrap(std::string _name) { - - std::cout << "ScavTrap assingment constructor called" << std::endl; - this->setAD(30); - this->setHP(100); - this->setName(_name); - this->setStamina(100); -} - -ScavTrap::ScavTrap(ScavTrap& copy) { - std::cout << "ScavTrap copy constructor called" << std::endl; - *this = copy; -} - -ScavTrap& ScavTrap::operator=(ScavTrap& copy) { - std::cout << "ScavTrap copy assingment operator called" << std::endl; - this->setAD(copy.getAD()); - this->setHP(copy.getHP()); - this->setName(copy.getName()); - this->setStamina(copy.getStamina()); - return *this; -} - -ScavTrap::~ScavTrap() { - std::cout << "ScavTrap deconstructor" << std::endl; -} - -void ScavTrap::guardGate() { - if (this->isGate == false) { - std::cout << "Not gating" << std::endl; - } else { - std::cout << "Gate Keeping Mode: Gating is so funny" << std::endl; - } -} - -void ScavTrap::attack(const std::string& target) { - if (this->getStamina() > 0 && this->getHP() > 0) { - std::cout << this->getName() << " locked the " << target - << " and given " << this->getAD() << " damage." << std::endl; - } -} - -std::ostream& operator<<(std::ostream& o, ScavTrap& c) { - o << "Name: " << c.getName() << " HP: " << c.getHP() << " Stamina: " << c.getStamina() << " AD: " << c.getAD(); - return o; -} diff --git a/cpp03/ex01/ScavTrap.hpp b/cpp03/ex01/ScavTrap.hpp deleted file mode 100644 index 8e42506..0000000 --- a/cpp03/ex01/ScavTrap.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "ClapTrap.hpp" - -class ScavTrap : public ClapTrap { -private: - bool isGate; -public: - ScavTrap(); - ScavTrap(std::string _name); - ScavTrap(ScavTrap& copy); - ScavTrap& operator=(ScavTrap& copy); - ~ScavTrap(); - - void guardGate(); - void attack(const std::string& target); -}; - -std::ostream& operator<<(std::ostream& o, ScavTrap& c); diff --git a/cpp03/ex01/main.cpp b/cpp03/ex01/main.cpp deleted file mode 100644 index ed48d45..0000000 --- a/cpp03/ex01/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "ScavTrap.hpp" - -int main() { - { - ScavTrap n("clap"); - std::cout << n << std::endl; - n.attack("aaa"); - n.beRepaired(20); - n.takeDamage(4); - n.attack("bb"); - } - { - std::cout << std::endl << "ScavTrap" << std::endl << std::endl; - ScavTrap a; - ScavTrap b("eyubi"); - ScavTrap c(b); - std::cout << c << std::endl; - a.attack("ClapTrap"); - b.attack("emircan"); - b.takeDamage(39); - b.guardGate(); - } -} diff --git a/cpp03/ex01/scavtrap b/cpp03/ex01/scavtrap deleted file mode 100755 index f78aa31..0000000 Binary files a/cpp03/ex01/scavtrap and /dev/null differ diff --git a/cpp03/ex02/ClapTrap.cpp b/cpp03/ex02/ClapTrap.cpp deleted file mode 100644 index bb6eb85..0000000 --- a/cpp03/ex02/ClapTrap.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "ClapTrap.hpp" - -ClapTrap::ClapTrap(std::string _name): name(_name), hp(10), stamina(10), ad(0) { - std::cout << "ClapTrap asignment constructor called" << std::endl; -} - -ClapTrap::ClapTrap(): hp(10), stamina(10), ad(0), name("ClapTrap") { - std::cout << "ClapTrap default constructer called" << std::endl; -} - -ClapTrap::ClapTrap(ClapTrap& c) { - *this = c; - std::cout << "ClapTrap copy constructor called" << std::endl; -} - -ClapTrap& ClapTrap::operator=(ClapTrap& c) { - std::cout << "ClapTrap copy asignment operator called" << std::endl; - this->name = c.name; - this->hp = c.hp; - this->stamina = c.stamina; - this->ad = c.ad; - return *this; -} - -ClapTrap::~ClapTrap() { - std::cout << "ClapTrap deconstructor called" << std::endl; -} - -void ClapTrap::attack(const std::string& target) { - if (this->stamina > 0 && this->getHP() > 0) { - std::cout << this->getName() << " has given " << this->ad << " damage to " << target << std::endl; - this->stamina -= 1; - } -} - -void ClapTrap::takeDamage(unsigned int amount) { - if (this->stamina > 0 && this->getHP() > 0) { - std::cout << this->getName() << " was take " << amount << " damage" << std::endl; - this->hp -= amount; - this->stamina -= 1; - if (this->getHP() < 0) - std::cout << this->getName() << " is died" << std::endl; - } -} - -void ClapTrap::beRepaired(unsigned int amount) { - if (this->stamina > 0 && this->getHP() > 0) { - this->hp += amount; - std::cout << this->getName() << " is " << amount << " hp repaired" << std::endl; - this->stamina -= 1; - } -} - -std::string ClapTrap::getName(void) const {return this->name;} -int ClapTrap::getHP(void) const {return this->hp;} -int ClapTrap::getStamina(void) const {return this->stamina;} -int ClapTrap::getAD(void) const {return this->ad;} - -void ClapTrap::setName(std::string _name) {this->name = _name;} -void ClapTrap::setHP(int _hp) {this->hp = _hp;} -void ClapTrap::setStamina(int _stamina) {this->stamina = _stamina;} -void ClapTrap::setAD(int _ad) {this->ad = _ad;} - -std::ostream& operator<<(std::ostream& o, ClapTrap& c) { - o << "Name: " << c.getName() << " HP: " << c.getHP() << " Stamina: " << c.getStamina() << " AD: " << c.getAD(); - return o; -} diff --git a/cpp03/ex02/ClapTrap.hpp b/cpp03/ex02/ClapTrap.hpp deleted file mode 100644 index b8c4c3b..0000000 --- a/cpp03/ex02/ClapTrap.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -class ClapTrap { -private: - std::string name; - int hp; - int stamina; - int ad; -public: - ClapTrap(); - ClapTrap(std::string name); - ClapTrap(ClapTrap& c); - ~ClapTrap(); - - ClapTrap& operator=(ClapTrap& c); - - std::string getName(void) const ; - int getHP(void) const ; - int getStamina(void) const ; - int getAD(void) const ; - - void setName(std::string); - void setHP(int _hp); - void setStamina(int _stamina); - void setAD(int _ad); - - void attack(const std::string& target); - void takeDamage(unsigned int amount); - void beRepaired(unsigned int amount); -}; diff --git a/cpp03/ex02/FragTrap.cpp b/cpp03/ex02/FragTrap.cpp deleted file mode 100644 index 93ec1b8..0000000 --- a/cpp03/ex02/FragTrap.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "FragTrap.hpp" - -FragTrap::FragTrap() { - std::cout << "FragTrap default constructor" << std::endl; - this->setAD(30); - this->setHP(100); - this->setStamina(100); - this->setName("FragTrap"); -} - -FragTrap::FragTrap(std::string _name) { - - std::cout << "FragTrap assingment constructor called" << std::endl; - this->setAD(30); - this->setHP(100); - this->setName(_name); - this->setStamina(100); -} - -FragTrap::FragTrap(FragTrap& copy) { - std::cout << "FragTrap copy constructor called" << std::endl; - *this = copy; -} - -FragTrap& FragTrap::operator=(FragTrap& copy) { - std::cout << "FragTrap copy assingment operator called" << std::endl; - this->setAD(copy.getAD()); - this->setHP(copy.getHP()); - this->setName(copy.getName()); - this->setStamina(copy.getStamina()); - return *this; -} - -FragTrap::~FragTrap() { - std::cout << "FragTrap deconstructor" << std::endl; -} - -void FragTrap::highFivesGuys(void) { - std::cout << this->getName() << " wanna pat pat your joe mama highFive" << std::endl; -} - -std::ostream& operator<<(std::ostream& o, FragTrap& c) { - o << "Name: " << c.getName() << " HP: " << c.getHP() << " Stamina: " << c.getStamina() << " AD: " << c.getAD(); - return o; -} diff --git a/cpp03/ex02/FragTrap.hpp b/cpp03/ex02/FragTrap.hpp deleted file mode 100644 index 45fd619..0000000 --- a/cpp03/ex02/FragTrap.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "ClapTrap.hpp" - -class FragTrap : public ClapTrap { -public: - FragTrap(); - FragTrap(std::string _name); - FragTrap(FragTrap& copy); - FragTrap& operator=(FragTrap& copy); - ~FragTrap(); - - void highFivesGuys(void); -}; - -std::ostream& operator<<(std::ostream& o, FragTrap& c); \ No newline at end of file diff --git a/cpp03/ex02/Makefile b/cpp03/ex02/Makefile deleted file mode 100644 index cea73b5..0000000 --- a/cpp03/ex02/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = fragtrap -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror -Wshadow - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp03/ex02/ex03/ClapTrap.cpp b/cpp03/ex02/ex03/ClapTrap.cpp deleted file mode 100644 index bb6eb85..0000000 --- a/cpp03/ex02/ex03/ClapTrap.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "ClapTrap.hpp" - -ClapTrap::ClapTrap(std::string _name): name(_name), hp(10), stamina(10), ad(0) { - std::cout << "ClapTrap asignment constructor called" << std::endl; -} - -ClapTrap::ClapTrap(): hp(10), stamina(10), ad(0), name("ClapTrap") { - std::cout << "ClapTrap default constructer called" << std::endl; -} - -ClapTrap::ClapTrap(ClapTrap& c) { - *this = c; - std::cout << "ClapTrap copy constructor called" << std::endl; -} - -ClapTrap& ClapTrap::operator=(ClapTrap& c) { - std::cout << "ClapTrap copy asignment operator called" << std::endl; - this->name = c.name; - this->hp = c.hp; - this->stamina = c.stamina; - this->ad = c.ad; - return *this; -} - -ClapTrap::~ClapTrap() { - std::cout << "ClapTrap deconstructor called" << std::endl; -} - -void ClapTrap::attack(const std::string& target) { - if (this->stamina > 0 && this->getHP() > 0) { - std::cout << this->getName() << " has given " << this->ad << " damage to " << target << std::endl; - this->stamina -= 1; - } -} - -void ClapTrap::takeDamage(unsigned int amount) { - if (this->stamina > 0 && this->getHP() > 0) { - std::cout << this->getName() << " was take " << amount << " damage" << std::endl; - this->hp -= amount; - this->stamina -= 1; - if (this->getHP() < 0) - std::cout << this->getName() << " is died" << std::endl; - } -} - -void ClapTrap::beRepaired(unsigned int amount) { - if (this->stamina > 0 && this->getHP() > 0) { - this->hp += amount; - std::cout << this->getName() << " is " << amount << " hp repaired" << std::endl; - this->stamina -= 1; - } -} - -std::string ClapTrap::getName(void) const {return this->name;} -int ClapTrap::getHP(void) const {return this->hp;} -int ClapTrap::getStamina(void) const {return this->stamina;} -int ClapTrap::getAD(void) const {return this->ad;} - -void ClapTrap::setName(std::string _name) {this->name = _name;} -void ClapTrap::setHP(int _hp) {this->hp = _hp;} -void ClapTrap::setStamina(int _stamina) {this->stamina = _stamina;} -void ClapTrap::setAD(int _ad) {this->ad = _ad;} - -std::ostream& operator<<(std::ostream& o, ClapTrap& c) { - o << "Name: " << c.getName() << " HP: " << c.getHP() << " Stamina: " << c.getStamina() << " AD: " << c.getAD(); - return o; -} diff --git a/cpp03/ex02/ex03/ClapTrap.hpp b/cpp03/ex02/ex03/ClapTrap.hpp deleted file mode 100644 index b8c4c3b..0000000 --- a/cpp03/ex02/ex03/ClapTrap.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include - -class ClapTrap { -private: - std::string name; - int hp; - int stamina; - int ad; -public: - ClapTrap(); - ClapTrap(std::string name); - ClapTrap(ClapTrap& c); - ~ClapTrap(); - - ClapTrap& operator=(ClapTrap& c); - - std::string getName(void) const ; - int getHP(void) const ; - int getStamina(void) const ; - int getAD(void) const ; - - void setName(std::string); - void setHP(int _hp); - void setStamina(int _stamina); - void setAD(int _ad); - - void attack(const std::string& target); - void takeDamage(unsigned int amount); - void beRepaired(unsigned int amount); -}; diff --git a/cpp03/ex02/ex03/DiamondTrap.cpp b/cpp03/ex02/ex03/DiamondTrap.cpp deleted file mode 100644 index 6a1cbaf..0000000 --- a/cpp03/ex02/ex03/DiamondTrap.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "DiamondTrap.hpp" - -DiamondTrap::DiamondTrap() { - std::cout << "DiamondTrap default constructor" << std::endl; - this->setName("DiamondTrap"); - this->setAD(DiamondTrap::FragTrap::getAD()); - this->setHP(DiamondTrap::FragTrap::getHP()); - this->setStamina(DiamondTrap::ScavTrap::getStamina()); -} - -DiamondTrap::DiamondTrap(std::string name) { - std::cout << "DiamondTrap assingment constructor" << std::endl; - this->setDiaTrapName(name); - this->setName(name + "_clap_name"); - this->setAD(FragTrap::getAD()); - this->setHP(FragTrap::getHP()); - this->setStamina(ScavTrap::getStamina()); -} - -DiamondTrap::DiamondTrap(const DiamondTrap& copy) { - std::cout << "DiamondTrap copy constructor" << std::endl; - *this = copy; -} - -DiamondTrap& DiamondTrap::operator=(const DiamondTrap& copy) { - std::cout << "DiamondTrap assingment operator" << std::endl; - this->setDiaTrapName(copy.getDiaTrapName()); - this->setAD(copy.getAD()); - this->setHP(copy.getHP()); - this->setName(copy.getName()); - this->setStamina(copy.getStamina()); - return *this; -} - -DiamondTrap::~DiamondTrap() { - std::cout << "DiamondTrap deconstructor" << std::endl; -} - -std::string DiamondTrap::getDiaTrapName(void) const {return this->name;} -void DiamondTrap::setDiaTrapName(std::string name) {this->name = name;} - -void DiamondTrap::attack(const std::string& target) { - DiamondTrap::ScavTrap::attack(target); -} - -void DiamondTrap::whoAmI(void) { - std::cout << "I am " << this->getDiaTrapName() << " but you can call me " << this->getName() << std::endl; -} - -std::ostream& operator<<(std::ostream& o, DiamondTrap& n) { - o << "Name: " << n.getName() << " DiamondName " << n.getDiaTrapName() << " HP: " << n.getHP() << " Stamina: " << n.getStamina() << " AD: " << n.getAD(); - return o; -} \ No newline at end of file diff --git a/cpp03/ex02/ex03/DiamondTrap.hpp b/cpp03/ex02/ex03/DiamondTrap.hpp deleted file mode 100644 index 7c84172..0000000 --- a/cpp03/ex02/ex03/DiamondTrap.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "FragTrap.hpp" -#include "ScavTrap.hpp" -#include - -class DiamondTrap : public FragTrap, public ScavTrap { -private: - std::string name; -public: - DiamondTrap(); - DiamondTrap(std::string name); - DiamondTrap(const DiamondTrap& copy); - DiamondTrap& operator=(const DiamondTrap& copy); - ~DiamondTrap(); - - std::string getDiaTrapName(void) const; - void setDiaTrapName(std::string name); - void attack(const std::string& target); - void whoAmI(void); -}; - -std::ostream& operator<<(std::ostream& o, DiamondTrap& n); \ No newline at end of file diff --git a/cpp03/ex02/ex03/FragTrap.cpp b/cpp03/ex02/ex03/FragTrap.cpp deleted file mode 100644 index eb8cc40..0000000 --- a/cpp03/ex02/ex03/FragTrap.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "FragTrap.hpp" - -FragTrap::FragTrap() { - std::cout << "FragTrap default constructor" << std::endl; - this->setAD(30); - this->setHP(100); - this->setStamina(100); - this->setName("FragTrap"); -} - -FragTrap::FragTrap(std::string _name) { - - std::cout << "FragTrap assingment constructor called" << std::endl; - this->setAD(30); - this->setHP(100); - this->setName(_name); - this->setStamina(100); -} - -FragTrap::FragTrap(FragTrap& copy) { - std::cout << "FragTrap copy constructor called" << std::endl; - *this = copy; -} - -FragTrap& FragTrap::operator=(FragTrap& copy) { - std::cout << "FragTrap copy assingment operator called" << std::endl; - this->setAD(copy.getAD()); - this->setHP(copy.getHP()); - this->setName(copy.getName()); - this->setStamina(copy.getStamina()); - return *this; -} - -FragTrap::~FragTrap() { - std::cout << "FragTrap deconstructor" << std::endl; -} - -void FragTrap::highFivesGuys(void) { - std::cout << this->getName() << " wanna pat pat joe mama highFive" << std::endl; -} diff --git a/cpp03/ex02/ex03/FragTrap.hpp b/cpp03/ex02/ex03/FragTrap.hpp deleted file mode 100644 index c7648f4..0000000 --- a/cpp03/ex02/ex03/FragTrap.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "ClapTrap.hpp" - -class FragTrap : virtual public ClapTrap { -public: - FragTrap(); - FragTrap(std::string _name); - FragTrap(FragTrap& copy); - FragTrap& operator=(FragTrap& copy); - ~FragTrap(); - - void highFivesGuys(void); -}; diff --git a/cpp03/ex02/ex03/Makefile b/cpp03/ex02/ex03/Makefile deleted file mode 100644 index 4736690..0000000 --- a/cpp03/ex02/ex03/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = diamondtrap -CC = g++ -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) -FLAG = -Wall -Wextra -Werror -Wshadow - -$(NAME): all - -all: $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - $(MAKE) clean - -clean: - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -re: fclean all \ No newline at end of file diff --git a/cpp03/ex02/ex03/ScavTrap.cpp b/cpp03/ex02/ex03/ScavTrap.cpp deleted file mode 100644 index e7c1211..0000000 --- a/cpp03/ex02/ex03/ScavTrap.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "ScavTrap.hpp" - -ScavTrap::ScavTrap() { - std::cout << "ScavTrap default constructor" << std::endl; - this->setAD(30); - this->setHP(100); - this->setStamina(100); - this->setName("ScavTrap"); -} - -ScavTrap::ScavTrap(std::string _name) { - - std::cout << "ScavTrap assingment constructor called" << std::endl; - this->setAD(30); - this->setHP(100); - this->setName(_name); - this->setStamina(100); -} - -ScavTrap::ScavTrap(ScavTrap& copy) { - std::cout << "ScavTrap copy constructor called" << std::endl; - *this = copy; -} - -ScavTrap& ScavTrap::operator=(ScavTrap& copy) { - std::cout << "ScavTrap copy assingment operator called" << std::endl; - this->setAD(copy.getAD()); - this->setHP(copy.getHP()); - this->setName(copy.getName()); - this->setStamina(copy.getStamina()); - return *this; -} - -ScavTrap::~ScavTrap() { - std::cout << "ScavTrap deconstructor" << std::endl; -} - -void ScavTrap::guardGate() { - if (this->isGate == false) { - std::cout << "Not gating" << std::endl; - } else { - std::cout << "Gate Keeping Mode: Gating is so funny" << std::endl; - } -} - -void ScavTrap::attack(const std::string& target) { - if (this->getStamina() > 0 && this->getHP() > 0) { - std::cout << this->getName() << " locked the " << target - << " and given " << this->getAD() << " damage." << std::endl; - } -} diff --git a/cpp03/ex02/ex03/ScavTrap.hpp b/cpp03/ex02/ex03/ScavTrap.hpp deleted file mode 100644 index ec5f714..0000000 --- a/cpp03/ex02/ex03/ScavTrap.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "ClapTrap.hpp" - -class ScavTrap : virtual public ClapTrap { -private: - bool isGate; -public: - ScavTrap(); - ScavTrap(std::string _name); - ScavTrap(ScavTrap& copy); - ScavTrap& operator=(ScavTrap& copy); - ~ScavTrap(); - - void guardGate(); - void attack(const std::string& target); -}; diff --git a/cpp03/ex02/ex03/diamondtrap b/cpp03/ex02/ex03/diamondtrap deleted file mode 100755 index 70cd291..0000000 Binary files a/cpp03/ex02/ex03/diamondtrap and /dev/null differ diff --git a/cpp03/ex02/ex03/main.cpp b/cpp03/ex02/ex03/main.cpp deleted file mode 100644 index 07809fb..0000000 --- a/cpp03/ex02/ex03/main.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "DiamondTrap.hpp" - -int main() { - { - DiamondTrap n("clap"); - std::cout << n << std::endl; - n.attack("aaa"); - n.beRepaired(20); - n.takeDamage(4); - n.attack("bb"); - } - { - std::cout << std::endl << "DiamondTrap" << std::endl << std::endl; - DiamondTrap a; - std::cout << a << std::endl; - DiamondTrap b("eyubi"); - std::cout << "getname: " << b.getName() << " dia::name: " << b.getDiaTrapName() << std::endl; - std::cout << b << std::endl; - DiamondTrap c(b); - std::cout << c.getName() << " " << c.getDiaTrapName() << std::endl; - a.attack("ClapTrap"); - b.attack("emircan"); - b.takeDamage(101); - - b.highFivesGuys(); - } -} diff --git a/cpp03/ex02/main.cpp b/cpp03/ex02/main.cpp deleted file mode 100644 index b3feaa1..0000000 --- a/cpp03/ex02/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "FragTrap.hpp" - -int main() { - { - FragTrap n("clap"); - std::cout << n << std::endl; - n.attack("aaa"); - n.beRepaired(20); - n.takeDamage(4); - n.attack("bb"); - } - { - std::cout << std::endl << "FragTrap" << std::endl << std::endl; - FragTrap a; - FragTrap b("eyubi"); - FragTrap c(b); - a.attack("ClapTrap"); - b.attack("emircan"); - b.takeDamage(101); - - b.highFivesGuys(); - } -} diff --git a/cpp04/ex00/Animal.cpp b/cpp04/ex00/Animal.cpp deleted file mode 100644 index 78e4a03..0000000 --- a/cpp04/ex00/Animal.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "Animal.hpp" - -Animal::Animal() { - std::cout << "Animal default called" << std::endl; -} - -Animal::Animal(Animal& c) { - std::cout << "Animal copy called" << std::endl; - *this = c; -} - -Animal& Animal::operator=(Animal& c) { - std::cout << "Animal assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -Animal::~Animal() { - std::cout << "Animal deconstructor called" << std::endl; -} - -std::string Animal::getType(void) const { - return this->type; -} - -void Animal::makeSound(void) const { - std::cout << "Animal sound" << std::endl; -} diff --git a/cpp04/ex00/Animal.hpp b/cpp04/ex00/Animal.hpp deleted file mode 100644 index bae848a..0000000 --- a/cpp04/ex00/Animal.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include - -class Animal { -protected: - std::string type; -public: - Animal(); - Animal(Animal& c); - Animal& operator=(Animal& c); - ~Animal(); - - std::string getType(void) const ; - virtual void makeSound(void) const; -}; diff --git a/cpp04/ex00/Cat.cpp b/cpp04/ex00/Cat.cpp deleted file mode 100644 index c438bd5..0000000 --- a/cpp04/ex00/Cat.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "Cat.hpp" - -Cat::Cat() { - std::cout << "Cat default called" << std::endl; - this->type = "Cat"; -} - -Cat::Cat(Cat& c) { - std::cout << "Cat copy constructor called" << std::endl; - *this = c; -} - -Cat& Cat::operator=(Cat& c) { - std::cout << "Cat assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -Cat::~Cat() { - std::cout << "Cat deconstructor called" << std::endl; -} - -void Cat::makeSound(void) const { - std::cout << "MeoW MeoW negativity" << std::endl; -} diff --git a/cpp04/ex00/Cat.hpp b/cpp04/ex00/Cat.hpp deleted file mode 100644 index eb24847..0000000 --- a/cpp04/ex00/Cat.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "Animal.hpp" - -class Cat : public Animal { -public: - Cat(); - Cat(Cat& c); - Cat& operator=(Cat& c); - ~Cat(); - - void makeSound(void) const; -}; diff --git a/cpp04/ex00/Dog.cpp b/cpp04/ex00/Dog.cpp deleted file mode 100644 index 6520a58..0000000 --- a/cpp04/ex00/Dog.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "Dog.hpp" - -Dog::Dog() { - std::cout << "Dog default called" << std::endl; - this->type = "Dog"; -} - -Dog::Dog(const Dog& c) { - std::cout << "Dog copy constructor called" << std::endl; - *this = c; -} - -Dog& Dog::operator=(const Dog& c) { - std::cout << "Dog assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -Dog::~Dog() { - std::cout << "Dog deconstructor called" << std::endl; -} - -void Dog::makeSound(void) const { - std::cout << "Woof Woof" << std::endl; -} diff --git a/cpp04/ex00/Dog.hpp b/cpp04/ex00/Dog.hpp deleted file mode 100644 index 62567c8..0000000 --- a/cpp04/ex00/Dog.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "Animal.hpp" - -class Dog : public Animal { -public: - Dog(); - Dog(const Dog& c); - Dog& operator=(const Dog& c); - ~Dog(); - - void makeSound(void) const; -}; diff --git a/cpp04/ex00/Makefile b/cpp04/ex00/Makefile deleted file mode 100644 index b36649e..0000000 --- a/cpp04/ex00/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = polymorphism -CC = g++ -FLAG = -Wall -Wextra -Werror -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) - -all: $(NAME) - -$(NAME): $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -clean: - rm -rf $(OBJECT) - -re: fclean all \ No newline at end of file diff --git a/cpp04/ex00/WrongAnimal.cpp b/cpp04/ex00/WrongAnimal.cpp deleted file mode 100644 index 21daf73..0000000 --- a/cpp04/ex00/WrongAnimal.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "WrongAnimal.hpp" - -WrongAnimal::WrongAnimal() { - std::cout << "WrongAnimal default called" << std::endl; -} - -WrongAnimal::WrongAnimal(WrongAnimal& c) { - std::cout << "WrongAnimal copy called" << std::endl; - *this = c; -} - -WrongAnimal& WrongAnimal::operator=(WrongAnimal& c) { - std::cout << "WrongAnimal assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -WrongAnimal::~WrongAnimal() { - std::cout << "WrongAnimal deconstructor called" << std::endl; -} - -std::string WrongAnimal::getType(void) const { - return this->type; -} - -void WrongAnimal::makeSound(void) const { - std::cout << "WrongAnimal sound" << std::endl; -} diff --git a/cpp04/ex00/WrongAnimal.hpp b/cpp04/ex00/WrongAnimal.hpp deleted file mode 100644 index bfc51b1..0000000 --- a/cpp04/ex00/WrongAnimal.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include - -class WrongAnimal{ -protected: - std::string type; -public: - WrongAnimal(); - WrongAnimal(WrongAnimal& c); - WrongAnimal& operator=(WrongAnimal& c); - ~WrongAnimal(); - - std::string getType(void) const ; - void makeSound(void) const; -}; diff --git a/cpp04/ex00/WrongCat.cpp b/cpp04/ex00/WrongCat.cpp deleted file mode 100644 index 5f9530f..0000000 --- a/cpp04/ex00/WrongCat.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "WrongCat.hpp" - -WrongCat::WrongCat() { - std::cout << "WrongCat default called" << std::endl; - this->type = "WrongCat"; -} - -WrongCat::WrongCat(WrongCat& c) { - std::cout << "WrongCat copy constructor called" << std::endl; - *this = c; -} - -WrongCat& WrongCat::operator=(WrongCat& c) { - std::cout << "WrongCat assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -WrongCat::~WrongCat() { - std::cout << "WrongCat deconstructor called" << std::endl; -} - -void WrongCat::makeSound(void) const { - std::cout << "MeoW MeoW negativity" << std::endl; -} diff --git a/cpp04/ex00/WrongCat.hpp b/cpp04/ex00/WrongCat.hpp deleted file mode 100644 index 4dc3848..0000000 --- a/cpp04/ex00/WrongCat.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "WrongAnimal.hpp" - -class WrongCat : public WrongAnimal { -public: - WrongCat(); - WrongCat(WrongCat& c); - WrongCat& operator=(WrongCat& c); - ~WrongCat(); - - void makeSound(void) const; -}; diff --git a/cpp04/ex00/main.cpp b/cpp04/ex00/main.cpp deleted file mode 100644 index a11aecd..0000000 --- a/cpp04/ex00/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "Dog.hpp" -#include "Cat.hpp" -#include "WrongCat.hpp" - -int main(void) { - const Animal* meta = new Animal(); - const Animal* j = new Dog(); - const Animal* i = new Cat(); - std::cout << j->getType() << " " << std::endl; - std::cout << i->getType() << " " << std::endl; - i->makeSound(); //will output the cat sound! - j->makeSound(); - meta->makeSound(); - const WrongAnimal* a = new WrongCat(); - delete meta; - delete j; - delete i; - delete a; - return 0; -} diff --git a/cpp04/ex00/polymorphism b/cpp04/ex00/polymorphism deleted file mode 100755 index 2bb20be..0000000 Binary files a/cpp04/ex00/polymorphism and /dev/null differ diff --git a/cpp04/ex01/Animal.cpp b/cpp04/ex01/Animal.cpp deleted file mode 100644 index 78e4a03..0000000 --- a/cpp04/ex01/Animal.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "Animal.hpp" - -Animal::Animal() { - std::cout << "Animal default called" << std::endl; -} - -Animal::Animal(Animal& c) { - std::cout << "Animal copy called" << std::endl; - *this = c; -} - -Animal& Animal::operator=(Animal& c) { - std::cout << "Animal assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -Animal::~Animal() { - std::cout << "Animal deconstructor called" << std::endl; -} - -std::string Animal::getType(void) const { - return this->type; -} - -void Animal::makeSound(void) const { - std::cout << "Animal sound" << std::endl; -} diff --git a/cpp04/ex01/Animal.hpp b/cpp04/ex01/Animal.hpp deleted file mode 100644 index 9ca4c59..0000000 --- a/cpp04/ex01/Animal.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include - -class Animal { -protected: - std::string type; -public: - Animal(); - Animal(Animal& c); - Animal& operator=(Animal& c); - virtual ~Animal(); - - std::string getType(void) const ; - virtual void makeSound(void) const; -}; diff --git a/cpp04/ex01/Brain.cpp b/cpp04/ex01/Brain.cpp deleted file mode 100644 index 30aadd6..0000000 --- a/cpp04/ex01/Brain.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Brain.hpp" - -Brain::Brain() { - std::cout << "Brain is loading..." << std::endl; -} - -Brain::~Brain() { - std::cout << "Brain is removing..." << std::endl; -} \ No newline at end of file diff --git a/cpp04/ex01/Brain.hpp b/cpp04/ex01/Brain.hpp deleted file mode 100644 index 3971487..0000000 --- a/cpp04/ex01/Brain.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -class Brain { -protected: - std::string ideas[100]; -public: - Brain(); - ~Brain(); -}; diff --git a/cpp04/ex01/Cat.cpp b/cpp04/ex01/Cat.cpp deleted file mode 100644 index f2695cf..0000000 --- a/cpp04/ex01/Cat.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "Cat.hpp" - -Cat::Cat() { - std::cout << "Cat default called" << std::endl; - this->type = "Cat"; - this->brain = new Brain(); -} - -Cat::Cat(Cat& c) { - std::cout << "Cat copy constructor called" << std::endl; - *this = c; -} - -Cat& Cat::operator=(Cat& c) { - std::cout << "Cat assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -Cat::~Cat() { - std::cout << "Cat deconstructor called" << std::endl; - delete this->brain; -} - -void Cat::makeSound(void) const { - std::cout << "MeoW MeoW negativity" << std::endl; -} diff --git a/cpp04/ex01/Cat.hpp b/cpp04/ex01/Cat.hpp deleted file mode 100644 index 64d960a..0000000 --- a/cpp04/ex01/Cat.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Animal.hpp" -#include "Brain.hpp" - -class Cat : public Animal { -private: - Brain* brain; -public: - Cat(); - Cat(Cat& c); - Cat& operator=(Cat& c); - ~Cat(); - - void makeSound(void) const; -}; diff --git a/cpp04/ex01/Dog.cpp b/cpp04/ex01/Dog.cpp deleted file mode 100644 index ddc5417..0000000 --- a/cpp04/ex01/Dog.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "Dog.hpp" - -Dog::Dog() { - std::cout << "Dog default called" << std::endl; - this->type = "Dog"; - this->brain = new Brain(); -} - -Dog::Dog(const Dog& c) { - std::cout << "Dog copy constructor called" << std::endl; - *this = c; -} - -Dog& Dog::operator=(const Dog& c) { - std::cout << "Dog assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -Dog::~Dog() { - std::cout << "Dog deconstructor called" << std::endl; - delete this->brain; -} - -void Dog::makeSound(void) const { - std::cout << "Woof Woof" << std::endl; -} diff --git a/cpp04/ex01/Dog.hpp b/cpp04/ex01/Dog.hpp deleted file mode 100644 index c2ef821..0000000 --- a/cpp04/ex01/Dog.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Animal.hpp" -#include "Brain.hpp" - -class Dog : public Animal { -private: - Brain* brain; -public: - Dog(); - Dog(const Dog& c); - Dog& operator=(const Dog& c); - ~Dog(); - - void makeSound(void) const; -}; diff --git a/cpp04/ex01/main.cpp b/cpp04/ex01/main.cpp deleted file mode 100644 index e850d0f..0000000 --- a/cpp04/ex01/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Cat.hpp" -#include "Dog.hpp" - -int main() { - const Animal* j = new Dog(); - const Animal* a = new Cat(); - delete j; - delete a; - // system("leaks worldonfire"); -} \ No newline at end of file diff --git a/cpp04/ex01/worldonfire b/cpp04/ex01/worldonfire deleted file mode 100755 index 8bded85..0000000 Binary files a/cpp04/ex01/worldonfire and /dev/null differ diff --git a/cpp04/ex02/Animal.cpp b/cpp04/ex02/Animal.cpp deleted file mode 100644 index 78e4a03..0000000 --- a/cpp04/ex02/Animal.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "Animal.hpp" - -Animal::Animal() { - std::cout << "Animal default called" << std::endl; -} - -Animal::Animal(Animal& c) { - std::cout << "Animal copy called" << std::endl; - *this = c; -} - -Animal& Animal::operator=(Animal& c) { - std::cout << "Animal assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -Animal::~Animal() { - std::cout << "Animal deconstructor called" << std::endl; -} - -std::string Animal::getType(void) const { - return this->type; -} - -void Animal::makeSound(void) const { - std::cout << "Animal sound" << std::endl; -} diff --git a/cpp04/ex02/Animal.hpp b/cpp04/ex02/Animal.hpp deleted file mode 100644 index 94fbb8c..0000000 --- a/cpp04/ex02/Animal.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include - -class Animal { -protected: - std::string type; -public: - Animal(); - Animal(Animal& c); - Animal& operator=(Animal& c); - virtual ~Animal() = 0; - - std::string getType(void) const ; - virtual void makeSound(void) const; -}; diff --git a/cpp04/ex02/Animal.o b/cpp04/ex02/Animal.o deleted file mode 100644 index cf452ac..0000000 Binary files a/cpp04/ex02/Animal.o and /dev/null differ diff --git a/cpp04/ex02/Brain.cpp b/cpp04/ex02/Brain.cpp deleted file mode 100644 index 30aadd6..0000000 --- a/cpp04/ex02/Brain.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Brain.hpp" - -Brain::Brain() { - std::cout << "Brain is loading..." << std::endl; -} - -Brain::~Brain() { - std::cout << "Brain is removing..." << std::endl; -} \ No newline at end of file diff --git a/cpp04/ex02/Brain.hpp b/cpp04/ex02/Brain.hpp deleted file mode 100644 index 3971487..0000000 --- a/cpp04/ex02/Brain.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -class Brain { -protected: - std::string ideas[100]; -public: - Brain(); - ~Brain(); -}; diff --git a/cpp04/ex02/Brain.o b/cpp04/ex02/Brain.o deleted file mode 100644 index 07da2b4..0000000 Binary files a/cpp04/ex02/Brain.o and /dev/null differ diff --git a/cpp04/ex02/Cat.cpp b/cpp04/ex02/Cat.cpp deleted file mode 100644 index f2695cf..0000000 --- a/cpp04/ex02/Cat.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "Cat.hpp" - -Cat::Cat() { - std::cout << "Cat default called" << std::endl; - this->type = "Cat"; - this->brain = new Brain(); -} - -Cat::Cat(Cat& c) { - std::cout << "Cat copy constructor called" << std::endl; - *this = c; -} - -Cat& Cat::operator=(Cat& c) { - std::cout << "Cat assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -Cat::~Cat() { - std::cout << "Cat deconstructor called" << std::endl; - delete this->brain; -} - -void Cat::makeSound(void) const { - std::cout << "MeoW MeoW negativity" << std::endl; -} diff --git a/cpp04/ex02/Cat.hpp b/cpp04/ex02/Cat.hpp deleted file mode 100644 index 64d960a..0000000 --- a/cpp04/ex02/Cat.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Animal.hpp" -#include "Brain.hpp" - -class Cat : public Animal { -private: - Brain* brain; -public: - Cat(); - Cat(Cat& c); - Cat& operator=(Cat& c); - ~Cat(); - - void makeSound(void) const; -}; diff --git a/cpp04/ex02/Cat.o b/cpp04/ex02/Cat.o deleted file mode 100644 index c8b9e50..0000000 Binary files a/cpp04/ex02/Cat.o and /dev/null differ diff --git a/cpp04/ex02/Dog.cpp b/cpp04/ex02/Dog.cpp deleted file mode 100644 index ddc5417..0000000 --- a/cpp04/ex02/Dog.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "Dog.hpp" - -Dog::Dog() { - std::cout << "Dog default called" << std::endl; - this->type = "Dog"; - this->brain = new Brain(); -} - -Dog::Dog(const Dog& c) { - std::cout << "Dog copy constructor called" << std::endl; - *this = c; -} - -Dog& Dog::operator=(const Dog& c) { - std::cout << "Dog assignment operator called" << std::endl; - this->type = c.type; - return *this; -} - -Dog::~Dog() { - std::cout << "Dog deconstructor called" << std::endl; - delete this->brain; -} - -void Dog::makeSound(void) const { - std::cout << "Woof Woof" << std::endl; -} diff --git a/cpp04/ex02/Dog.hpp b/cpp04/ex02/Dog.hpp deleted file mode 100644 index c2ef821..0000000 --- a/cpp04/ex02/Dog.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Animal.hpp" -#include "Brain.hpp" - -class Dog : public Animal { -private: - Brain* brain; -public: - Dog(); - Dog(const Dog& c); - Dog& operator=(const Dog& c); - ~Dog(); - - void makeSound(void) const; -}; diff --git a/cpp04/ex02/Dog.o b/cpp04/ex02/Dog.o deleted file mode 100644 index a23fc9b..0000000 Binary files a/cpp04/ex02/Dog.o and /dev/null differ diff --git a/cpp04/ex02/Makefile b/cpp04/ex02/Makefile deleted file mode 100644 index b493cd4..0000000 --- a/cpp04/ex02/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -NAME = worldonfire -CC = g++ -FLAG = -Wall -Wextra -Werror -std=c++98 -SOURCE = $(wildcard *.cpp) -OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) - -all: $(NAME) - -$(NAME): $(OBJECT) - $(CC) $(FLAG) $(OBJECT) -o $(NAME) - rm -rf $(OBJECT) - -fclean: clean - rm -rf $(NAME) - -clean: - rm -rf $(OBJECT) - -re: fclean all \ No newline at end of file diff --git a/cpp04/ex02/main.cpp b/cpp04/ex02/main.cpp deleted file mode 100644 index 401f5ea..0000000 --- a/cpp04/ex02/main.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "Cat.hpp" -#include "Dog.hpp" - -int main() { - const Animal* j = new Dog(); - const Animal* a = new Cat(); - const Animal i; - delete j; - delete a; - // system("leaks worldonfire"); -} \ No newline at end of file diff --git a/cpp05/ex00/Bureaucrat.cpp b/cpp05/ex00/Bureaucrat.cpp new file mode 100644 index 0000000..96e394b --- /dev/null +++ b/cpp05/ex00/Bureaucrat.cpp @@ -0,0 +1,53 @@ +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat(const std::string _name, int _grade): name(_name) { + std::cout << "default constructor called" << std::endl; + this->setGrade(_grade); +} + +Bureaucrat::Bureaucrat(const Bureaucrat& _copy) { + *this = _copy; +} + +const Bureaucrat& Bureaucrat::operator=(const Bureaucrat& _copy) { + this->setGrade(_copy.getGrade()); + this->setName(_copy.getName()); + return *this; +} + +void Bureaucrat::increment(void) { + this->setGrade(this->getGrade() - 1); +} +void Bureaucrat::decrement(void) { + this->setGrade(this->getGrade() + 1); +} + +Bureaucrat::~Bureaucrat() { std::cout << "deconstructor" << std::endl; } + +const std::string Bureaucrat::getName(void) const { return(this->name); } +void Bureaucrat::setName(std::string _n) { const_cast(this->name) = const_cast(_n); } +int Bureaucrat::getGrade(void) const { return(this->grade); } +void Bureaucrat::setGrade(int _grade) { + if (_grade > 150) { + this->grade = 0; + throw GradeTooLowException(); + } else if (_grade < 1) { + this->grade = 0; + throw GradeTooHighException(); + } else { + this->grade = _grade; + } +} + +std::ostream& operator<<(std::ostream& o, const Bureaucrat& b) { + o << b.getName() << ", grade level is " << b.getGrade(); + return (o); +} + +const char *Bureaucrat::GradeTooHighException::what() const throw() { + return "Grade is must lower than"; +} + +const char *Bureaucrat::GradeTooLowException::what() const throw() { + return "Grade is must bigger than"; +} diff --git a/cpp05/ex00/Bureaucrat.hpp b/cpp05/ex00/Bureaucrat.hpp new file mode 100644 index 0000000..4d8ea81 --- /dev/null +++ b/cpp05/ex00/Bureaucrat.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +class Bureaucrat { +protected: + const std::string name; + int grade; +public: + Bureaucrat(const std::string _name, int _grade); + Bureaucrat(const Bureaucrat& _copy); + const Bureaucrat& operator=(const Bureaucrat& _copy); + ~Bureaucrat(); + + const std::string getName(void) const; + void setName(std::string _n) ; + int getGrade(void) const; + void setGrade(int _grade); + + void increment(void); + void decrement(void); + + class GradeTooLowException : public std::exception { + public: + virtual const char *what() const throw(); + }; + + class GradeTooHighException : public std::exception { + public: + virtual const char *what() const throw(); + }; +}; + +std::ostream& operator<<(std::ostream& o, const Bureaucrat& b); diff --git a/cpp00/ex_01/Makefile b/cpp05/ex00/Makefile similarity index 88% rename from cpp00/ex_01/Makefile rename to cpp05/ex00/Makefile index f89ca28..cad8606 100644 --- a/cpp00/ex_01/Makefile +++ b/cpp05/ex00/Makefile @@ -1,4 +1,4 @@ -NAME = phonebook +NAME = bureaucrat CC = g++ FLAG = -Wall -Wextra -Werror -std=c++98 SOURCE = $(wildcard *.cpp) @@ -14,6 +14,6 @@ fclean: clean rm -rf $(NAME) clean: - rm -rf $(OBJECT) + rm -rf re: fclean all \ No newline at end of file diff --git a/cpp03/ex00/claptrap b/cpp05/ex00/bureaucrat similarity index 57% rename from cpp03/ex00/claptrap rename to cpp05/ex00/bureaucrat index d8183fc..05c2fe8 100755 Binary files a/cpp03/ex00/claptrap and b/cpp05/ex00/bureaucrat differ diff --git a/cpp05/ex00/main.cpp b/cpp05/ex00/main.cpp new file mode 100644 index 0000000..1c46b0c --- /dev/null +++ b/cpp05/ex00/main.cpp @@ -0,0 +1,93 @@ +#include "Bureaucrat.hpp" + +int main(void) +{ + Bureaucrat b1("b1", 150); + Bureaucrat b2("b2", 1); + Bureaucrat b3("b3", 10); + Bureaucrat b4(b3); + b4 = b2; + + std::cout << std::endl; + + try + { + Bureaucrat b6("b6", 155); + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + + try + { + Bureaucrat b7("b7", 0); + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + + std::cout << std::endl; + + std::cout << b1 << std::endl; + std::cout << b2 << std::endl; + std::cout << b3 << std::endl; + std::cout << b4 << std::endl; + std::cout << std::endl; + + try + { + + std::cout << "************TEST1***********" << std::endl; + b1.decrement(); + + std::cout << b1 << std::endl; + + } + catch(const std::exception& e) + { + std::cerr << e.what() << std::endl; + } + + std::cout << std::endl; + + try + { + std::cout << "***********TEST2************" << std::endl; + b2.increment(); + std::cout << b2 << std::endl; + } + catch(const std::exception& e) + { + std::cerr << e.what() << std::endl; + } + + std::cout << std::endl; + + try + { + std::cout << "************TEST3***********" << std::endl; + b3.increment(); + std::cout << b3 << std::endl; + } + catch(const std::exception& e) + { + std::cerr << e.what() << std::endl; + } + + std::cout << std::endl; + + try + { + std::cout << "************TEST4***********" << std::endl; + b4.decrement(); + std::cout << b4 << std::endl; + } + catch(const std::exception& e) + { + std::cerr << e.what() << std::endl; + } + std::cout << std::endl; + return 0; +} \ No newline at end of file diff --git a/cpp05/ex01/Bureaucrat.cpp b/cpp05/ex01/Bureaucrat.cpp new file mode 100644 index 0000000..bd68098 --- /dev/null +++ b/cpp05/ex01/Bureaucrat.cpp @@ -0,0 +1,64 @@ +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat(const std::string _name, int _grade): name(_name) { + std::cout << green << "Bureaucrat constructor called" << white << std::endl; + this->setGrade(_grade); +} + +Bureaucrat::Bureaucrat(const Bureaucrat& _copy) { + *this = _copy; + std::cout << green << "Bureaucrat constructor called" << white << std::endl; +} + +const Bureaucrat& Bureaucrat::operator=(const Bureaucrat& _copy) { + this->setGrade(_copy.getGrade()); + this->setName(_copy.getName()); + return *this; +} + +void Bureaucrat::increment(void) { + this->setGrade(this->getGrade() - 1); +} +void Bureaucrat::decrement(void) { + this->setGrade(this->getGrade() + 1); +} + +Bureaucrat::~Bureaucrat() { std::cout << red << "Bureaucrat deconstructor" << white << std::endl;} + +void Bureaucrat::signForm(Form& c) { + if (c.getmustGrade() < this->getGrade()) { + std::cout << this->getName() << " couldn't sign " << c.getName() << " because " << std::endl; + throw GradeTooLowException(); + } else { + c.setisSigned(1); + std::cout << this->getName() << " signed " << c.getName() << std::endl; + } +} + +const std::string Bureaucrat::getName(void) const { return(this->name); } +void Bureaucrat::setName(std::string _n) { const_cast(this->name) = const_cast(_n); } +int Bureaucrat::getGrade(void) const { return(this->grade); } +void Bureaucrat::setGrade(int _grade) { + if (_grade > 150) { + this->grade = 0; + throw GradeTooLowException(); + } else if (_grade < 1) { + this->grade = 0; + throw GradeTooHighException(); + } else { + this->grade = _grade; + } +} + +std::ostream& operator<<(std::ostream& o, const Bureaucrat& b) { + o << b.getName() << ", grade level is " << b.getGrade(); + return (o); +} + +const char *Bureaucrat::GradeTooHighException::what() const throw() { + return "Grade is must be lower than"; +} + +const char *Bureaucrat::GradeTooLowException::what() const throw() { + return "Grade is must be bigger than"; +} diff --git a/cpp05/ex01/Bureaucrat.hpp b/cpp05/ex01/Bureaucrat.hpp new file mode 100644 index 0000000..82a0193 --- /dev/null +++ b/cpp05/ex01/Bureaucrat.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include "Form.hpp" + +#define green "\033[1;32m" +#define red "\033[1;31m" +#define white "\033[0m" + +class Form; + +class Bureaucrat { +protected: + const std::string name; + int grade; +public: + Bureaucrat(const std::string _name, int _grade); + Bureaucrat(const Bureaucrat& _copy); + const Bureaucrat& operator=(const Bureaucrat& _copy); + ~Bureaucrat(); + + void signForm(Form& c); + + const std::string getName(void) const; + void setName(std::string _n) ; + int getGrade(void) const; + void setGrade(int _grade); + + void increment(void); + void decrement(void); + + class GradeTooLowException : public std::exception { + public: + virtual const char *what() const throw(); + }; + + class GradeTooHighException : public std::exception { + public: + virtual const char *what() const throw(); + }; +}; + +std::ostream& operator<<(std::ostream& o, const Bureaucrat& b); diff --git a/cpp05/ex01/Form.cpp b/cpp05/ex01/Form.cpp new file mode 100644 index 0000000..27143f2 --- /dev/null +++ b/cpp05/ex01/Form.cpp @@ -0,0 +1,77 @@ +#include "Form.hpp" + +Form::Form(std::string _name, int _mustGrade, int _mustExecute): isSigned(0), mustGrade(_mustGrade), mustExecute(_mustExecute) { + this->setmustGrade(_mustGrade); + this->setmustExecute(_mustExecute); + this->setName(_name); + std::cout << green << "Form constructor" << white << std::endl; +} + +Form::Form(Form& c): isSigned(c.getSigned()), mustGrade(c.getmustGrade()), mustExecute(c.getmustExecute()) { + std::cout << green << "Form copy constructor" << white << std::endl; +} + +Form::~Form() { + std::cout << red << "Form Deconstructor Called" << white << std::endl; +} + +Form& Form::operator=(Form& c) { + this->setName(c.getName()); + this->setisSigned(c.getSigned()); + this->setmustGrade(c.getmustGrade()); + this->setmustExecute(c.getmustExecute()); + return *this; +} + +void Form::beSigned(Bureaucrat& c) { + if (c.getGrade() > this->getmustGrade()) { + throw GradeTooLowException(); + } else { + std::cout << this->getName() << ", signed from " << c.getName() << std::endl; + } +} + +const std::string Form::getName() const {return this->name;} +const bool Form::getSigned() const {return this->isSigned;} +const int Form::getmustGrade() const {return this->mustGrade;} +const int Form::getmustExecute() const {return this->mustExecute;} + + +void Form::setName(std::string nameTmp) { const_cast(this->name) = const_cast(nameTmp); } +void Form::setisSigned(bool signedTmp) { this->isSigned = signedTmp; } + +void Form::setmustGrade(const int mustGradeTmp) { + if (mustGradeTmp > 150) { + throw GradeTooLowException(); + } else if (mustGradeTmp < 1) { + throw GradeTooHightException(); + } else { + const_cast(this->mustGrade) = const_cast(mustGradeTmp); + } +} + +void Form::setmustExecute(int mustExecuteTmp) { + if (mustExecuteTmp > 150) { + throw GradeTooLowException(); + } else if (mustExecuteTmp < 1) { + throw GradeTooHightException(); + } else { + const_cast(this->mustExecute) = const_cast(mustExecuteTmp); + } +} + +const char *Form::GradeTooLowException::what() const throw() { + return "Grade must be bigger than"; +} + +const char *Form::GradeTooHightException::what() const throw() { + return "Grade must be lower than"; +} + +std::ostream& operator<<(std::ostream& o, Form& n) { + o << "name " << n.getName() + << " signed " << n.getSigned() + << " Grade " << n.getmustGrade() + << " Execute " << n.getmustExecute(); + return o; +} diff --git a/cpp05/ex01/Form.hpp b/cpp05/ex01/Form.hpp new file mode 100644 index 0000000..d9b04d2 --- /dev/null +++ b/cpp05/ex01/Form.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include "Bureaucrat.hpp" + +class Bureaucrat; + +class Form { +private: + const std::string name; + bool isSigned; + const int mustGrade; + const int mustExecute; +public: + Form(std::string _name, int _mustGrade, int _mustExecute); + Form(Form& c); + ~Form(); + + Form& operator=(Form& c); + + void beSigned(Bureaucrat& c); + + const std::string getName() const; + const bool getSigned() const; + const int getmustGrade() const; + const int getmustExecute() const; + + void setName(std::string nameTmp); + void setisSigned(bool signedTmp); + void setmustGrade(const int mustGradeTmp); + void setmustExecute(const int mustExecuteTmp); + + class GradeTooLowException : public std::exception { + public: + virtual const char *what() const throw(); + }; + class GradeTooHightException : public std::exception { + public: + virtual const char *what() const throw(); + }; +}; + +std::ostream& operator<<(std::ostream& o, Form& n); diff --git a/cpp00/ex_00/Makefile b/cpp05/ex01/Makefile similarity index 94% rename from cpp00/ex_00/Makefile rename to cpp05/ex01/Makefile index 8552166..2e2139b 100644 --- a/cpp00/ex_00/Makefile +++ b/cpp05/ex01/Makefile @@ -1,4 +1,4 @@ -NAME = megaphone +NAME = form CC = g++ FLAG = -Wall -Wextra -Werror -std=c++98 SOURCE = $(wildcard *.cpp) diff --git a/cpp03/ex02/fragtrap b/cpp05/ex01/form similarity index 57% rename from cpp03/ex02/fragtrap rename to cpp05/ex01/form index d8ed85c..229dd28 100755 Binary files a/cpp03/ex02/fragtrap and b/cpp05/ex01/form differ diff --git a/cpp05/ex01/main.cpp b/cpp05/ex01/main.cpp new file mode 100644 index 0000000..5ed223d --- /dev/null +++ b/cpp05/ex01/main.cpp @@ -0,0 +1,65 @@ +#include "Bureaucrat.hpp" +#include "Form.hpp" + +int main(void) +{ + Bureaucrat b1("b1", 99); + Bureaucrat b2("b2", 10); + + try + { + std::cout << "=========Test 1=========" << std::endl; + Form f1("f1", 51, 70); + Form f2("f2", 100, 151); + + std::cout << f1 << std::endl; + std::cout << std::endl; + std::cout << f2 << std::endl; + } + catch(const std::exception& e) + { + std::cerr << e.what() << std::endl; + } + + std::cout << std::endl; + + try + { + std::cout << "=========Test 2=========" << std::endl; + Form f3("f3", 50, 30); + Form f4 = f3; + f3.beSigned(b1); + f4.beSigned(b2); + + b1.signForm(f3); + b2.signForm(f4); + std::cout << std::endl; + + std::cout << f3 << std::endl; + std::cout << std::endl; + std::cout << f4 << std::endl; + std::cout << std::endl; + } + catch(const std::exception& e) + { + std::cerr << e.what() << std::endl; + } + + try + { + std::cout << "=========Test 2=========" << std::endl; + Form f5("f5", 50, 11); + f5.beSigned(b2); + + b2.signForm(f5); + std::cout << std::endl; + + std::cout << f5 << std::endl; + std::cout << std::endl; + } + catch(const std::exception& e) + { + std::cerr << e.what() << std::endl; + } + return 0; +} \ No newline at end of file diff --git a/cpp05/ex02/AForm.cpp b/cpp05/ex02/AForm.cpp new file mode 100644 index 0000000..1848cd9 --- /dev/null +++ b/cpp05/ex02/AForm.cpp @@ -0,0 +1,86 @@ +#include "AForm.hpp" + +AForm::AForm(): mustGrade(0), mustExecute(0) { + std::cout << green << "AForm constructor" << white << std::endl; +} + +AForm::AForm(std::string _name, int _mustGrade, int _mustExecute): isSigned(0), mustGrade(_mustGrade), mustExecute(_mustExecute) { + this->setmustGrade(_mustGrade); + this->setmustExecute(_mustExecute); + this->setName(_name); + std::cout << green << "AForm constructor" << white << std::endl; +} + +AForm::AForm(AForm& c): isSigned(c.getSigned()), mustGrade(c.getmustGrade()), mustExecute(c.getmustExecute()) { + std::cout << green << "AForm copy constructor" << white << std::endl; +} + +AForm::~AForm() { + std::cout << red << "AForm Deconstructor Called" << white << std::endl; +} + +AForm& AForm::operator=(AForm& c) { + this->setName(c.getName()); + this->setisSigned(c.getSigned()); + this->setmustGrade(c.getmustGrade()); + this->setmustExecute(c.getmustExecute()); + return *this; +} + +void AForm::beSigned(Bureaucrat& c) { + if (c.getGrade() > this->getmustGrade()) { + throw GradeTooLowException(); + } else { + this->setisSigned(1); + std::cout << this->getName() << ", signed from " << c.getName() << std::endl; + } +} + +void AForm::execute(const Bureaucrat& executer) const { + std::cout << this->getName() << ", executed from " << executer.getName(); +} + +const std::string AForm::getName() const {return this->name;} +const bool AForm::getSigned() const {return this->isSigned;} +const int AForm::getmustGrade() const {return this->mustGrade;} +const int AForm::getmustExecute() const {return this->mustExecute;} + + +void AForm::setName(std::string nameTmp) { const_cast(this->name) = const_cast(nameTmp); } +void AForm::setisSigned(bool signedTmp) { this->isSigned = signedTmp; } + +void AForm::setmustGrade(const int mustGradeTmp) { + if (mustGradeTmp > 150) { + throw GradeTooLowException(); + } else if (mustGradeTmp < 1) { + throw GradeTooHightException(); + } else { + const_cast(this->mustGrade) = const_cast(mustGradeTmp); + } +} + +void AForm::setmustExecute(int mustExecuteTmp) { + if (mustExecuteTmp > 150) { + throw GradeTooLowException(); + } else if (mustExecuteTmp < 1) { + throw GradeTooHightException(); + } else { + const_cast(this->mustExecute) = const_cast(mustExecuteTmp); + } +} + +const char *AForm::GradeTooLowException::what() const throw() { + return "Grade must be bigger than"; +} + +const char *AForm::GradeTooHightException::what() const throw() { + return "Grade must be lower than"; +} + +std::ostream& operator<<(std::ostream& o, AForm& n) { + o << "name " << n.getName() + << " signed " << n.getSigned() + << " Grade " << n.getmustGrade() + << " Execute " << n.getmustExecute(); + return o; +} diff --git a/cpp05/ex02/AForm.hpp b/cpp05/ex02/AForm.hpp new file mode 100644 index 0000000..fc108a3 --- /dev/null +++ b/cpp05/ex02/AForm.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include "Bureaucrat.hpp" + +#define green "\033[1;32m" +#define red "\033[1;31m" +#define white "\033[0m" + +class Bureaucrat; + +class AForm { +private: + const std::string name; + bool isSigned; + const int mustGrade; + const int mustExecute; +public: + AForm(); + AForm(std::string _name, int _mustGrade, int _mustExecute); + AForm(AForm& c); + virtual ~AForm(); + + AForm& operator=(AForm& c); + + void beSigned(Bureaucrat& c); + virtual void execute(const Bureaucrat& executer) const = 0; + + const std::string getName() const; + const bool getSigned() const; + const int getmustGrade() const; + const int getmustExecute() const; + + void setName(std::string nameTmp); + void setisSigned(bool signedTmp); + void setmustGrade(const int mustGradeTmp); + void setmustExecute(const int mustExecuteTmp); + + class GradeTooLowException : public std::exception { + public: + virtual const char *what() const throw(); + }; + class GradeTooHightException : public std::exception { + public: + virtual const char *what() const throw(); + }; +}; + +std::ostream& operator<<(std::ostream& o, AForm& n); diff --git a/cpp05/ex02/Bureaucrat.cpp b/cpp05/ex02/Bureaucrat.cpp new file mode 100644 index 0000000..b502e68 --- /dev/null +++ b/cpp05/ex02/Bureaucrat.cpp @@ -0,0 +1,88 @@ +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat(const std::string _name, int _grade): name(_name) { + std::cout << green << "Bureaucrat constructor called" << white << std::endl; + try { + this->setGrade(_grade); + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + } +} + +Bureaucrat::Bureaucrat(const Bureaucrat& _copy) { + *this = _copy; + std::cout << green << "Bureaucrat constructor called" << white << std::endl; +} + +const Bureaucrat& Bureaucrat::operator=(const Bureaucrat& _copy) { + try { + this->setGrade(_copy.getGrade()); + this->setName(_copy.getName()); + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + } + return *this; +} + +void Bureaucrat::increment(void) { + try { + this->setGrade(this->getGrade() - 1); + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + } +} +void Bureaucrat::decrement(void) { + try { + this->setGrade(this->getGrade() + 1); + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + } +} + +Bureaucrat::~Bureaucrat() { std::cout << red << "Bureaucrat deconstructor" << white << std::endl;} + +void Bureaucrat::signForm(AForm& c) const { + try { + if (c.getmustGrade() < this->getGrade()) { + std::cout << this->getName() << " couldn't sign " << c.getName() << " because " << std::endl; + throw GradeTooLowException(); + } else { + c.setisSigned(1); + std::cout << this->getName() << " signed " << c.getName() << std::endl; + } + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + } +} + +void Bureaucrat::executeForm(const AForm& form) { + form.execute(*this); +} + +const std::string Bureaucrat::getName(void) const { return(this->name); } +void Bureaucrat::setName(std::string _n) { const_cast(this->name) = const_cast(_n); } +int Bureaucrat::getGrade(void) const { return(this->grade); } +void Bureaucrat::setGrade(int _grade) { + if (_grade > 150) { + this->grade = 0; + throw GradeTooLowException(); + } else if (_grade < 1) { + this->grade = 0; + throw GradeTooHighException(); + } else { + this->grade = _grade; + } +} + +std::ostream& operator<<(std::ostream& o, const Bureaucrat& b) { + o << b.getName() << ", grade level is " << b.getGrade(); + return (o); +} + +const char *Bureaucrat::GradeTooHighException::what() const throw() { + return "Grade is must be lower than"; +} + +const char *Bureaucrat::GradeTooLowException::what() const throw() { + return "Grade is must be bigger than"; +} diff --git a/cpp05/ex02/Bureaucrat.hpp b/cpp05/ex02/Bureaucrat.hpp new file mode 100644 index 0000000..20cba3b --- /dev/null +++ b/cpp05/ex02/Bureaucrat.hpp @@ -0,0 +1,48 @@ +#ifndef BUREAUCRAT_HPP +#define BUREAUCRAT_HPP + +#include +#include +#include "AForm.hpp" + +#define green "\033[1;32m" +#define red "\033[1;31m" +#define white "\033[0m" + +class AForm; + +class Bureaucrat { +protected: + const std::string name; + int grade; +public: + Bureaucrat(const std::string _name, int _grade); + Bureaucrat(const Bureaucrat& _copy); + const Bureaucrat& operator=(const Bureaucrat& _copy); + ~Bureaucrat(); + + void signForm(AForm& c) const ; + void executeForm(const AForm& form); + + const std::string getName(void) const; + void setName(std::string _n) ; + int getGrade(void) const; + void setGrade(int _grade); + + void increment(void); + void decrement(void); + + class GradeTooLowException : public std::exception { + public: + virtual const char *what() const throw(); + }; + + class GradeTooHighException : public std::exception { + public: + virtual const char *what() const throw(); + }; +}; + +std::ostream& operator<<(std::ostream& o, const Bureaucrat& b); + +#endif \ No newline at end of file diff --git a/cpp00/ex_02/Makefile b/cpp05/ex02/Makefile similarity index 94% rename from cpp00/ex_02/Makefile rename to cpp05/ex02/Makefile index a42bc56..75246ed 100644 --- a/cpp00/ex_02/Makefile +++ b/cpp05/ex02/Makefile @@ -1,4 +1,4 @@ -NAME = account +NAME = form CC = g++ FLAG = -Wall -Wextra -Werror -std=c++98 SOURCE = $(wildcard *.cpp) diff --git a/cpp05/ex02/PresidentialPardonForm.cpp b/cpp05/ex02/PresidentialPardonForm.cpp new file mode 100644 index 0000000..7c5816c --- /dev/null +++ b/cpp05/ex02/PresidentialPardonForm.cpp @@ -0,0 +1,39 @@ +#include "PresidentialPardonForm.hpp" + +PresidentialPardonForm::PresidentialPardonForm(): AForm() { + +} + +PresidentialPardonForm::PresidentialPardonForm(std::string _target): target(_target) { + this->setName("PresidentialPardonForm"); + this->setmustExecute(5); + this->setmustGrade(25); + std::cout << green << "PresidentialPardonForm constructor called" << white << std::endl; +} + +PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm& _copy) { + *this = _copy; + std::cout << green << "PresidentialPardonForm copy called" << white << std::endl; +} + +const PresidentialPardonForm& PresidentialPardonForm::operator=(const PresidentialPardonForm& _copy) { + this->setisSigned(_copy.getSigned()); + this->setmustExecute(_copy.getmustExecute()); + this->setmustGrade(_copy.getmustGrade()); + this->setName(_copy.getName()); + return *this; +} + +PresidentialPardonForm::~PresidentialPardonForm() { + std::cout << red << "PresidentialPardonForm deconstructor" << white << std::endl; +} + +void PresidentialPardonForm::execute(Bureaucrat const& executer) const { + if (executer.getGrade() > this->getmustGrade() || executer.getGrade() > this->getmustExecute()) + throw GradeTooLowException(); + else if (this->getSigned() == false) + std::cout << "Form not signed" << std::endl; + else { + std::cout << "Informs that " << this->target << " has been pardoned by Zaphod Beeblebrox" << std::endl; + } +} diff --git a/cpp05/ex02/PresidentialPardonForm.hpp b/cpp05/ex02/PresidentialPardonForm.hpp new file mode 100644 index 0000000..617fd85 --- /dev/null +++ b/cpp05/ex02/PresidentialPardonForm.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include "AForm.hpp" + +class AForm; + +class PresidentialPardonForm : public AForm { +private: + std::string target; +public: + void execute(Bureaucrat const& executer) const ; + + PresidentialPardonForm(); + PresidentialPardonForm(std::string _target); + PresidentialPardonForm(const PresidentialPardonForm& _copy); + const PresidentialPardonForm& operator=(const PresidentialPardonForm& _copy); + ~PresidentialPardonForm(); +}; diff --git a/cpp05/ex02/RobotomyRequestForm.cpp b/cpp05/ex02/RobotomyRequestForm.cpp new file mode 100644 index 0000000..41dfd5b --- /dev/null +++ b/cpp05/ex02/RobotomyRequestForm.cpp @@ -0,0 +1,39 @@ +#include "RobotomyRequestForm.hpp" + +RobotomyRequestForm::RobotomyRequestForm(std::string _target): target(_target) { + this->setName("RobotomyRequestForm"); + this->setmustGrade(72); + this->setmustExecute(45); + std::cout << green << "Robotomy default const called" << white << std::endl; +} + +RobotomyRequestForm::RobotomyRequestForm(RobotomyRequestForm& c) { + *this = c; + std::cout << green << "Robotomy copy const called" << white << std::endl; +} + +RobotomyRequestForm& RobotomyRequestForm::operator=(const RobotomyRequestForm& c) { + this->setisSigned(c.getSigned()); + this->setmustExecute(c.getmustExecute()); + this->setmustGrade(c.getmustGrade()); + this->setName(c.getName()); + return *this; +} + +RobotomyRequestForm::~RobotomyRequestForm() { + std::cout << red << "Robotomy deconst called" << white << std::endl; +} + +void RobotomyRequestForm::execute(const Bureaucrat& executer) const { + std::srand(std::time(NULL)); + if (executer.getGrade() > this->getmustGrade() || executer.getGrade() > this->getmustExecute()) + throw GradeTooLowException(); + else if (this->getSigned() == false) + std::cout << "Form not signed" << std::endl; + else { + if (rand() % 2 == 0) + std::cout << this->target << " has been robotomized succesfully" << std::endl; + else + std::cout << this->target << " has been robotomized failed" << std::endl; + } +} diff --git a/cpp05/ex02/RobotomyRequestForm.hpp b/cpp05/ex02/RobotomyRequestForm.hpp new file mode 100644 index 0000000..d5dcca9 --- /dev/null +++ b/cpp05/ex02/RobotomyRequestForm.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "AForm.hpp" +#include + +class RobotomyRequestForm : public AForm { +private: + std::string target; +public: + void execute(const Bureaucrat& executer) const ; + + RobotomyRequestForm(std::string _target); + RobotomyRequestForm(RobotomyRequestForm& c); + RobotomyRequestForm& operator=(const RobotomyRequestForm& c); + ~RobotomyRequestForm(); +}; \ No newline at end of file diff --git a/cpp05/ex02/ShrubberyCreationForm.cpp b/cpp05/ex02/ShrubberyCreationForm.cpp new file mode 100644 index 0000000..870d33a --- /dev/null +++ b/cpp05/ex02/ShrubberyCreationForm.cpp @@ -0,0 +1,57 @@ +#include "ShrubberyCreationForm.hpp" + +ShrubberyCreationForm::ShrubberyCreationForm(std::string _target): target(_target) { + this->setisSigned(false); + this->setmustGrade(145); + this->setmustExecute(137); + this->setName("ShrubberyCreationForm"); + std::cout << green << "ShrubberyCreation constructor called" << white << std::endl; +} + +ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm& c) { + *this = c; + std::cout << green << "ShrubberyCreation copy constructor called" << white << std::endl; +} + +ShrubberyCreationForm::~ShrubberyCreationForm() { + std::cout << green << "ShrubberyCreation deconstructor called" << white << std::endl; +} + +ShrubberyCreationForm& ShrubberyCreationForm::operator=(const ShrubberyCreationForm& c) { + this->setisSigned(c.getSigned()); + this->setmustExecute(c.getmustExecute()); + this->setmustGrade(c.getmustGrade()); + this->setName(c.getName()); + return *this; +} + +void ShrubberyCreationForm::execute(const Bureaucrat& executer) const { + if (executer.getGrade() > this->getmustGrade() || executer.getGrade() > this->getmustExecute()) + throw GradeTooLowException(); + else if (this->getSigned() == false) + std::cout << "Form not signed" << std::endl; + else { + std::string ascii_trees = "\n" + " O O\n" + " $$$ $$$\n" + " $$$$$ $$$$$\n" + " $$$$$$$ $$$$$$$\n" + " $$$$$$$$$ $$$$$$$$$\n" + " $$$$$$$$$$$ $$$$$$$$$$$\n" + " $$$$$$$$$$$$$ $$$$$$$$$$$$$\n" + " $$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$\n" + " $$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$\n" + "$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$\n" + " ||| |||\n" + " ||| |||\n" + " ||| |||\n" + " ||| |||"; + std::string filename(this->target + "_shrubbery"); + std::ofstream a(filename, std::ofstream::trunc | std::ofstream::out); + if (a.is_open()) + a << ascii_trees << std::endl; + else + std::cout << "file is not created" << std::endl; + a.close(); + } +} \ No newline at end of file diff --git a/cpp05/ex02/ShrubberyCreationForm.hpp b/cpp05/ex02/ShrubberyCreationForm.hpp new file mode 100644 index 0000000..54b9ed8 --- /dev/null +++ b/cpp05/ex02/ShrubberyCreationForm.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "AForm.hpp" +#include +#include + +class ShrubberyCreationForm : public AForm { +private: + std::string target; +public: + ShrubberyCreationForm(std::string _target); + ShrubberyCreationForm(const ShrubberyCreationForm& c); + ShrubberyCreationForm& operator=(const ShrubberyCreationForm& c); + virtual ~ShrubberyCreationForm(); + + void execute(const Bureaucrat& executer) const ; +}; \ No newline at end of file diff --git a/cpp05/ex02/Shrubbery_shrubbery b/cpp05/ex02/Shrubbery_shrubbery new file mode 100644 index 0000000..02f050e --- /dev/null +++ b/cpp05/ex02/Shrubbery_shrubbery @@ -0,0 +1,15 @@ + + O O + $$$ $$$ + $$$$$ $$$$$ + $$$$$$$ $$$$$$$ + $$$$$$$$$ $$$$$$$$$ + $$$$$$$$$$$ $$$$$$$$$$$ + $$$$$$$$$$$$$ $$$$$$$$$$$$$ + $$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ + $$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$ +$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$ + ||| ||| + ||| ||| + ||| ||| + ||| ||| diff --git a/cpp05/ex02/eyup_shrubbery b/cpp05/ex02/eyup_shrubbery new file mode 100644 index 0000000..02f050e --- /dev/null +++ b/cpp05/ex02/eyup_shrubbery @@ -0,0 +1,15 @@ + + O O + $$$ $$$ + $$$$$ $$$$$ + $$$$$$$ $$$$$$$ + $$$$$$$$$ $$$$$$$$$ + $$$$$$$$$$$ $$$$$$$$$$$ + $$$$$$$$$$$$$ $$$$$$$$$$$$$ + $$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ + $$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$ +$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$ + ||| ||| + ||| ||| + ||| ||| + ||| ||| diff --git a/cpp05/ex02/form b/cpp05/ex02/form new file mode 100755 index 0000000..e0e3347 Binary files /dev/null and b/cpp05/ex02/form differ diff --git a/cpp05/ex02/main.cpp b/cpp05/ex02/main.cpp new file mode 100644 index 0000000..b748527 --- /dev/null +++ b/cpp05/ex02/main.cpp @@ -0,0 +1,116 @@ +#include "ShrubberyCreationForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "PresidentialPardonForm.hpp" + +int main(void) +{ + Bureaucrat b1("b1", 1); + Bureaucrat b2("b2", 50); + Bureaucrat b3("b3", 150); + + std::cout << std::endl; + try + { + Bureaucrat b4("b4", 160); + } + catch(const std::exception& e) + { + std::cout << e.what() << std::endl; + } + + std::cout << std::endl; + try{ + std::cout << "===========ShrubberyCreationForm Success Test===========" << std::endl; + ShrubberyCreationForm s1("eyup"); + s1.beSigned(b1); + b1.signForm(s1); + b1.executeForm(s1); + std::cout << std::endl; + std::cout << s1 << std::endl; + std::cout << std::endl << std::endl; + } + catch(std::exception & e) + { + std::cout << e.what() << std::endl; + } + + std::cout << std::endl; + try{ + + std::cout << "============ShrubberyCreationForm Fail Test============" << std::endl; + ShrubberyCreationForm s2("furkan"); + s2.beSigned(b3); + b3.signForm(s2); + b3.executeForm(s2); + std::cout << std::endl; + std::cout << s2 << std::endl; + std::cout << std::endl << std::endl; + } + catch(std::exception & e) + { + std::cout << e.what() << std::endl; + } + + std::cout << std::endl; + try{ + std::cout << "============RobotomyRequestForm Success Test============" << std::endl; + RobotomyRequestForm r1("Robotomy"); + r1.beSigned(b1); + b1.signForm(r1); + b1.executeForm(r1); + std::cout << std::endl; + std::cout << r1 << std::endl; + std::cout << std::endl << std::endl; + } + catch(std::exception & e) + { + std::cout << e.what() << std::endl; + } + std::cout << std::endl; + try{ + std::cout << "=============RobotomyRequestForm Fail Test=============" << std::endl; + RobotomyRequestForm r2("Robotomy"); + r2.beSigned(b2); + b2.signForm(r2); + b2.executeForm(r2); + std::cout << std::endl; + std::cout << r2 << std::endl; + std::cout << std::endl << std::endl; + } + catch(std::exception & e) + { + std::cout << e.what() << std::endl; + } + std::cout << std::endl; + try{ + std::cout << "===========PresidentialPardonForm Success Test===========" << std::endl; + PresidentialPardonForm p1("Presidential"); + p1.beSigned(b1); + b1.signForm(p1); + b1.executeForm(p1); + std::cout << std::endl; + std::cout << p1 << std::endl; + std::cout << std::endl << std::endl; + } + catch (std::exception & e) + { + std::cout << e.what() << std::endl; + } + + std::cout << std::endl; + try{ + std::cout << "============PresidentialPardonForm Fail Test============" << std::endl; + PresidentialPardonForm p2("Presidential"); + p2.beSigned(b2); + b2.signForm(p2); + b2.executeForm(p2); + std::cout << std::endl; + std::cout << p2 << std::endl; + std::cout << std::endl << std::endl; + } + catch(std::exception & e) + { + std::cout << e.what() << std::endl; + } + return 0; +} \ No newline at end of file diff --git a/cpp05/ex03/Bureaucrat.cpp b/cpp05/ex03/Bureaucrat.cpp new file mode 100644 index 0000000..2ffb30e --- /dev/null +++ b/cpp05/ex03/Bureaucrat.cpp @@ -0,0 +1,89 @@ +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat(const std::string _name, int _grade): name(_name) { + std::cout << green << "Bureaucrat constructor called" << white << std::endl; + try { + this->setGrade(_grade); + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + } +} + +Bureaucrat::Bureaucrat(const Bureaucrat& _copy) { + *this = _copy; + std::cout << green << "Bureaucrat constructor called" << white << std::endl; +} + +const Bureaucrat& Bureaucrat::operator=(const Bureaucrat& _copy) { + try { + this->setGrade(_copy.getGrade()); + this->setName(_copy.getName()); + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + } + return *this; +} + +void Bureaucrat::increment(void) { + try { + this->setGrade(this->getGrade() - 1); + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + } +} +void Bureaucrat::decrement(void) { + try { + this->setGrade(this->getGrade() + 1); + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + } +} + +Bureaucrat::~Bureaucrat() { std::cout << red << "Bureaucrat deconstructor" << white << std::endl;} + +void Bureaucrat::signForm(Form& c) const { + try { + if (c.getmustGrade() < this->getGrade()) { + std::cout << this->getName() << " couldn't sign " << c.getName() << " because " << std::endl; + throw GradeTooLowException(); + } else { + c.setisSigned(1); + std::cout << this->getName() << " signed " << c.getName() << std::endl; + } + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + } +} + +void Bureaucrat::executeForm(const Form& form) { + form.execute(*this); + // std::cout << form.getName() << "executed from " << this->getName() << std::endl; +} + +const std::string Bureaucrat::getName(void) const { return(this->name); } +void Bureaucrat::setName(std::string _n) { const_cast(this->name) = const_cast(_n); } +int Bureaucrat::getGrade(void) const { return(this->grade); } +void Bureaucrat::setGrade(int _grade) { + if (_grade > 150) { + this->grade = 0; + throw GradeTooLowException(); + } else if (_grade < 1) { + this->grade = 0; + throw GradeTooHighException(); + } else { + this->grade = _grade; + } +} + +std::ostream& operator<<(std::ostream& o, const Bureaucrat& b) { + o << b.getName() << ", grade level is " << b.getGrade(); + return (o); +} + +const char *Bureaucrat::GradeTooHighException::what() const throw() { + return "Grade is must be lower than"; +} + +const char *Bureaucrat::GradeTooLowException::what() const throw() { + return "Grade is must be bigger than"; +} diff --git a/cpp05/ex03/Bureaucrat.hpp b/cpp05/ex03/Bureaucrat.hpp new file mode 100644 index 0000000..22dd04e --- /dev/null +++ b/cpp05/ex03/Bureaucrat.hpp @@ -0,0 +1,48 @@ +#ifndef BUREAUCRAT_HPP +#define BUREAUCRAT_HPP + +#include +#include +#include "Form.hpp" + +#define green "\033[1;32m" +#define red "\033[1;31m" +#define white "\033[0m" + +class Form; + +class Bureaucrat { +protected: + const std::string name; + int grade; +public: + Bureaucrat(const std::string _name, int _grade); + Bureaucrat(const Bureaucrat& _copy); + const Bureaucrat& operator=(const Bureaucrat& _copy); + ~Bureaucrat(); + + void signForm(Form& c) const ; + void executeForm(const Form& form); + + const std::string getName(void) const; + void setName(std::string _n) ; + int getGrade(void) const; + void setGrade(int _grade); + + void increment(void); + void decrement(void); + + class GradeTooLowException : public std::exception { + public: + virtual const char *what() const throw(); + }; + + class GradeTooHighException : public std::exception { + public: + virtual const char *what() const throw(); + }; +}; + +std::ostream& operator<<(std::ostream& o, const Bureaucrat& b); + +#endif \ No newline at end of file diff --git a/cpp05/ex03/Form.cpp b/cpp05/ex03/Form.cpp new file mode 100644 index 0000000..84ac08b --- /dev/null +++ b/cpp05/ex03/Form.cpp @@ -0,0 +1,86 @@ +#include "Form.hpp" + +Form::Form(): mustGrade(0), mustExecute(0) { + std::cout << green << "Form constructor" << white << std::endl; +} + +Form::Form(std::string _name, int _mustGrade, int _mustExecute): isSigned(0), mustGrade(_mustGrade), mustExecute(_mustExecute) { + this->setmustGrade(_mustGrade); + this->setmustExecute(_mustExecute); + this->setName(_name); + std::cout << green << "Form constructor" << white << std::endl; +} + +Form::Form(Form& c): isSigned(c.getSigned()), mustGrade(c.getmustGrade()), mustExecute(c.getmustExecute()) { + std::cout << green << "Form copy constructor" << white << std::endl; +} + +Form::~Form() { + std::cout << red << "Form Deconstructor Called" << white << std::endl; +} + +Form& Form::operator=(Form& c) { + this->setName(c.getName()); + this->setisSigned(c.getSigned()); + this->setmustGrade(c.getmustGrade()); + this->setmustExecute(c.getmustExecute()); + return *this; +} + +void Form::beSigned(Bureaucrat& c) { + if (c.getGrade() > this->getmustGrade()) { + throw GradeTooLowException(); + } else { + this->setisSigned(1); + std::cout << this->getName() << ", signed from " << c.getName() << std::endl; + } +} + +void Form::execute(const Bureaucrat& executer) const { + std::cout << this->getName() << ", executed from " << executer.getName(); +} + +const std::string Form::getName() const {return this->name;} +const bool Form::getSigned() const {return this->isSigned;} +const int Form::getmustGrade() const {return this->mustGrade;} +const int Form::getmustExecute() const {return this->mustExecute;} + + +void Form::setName(std::string nameTmp) { const_cast(this->name) = const_cast(nameTmp); } +void Form::setisSigned(bool signedTmp) { this->isSigned = signedTmp; } + +void Form::setmustGrade(const int mustGradeTmp) { + if (mustGradeTmp > 150) { + throw GradeTooLowException(); + } else if (mustGradeTmp < 1) { + throw GradeTooHightException(); + } else { + const_cast(this->mustGrade) = const_cast(mustGradeTmp); + } +} + +void Form::setmustExecute(int mustExecuteTmp) { + if (mustExecuteTmp > 150) { + throw GradeTooLowException(); + } else if (mustExecuteTmp < 1) { + throw GradeTooHightException(); + } else { + const_cast(this->mustExecute) = const_cast(mustExecuteTmp); + } +} + +const char *Form::GradeTooLowException::what() const throw() { + return "Grade must be bigger than"; +} + +const char *Form::GradeTooHightException::what() const throw() { + return "Grade must be lower than"; +} + +std::ostream& operator<<(std::ostream& o, Form& n) { + o << "name " << n.getName() + << " signed " << n.getSigned() + << " Grade " << n.getmustGrade() + << " Execute " << n.getmustExecute(); + return o; +} diff --git a/cpp05/ex03/Form.hpp b/cpp05/ex03/Form.hpp new file mode 100644 index 0000000..58dc1ec --- /dev/null +++ b/cpp05/ex03/Form.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include "Bureaucrat.hpp" + +#define green "\033[1;32m" +#define red "\033[1;31m" +#define white "\033[0m" + +class Bureaucrat; + +class Form { +private: + const std::string name; + bool isSigned; + const int mustGrade; + const int mustExecute; +public: + Form(); + Form(std::string _name, int _mustGrade, int _mustExecute); + Form(Form& c); + virtual ~Form(); + + Form& operator=(Form& c); + + void beSigned(Bureaucrat& c); + virtual void execute(const Bureaucrat& executer) const = 0; + + const std::string getName() const; + const bool getSigned() const; + const int getmustGrade() const; + const int getmustExecute() const; + + void setName(std::string nameTmp); + void setisSigned(bool signedTmp); + void setmustGrade(const int mustGradeTmp); + void setmustExecute(const int mustExecuteTmp); + + class GradeTooLowException : public std::exception { + public: + virtual const char *what() const throw(); + }; + class GradeTooHightException : public std::exception { + public: + virtual const char *what() const throw(); + }; +}; + +std::ostream& operator<<(std::ostream& o, Form& n); diff --git a/cpp05/ex03/Intern.cpp b/cpp05/ex03/Intern.cpp new file mode 100644 index 0000000..491e2c7 --- /dev/null +++ b/cpp05/ex03/Intern.cpp @@ -0,0 +1,43 @@ +#include "Intern.hpp" +#include + +Intern::Intern() { + std::cout << green << "The slave has been created" << white << std::endl; +} + +Intern::Intern(Intern& c) { + *this = c; +} + +Intern& Intern::operator=(Intern& c) { + std::cout << "assaingment" << green << "operator" << white << "called" << std::endl; + return *this; +} + +Intern::~Intern() { + std::cout << red << "The slave need a break" << white << std::endl; +} + +Form* Intern::makeForm(std::string s1, std::string s2) { + std::string name[3] = {"PresidentialPardonForm", "RobotomyRequestForm", "ShrubberyCreationForm"}; + int i = 0; + for (; name[i].find(s1) && i < 3;i ++) { + ; + } + switch (i) + { + case 0: + return new PresidentialPardonForm(s2); + case 1: + return new RobotomyRequestForm(s2); + case 2: + return new ShrubberyCreationForm(s2); + default: + break; + } + return NULL; +} + +const char *Intern::FormNotFound::what() const throw() { + return "Form can not created"; +} diff --git a/cpp05/ex03/Intern.hpp b/cpp05/ex03/Intern.hpp new file mode 100644 index 0000000..8730854 --- /dev/null +++ b/cpp05/ex03/Intern.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "PresidentialPardonForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "ShrubberyCreationForm.hpp" + +class Intern { +public: + Intern(); + Intern(Intern& c); + Intern& operator=(Intern& c); + ~Intern(); + + Form* makeForm(std::string name, std::string target); + + class FormNotFound : public std::exception { + virtual const char *what() const throw(); + }; +}; diff --git a/cpp04/ex01/Makefile b/cpp05/ex03/Makefile similarity index 80% rename from cpp04/ex01/Makefile rename to cpp05/ex03/Makefile index b493cd4..e91e6c5 100644 --- a/cpp04/ex01/Makefile +++ b/cpp05/ex03/Makefile @@ -1,6 +1,6 @@ -NAME = worldonfire +NAME = form CC = g++ -FLAG = -Wall -Wextra -Werror -std=c++98 +FLAG = -Wall -Wextra -Werror SOURCE = $(wildcard *.cpp) OBJECT = $(patsubst %.cpp, %.o, $(SOURCE)) diff --git a/cpp05/ex03/PresidentialPardonForm.cpp b/cpp05/ex03/PresidentialPardonForm.cpp new file mode 100644 index 0000000..4b78f66 --- /dev/null +++ b/cpp05/ex03/PresidentialPardonForm.cpp @@ -0,0 +1,39 @@ +#include "PresidentialPardonForm.hpp" + +PresidentialPardonForm::PresidentialPardonForm(): Form() { + +} + +PresidentialPardonForm::PresidentialPardonForm(std::string _target): target(_target) { + this->setName("PresidentialPardonForm"); + this->setmustExecute(5); + this->setmustGrade(25); + std::cout << green << "PresidentialPardonForm constructor called" << white << std::endl; +} + +PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm& _copy) { + *this = _copy; + std::cout << green << "PresidentialPardonForm copy called" << white << std::endl; +} + +const PresidentialPardonForm& PresidentialPardonForm::operator=(const PresidentialPardonForm& _copy) { + this->setisSigned(_copy.getSigned()); + this->setmustExecute(_copy.getmustExecute()); + this->setmustGrade(_copy.getmustGrade()); + this->setName(_copy.getName()); + return *this; +} + +PresidentialPardonForm::~PresidentialPardonForm() { + std::cout << red << "PresidentialPardonForm deconstructor" << white << std::endl; +} + +void PresidentialPardonForm::execute(Bureaucrat const& executer) const { + if (executer.getGrade() > this->getmustGrade() || executer.getGrade() > this->getmustExecute()) + throw GradeTooLowException(); + else if (this->getSigned() == false) + std::cout << "Form not signed" << std::endl; + else { + std::cout << "Informs that " << this->target << " has been pardoned by Zaphod Beeblebrox" << std::endl; + } +} diff --git a/cpp05/ex03/PresidentialPardonForm.hpp b/cpp05/ex03/PresidentialPardonForm.hpp new file mode 100644 index 0000000..f81e53b --- /dev/null +++ b/cpp05/ex03/PresidentialPardonForm.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include "Form.hpp" + +class Form; + +class PresidentialPardonForm : public Form { +private: + std::string target; +public: + void execute(Bureaucrat const& executer) const ; + + PresidentialPardonForm(); + PresidentialPardonForm(std::string _target); + PresidentialPardonForm(const PresidentialPardonForm& _copy); + const PresidentialPardonForm& operator=(const PresidentialPardonForm& _copy); + ~PresidentialPardonForm(); +}; diff --git a/cpp05/ex03/RobotomyRequestForm.cpp b/cpp05/ex03/RobotomyRequestForm.cpp new file mode 100644 index 0000000..97c6348 --- /dev/null +++ b/cpp05/ex03/RobotomyRequestForm.cpp @@ -0,0 +1,38 @@ +#include "RobotomyRequestForm.hpp" + +RobotomyRequestForm::RobotomyRequestForm(std::string _target): target(_target) { + this->setName("RobotomyRequestForm"); + this->setmustGrade(72); + this->setmustExecute(45); + std::cout << green << "Robotomy default const called" << white << std::endl; +} + +RobotomyRequestForm::RobotomyRequestForm(RobotomyRequestForm& c) { + *this = c; + std::cout << green << "Robotomy copy const called" << white << std::endl; +} + +RobotomyRequestForm& RobotomyRequestForm::operator=(const RobotomyRequestForm& c) { + this->setisSigned(c.getSigned()); + this->setmustExecute(c.getmustExecute()); + this->setmustGrade(c.getmustGrade()); + this->setName(c.getName()); + return *this; +} + +RobotomyRequestForm::~RobotomyRequestForm() { + std::cout << red << "Robotomy deconst called" << white << std::endl; +} + +void RobotomyRequestForm::execute(const Bureaucrat& executer) const { + if (executer.getGrade() > this->getmustGrade() || executer.getGrade() > this->getmustExecute()) + throw GradeTooLowException(); + else if (this->getSigned() == false) + std::cout << "Form not signed" << std::endl; + else { + if (rand() % 2 == 0) + std::cout << this->target << " has been robotomized succesfully" << std::endl; + else + std::cout << this->target << " has been robotomized failed" << std::endl; + } +} diff --git a/cpp05/ex03/RobotomyRequestForm.hpp b/cpp05/ex03/RobotomyRequestForm.hpp new file mode 100644 index 0000000..8fb8863 --- /dev/null +++ b/cpp05/ex03/RobotomyRequestForm.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "Form.hpp" +#include + +class RobotomyRequestForm : public Form { +private: + std::string target; +public: + void execute(const Bureaucrat& executer) const ; + + RobotomyRequestForm(std::string _target); + RobotomyRequestForm(RobotomyRequestForm& c); + RobotomyRequestForm& operator=(const RobotomyRequestForm& c); + ~RobotomyRequestForm(); +}; \ No newline at end of file diff --git a/cpp05/ex03/ShrubberyCreationForm.cpp b/cpp05/ex03/ShrubberyCreationForm.cpp new file mode 100644 index 0000000..4aa7c0c --- /dev/null +++ b/cpp05/ex03/ShrubberyCreationForm.cpp @@ -0,0 +1,54 @@ +#include "ShrubberyCreationForm.hpp" + +ShrubberyCreationForm::ShrubberyCreationForm(std::string _target): target(_target) { + this->setisSigned(false); + this->setmustGrade(145); + this->setmustExecute(137); + this->setName("ShrubberyCreationForm"); + std::cout << green << "ShrubberyCreation constructor called" << white << std::endl; +} + +ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm& c) { + *this = c; + std::cout << green << "ShrubberyCreation copy constructor called" << white << std::endl; +} + +ShrubberyCreationForm::~ShrubberyCreationForm() { + std::cout << red << "ShrubberyCreation deconstructor called" << white << std::endl; +} + +ShrubberyCreationForm& ShrubberyCreationForm::operator=(const ShrubberyCreationForm& c) { + this->setisSigned(c.getSigned()); + this->setmustExecute(c.getmustExecute()); + this->setmustGrade(c.getmustGrade()); + this->setName(c.getName()); + return *this; +} + +void ShrubberyCreationForm::execute(const Bureaucrat& executer) const { + if (executer.getGrade() > this->getmustGrade() || executer.getGrade() > this->getmustExecute()) + throw GradeTooLowException(); + else if (this->getSigned() == false) + std::cout << "Form not signed" << std::endl; + else { + std::string ascii_trees = "\n" + " O O\n" + " $$$ $$$\n" + " $$$$$ $$$$$\n" + " $$$$$$$ $$$$$$$\n" + " $$$$$$$$$ $$$$$$$$$\n" + " $$$$$$$$$$$ $$$$$$$$$$$\n" + " $$$$$$$$$$$$$ $$$$$$$$$$$$$\n" + " $$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$\n" + " $$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$\n" + "$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$\n" + " ||| |||\n" + " ||| |||\n" + " ||| |||\n" + " ||| |||"; + std::string filename(this->target+"_shrubbery"); + std::ofstream a(filename, std::ofstream::trunc | std::ofstream::out); + a << ascii_trees << std::endl; + a.close(); + } +} \ No newline at end of file diff --git a/cpp05/ex03/ShrubberyCreationForm.hpp b/cpp05/ex03/ShrubberyCreationForm.hpp new file mode 100644 index 0000000..9aa2dc1 --- /dev/null +++ b/cpp05/ex03/ShrubberyCreationForm.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "Form.hpp" +#include +#include + +class ShrubberyCreationForm : public Form { +private: + std::string target; +public: + ShrubberyCreationForm(std::string _target); + ShrubberyCreationForm(const ShrubberyCreationForm& c); + ShrubberyCreationForm& operator=(const ShrubberyCreationForm& c); + virtual ~ShrubberyCreationForm(); + + void execute(const Bureaucrat& executer) const ; +}; \ No newline at end of file diff --git a/cpp05/ex03/Shrubbery_shrubbery b/cpp05/ex03/Shrubbery_shrubbery new file mode 100644 index 0000000..02f050e --- /dev/null +++ b/cpp05/ex03/Shrubbery_shrubbery @@ -0,0 +1,15 @@ + + O O + $$$ $$$ + $$$$$ $$$$$ + $$$$$$$ $$$$$$$ + $$$$$$$$$ $$$$$$$$$ + $$$$$$$$$$$ $$$$$$$$$$$ + $$$$$$$$$$$$$ $$$$$$$$$$$$$ + $$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$ + $$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$ +$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$ + ||| ||| + ||| ||| + ||| ||| + ||| ||| diff --git a/cpp05/ex03/form b/cpp05/ex03/form new file mode 100755 index 0000000..abb0f89 Binary files /dev/null and b/cpp05/ex03/form differ diff --git a/cpp05/ex03/main.cpp b/cpp05/ex03/main.cpp new file mode 100644 index 0000000..c299539 --- /dev/null +++ b/cpp05/ex03/main.cpp @@ -0,0 +1,119 @@ +#include "ShrubberyCreationForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "PresidentialPardonForm.hpp" +#include "Intern.hpp" + +int main(void) +{ + Intern slave; + slave.makeForm("NEWNAME", "TARGET"); + Bureaucrat b1("b1", 1); + Bureaucrat b2("b2", 50); + Bureaucrat b3("b3", 150); + + std::cout << std::endl; + try + { + Bureaucrat b4("b4", 160); + } + catch(const std::exception& e) + { + std::cout << e.what() << std::endl; + } + + std::cout << std::endl; + try{ + std::cout << "===========ShrubberyCreationForm Success Test===========" << std::endl; + ShrubberyCreationForm s1("Shrubbery"); + s1.beSigned(b1); + b1.signForm(s1); + b1.executeForm(s1); + std::cout << std::endl; + std::cout << s1 << std::endl; + std::cout << std::endl << std::endl; + } + catch(std::exception & e) + { + std::cout << e.what() << std::endl; + } + + std::cout << std::endl; + try{ + + std::cout << "============ShrubberyCreationForm Fail Test============" << std::endl; + ShrubberyCreationForm s2("Shrubbery"); + s2.beSigned(b3); + b3.signForm(s2); + b3.executeForm(s2); + std::cout << std::endl; + std::cout << s2 << std::endl; + std::cout << std::endl << std::endl; + } + catch(std::exception & e) + { + std::cout << e.what() << std::endl; + } + + std::cout << std::endl; + try{ + std::cout << "============RobotomyRequestForm Success Test============" << std::endl; + RobotomyRequestForm r1("Robotomy"); + r1.beSigned(b1); + b1.signForm(r1); + b1.executeForm(r1); + std::cout << std::endl; + std::cout << r1 << std::endl; + std::cout << std::endl << std::endl; + } + catch(std::exception & e) + { + std::cout << e.what() << std::endl; + } + std::cout << std::endl; + try{ + std::cout << "=============RobotomyRequestForm Fail Test=============" << std::endl; + RobotomyRequestForm r2("Robotomy"); + r2.beSigned(b2); + b2.signForm(r2); + b2.executeForm(r2); + std::cout << std::endl; + std::cout << r2 << std::endl; + std::cout << std::endl << std::endl; + } + catch(std::exception & e) + { + std::cout << e.what() << std::endl; + } + std::cout << std::endl; + try{ + std::cout << "===========PresidentialPardonForm Success Test===========" << std::endl; + PresidentialPardonForm p1("Presidential"); + p1.beSigned(b1); + b1.signForm(p1); + b1.executeForm(p1); + std::cout << std::endl; + std::cout << p1 << std::endl; + std::cout << std::endl << std::endl; + } + catch (std::exception & e) + { + std::cout << e.what() << std::endl; + } + + std::cout << std::endl; + try{ + std::cout << "============PresidentialPardonForm Fail Test============" << std::endl; + PresidentialPardonForm p2("Presidential"); + p2.beSigned(b2); + b2.signForm(p2); + b2.executeForm(p2); + std::cout << std::endl; + std::cout << p2 << std::endl; + std::cout << std::endl << std::endl; + } + catch(std::exception & e) + { + std::cout << e.what() << std::endl; + } + return 0; +} \ No newline at end of file