all CPP in one repo

This commit is contained in:
Xamora 2024-12-04 17:29:31 +01:00
commit 2ba1ab346d
186 changed files with 10047 additions and 0 deletions

129
CPP00/ex00/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = megaphone.cpp
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror
NAME = Megaphone
all: ${NAME}
${NAME}: ${OBJS}
${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

31
CPP00/ex00/megaphone.cpp Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Megaphone.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/08 17:08:17 by erey-bet #+# #+# */
/* Updated: 2023/04/19 15:19:19 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <ctype.h>
#include <string.h>
int main(int argc, char **argv) {
if (argc == 1)
std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *" << std::endl;
else {
argc--;
argv++;
for (int i = 0; i < argc; i++) {
for (int y = 0; y < (int)strlen(argv[i]); y++) {
argv[i][y] = toupper(argv[i][y]);
}
std::cout << argv[i] << std::flush;
}
std::cout << "\n" << std::flush;
}
}

50
CPP00/ex01/Contact.cpp Normal file
View file

@ -0,0 +1,50 @@
#include "Contact.hpp"
Contact::Contact(void) {
this->init = false;
}
Contact::Contact(std::string fname, std::string lname, std::string nname, std::string phnbr, std::string drksct) {
this->init = true;
this->fname = fname;
this->lname = lname;
this->nname = nname;
this->phnbr = phnbr;
this->drksct = drksct;
}
Contact& Contact::operator=(const Contact& other) {
if (this != &other) {
this->init = true;
this->fname = other.fname;
this->lname = other.lname;
this->nname = other.nname;
this->phnbr = other.phnbr;
this->drksct = other.drksct;
}
return (*this);
}
std::string Contact::getFname(void) {
return (fname);
}
std::string Contact::getLname(void) {
return (lname);
}
std::string Contact::getNname(void) {
return (nname);
}
std::string Contact::getPhnbr(void) {
return (phnbr);
}
std::string Contact::getDrksct(void) {
return (drksct);
}
bool Contact::getInit(void) {
return (init);
}

28
CPP00/ex01/Contact.hpp Normal file
View file

@ -0,0 +1,28 @@
#ifndef CONTACT_HPP
# define CONTACT_HPP
# include <string>
class Contact {
public:
Contact();
Contact(std::string fname, std::string lname, std::string nname, std::string phnbr, std::string drksct);
Contact& operator=(const Contact& other);
std::string getFname(void);
std::string getLname(void);
std::string getNname(void);
std::string getPhnbr(void);
std::string getDrksct(void);
bool getInit(void);
private:
std::string fname;
std::string lname;
std::string nname;
std::string phnbr;
std::string drksct;
bool init;
};
#endif

129
CPP00/ex01/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = PhoneBook
all: ${NAME}
${NAME}: ${OBJS}
${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

107
CPP00/ex01/PhoneBook.cpp Normal file
View file

@ -0,0 +1,107 @@
#include "PhoneBook.hpp"
#include "Contact.hpp"
# include <iostream>
# include <string.h>
# include <cstdlib>
# include <iomanip>
PhoneBook::PhoneBook(void) {
size = 0;
index = 0;
std::cout << "New PhoneBook" << std::endl;
}
std::string write_read(std::string text)
{
std::string input;
while (input.size() == 0)
{
std::cout << text;
if (!std::getline(std::cin, input))
exit(0);
}
return (input);
}
void PhoneBook::add(void) {
std::string fname;
std::string lname;
std::string nname;
std::string phnbr;
std::string drksct;
fname = write_read("firstname:");
lname = write_read("lastname:");
nname = write_read("nickname:");
phnbr = write_read("phone number:");
drksct = write_read("darkest secret:");
Contact contact;
contact = Contact(fname, lname, nname, phnbr, drksct);
contact_list[index % 8] = contact;
index++;
if (size < 8)
size++;
std::cout << "The contact has been added." << std::endl;
}
bool isDigital(std::string str) {
for (unsigned long i = 0; i < str.size(); i++) {
if (!isdigit(str[i])) {
return false;
}
}
return true;
}
void PhoneBook::search(void) {
if (size == 0)
{
std::cout << "No contact" << std::endl;
return ;
}
for (int i = 0; i < size; i++) {
std::string info[3];
std::string list_info[3] = {contact_list[i].getFname(), contact_list[i].getLname(),
contact_list[i].getNname()};
for (int y = 0; y < 3; y++) {
info[y] = list_info[y].substr(0, 10);
if (list_info[y].size() > 10)
info[y][9] = '.';
}
std::cout << std::left << std::setw(10) << i;
std::cout << " | ";
std::cout << std::left << std::setw(10) << info[0];
std::cout << " | ";
std::cout << std::left << std::setw(10) << info[1];
std::cout << " | ";
std::cout << std::left << std::setw(10) << info[2];
std::cout << "\n";
}
std::string input;
while (input.size() == 0)
{
std::cout << "index:";
if (!std::getline(std::cin, input))
return ;
}
if (!isDigital(input))
{
std::cout << "Error index" << std::endl;
return ;
}
int index = std::atoi(input.c_str());
if (index > 7 || !contact_list[index].getInit())
{
std::cout << "Out of range" << std::endl;
return ;
}
std::cout << "lastname: " + contact_list[index].getFname() << std::endl;
std::cout << "lastname: " + contact_list[index].getLname() << std::endl;
std::cout << "nickname: " + contact_list[index].getNname() << std::endl;
std::cout << "phone number: " + contact_list[index].getPhnbr() << std::endl;
std::cout << "darkest secret: " + contact_list[index].getDrksct() << std::endl;
}

32
CPP00/ex01/PhoneBook.hpp Normal file
View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* PhoneBook.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/08 17:41:02 by erey-bet #+# #+# */
/* Updated: 2023/04/19 14:07:39 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PHONEBOOK_HPP
# define PHONEBOOK_HPP
# include "Contact.hpp"
class PhoneBook {
public:
PhoneBook(void);
void add(void);
void search(void);
void exit(void);
private:
Contact contact_list[8];
int size;
int index;
};
#endif

40
CPP00/ex01/main.cpp Normal file
View file

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/08 17:58:31 by erey-bet #+# #+# */
/* Updated: 2023/04/20 14:47:32 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "PhoneBook.hpp"
#include <iostream>
#include <string>
int main(void) {
std::string input;
PhoneBook PhoneB = PhoneBook();
while (true) {
std::cout << "PhoneBook Menu: ADD, SEARCH or EXIT to ... exit" << std::endl;
if (!std::getline(std::cin, input))
break;
if (input.compare("ADD") == 0)
PhoneB.add();
if (input.compare("SEARCH") == 0)
PhoneB.search();
if (input.compare("EXIT") == 0)
break;
std::cout << "You entered: " << input << std::endl;
}
std::cout << "Exiting program..." << std::endl;
return (0);
}

129
CPP01/ex00/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Zombie
all: ${NAME}
${NAME}: ${OBJS}
${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

25
CPP01/ex00/Zombie.cpp Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 13:50:14 by erey-bet #+# #+# */
/* Updated: 2023/04/20 15:21:06 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie::Zombie(std::string name) {
this->name = name;
}
Zombie::~Zombie(void) {
std::cout << name + ": has been destroyed" << std::endl;
}
void Zombie::announce(void) {
std::cout << name + ": BraiiiiiiinnnzzzZ..." << std::endl;
}

33
CPP01/ex00/Zombie.hpp Normal file
View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 13:50:12 by erey-bet #+# #+# */
/* Updated: 2023/04/20 15:56:40 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
# include <string>
# include <iostream>
# include <ostream>
class Zombie {
public:
Zombie(std::string name);
~Zombie(void);
void announce(void);
private:
std::string name;
};
Zombie* newZombie(std::string name);
void randomChump(std::string name);
#endif

30
CPP01/ex00/main.cpp Normal file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 15:14:34 by erey-bet #+# #+# */
/* Updated: 2023/04/20 15:38:31 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
int main(void)
{
Zombie z1 = Zombie("z1");
Zombie z2 = Zombie("z2");
z1.announce();
z2.announce();
Zombie *nZombie = newZombie("NewZombie");
nZombie->announce();
randomChump("randomChump");
delete(nZombie);
return (0);
}

17
CPP01/ex00/newZombie.cpp Normal file
View file

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* newZombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 13:50:38 by erey-bet #+# #+# */
/* Updated: 2023/04/20 15:56:43 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie *newZombie(std::string name) {
return (new Zombie(name));
}

View file

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* randomChump.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 13:50:48 by erey-bet #+# #+# */
/* Updated: 2023/04/20 15:23:25 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
void randomChump(std::string name) {
Zombie(name).announce();
}

129
CPP01/ex01/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Zombie
all: ${NAME}
${NAME}: ${OBJS}
${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

35
CPP01/ex01/Zombie.cpp Normal file
View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 13:50:14 by erey-bet #+# #+# */
/* Updated: 2023/04/20 16:34:18 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie::Zombie() {
this->name = "";
std::cout << "noName : has been created" << std::endl;
}
Zombie::Zombie(std::string name) {
this->name = name;
std::cout << name + ": has been created" << std::endl;
}
Zombie::~Zombie(void) {
std::cout << name + ": has been destroyed" << std::endl;
}
void Zombie::announce(void) {
std::cout << name + ": BraiiiiiiinnnzzzZ..." << std::endl;
}
void Zombie::setName(std::string name) {
this->name = name;
}

36
CPP01/ex01/Zombie.hpp Normal file
View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 13:50:12 by erey-bet #+# #+# */
/* Updated: 2023/04/20 16:34:05 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
# include <string>
# include <iostream>
# include <ostream>
class Zombie {
public:
Zombie();
Zombie(std::string name);
~Zombie();
void announce(void);
void setName(std::string name);
private:
std::string name;
};
Zombie* newZombie(std::string name);
void randomChump(std::string name);
Zombie* zombieHorde(int N, std::string name);
#endif

25
CPP01/ex01/main.cpp Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 15:14:34 by erey-bet #+# #+# */
/* Updated: 2023/04/20 16:38:53 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
int main(void)
{
Zombie* horde = zombieHorde(10, "Zombise");
for (int i = 0; i < 10; i++) {
std::cout << i << "-";
horde[i].announce();
}
delete[] horde;
return (0);
}

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* zombieHorde.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 16:27:00 by erey-bet #+# #+# */
/* Updated: 2023/04/20 16:33:02 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie* zombieHorde(int N, std::string name)
{
Zombie* horde = new Zombie[N];
for (int i = 0; i < N; i++)
horde[i].setName(name);
return (horde);
}

129
CPP01/ex02/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Zombie
all: ${NAME}
${NAME}: ${OBJS}
${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

30
CPP01/ex02/main.cpp Normal file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 16:39:49 by erey-bet #+# #+# */
/* Updated: 2023/04/20 16:47:46 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include <string>
#include <iostream>
int main(void){
std::string brain = "HI THIS IS BRAIN";
std::string *stringPTR = &brain;
std::string &stringREF = brain;
std::cout << &brain << std::endl;
std::cout << stringPTR << std::endl;
std::cout << &stringREF << std::endl;
std::cout << brain << std::endl;
std::cout << *stringPTR << std::endl;
std::cout << stringREF << std::endl;
return (0);
}

21
CPP01/ex03/HumanA.cpp Normal file
View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanA.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 17:02:21 by erey-bet #+# #+# */
/* Updated: 2023/04/20 17:23:20 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanA.hpp"
HumanA::HumanA(std::string name, Weapon &weapon): weapon(weapon) {
this->name = name;
}
void HumanA::attack(void) {
std::cout << name + " attacks with their " + weapon.getType() << std::endl;
}

29
CPP01/ex03/HumanA.hpp Normal file
View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanA.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 16:56:55 by erey-bet #+# #+# */
/* Updated: 2023/04/20 17:19:21 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HUMANA_HPP
# define HUMANA_HPP
# include "Weapon.hpp"
# include <string>
class HumanA {
public:
HumanA(std::string name, Weapon &weapon);
void attack(void);
private:
std::string name;
Weapon &weapon;
};
#endif

32
CPP01/ex03/HumanB.cpp Normal file
View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanB.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 17:02:21 by erey-bet #+# #+# */
/* Updated: 2023/04/20 17:32:17 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanB.hpp"
HumanB::HumanB(std::string name): weapon(NULL) {
this->name = name;
}
HumanB::HumanB(std::string name, Weapon &weapon): weapon(&weapon) {
this->name = name;
}
void HumanB::attack(void) {
if (weapon == NULL)
std::cout << name + " attacks with their fist"<< std::endl;
else
std::cout << name + " attacks with their " + weapon->getType() << std::endl;
}
void HumanB::setWeapon(Weapon &weapon) {
this->weapon = &weapon;
}

31
CPP01/ex03/HumanB.hpp Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanB.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 16:56:55 by erey-bet #+# #+# */
/* Updated: 2023/04/20 17:32:28 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HUMANB_HPP
# define HUMANB_HPP
# include "Weapon.hpp"
# include <string>
class HumanB {
public:
HumanB(std::string name);
HumanB(std::string name, Weapon &weapon);
void attack(void);
void setWeapon(Weapon &weapon);
private:
std::string name;
Weapon *weapon;
};
#endif

129
CPP01/ex03/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Weapon
all: ${NAME}
${NAME}: ${OBJS}
${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

29
CPP01/ex03/Weapon.cpp Normal file
View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Weapon.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 16:52:53 by erey-bet #+# #+# */
/* Updated: 2023/04/20 17:10:47 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon.hpp"
Weapon::Weapon(void) {
this->type = "";
}
Weapon::Weapon(std::string type) {
this->type = type;
}
const std::string &Weapon::getType(void) {
return (this->type);
}
void Weapon::setType(std::string type) {
this->type = type;
}

30
CPP01/ex03/Weapon.hpp Normal file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Weapon.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 16:50:04 by erey-bet #+# #+# */
/* Updated: 2023/04/20 17:14:44 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef WEAPON_HPP
# define WEAPON_HPP
# include <string>
# include <iostream>
class Weapon {
public:
Weapon();
Weapon(std::string type);
const std::string &getType(void);
void setType(std::string type);
private:
std::string type;
};
#endif

45
CPP01/ex03/main.cpp Normal file
View file

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 16:48:48 by erey-bet #+# #+# */
/* Updated: 2023/04/20 17:14:36 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon.hpp"
#include "HumanA.hpp"
#include "HumanB.hpp"
int main()
{
{
Weapon club = Weapon("crude spiked club");
HumanA bob("Bob", club);
bob.attack();
club.setType("some other type of club");
bob.attack();
}
std::cout << "------------------------------" << std::endl;
{
Weapon club = Weapon("crude spiked club");
HumanB jim("Jim");
jim.attack();
jim.setWeapon(club);
jim.attack();
club.setType("some other type of club");
jim.attack();
}
std::cout << "------------------------------" << std::endl;
{
Weapon sword = Weapon("strange sword");
HumanB jim("Timeo", sword);
jim.attack();
sword.setType("other strange sword");
jim.attack();
}
return 0;
}

129
CPP01/ex04/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = SedForLooser
all: ${NAME}
${NAME}: ${OBJS}
${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

View file

@ -0,0 +1,63 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* SedForLooser.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/21 15:56:56 by erey-bet #+# #+# */
/* Updated: 2023/05/18 16:20:42 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "SedForLooser.hpp"
#include <cerrno>
SedForLooser::SedForLooser(char *filename) {
this->filename = filename;
}
void SedForLooser::replace(std::string s1, std::string s2) {
std::ifstream infile(this->filename);
if (infile == NULL)
{
if (errno == EACCES)
std::cout << "You don't have the permissions to open the file." << std::endl;
else
std::cout << "Error to open the file." << std::endl;
return ;
}
std::ofstream outfile(strcat(this->filename, ".replace"));
if (infile == NULL)
{
if (errno == EACCES)
std::cout << "You don't have the permissions to open the file." << std::endl;
else
std::cout << "Error to open the file." << std::endl;
return ;
}
std::string text;
std::string line;
while (std::getline(infile, line))
text += line + "\n";
infile.close();
std::string result;
for (std::size_t i = 0; i < text.size(); i++)
{
for (std::size_t y = 0; y < s1.size(); y++)
{
if (text[i] != s1[y])
{
result += text[i];
break;
}
else if (y == s1.size() - 1)
result += s2;
}
}
outfile << result << std::endl;
}

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* SedForLooser.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/21 15:53:07 by erey-bet #+# #+# */
/* Updated: 2023/04/21 15:56:01 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SEDFORLOOSER_HPP
# define SEDFORLOOSER_HPP
# include <iostream>
# include <string>
# include <fstream>
# include <cstring>
class SedForLooser {
public:
SedForLooser(char *filename);
void replace(std::string s1, std::string s2);
private:
char *filename;
};
#endif

25
CPP01/ex04/main.cpp Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/21 15:51:24 by erey-bet #+# #+# */
/* Updated: 2023/04/21 16:14:12 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "SedForLooser.hpp"
int main(int argc, char **argv) {
if (argc != 4) {
std::cout << "Wrong Number of Argument" << std::endl;
return (1);
}
SedForLooser Sfl = SedForLooser(argv[1]);
Sfl.replace(std::string(argv[2]), std::string(argv[3]));
return (0);
}

41
CPP01/ex05/Harl.cpp Normal file
View file

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 17:40:42 by erey-bet #+# #+# */
/* Updated: 2023/04/20 18:08:44 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
Harl::Harl(void) {}
void Harl::debug(void) {
std::cout << "DEBUG" << std::endl;
}
void Harl::info(void) {
std::cout << "INFO" << std::endl;
}
void Harl::warning(void) {
std::cout << "WARNING" << std::endl;
}
void Harl::error(void) {
std::cout << "ERROR" << std::endl;
}
void Harl::complain(std::string level) {
void(Harl::*funcs[4])() = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
std::string all_level[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
for (int i = 0; i < 4; i++)
if (all_level[i] == level)
return (this->*funcs[i])();
std::cout << "Only 'DEBUG', 'INFO', 'WARNING', 'ERROR' was allowed" << std::endl;
}

30
CPP01/ex05/Harl.hpp Normal file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 17:36:19 by erey-bet #+# #+# */
/* Updated: 2023/04/20 18:00:04 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HARL_HPP
# define HARL_HPP
# include <iostream>
class Harl {
public:
Harl(void);
void complain(std::string level);
private:
void debug(void);
void info(void);
void warning(void);
void error(void);
};
#endif

129
CPP01/ex05/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Harl
all: ${NAME}
${NAME}: ${OBJS}
${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

22
CPP01/ex05/main.cpp Normal file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 18:09:58 by erey-bet #+# #+# */
/* Updated: 2023/04/20 18:18:44 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
#include <string>
int main(int argc, char **argv) {
Harl harl = Harl();
if (argc == 2)
harl.complain(std::string(argv[1]));
return (0);
}

61
CPP01/ex06/Harl.cpp Normal file
View file

@ -0,0 +1,61 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 17:40:42 by erey-bet #+# #+# */
/* Updated: 2023/04/20 18:38:26 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
Harl::Harl(void) {}
void Harl::debug(void) {
std::cout << "DEBUG" << std::endl;
}
void Harl::info(void) {
std::cout << "INFO" << std::endl;
}
void Harl::warning(void) {
std::cout << "WARNING" << std::endl;
}
void Harl::error(void) {
std::cout << "ERROR" << std::endl;
}
void Harl::complain(std::string level) {
void(Harl::*funcs[4])() = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
std::string all_level[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
int i;
for (i = 0; i < 4; i++)
if (all_level[i] == level)
break ;
switch (i) {
case 0:
(this->*funcs[0])();
this->complain("INFO");
break;
case 1:
(this->*funcs[1])();
this->complain("WARNING");
break;
case 2:
(this->*funcs[2])();
this->complain("ERROR");
break;
case 3:
(this->*funcs[3])();
break;
default:
return ;
}
}

30
CPP01/ex06/Harl.hpp Normal file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 17:36:19 by erey-bet #+# #+# */
/* Updated: 2023/04/20 18:00:04 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HARL_HPP
# define HARL_HPP
# include <iostream>
class Harl {
public:
Harl(void);
void complain(std::string level);
private:
void debug(void);
void info(void);
void warning(void);
void error(void);
};
#endif

129
CPP01/ex06/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Harl
all: ${NAME}
${NAME}: ${OBJS}
${CXX} ${CPPFLAGS} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

22
CPP01/ex06/main.cpp Normal file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/20 18:09:58 by erey-bet #+# #+# */
/* Updated: 2023/04/20 18:18:44 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
#include <string>
int main(int argc, char **argv) {
Harl harl = Harl();
if (argc == 2)
harl.complain(std::string(argv[1]));
return (0);
}

33
CPP02/ex00/Fixed.cpp Normal file
View file

@ -0,0 +1,33 @@
#include "Fixed.hpp"
Fixed::Fixed() {
this->rawBits = 0;
std::cout << "Default constructor called" << std::endl;
}
Fixed::~Fixed() {
std::cout << "Destructor called" << std::endl;
}
Fixed& Fixed::operator=(const Fixed &fixed) {
if (this != &fixed) {
this->rawBits = fixed.rawBits;
}
std::cout << "Copy assignment operator called" << std::endl;
return *this;
}
Fixed::Fixed(const Fixed &fixed) {
this->rawBits = fixed.rawBits;
std::cout << "Copy constructor called" << std::endl;
}
int Fixed::getRawBits() const{
std::cout << "getRawBits member function called ";
return this->rawBits;
}
void Fixed::setRawBits(int const raw) {
this->rawBits = raw;
std::cout << "setRawBits member function called" << std::endl;
}

21
CPP02/ex00/Fixed.hpp Normal file
View file

@ -0,0 +1,21 @@
#ifndef FIXED_HPP
# define FIXED_HPP
# include <iostream>
# include <string>
class Fixed {
public:
Fixed();
Fixed(const Fixed &fixed);
~Fixed();
Fixed& operator=(const Fixed &fixed);
int getRawBits() const;
void setRawBits(int const raw);
private:
int rawBits;
const static int bits = 8;
};
#endif

129
CPP02/ex00/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Fixed
all: ${NAME}
${NAME}: ${OBJS}
${CXX} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

36
CPP02/ex00/main.cpp Normal file
View file

@ -0,0 +1,36 @@
#include "Fixed.hpp"
int main() {
{
Fixed a;
a.setRawBits(2);
Fixed b( a );
Fixed c;
c = b;
std::cout << " a:" << a.getRawBits() << std::endl;
std::cout << " b:" << b.getRawBits() << std::endl;
std::cout << " c:" << c.getRawBits() << std::endl;
}
std::cout << "---------------------" << std::endl;
{
Fixed a;
a.setRawBits(5);
std::cout << " a:" << a.getRawBits() << std::endl;
Fixed b(a);
std::cout << " a:" << a.getRawBits() << std::endl;
std::cout << " b:" << b.getRawBits() << std::endl;
a.setRawBits(12);
std::cout << " a:" << a.getRawBits() << std::endl;
std::cout << " b:" << b.getRawBits() << std::endl;
b.setRawBits(2);
std::cout << " a:" << a.getRawBits() << std::endl;
std::cout << " b:" << b.getRawBits() << std::endl;
}
return 0;
}

54
CPP02/ex01/Fixed.cpp Normal file
View file

@ -0,0 +1,54 @@
#include "Fixed.hpp"
Fixed::Fixed(void) {
this->rawBits = 0;
std::cout << "Default constructor called" << std::endl;
}
Fixed::Fixed(const int raw) {
this->rawBits = int(raw * (1 << bits));
std::cout << "Int constructor called" << std::endl;
}
Fixed::Fixed(const float raw) {
this->rawBits = int(roundf(raw * (1 << bits)));
std::cout << "Float constructor called" << std::endl;
}
Fixed::~Fixed() {
std::cout << "Destructor called" << std::endl;
}
Fixed& Fixed::operator=(const Fixed &fixed) {
if (this != &fixed) {
this->rawBits = fixed.rawBits;
}
std::cout << "Copy assignment operator called" << std::endl;
return *this;
}
std::ostream& operator<<(std::ostream& os, const Fixed &fixed) {
os << fixed.toFloat();
return os;
}
Fixed::Fixed(const Fixed &fixed) {
this->rawBits = fixed.rawBits;
std::cout << "Copy constructor called" << std::endl;
}
int Fixed::toInt(void) const{
return int(this->rawBits) / int(1 << this->bits);
}
float Fixed::toFloat(void) const{
return float(this->rawBits) / float(1 << this->bits);
}
int Fixed::getRawBits(void) const {
return this->rawBits;
}
void Fixed::setRawBits(const int raw) {
this->rawBits = raw;
}

29
CPP02/ex01/Fixed.hpp Normal file
View file

@ -0,0 +1,29 @@
#ifndef FIXED_HPP
# define FIXED_HPP
# include <iostream>
# include <string>
# include <cmath>
class Fixed {
public:
Fixed(void);
Fixed(int const raw);
Fixed(float const raw);
Fixed(const Fixed &fixed);
~Fixed();
Fixed& operator=(const Fixed &fixed);
int toInt(void) const;
float toFloat(void) const;
int getRawBits(void) const;
void setRawBits(int const raw);
private:
int rawBits;
const static int bits = 8;
};
std::ostream& operator<<(std::ostream& os, const Fixed& fixed);
#endif

129
CPP02/ex01/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Fixed
all: ${NAME}
${NAME}: ${OBJS}
${CXX} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

25
CPP02/ex01/main.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "Fixed.hpp"
int main( void ) {
Fixed a;
Fixed const b( 10 );
Fixed const c( 42.42f );
Fixed const d( b );
a = Fixed( 1234.4321f );
std::cout << "a is " << a << std::endl;
std::cout << "b is " << b << std::endl;
std::cout << "c is " << c << std::endl;
std::cout << "d is " << d << std::endl;
std::cout << "a is " << a.toInt() << " as integer" << std::endl;
std::cout << "b is " << b.toInt() << " as integer" << std::endl;
std::cout << "c is " << c.toInt() << " as integer" << std::endl;
std::cout << "d is " << d.toInt() << " as integer" << std::endl;
std::cout << "-------------------------" << std::endl;
std::cout << "a is " << a.getRawBits() << std::endl;
std::cout << "b is " << b.getRawBits() << std::endl;
std::cout << "c is " << c.getRawBits() << std::endl;
return 0;
}

130
CPP02/ex02/Fixed.cpp Normal file
View file

@ -0,0 +1,130 @@
#include "Fixed.hpp"
Fixed::Fixed(void) {
this->rawBits = 0;
}
Fixed::Fixed(const int raw) {
this->rawBits = int(raw * (1 << bits));
}
Fixed::Fixed(const float raw) {
this->rawBits = int(roundf(raw * (1 << bits)));
}
Fixed::~Fixed() {
}
Fixed& Fixed::operator=(const Fixed &fixed) {
if (this != &fixed) {
this->rawBits = fixed.rawBits;
}
return *this;
}
std::ostream& operator<<(std::ostream& os, const Fixed &fixed) {
os << fixed.toFloat();
return os;
}
Fixed::Fixed(const Fixed &fixed) {
this->rawBits = fixed.rawBits;
}
int Fixed::toInt(void) const{
return int(this->rawBits) / int(1 << this->bits);
}
float Fixed::toFloat(void) const{
return float(this->rawBits) / float(1 << this->bits);
}
int Fixed::getRawBits(void) const {
return this->rawBits;
}
void Fixed::setRawBits(const int raw) {
this->rawBits = raw;
}
bool Fixed::operator>(const Fixed &fixed) const {
return this->rawBits > fixed.rawBits;
}
bool Fixed::operator<(const Fixed &fixed) const {
return this->rawBits < fixed.rawBits;
}
bool Fixed::operator>=(const Fixed &fixed) const {
return this->rawBits >= fixed.rawBits;
}
bool Fixed::operator<=(const Fixed &fixed) const {
return this->rawBits <= fixed.rawBits;
}
bool Fixed::operator==(const Fixed &fixed) const {
return this->rawBits == fixed.rawBits;
}
bool Fixed::operator!=(const Fixed &fixed) const {
return this->rawBits != fixed.rawBits;
}
Fixed Fixed::operator+(const Fixed &fixed) const {
Fixed result = Fixed(this->toFloat() + fixed.toFloat());
return result;
}
Fixed Fixed::operator-(const Fixed &fixed) const {
Fixed result = Fixed(this->toFloat() - fixed.toFloat());
return result;
}
Fixed Fixed::operator*(const Fixed &fixed) const {
Fixed result = Fixed(this->toFloat() * fixed.toFloat());
return result;
}
Fixed Fixed::operator/(const Fixed &fixed) const {
Fixed result = Fixed(this->toFloat() / fixed.toFloat());
return result;
}
Fixed& Fixed::operator++(void) {
this->rawBits++;
return *this;
}
Fixed Fixed::operator++(int) {
Fixed tmp(*this);
this->rawBits++;
return tmp;
}
Fixed& Fixed::operator--(void) {
this->rawBits--;
return *this;
}
Fixed Fixed::operator--(int) {
Fixed tmp(*this);
this->rawBits--;
return tmp;
}
const Fixed& Fixed::min(Fixed& a, Fixed& b) {
return (a < b) ? a : b;
}
const Fixed& Fixed::min(const Fixed& a, const Fixed& b) {
return (a < b) ? a : b;
}
const Fixed& Fixed::max(Fixed& a, Fixed& b) {
return (a > b) ? a : b;
}
const Fixed& Fixed::max(const Fixed& a, const Fixed& b) {
return (a > b) ? a : b;
}

51
CPP02/ex02/Fixed.hpp Normal file
View file

@ -0,0 +1,51 @@
#ifndef FIXED_HPP
# define FIXED_HPP
# include <iostream>
# include <string>
# include <cmath>
class Fixed {
public:
Fixed(void);
Fixed(int const raw);
Fixed(float const raw);
Fixed(const Fixed &fixed);
~Fixed();
Fixed& operator=(const Fixed &fixed);
static const Fixed& min(Fixed& a, Fixed& b);
static const Fixed& max(Fixed& a, Fixed& b);
static const Fixed& min(const Fixed& a, const Fixed& b);
static const Fixed& max(const Fixed& a, const Fixed& b);
bool operator>(const Fixed& fixed) const;
bool operator<(const Fixed& fixed) const;
bool operator>=(const Fixed& fixed) const;
bool operator<=(const Fixed& fixed) const;
bool operator==(const Fixed& fixed) const;
bool operator!=(const Fixed& fixed) const;
Fixed operator+(const Fixed& fixed) const;
Fixed operator-(const Fixed& fixed) const;
Fixed operator*(const Fixed& fixed) const;
Fixed operator/(const Fixed& fixed) const;
Fixed& operator++();
Fixed operator++(int);
Fixed& operator--();
Fixed operator--(int);
int toInt(void) const;
float toFloat(void) const;
int getRawBits(void) const;
void setRawBits(int const raw);
private:
int rawBits;
const static int bits = 8;
};
std::ostream& operator<<(std::ostream& os, const Fixed& fixed);
#endif

129
CPP02/ex02/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Fixed
all: ${NAME}
${NAME}: ${OBJS}
${CXX} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

87
CPP02/ex02/main.cpp Normal file
View file

@ -0,0 +1,87 @@
#include "Fixed.hpp"
void ft_test(bool test, std::string text) {
if (test)
std::cout << "test: " + text + ", bool: \033[1;32mTrue\033[0m" << std::endl;
else
std::cout << "test: " + text + ", bool: \033[1;31mFalse\033[0m" << std::endl;
}
void bool_test(Fixed nbr1, Fixed nbr2, std::string name1, std::string name2) {
ft_test(nbr1 == nbr2, name1 + " == " + name2);
ft_test(nbr1 != nbr2, name1 + " != " + name2);
ft_test(nbr1 <= nbr2, name1 + " <= " + name2);
ft_test(nbr1 >= nbr2, name1 + " >= " + name2);
ft_test(nbr1 < nbr2, name1 + " < " + name2);
ft_test(nbr1 > nbr2, name1 + " > " + name2);
}
void operator_test(Fixed nbr1, Fixed nbr2, std::string name1, std::string name2) {
std::cout << "result: " << nbr1 * nbr2 << " waiting: " << nbr1.toFloat() * nbr2.toFloat() << std::endl;
ft_test(nbr1 * nbr2 == nbr1.toFloat() * nbr2.toFloat(), name1 + " * " + name2);
std::cout << "result: " << nbr1 / nbr2 << " waiting: " << nbr1.toFloat() / nbr2.toFloat() << std::endl;
ft_test(nbr1 / nbr2 == nbr1.toFloat() / nbr2.toFloat(), name1 + " / " + name2);
std::cout << "result: " << nbr1 + nbr2 << " waiting: " << nbr1.toFloat() + nbr2.toFloat() << std::endl;
ft_test(nbr1 + nbr2 == nbr1.toFloat() + nbr2.toFloat(), name1 + " + " + name2);
std::cout << "result: " << nbr1 - nbr2 << " waiting: " << nbr1.toFloat() - nbr2.toFloat() << std::endl;
ft_test(nbr1 - nbr2 == nbr1.toFloat() - nbr2.toFloat(), name1 + " - " + name2);
}
int main( void ) {
/* BOOL */
{
std::cout << "\n--BOOL TEST--" << std::endl;
Fixed a(10);
Fixed b(10.1f);
Fixed c(9.9f);
std::cout << "a:" << a << std::endl;
std::cout << "b:" << b << std::endl;
std::cout << "c:" << c << std::endl;
std::cout << "\n-------------------------------\n" << std::endl;
bool_test(a, b, "a", "b");
std::cout << "\n-------------------------------\n" << std::endl;
bool_test(a, c, "a", "c");
std::cout << "\n-------------------------------\n"<< std::endl;
bool_test(b, c, "b", "c");
}
/* OPERATOR */
{
std::cout << "\n--OPERATOR TEST--" << std::endl;
Fixed a(2);
Fixed b(41.1f);
Fixed c(-2.9f);
std::cout << "a:" << a << std::endl;
std::cout << "b:" << b << std::endl;
std::cout << "c:" << c << std::endl;
std::cout << "\n-------------------------------\n" << std::endl;
operator_test(a, b, "a", "b");
std::cout << "\n-------------------------------\n" << std::endl;
operator_test(a, c, "a", "c");
std::cout << "\n-------------------------------\n"<< std::endl;
operator_test(b, c, "b", "c");
}
std::cout << "\n-------------------------------\n" << std::endl;
/* OTHER */
{
Fixed a;
Fixed const b( Fixed( 5.05f ) * Fixed( 2 ) );
std::cout << "a:" << a << std::endl;
std::cout << "++a:" << ++a << std::endl;
std::cout << "a:" << a << std::endl;
std::cout << "a++:" << a++ << std::endl;
std::cout << "a:" << a << std::endl;
std::cout << "b:" << b << std::endl;
std::cout << "max(a,b):" << Fixed::max( a, b ) << std::endl;
std::cout << "min(a,b):" << Fixed::min( a, b ) << std::endl;
}
return 0;
}

66
CPP03/ex00/ClapTrap.cpp Normal file
View file

@ -0,0 +1,66 @@
#include "ClapTrap.hpp"
ClapTrap::ClapTrap() {
this->name = "Default";
this->hp = 10;
this->energy = 10;
this->damage = 0;
std::cout << this->name + " is created" << std::endl;
}
ClapTrap::ClapTrap(std::string name) {
this->name = name;
this->hp = 10;
this->energy = 10;
this->damage = 0;
std::cout << this->name + " is created" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap &clap) {
*this = clap;
std::cout << this->name + " is created" << std::endl;
}
ClapTrap::~ClapTrap() {
std::cout << this->name + " is destroyed" << std::endl;
}
ClapTrap& ClapTrap::operator=(const ClapTrap &clap) {
if (this != &clap) {
this->name = clap.name;
this->hp = clap.hp;
this->energy = clap.energy;
this->damage = clap.damage;
}
return *this;
}
void ClapTrap::attack(const std::string& target) {
if (this->energy > 0 && this->hp > 0) {
std::cout << "ClapTrap " + this->name + " attacks " + target + ", causing "
<< this->damage << " points of damage! " << std::endl;
this->energy--;
}
else
std::cout << "ClapTrap " + this->name + " is out of combat" << std::endl;
}
void ClapTrap::takeDamage(unsigned int amount) {
if (this->hp > 0) {
std::cout << "ClapTrap " + this->name + " takes " << amount << " damages" << std::endl;
this->energy--;
this->hp -= amount;
}
else
std::cout << "ClapTrap " + this->name + " is out of combat" << std::endl;
}
void ClapTrap::beRepaired(unsigned int amount) {
if (this->energy > 0 && this->hp > 0) {
std::cout << "ClapTrap " + this->name + " is repaired by " << amount << std::endl;
this->energy--;
this->hp += amount;
}
else
std::cout << "ClapTrap " + this->name + " is out of combat" << std::endl;
}

25
CPP03/ex00/ClapTrap.hpp Normal file
View file

@ -0,0 +1,25 @@
#ifndef CLAPTRAP_HPP
# define CLAPTRAP_HPP
#include <iostream>
class ClapTrap {
public:
ClapTrap();
ClapTrap(std::string name);
~ClapTrap();
ClapTrap(const ClapTrap &clap);
ClapTrap& operator=(const ClapTrap &clap);
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
private:
std::string name;
int hp;
int energy;
int damage;
};
#endif

129
CPP03/ex00/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = ClapTrap
all: ${NAME}
${NAME}: ${OBJS}
${CXX} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

38
CPP03/ex00/main.cpp Normal file
View file

@ -0,0 +1,38 @@
#include "ClapTrap.hpp"
int main(void) {
ClapTrap none;
ClapTrap clapy("Clapy");
ClapTrap clapo("Clapo");
std::cout << "\n----------------------------\n" << std::endl;
none.attack("Clapy");
none.takeDamage(20);
none.attack("Clapy");
none.beRepaired(10);
std::cout << "\n----------------------------\n" << std::endl;
clapy.attack("Clapo");
clapo.takeDamage(0);
clapy.takeDamage(5);
clapy.beRepaired(5);
clapy.takeDamage(5);
for (int i = 0; i < 8; i++)
clapy.attack("Clapo");
std::cout << "\n----------------------------\n" << std::endl;
std::cout << "/*ClapTrap clapy2(clapy);" << std::endl;
std::cout << "ClapTrap clapy3 = clapy;*/\n" << std::endl;
ClapTrap clapy2(clapy);
ClapTrap clapy3 = clapy;
clapy2.attack("Clapo");
clapy3.attack("Clapo");
std::cout << "\n----------------------------\n" << std::endl;
}

66
CPP03/ex01/ClapTrap.cpp Normal file
View file

@ -0,0 +1,66 @@
#include "ClapTrap.hpp"
ClapTrap::ClapTrap() {
this->name = "Default";
this->hp = 10;
this->energy = 10;
this->damage = 0;
std::cout << "ClapTrap " + this->name + " is created" << std::endl;
}
ClapTrap::ClapTrap(std::string name) {
this->name = name;
this->hp = 10;
this->energy = 10;
this->damage = 0;
std::cout << "ClapTrap " + this->name + " is created" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap &clap) {
*this = clap;
std::cout << "ClapTrap " + this->name + " is created" << std::endl;
}
ClapTrap::~ClapTrap() {
std::cout << "ClapTrap " + this->name + " is destroyed" << std::endl;
}
ClapTrap& ClapTrap::operator=(const ClapTrap &clap) {
if (this != &clap) {
this->name = clap.name;
this->hp = clap.hp;
this->energy = clap.energy;
this->damage = clap.damage;
}
return *this;
}
void ClapTrap::attack(const std::string& target) {
if (this->energy > 0 && this->hp > 0) {
std::cout << "ClapTrap " + this->name + " attacks " + target + ", causing "
<< this->damage << " points of damage! " << std::endl;
this->energy--;
}
else
std::cout << this->name + " is out of combat" << std::endl;
}
void ClapTrap::takeDamage(unsigned int amount) {
if (this->hp > 0) {
std::cout << this->name + " takes " << amount << " damages" << std::endl;
this->energy--;
this->hp -= amount;
}
else
std::cout << this->name + " is out of combat" << std::endl;
}
void ClapTrap::beRepaired(unsigned int amount) {
if (this->energy > 0 && this->hp > 0) {
std::cout << this->name + " is repaired by " << amount << std::endl;
this->energy--;
this->hp += amount;
}
else
std::cout << this->name + " is out of combat" << std::endl;
}

25
CPP03/ex01/ClapTrap.hpp Normal file
View file

@ -0,0 +1,25 @@
#ifndef CLAPTRAP_HPP
# define CLAPTRAP_HPP
#include <iostream>
class ClapTrap {
public:
ClapTrap();
ClapTrap(std::string name);
~ClapTrap();
ClapTrap(const ClapTrap &clap);
ClapTrap& operator=(const ClapTrap &clap);
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
protected:
std::string name;
int hp;
int energy;
int damage;
};
#endif

129
CPP03/ex01/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = ScavTrap
all: ${NAME}
${NAME}: ${OBJS}
${CXX} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

52
CPP03/ex01/ScavTrap.cpp Normal file
View file

@ -0,0 +1,52 @@
#include "ScavTrap.hpp"
ScavTrap::ScavTrap() : ClapTrap() {
this->name = "Default";
this->hp = 100;
this->energy = 50;
this->damage = 20;
std::cout << "ScavTrap " + this->name + " is created" << std::endl;
}
ScavTrap::ScavTrap(std::string name) : ClapTrap() {
this->name = name;
this->hp = 100;
this->energy = 50;
this->damage = 20;
std::cout << "ScavTrap " + this->name + " is created" << std::endl;
}
ScavTrap::ScavTrap(const ScavTrap &scav) : ClapTrap(scav) {
*this = scav;
std::cout << "ScavTrap " + this->name + " is created" << std::endl;
}
ScavTrap::~ScavTrap() {
std::cout << "ScavTrap " + this->name + " is destroyed" << std::endl;
}
ScavTrap& ScavTrap::operator=(const ScavTrap &scav) {
if (this != &scav) {
ClapTrap::operator=(scav);
}
return *this;
}
void ScavTrap::attack(const std::string& target) {
if (this->energy > 0 && this->hp > 0) {
std::cout << "ScavTrap " + this->name + " attacks " + target + ", causing "
<< this->damage << " points of damage! " << std::endl;
this->energy--;
}
else
std::cout << this->name + " is out of combat" << std::endl;
}
void ScavTrap::guardGate() {
if (this->energy > 0 && this->hp > 0) {
std::cout << "ScavTrap is now in Gate Keeper Mode" << std::endl;
this->energy--;
}
else
std::cout << "ScavTrap " + this->name + " is out of combat" << std::endl;
}

19
CPP03/ex01/ScavTrap.hpp Normal file
View file

@ -0,0 +1,19 @@
#ifndef SCAVTRAP_HPP
# define SCAVTRAP_HPP
#include "ClapTrap.hpp"
#include <iostream>
class ScavTrap : public ClapTrap {
public:
ScavTrap();
ScavTrap(std::string name);
~ScavTrap();
ScavTrap(const ScavTrap &clap);
ScavTrap& operator=(const ScavTrap &clap);
void attack(const std::string& target);
void guardGate();
};
#endif

52
CPP03/ex01/main.cpp Normal file
View file

@ -0,0 +1,52 @@
#include "ClapTrap.hpp"
#include "ScavTrap.hpp"
int main(void) {
std::cout << "\n";
ScavTrap none;
ScavTrap clapy("Clapy");
ClapTrap clapo("Clapo");
std::cout << "\n----------------------------\n" << std::endl;
none.attack("Clapy");
none.takeDamage(100);
none.attack("Clapy");
none.beRepaired(10);
std::cout << "\n----------------------------\n" << std::endl;
{
clapy.attack("Clapo");
clapo.takeDamage(0);
clapy.takeDamage(50);
clapy.beRepaired(5);
clapy.takeDamage(50);
for (int i = 0; i < 50; i++)
clapy.attack("Clapo");
}
std::cout << "\n----------------------------\n" << std::endl;
{
ScavTrap clapy2(clapy);
ScavTrap clapy3 = clapy;
clapy2.attack("Clapo");
clapy3.attack("Clapo");
}
std::cout << "\n----------------------------\n" << std::endl;
{
ScavTrap guard("Gigi");
guard.guardGate();
guard.takeDamage(100);
guard.guardGate();
}
std::cout << "\n----------------------------\n" << std::endl;
}

66
CPP03/ex02/ClapTrap.cpp Normal file
View file

@ -0,0 +1,66 @@
#include "ClapTrap.hpp"
ClapTrap::ClapTrap() {
this->name = "Default";
this->hp = 10;
this->energy = 10;
this->damage = 0;
std::cout << "ClapTrap " + this->name + " is created" << std::endl;
}
ClapTrap::ClapTrap(std::string name) {
this->name = name;
this->hp = 10;
this->energy = 10;
this->damage = 0;
std::cout << "ClapTrap " + this->name + " is created" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap &clap) {
*this = clap;
std::cout << "ClapTrap " + this->name + " is created" << std::endl;
}
ClapTrap::~ClapTrap() {
std::cout << "ClapTrap " + this->name + " is destroyed" << std::endl;
}
ClapTrap& ClapTrap::operator=(const ClapTrap &clap) {
if (this != &clap) {
this->name = clap.name;
this->hp = clap.hp;
this->energy = clap.energy;
this->damage = clap.damage;
}
return *this;
}
void ClapTrap::attack(const std::string& target) {
if (this->energy > 0 && this->hp > 0) {
std::cout << "ClapTrap " + this->name + " attacks " + target + ", causing "
<< this->damage << " points of damage! " << std::endl;
this->energy--;
}
else
std::cout << this->name + " is out of combat" << std::endl;
}
void ClapTrap::takeDamage(unsigned int amount) {
if (this->hp > 0) {
std::cout << this->name + " takes " << amount << " damages" << std::endl;
this->energy--;
this->hp -= amount;
}
else
std::cout << this->name + " is out of combat" << std::endl;
}
void ClapTrap::beRepaired(unsigned int amount) {
if (this->energy > 0 && this->hp > 0) {
std::cout << this->name + " is repaired by " << amount << std::endl;
this->energy--;
this->hp += amount;
}
else
std::cout << this->name + " is out of combat" << std::endl;
}

25
CPP03/ex02/ClapTrap.hpp Normal file
View file

@ -0,0 +1,25 @@
#ifndef CLAPTRAP_HPP
# define CLAPTRAP_HPP
#include <iostream>
class ClapTrap {
public:
ClapTrap();
ClapTrap(std::string name);
~ClapTrap();
ClapTrap(const ClapTrap &clap);
ClapTrap& operator=(const ClapTrap &clap);
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
protected:
std::string name;
int hp;
int energy;
int damage;
};
#endif

52
CPP03/ex02/FragTrap.cpp Normal file
View file

@ -0,0 +1,52 @@
#include "FragTrap.hpp"
FragTrap::FragTrap() : ClapTrap() {
this->name = "Default";
this->hp = 100;
this->energy = 100;
this->damage = 30;
std::cout << "FragTrap " + this->name + " is created" << std::endl;
}
FragTrap::FragTrap(std::string name) : ClapTrap() {
this->name = name;
this->hp = 100;
this->energy = 100;
this->damage = 30;
std::cout << "FragTrap " + this->name + " is created" << std::endl;
}
FragTrap::FragTrap(const FragTrap &frag) : ClapTrap(frag) {
*this = frag;
std::cout << "FragTrap " + this->name + " is created" << std::endl;
}
FragTrap::~FragTrap() {
std::cout << "FragTrap " + this->name + " is destroyed" << std::endl;
}
FragTrap& FragTrap::operator=(const FragTrap &frag) {
if (this != &frag) {
ClapTrap::operator=(frag);
}
return *this;
}
void FragTrap::attack(const std::string& target) {
if (this->energy > 0 && this->hp > 0) {
std::cout << "FragTrap " + this->name + " attacks " + target + ", causing "
<< this->damage << " points of damage! " << std::endl;
this->energy--;
}
else
std::cout << this->name + " is out of combat" << std::endl;
}
void FragTrap::highFivesGuys() {
if (this->energy > 0 && this->hp > 0) {
std::cout << "FragTrap " + this->name + " making a high fives" << std::endl;
this->energy--;
}
else
std::cout << this->name + " is out of combat" << std::endl;
}

19
CPP03/ex02/FragTrap.hpp Normal file
View file

@ -0,0 +1,19 @@
#ifndef SCAVTRAP_HPP
# define SCAVTRAP_HPP
#include "ClapTrap.hpp"
#include <iostream>
class FragTrap : public ClapTrap {
public:
FragTrap();
FragTrap(std::string name);
~FragTrap();
FragTrap(const FragTrap &clap);
FragTrap& operator=(const FragTrap &clap);
void attack(const std::string& target);
void highFivesGuys();
};
#endif

129
CPP03/ex02/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = FragTrap
all: ${NAME}
${NAME}: ${OBJS}
${CXX} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

72
CPP03/ex02/ScavTrap.cpp Normal file
View file

@ -0,0 +1,72 @@
#include "ScavTrap.hpp"
ScavTrap::ScavTrap() : ClapTrap() {
this->name = "Default";
this->hp = 100;
this->energy = 50;
this->damage = 20;
std::cout << "ScavTrap " + this->name + " is created" << std::endl;
}
ScavTrap::ScavTrap(std::string name) : ClapTrap() {
this->name = name;
this->hp = 100;
this->energy = 50;
this->damage = 20;
std::cout << "ScavTrap " + this->name + " is created" << std::endl;
}
ScavTrap::ScavTrap(const ScavTrap &scav) : ClapTrap(scav) {
*this = scav;
std::cout << "ScavTrap " + this->name + " is created" << std::endl;
}
ScavTrap::~ScavTrap() {
std::cout << "ScavTrap " + this->name + " is destroyed" << std::endl;
}
ScavTrap& ScavTrap::operator=(const ScavTrap &scav) {
if (this != &scav) {
ClapTrap::operator=(scav);
}
return *this;
}
void ScavTrap::attack(const std::string& target) {
if (this->energy > 0 && this->hp > 0) {
std::cout << "ScavTrap " + this->name + " attacks " + target + ", causing "
<< this->damage << " points of damage! " << std::endl;
this->energy--;
}
else
std::cout << "ScavTrap " + this->name + " is out of combat" << std::endl;
}
void ScavTrap::takeDamage(unsigned int amount) {
if (this->hp > 0) {
std::cout << "ScavTrap " + this->name + " takes " << amount << " damages" << std::endl;
this->energy--;
this->hp -= amount;
}
else
std::cout << "ScavTrap " + this->name + " is out of combat" << std::endl;
}
void ScavTrap::beRepaired(unsigned int amount) {
if (this->energy > 0 && this->hp > 0) {
std::cout << "ScavTrap " + this->name + " is repaired by " << amount << std::endl;
this->energy--;
this->hp += amount;
}
else
std::cout << "ScavTrap " + this->name + " is out of combat" << std::endl;
}
void ScavTrap::guardGate() {
if (this->energy > 0 && this->hp > 0) {
std::cout << "ScavTrap is now in Gate Keeper Mode" << std::endl;
this->energy--;
}
else
std::cout << "ScavTrap " + this->name + " is out of combat" << std::endl;
}

21
CPP03/ex02/ScavTrap.hpp Normal file
View file

@ -0,0 +1,21 @@
#ifndef SCAVTRAP_HPP
# define SCAVTRAP_HPP
#include "ClapTrap.hpp"
#include <iostream>
class ScavTrap : public ClapTrap {
public:
ScavTrap();
ScavTrap(std::string name);
~ScavTrap();
ScavTrap(const ScavTrap &clap);
ScavTrap& operator=(const ScavTrap &clap);
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
void guardGate();
};
#endif

54
CPP03/ex02/main.cpp Normal file
View file

@ -0,0 +1,54 @@
#include "ClapTrap.hpp"
#include "FragTrap.hpp"
int main(void) {
std::cout << "\n";
FragTrap none;
FragTrap clapy("Clapy");
ClapTrap clapo("Clapo");
std::cout << "\n----------------------------\n" << std::endl;
none.attack("Clapy");
none.takeDamage(100);
none.attack("Clapy");
none.beRepaired(10);
std::cout << "\n----------------------------\n" << std::endl;
clapy.attack("Clapo");
clapo.takeDamage(0);
clapy.takeDamage(50);
clapy.beRepaired(5);
clapy.takeDamage(50);
for (int i = 0; i < 100; i++)
clapy.attack("Clapo");
std::cout << "\n----------------------------\n" << std::endl;
{
FragTrap clapy2(clapy);
FragTrap clapy3 = clapy;
clapy2.attack("Clapo");
clapy3.attack("Clapo");
}
std::cout << "\n----------------------------\n" << std::endl;
{
FragTrap five("Fifi");
five.highFivesGuys();
five.takeDamage(100);
five.highFivesGuys();
ClapTrap *six = new FragTrap("Fyfy");
delete six;
}
std::cout << "\n----------------------------\n" << std::endl;
}

29
CPP04/ex00/Animal.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "Animal.hpp"
Animal::Animal() {
std::cout << "Animal born" << std::endl;
this->type = "Animal";
}
Animal::Animal(const Animal &other) {
*this = other;
}
Animal& Animal::operator=(const Animal &other) {
if (this != &other) {
this->type = other.type;
}
return (*this);
}
Animal::~Animal() {
std::cout << "Animal die" << std::endl;
}
std::string Animal::getType() const {
return type;
}
void Animal::makeSound() const {
std::cout << "Animal Sound" << std::endl;
}

20
CPP04/ex00/Animal.hpp Normal file
View file

@ -0,0 +1,20 @@
#ifndef ANIMAL_HPP
# define ANIMAL_HPP
# include <iostream>
class Animal {
public:
Animal();
virtual ~Animal();
Animal(const Animal &other);
Animal& operator=(const Animal &other);
virtual void makeSound() const;
std::string getType() const;
protected:
std::string type;
};
#endif

25
CPP04/ex00/Cat.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "Cat.hpp"
Cat::Cat() {
std::cout << "Cat born" << std::endl;
this->type = "Cat";
}
Cat::Cat(const Cat &other) : Animal() {
*this = other;
}
Cat& Cat::operator=(const Cat &other) {
if (this != &other) {
this->type = other.type;
}
return (*this);
}
Cat::~Cat() {
std::cout << "Cat die" << std::endl;
}
void Cat::makeSound() const {
std::cout << "Miaou" << std::endl;
}

16
CPP04/ex00/Cat.hpp Normal file
View file

@ -0,0 +1,16 @@
#ifndef CAT_HPP
# define CAT_HPP
#include "Animal.hpp"
class Cat : public Animal {
public:
Cat();
~Cat();
Cat(const Cat &other);
Cat& operator=(const Cat &other);
virtual void makeSound() const;
};
#endif

25
CPP04/ex00/Dog.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "Dog.hpp"
Dog::Dog() {
std::cout << "Dog born" << std::endl;
this->type = "Dog";
}
Dog::Dog(const Dog &other) : Animal() {
*this = other;
}
Dog& Dog::operator=(const Dog &other) {
if (this != &other) {
this->type = other.type;
}
return (*this);
}
Dog::~Dog() {
std::cout << "Dog die" << std::endl;
}
void Dog::makeSound() const {
std::cout << "Waf" << std::endl;
}

16
CPP04/ex00/Dog.hpp Normal file
View file

@ -0,0 +1,16 @@
#ifndef DOG_HPP
# define DOG_HPP
#include "Animal.hpp"
class Dog : public Animal {
public:
Dog();
~Dog();
Dog(const Dog &other);
Dog& operator=(const Dog &other);
virtual void makeSound() const;
};
#endif

129
CPP04/ex00/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Animal
all: ${NAME}
${NAME}: ${OBJS}
${CXX} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

View file

@ -0,0 +1,29 @@
#include "WrongAnimal.hpp"
WrongAnimal::WrongAnimal() {
std::cout << "WrongAnimal born" << std::endl;
this->type = "WrongAnimal";
}
WrongAnimal::WrongAnimal(const WrongAnimal &other) {
*this = other;
}
WrongAnimal& WrongAnimal::operator=(const WrongAnimal &other) {
if (this != &other) {
this->type = other.type;
}
return (*this);
}
WrongAnimal::~WrongAnimal() {
std::cout << "WrongAnimal die" << std::endl;
}
std::string WrongAnimal::getType() const {
return type;
}
void WrongAnimal::makeSound() const {
std::cout << "WrongAnimal Sound" << std::endl;
}

View file

@ -0,0 +1,20 @@
#ifndef WRONGANIMAL_HPP
# define WRONGANIMAL_HPP
# include <iostream>
class WrongAnimal {
public:
WrongAnimal();
virtual ~WrongAnimal();
WrongAnimal(const WrongAnimal &other);
WrongAnimal& operator=(const WrongAnimal &other);
void makeSound() const;
std::string getType() const;
protected:
std::string type;
};
#endif

25
CPP04/ex00/WrongCat.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "WrongCat.hpp"
WrongCat::WrongCat() {
std::cout << "WrongCat born" << std::endl;
this->type = "WrongCat";
}
WrongCat::WrongCat(const WrongCat &other) : WrongAnimal() {
*this = other;
}
WrongCat& WrongCat::operator=(const WrongCat &other) {
if (this != &other) {
this->type = other.type;
}
return (*this);
}
WrongCat::~WrongCat() {
std::cout << "WrongCat die" << std::endl;
}
void WrongCat::makeSound() const {
std::cout << "Meuh" << std::endl;
}

16
CPP04/ex00/WrongCat.hpp Normal file
View file

@ -0,0 +1,16 @@
#ifndef WRONGCAT_HPP
# define WRONGCAT_HPP
#include "WrongAnimal.hpp"
class WrongCat : public WrongAnimal {
public:
WrongCat();
~WrongCat();
WrongCat(const WrongCat &other);
WrongCat& operator=(const WrongCat &other);
void makeSound() const;
};
#endif

59
CPP04/ex00/main.cpp Normal file
View file

@ -0,0 +1,59 @@
#include "Animal.hpp"
#include "WrongAnimal.hpp"
#include "Cat.hpp"
#include "WrongCat.hpp"
#include "Dog.hpp"
int main() {
std::cout << "\n--Test0--\n" << std::endl;
{
const Animal* meta = new Animal();
const Animal* dog = new Dog();
const Animal* cat = new Cat();
std::cout << "\n";
std::cout << "animal: " + meta->getType() << std::endl;
std::cout << "dog: " + dog->getType() << std::endl;
std::cout << "cat: " + cat->getType() << std::endl;
std::cout << "dog Sound : ";
dog->makeSound();
std::cout << "cat Sound : ";
cat->makeSound();
std::cout << "animal Sound : ";
meta->makeSound();
std::cout << "\n";
delete meta;
delete dog;
delete cat;
}
std::cout << "\n--Test1--\n" << std::endl;
{
const WrongAnimal* wrongAnimal = new WrongAnimal();
const WrongAnimal* wrongCat = new WrongCat();
std::cout << "\n";
std::cout << "WrongAnimal: " + wrongAnimal->getType() << std::endl;
std::cout << "WrongCat: " + wrongCat->getType() << std::endl;
std::cout << "WrongAnimal Sound : ";
wrongAnimal->makeSound();
std::cout << "WrongCat Sound : ";
wrongCat->makeSound();
std::cout << "\n";
delete wrongAnimal;
delete wrongCat;
}
std::cout << "\n--End--\n" << std::endl;
return (0);
}

29
CPP04/ex01/Animal.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "Animal.hpp"
Animal::Animal() {
std::cout << "Animal born" << std::endl;
this->type = "Animal";
}
Animal::Animal(const Animal &other) {
*this = other;
}
Animal& Animal::operator=(const Animal &other) {
if (this != &other) {
this->type = other.type;
}
return (*this);
}
Animal::~Animal() {
std::cout << "Animal die" << std::endl;
}
std::string Animal::getType() const {
return type;
}
void Animal::makeSound() const {
std::cout << "Animal Sound" << std::endl;
}

20
CPP04/ex01/Animal.hpp Normal file
View file

@ -0,0 +1,20 @@
#ifndef ANIMAL_HPP
# define ANIMAL_HPP
# include <iostream>
class Animal {
public:
Animal();
virtual ~Animal();
Animal(const Animal &other);
Animal& operator=(const Animal &other);
virtual void makeSound() const;
std::string getType() const;
protected:
std::string type;
};
#endif

21
CPP04/ex01/Brain.cpp Normal file
View file

@ -0,0 +1,21 @@
#include "Brain.hpp"
Brain::Brain() {
std::cout << "Brain created" << std::endl;
}
Brain::~Brain() {
std::cout << "Brain destroyed" << std::endl;
}
Brain::Brain(const Brain &other) {
*this = other;
}
Brain& Brain::operator=(const Brain &other) {
if (this != &other) {
for (int i = 0; i < 100; i++)
this->ideas[i] = other.ideas[i];
}
return *this;
}

18
CPP04/ex01/Brain.hpp Normal file
View file

@ -0,0 +1,18 @@
#ifndef BRAIN_HPP
# define BRAIN_HPP
#include <string>
#include <iostream>
class Brain {
public:
Brain();
~Brain();
Brain(const Brain &other);
Brain& operator=(const Brain &other);
private:
std::string ideas[100];
};
#endif

29
CPP04/ex01/Cat.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "Cat.hpp"
Cat::Cat() : Animal() {
std::cout << "Cat born" << std::endl;
this->type = "Cat";
this->brain = new Brain();
}
Cat::Cat(const Cat &other) : Animal() {
this->brain = new Brain();
*this = other;
}
Cat& Cat::operator=(const Cat &other) {
if (this != &other) {
this->type = other.type;
*this->brain = *other.brain;
}
return (*this);
}
Cat::~Cat() {
std::cout << "Cat die" << std::endl;
delete this->brain;
}
void Cat::makeSound() const {
std::cout << "Miaou" << std::endl;
}

20
CPP04/ex01/Cat.hpp Normal file
View file

@ -0,0 +1,20 @@
#ifndef CAT_HPP
# define CAT_HPP
#include "Animal.hpp"
#include "Brain.hpp"
class Cat : public Animal {
public:
Cat();
~Cat();
Cat(const Cat &other);
Cat& operator=(const Cat &other);
virtual void makeSound() const;
private:
Brain *brain;
};
#endif

29
CPP04/ex01/Dog.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "Dog.hpp"
Dog::Dog() : Animal() {
std::cout << "Dog born" << std::endl;
this->type = "Dog";
this->brain = new Brain();
}
Dog::Dog(const Dog &other) : Animal() {
this->brain = new Brain();
*this = other;
}
Dog& Dog::operator=(const Dog &other) {
if (this != &other) {
this->type = other.type;
*this->brain = *other.brain;
}
return (*this);
}
Dog::~Dog() {
std::cout << "Dog die" << std::endl;
delete this->brain;
}
void Dog::makeSound() const {
std::cout << "Waf" << std::endl;
}

20
CPP04/ex01/Dog.hpp Normal file
View file

@ -0,0 +1,20 @@
#ifndef DOG_HPP
# define DOG_HPP
#include "Animal.hpp"
#include "Brain.hpp"
class Dog : public Animal {
public:
Dog();
~Dog();
Dog(const Dog &other);
Dog& operator=(const Dog &other);
virtual void makeSound() const;
private:
Brain *brain;
};
#endif

129
CPP04/ex01/Makefile Normal file
View file

@ -0,0 +1,129 @@
SRCS = $(shell find . -name "*.cpp")
OBJS = ${SRCS:.cpp=.o}
CXX = c++
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
NAME = Brain
all: ${NAME}
${NAME}: ${OBJS}
${CXX} -o ${NAME} ${OBJS} ${UTILS}
clean:
rm -f ${OBJS}
fclean:
rm -f ${OBJS} ${NAME}
re: fclean all
.PHONY: all clean fclean re coffee bozo
coffee:
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___...(-------)-....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ("
@echo " ) ("
@echo " ___..(.------)--....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
@sleep 0.3
@clear
@echo ""
@echo " ( ) "
@echo " ) ("
@echo " ___)...----)----....___"
@echo ' .-"" ) ( ""-.'
@echo " .-''''|-._ ( ) _.-|"
@echo ' / .--.| `""---...........---""` |'
@echo " / / | |"
@echo " | | | |"
@echo " \ \ | |"
@echo " '\ '\ | |"
@echo " '\ '| |"
@echo " _/ /\ /"
@echo " (__/ \ /"
@echo ' _..---""` \ /`""---.._'
@echo " .-' \ / '-."
@echo ": '-.__ __.-' :"
@echo ': ) ""---...---"" ( :'
@echo "\'._ '"--...___...--"' _.'"
@echo ' \""--..__ __..--""/'
@echo " '._ """----.....______.....----""" _.'"
@echo ' ""--..,,_____ _____,,..--"""'''
@echo ' """------"""'
make coffee
bozo :
@wget -q -O bozo.gif https://i.kym-cdn.com/photos/images/newsfeed/002/322/200/e51.gif
@xdg-open bozo.gif
@@sleep 2.13
@pkill eog
@rm bozo.gif

View file

@ -0,0 +1,29 @@
#include "WrongAnimal.hpp"
WrongAnimal::WrongAnimal() {
std::cout << "WrongAnimal born" << std::endl;
this->type = "WrongAnimal";
}
WrongAnimal::WrongAnimal(const WrongAnimal &other) {
*this = other;
}
WrongAnimal& WrongAnimal::operator=(const WrongAnimal &other) {
if (this != &other) {
this->type = other.type;
}
return (*this);
}
WrongAnimal::~WrongAnimal() {
std::cout << "WrongAnimal die" << std::endl;
}
std::string WrongAnimal::getType() const {
return type;
}
void WrongAnimal::makeSound() const {
std::cout << "WrongAnimal Sound" << std::endl;
}

View file

@ -0,0 +1,20 @@
#ifndef WRONGANIMAL_HPP
# define WRONGANIMAL_HPP
# include <iostream>
class WrongAnimal {
public:
WrongAnimal();
virtual ~WrongAnimal();
WrongAnimal(const WrongAnimal &other);
WrongAnimal& operator=(const WrongAnimal &other);
void makeSound() const;
std::string getType() const;
protected:
std::string type;
};
#endif

25
CPP04/ex01/WrongCat.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "WrongCat.hpp"
WrongCat::WrongCat() {
std::cout << "WrongCat born" << std::endl;
this->type = "WrongCat";
}
WrongCat::WrongCat(const WrongCat &other) : WrongAnimal() {
*this = other;
}
WrongCat& WrongCat::operator=(const WrongCat &other) {
if (this != &other) {
this->type = other.type;
}
return (*this);
}
WrongCat::~WrongCat() {
std::cout << "WrongCat die" << std::endl;
}
void WrongCat::makeSound() const {
std::cout << "Meuh" << std::endl;
}

16
CPP04/ex01/WrongCat.hpp Normal file
View file

@ -0,0 +1,16 @@
#ifndef WRONGCAT_HPP
# define WRONGCAT_HPP
#include "WrongAnimal.hpp"
class WrongCat : public WrongAnimal {
public:
WrongCat();
~WrongCat();
WrongCat(const WrongCat &other);
WrongCat& operator=(const WrongCat &other);
void makeSound() const;
};
#endif

33
CPP04/ex01/main.cpp Normal file
View file

@ -0,0 +1,33 @@
#include "Animal.hpp"
#include "WrongAnimal.hpp"
#include "Cat.hpp"
#include "WrongCat.hpp"
#include "Dog.hpp"
int main() {
std::cout << "\n--Test0--\n" << std::endl;
{
Cat cat1;
{
Cat cat2 = cat1;
}
}
std::cout << "\n--Test1--\n" << std::endl;
{
Dog dog1;
{
Dog dog2(dog1);
dog1 = dog2;
dog2 = dog1;
}
}
std::cout << "\n--Test2--\n" << std::endl;
{
Animal *dogo = new Dog();
delete dogo;
}
std::cout << "\n--End--\n" << std::endl;
return (0);
}

25
CPP04/ex02/Animal.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "Animal.hpp"
Animal::Animal() {
std::cout << "Animal born" << std::endl;
this->type = "Animal";
}
Animal::Animal(const Animal &other) {
*this = other;
}
Animal& Animal::operator=(const Animal &other) {
if (this != &other) {
this->type = other.type;
}
return (*this);
}
Animal::~Animal() {
std::cout << "Animal die" << std::endl;
}
std::string Animal::getType() const {
return type;
}

20
CPP04/ex02/Animal.hpp Normal file
View file

@ -0,0 +1,20 @@
#ifndef ANIMAL_HPP
# define ANIMAL_HPP
# include <iostream>
class Animal {
public:
Animal();
virtual ~Animal();
Animal(const Animal &other);
Animal& operator=(const Animal &other);
virtual void makeSound() const = 0;
std::string getType() const;
protected:
std::string type;
};
#endif

21
CPP04/ex02/Brain.cpp Normal file
View file

@ -0,0 +1,21 @@
#include "Brain.hpp"
Brain::Brain() {
std::cout << "Brain created" << std::endl;
}
Brain::~Brain() {
std::cout << "Brain Destroyed" << std::endl;
}
Brain::Brain(const Brain &other) {
*this = other;
}
Brain& Brain::operator=(const Brain &other) {
if (this != &other) {
for (int i = 0; i < 100; i++)
this->ideas[i] = other.ideas[i];
}
return *this;
}

Some files were not shown because too many files have changed in this diff Show more