diff --git a/d05/ex02/28b_28c b/d05/ex02/28b_28c deleted file mode 100755 index 4298f09..0000000 Binary files a/d05/ex02/28b_28c and /dev/null differ diff --git a/d05/ex02/Makefile b/d05/ex02/Makefile index 53d7be2..ef6aa67 100644 --- a/d05/ex02/Makefile +++ b/d05/ex02/Makefile @@ -25,12 +25,16 @@ D_SRCS = srcs SRCS = main.cpp \ Bureaucrat.cpp \ AForm.cpp \ - ShrubberyCreationForm.cpp + ShrubberyCreationForm.cpp \ + RobotomyRequestForm.cpp \ + PresidentialPardonForm.cpp D_HEADERS = headers HEADERS = Bureaucrat.hpp \ AForm.hpp \ - ShrubberyCreationForm.hpp + ShrubberyCreationForm.hpp \ + RobotomyRequestForm.hpp \ + PresidentialPardonForm.hpp D_OBJS = builds OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) diff --git a/d05/ex02/Shrubbery.txt b/d05/ex02/Shrubbery.txt deleted file mode 100644 index 5a1591f..0000000 --- a/d05/ex02/Shrubbery.txt +++ /dev/null @@ -1,17 +0,0 @@ - * * - * * * - * * * * * - * * * * * - * * * * * * * - * * * * * .# * * - * * * #. .# * * - * "#. #: #" * * * - * * * "#. ##" * - * "### - "## - ##. - .##: - :### - ;### - ,####. - /\/\/\/\/\/.######.\/\/\/\/\ diff --git a/d05/ex02/ascii.txt b/d05/ex02/ascii.txt new file mode 100644 index 0000000..787ae08 --- /dev/null +++ b/d05/ex02/ascii.txt @@ -0,0 +1,18 @@ + * * + * * * + * * * * * + * * * * * + * * * * * * * + * * * * * .# * * + * * * #. .# * * + * "#. #: #" * * * + * * * "#. ##" * + * "### + "## + ##. + .##: + :### + ;### + ,####. +/\/\/\/\/\/.######.\/\/\/\/\ + diff --git a/d05/ex02/headers/PresidentialPardonForm.hpp b/d05/ex02/headers/PresidentialPardonForm.hpp new file mode 100644 index 0000000..027661a --- /dev/null +++ b/d05/ex02/headers/PresidentialPardonForm.hpp @@ -0,0 +1,28 @@ +#ifndef PRESIDENTIALPARDONFORM_HPP +# define PRESIDENTIALPARDONFORM_HPP + +# include "color.h" +# include +# include +# include + +# include "AForm.hpp" + +class PresidentialPardonForm : public AForm { + +public: + + PresidentialPardonForm( std::string target ); + PresidentialPardonForm( PresidentialPardonForm const & src ); + ~PresidentialPardonForm(); + PresidentialPardonForm & operator=( PresidentialPardonForm const & rhs ); + + void formAction() const; + +private: + + PresidentialPardonForm(); +}; + +#endif + diff --git a/d05/ex02/headers/RobotomyRequestForm.hpp b/d05/ex02/headers/RobotomyRequestForm.hpp new file mode 100644 index 0000000..abeb7a9 --- /dev/null +++ b/d05/ex02/headers/RobotomyRequestForm.hpp @@ -0,0 +1,28 @@ +#ifndef ROBOTOMYREQUESTFORM_HPP +# define ROBOTOMYREQUESTFORM_HPP + +# include "color.h" +# include +# include +# include + +# include "AForm.hpp" + +class RobotomyRequestForm : public AForm { + +public: + + RobotomyRequestForm( std::string target ); + RobotomyRequestForm( RobotomyRequestForm const & src ); + ~RobotomyRequestForm(); + RobotomyRequestForm & operator=( RobotomyRequestForm const & rhs ); + + void formAction() const; + +private: + + RobotomyRequestForm(); +}; + +#endif + diff --git a/d05/ex02/headers/ShrubberyCreationForm.hpp b/d05/ex02/headers/ShrubberyCreationForm.hpp index 5b5c84e..0906a12 100644 --- a/d05/ex02/headers/ShrubberyCreationForm.hpp +++ b/d05/ex02/headers/ShrubberyCreationForm.hpp @@ -19,13 +19,9 @@ public: void formAction() const; -// std::string getTarget() const; - private: ShrubberyCreationForm(); -// std::string const _target; - }; #endif diff --git a/d05/ex02/main.cpp b/d05/ex02/main.cpp index 07d22ec..1b8f0c0 100644 --- a/d05/ex02/main.cpp +++ b/d05/ex02/main.cpp @@ -1,6 +1,8 @@ #include "Bureaucrat.hpp" #include "AForm.hpp" #include "ShrubberyCreationForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "PresidentialPardonForm.hpp" #define N_TEST "5" @@ -10,7 +12,7 @@ int main() { std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] " << "Shrubbery ok :" RESET "\n"; { - Bureaucrat b("natasha", 50); + Bureaucrat b("natasha", 1); ShrubberyCreationForm s("sekoia"); std::cout << s << '\n'; @@ -22,7 +24,7 @@ int main() { } std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] " - << "Shrubbery too low signe and execute :" RESET "\n"; + << "Shrubbery too low sign and execute :" RESET "\n"; { Bureaucrat b("jordan", 150); ShrubberyCreationForm s("chemney"); @@ -72,11 +74,42 @@ int main() { std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] " << "Robotomy :" RESET "\n"; { + Bureaucrat b("romeo", 15); + RobotomyRequestForm r("oven"); + + std::cout << r << '\n'; + std::cout << b << '\n'; + std::cout << B_BLUE "b.signForm :" RESET "\n"; + b.signForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + b.executeForm(r); + std::cout << r << '\n'; } std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] " << "Presidential :" RESET "\n"; { + Bureaucrat b("sylvestre", 1); + PresidentialPardonForm p("queen"); + + std::cout << p << '\n'; + std::cout << b << '\n'; + std::cout << B_BLUE "b.signForm :" RESET "\n"; + b.signForm(p); + b.executeForm(p); + std::cout << p << '\n'; } std::cout << "\n"; diff --git a/d05/ex02/srcs/PresidentialPardonForm.cpp b/d05/ex02/srcs/PresidentialPardonForm.cpp new file mode 100644 index 0000000..b22cffb --- /dev/null +++ b/d05/ex02/srcs/PresidentialPardonForm.cpp @@ -0,0 +1,47 @@ +#include "PresidentialPardonForm.hpp" + +#define COPLIEN_COLOR B_CYAN + +/********************************************* + * CONSTRUCTORS + *********************************************/ + +PresidentialPardonForm::PresidentialPardonForm( std::string target ) +: AForm("presidential_creation", target, 25, 5){ + std::cout << COPLIEN_COLOR "RobotomyRequestForm constructor" RESET "\n"; + return; +} + +PresidentialPardonForm::PresidentialPardonForm( PresidentialPardonForm const & src ) +: AForm("presidential_creation", this->getTarget(), 25, 5) { + std::cout << COPLIEN_COLOR "RobotomyRequestForm copy constructor" RESET "\n"; + *this = src; + return; +} + +/********************************************* + * DESTRUCTORS + *********************************************/ + +PresidentialPardonForm::~PresidentialPardonForm() { + std::cout << COPLIEN_COLOR "RobotomyRequestForm destructor" RESET "\n"; + return; +} + +/********************************************* + * OPERATORS + *********************************************/ + +PresidentialPardonForm & PresidentialPardonForm::operator=( PresidentialPardonForm const & rhs ) { + AForm::operator=(rhs); + return *this; +} + +/********************************************* + * PUBLIC MEMBER FUNCTIONS + *********************************************/ + +void PresidentialPardonForm::formAction() const { + std::cout << "Zaphod Beeblebrox pardon " << _target << "\n"; +} + diff --git a/d05/ex02/srcs/RobotomyRequestForm.cpp b/d05/ex02/srcs/RobotomyRequestForm.cpp new file mode 100644 index 0000000..a361f4a --- /dev/null +++ b/d05/ex02/srcs/RobotomyRequestForm.cpp @@ -0,0 +1,51 @@ +#include "RobotomyRequestForm.hpp" + +#define COPLIEN_COLOR B_CYAN + +/********************************************* + * CONSTRUCTORS + *********************************************/ + +RobotomyRequestForm::RobotomyRequestForm( std::string target ) +: AForm("robotomy_creation", target, 72, 45){ + std::cout << COPLIEN_COLOR "RobotomyRequestForm constructor" RESET "\n"; + return; +} + +RobotomyRequestForm::RobotomyRequestForm( RobotomyRequestForm const & src ) +: AForm("robotomy_creation", this->getTarget(), 72, 45) { + std::cout << COPLIEN_COLOR "RobotomyRequestForm copy constructor" RESET "\n"; + *this = src; + return; +} + +/********************************************* + * DESTRUCTORS + *********************************************/ + +RobotomyRequestForm::~RobotomyRequestForm() { + std::cout << COPLIEN_COLOR "RobotomyRequestForm destructor" RESET "\n"; + return; +} + +/********************************************* + * OPERATORS + *********************************************/ + +RobotomyRequestForm & RobotomyRequestForm::operator=( RobotomyRequestForm const & rhs ) { + AForm::operator=(rhs); + return *this; +} + +/********************************************* + * PUBLIC MEMBER FUNCTIONS + *********************************************/ + +void RobotomyRequestForm::formAction() const { + std::cout << "*drill sounds*\n"; + if (std::rand() % 2) + std::cout << _target << " robotomized with success\n"; + else + std::cout << _target << " robotomization failed\n"; +} + diff --git a/d05/ex02/srcs/ShrubberyCreationForm.cpp b/d05/ex02/srcs/ShrubberyCreationForm.cpp index 576083d..f018052 100644 --- a/d05/ex02/srcs/ShrubberyCreationForm.cpp +++ b/d05/ex02/srcs/ShrubberyCreationForm.cpp @@ -42,7 +42,8 @@ ShrubberyCreationForm & ShrubberyCreationForm::operator=( ShrubberyCreationForm *********************************************/ void ShrubberyCreationForm::formAction() const { - std::ofstream ofs("Shrubbery.txt", std::ofstream::out); + std::string name = _target + "_shrubbery"; + std::ofstream ofs(name.c_str(), std::ofstream::out); if (!ofs) {