From 26aae431ac647392e8519cd85582ea91f87c6218 Mon Sep 17 00:00:00 2001 From: kinou-p Date: Fri, 5 Aug 2022 15:39:46 +0200 Subject: [PATCH] ex05 presque fini --- cpp05/ex00/Bureaucrat.cpp | 11 ++- cpp05/ex00/Bureaucrat.hpp | 1 + cpp05/ex00/main.cpp | 72 +++++++++++++- cpp05/ex01/Bureaucrat.cpp | 11 ++- cpp05/ex01/Bureaucrat.hpp | 1 + cpp05/ex01/Form.cpp | 7 ++ cpp05/ex01/Form.hpp | 1 + cpp05/ex01/main.cpp | 91 ++++++++++++++++- cpp05/ex02/AForm.cpp | 9 +- cpp05/ex02/AForm.hpp | 6 +- cpp05/ex02/Bureaucrat.cpp | 14 ++- cpp05/ex02/Bureaucrat.hpp | 5 +- cpp05/ex02/PresidentialPardonForm.cpp | 5 +- cpp05/ex02/RobotomyRequestForm.cpp | 10 +- cpp05/ex02/ShrubberyCreationForm.cpp | 9 +- cpp05/ex02/main.cpp | 17 +++- cpp05/ex03/AForm.cpp | 133 +++++++++++++++++++++++++ cpp05/ex03/AForm.hpp | 83 ++++++++++++++++ cpp05/ex03/Assassin_shrubbery | 28 ++++++ cpp05/ex03/Bureaucrat.cpp | 110 +++++++++++++++++++++ cpp05/ex03/Bureaucrat.hpp | 61 ++++++++++++ cpp05/ex03/Intern.cpp | 65 ++++++++++++ cpp05/ex03/Intern.hpp | 27 +++++ cpp05/ex03/Makefile | 44 +++++++++ cpp05/ex03/PresidentialPardonForm.cpp | 46 +++++++++ cpp05/ex03/PresidentialPardonForm.hpp | 34 +++++++ cpp05/ex03/RobotomyRequestForm.cpp | 51 ++++++++++ cpp05/ex03/RobotomyRequestForm.hpp | 34 +++++++ cpp05/ex03/ShrubberyCreationForm.cpp | 52 ++++++++++ cpp05/ex03/ShrubberyCreationForm.hpp | 34 +++++++ cpp05/ex03/jardin_shrubbery | 28 ++++++ cpp05/ex03/main.cpp | 137 ++++++++++++++++++++++++++ cpp05/ex03/niceTree_shrubbery | 28 ++++++ 33 files changed, 1232 insertions(+), 33 deletions(-) create mode 100644 cpp05/ex03/AForm.cpp create mode 100644 cpp05/ex03/AForm.hpp create mode 100644 cpp05/ex03/Assassin_shrubbery create mode 100644 cpp05/ex03/Bureaucrat.cpp create mode 100644 cpp05/ex03/Bureaucrat.hpp create mode 100644 cpp05/ex03/Intern.cpp create mode 100644 cpp05/ex03/Intern.hpp create mode 100644 cpp05/ex03/Makefile create mode 100644 cpp05/ex03/PresidentialPardonForm.cpp create mode 100644 cpp05/ex03/PresidentialPardonForm.hpp create mode 100644 cpp05/ex03/RobotomyRequestForm.cpp create mode 100644 cpp05/ex03/RobotomyRequestForm.hpp create mode 100644 cpp05/ex03/ShrubberyCreationForm.cpp create mode 100644 cpp05/ex03/ShrubberyCreationForm.hpp create mode 100644 cpp05/ex03/jardin_shrubbery create mode 100644 cpp05/ex03/main.cpp create mode 100644 cpp05/ex03/niceTree_shrubbery diff --git a/cpp05/ex00/Bureaucrat.cpp b/cpp05/ex00/Bureaucrat.cpp index 54c0a61..a345240 100644 --- a/cpp05/ex00/Bureaucrat.cpp +++ b/cpp05/ex00/Bureaucrat.cpp @@ -6,21 +6,26 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/18 21:34:42 by apommier #+# #+# */ -/* Updated: 2022/07/19 11:59:12 by apommier ### ########.fr */ +/* Updated: 2022/08/05 13:12:53 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" +Bureaucrat::Bureaucrat() : _name("unnamed bureaucrat") +{ + this->_grade = 150; +} + Bureaucrat::Bureaucrat(int grade, std::string name) : _name(name) { this->_grade = grade; this->checkGrade(); } -Bureaucrat::Bureaucrat(const Bureaucrat& copy) +Bureaucrat::Bureaucrat(const Bureaucrat& copy) : _name(copy.getName()) { - *this = copy; + this->_grade = copy.getGrade(); } Bureaucrat::~Bureaucrat() diff --git a/cpp05/ex00/Bureaucrat.hpp b/cpp05/ex00/Bureaucrat.hpp index fd244b0..56d665a 100644 --- a/cpp05/ex00/Bureaucrat.hpp +++ b/cpp05/ex00/Bureaucrat.hpp @@ -20,6 +20,7 @@ class Bureaucrat{ public: + Bureaucrat(); Bureaucrat(int grade, std::string name); Bureaucrat(const Bureaucrat& copy); ~Bureaucrat(); diff --git a/cpp05/ex00/main.cpp b/cpp05/ex00/main.cpp index 92e1bee..69ee16c 100644 --- a/cpp05/ex00/main.cpp +++ b/cpp05/ex00/main.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/18 21:34:45 by apommier #+# #+# */ -/* Updated: 2022/07/19 11:32:05 by apommier ### ########.fr */ +/* Updated: 2022/08/05 13:24:05 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,14 +14,80 @@ int main() { + std::cout << "================Bureaucrat exeption and assignation test=================\n\n"; + std::cout << "---Bureaucrat grade of 151 :\n"; try { - Bureaucrat First(151, "john"); + Bureaucrat john1(151, "john"); + std::cout << "Bureaucrat become bureaucrat!\n"; } catch(std::exception &e) { std::cout << e.what(); - return (-1); } + std::cout << "\n---Bureaucrat grade of -1 :\n"; + try + { + Bureaucrat john2(-1, "john"); + std::cout << "Bureaucrat become bureaucrat!\n"; + } + catch(std::exception &e) + { + std::cout << e.what(); + } + std::cout << "\n---Bureaucrat grade of 50 :\n"; + try + { + Bureaucrat john3(50, "john"); + std::cout << "Bureaucrat become bureaucrat!\n"; + std::cout << john3 << std::endl; + std::cout << "\n---Copy test :\n"; + Bureaucrat john4(john3); + std::cout << john4 << std::endl; + std::cout << "---Assignement test :\n"; + Bureaucrat john5; + john5 = john4; + std::cout << john5 << std::endl; + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + + std::cout << "\n================Bureaucrat member function test=================\n\n"; + try + { + Bureaucrat john2(50, "john"); + std::cout << "Bureaucrat become bureaucrat!\n";\ + std::cout << john2 << std::endl; + john2.upGrade(); + std::cout << john2 << std::endl; + john2.upGrade(); + std::cout << john2 << std::endl; + john2.downGrade(); + std::cout << john2 << std::endl; + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + std::cout << "---same but with exeption\n"; + try + { + Bureaucrat john2(1, "john"); + std::cout << "Bureaucrat become bureaucrat!\n"; + std::cout << john2 << std::endl; + john2.upGrade(); + std::cout << john2 << std::endl; + john2.downGrade(); + std::cout << john2 << std::endl; + } + catch(std::exception &e) + { + std::cout << e.what(); + } + return (0); } \ No newline at end of file diff --git a/cpp05/ex01/Bureaucrat.cpp b/cpp05/ex01/Bureaucrat.cpp index daef1f9..ba2bbf7 100644 --- a/cpp05/ex01/Bureaucrat.cpp +++ b/cpp05/ex01/Bureaucrat.cpp @@ -6,21 +6,26 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/18 21:34:42 by apommier #+# #+# */ -/* Updated: 2022/07/19 12:55:48 by apommier ### ########.fr */ +/* Updated: 2022/08/05 13:13:08 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" +Bureaucrat::Bureaucrat() : _name("unnamed_bureaucrat") +{ + this->_grade = 150; +} + Bureaucrat::Bureaucrat(int grade, std::string name) : _name(name) { this->_grade = grade; this->checkGrade(); } -Bureaucrat::Bureaucrat(const Bureaucrat& copy) +Bureaucrat::Bureaucrat(const Bureaucrat& copy) : _name(copy.getName()) { - *this = copy; + this->_grade = copy.getGrade(); } Bureaucrat::~Bureaucrat() diff --git a/cpp05/ex01/Bureaucrat.hpp b/cpp05/ex01/Bureaucrat.hpp index c691d87..5364ae5 100644 --- a/cpp05/ex01/Bureaucrat.hpp +++ b/cpp05/ex01/Bureaucrat.hpp @@ -23,6 +23,7 @@ class Form; class Bureaucrat{ public: + Bureaucrat(); Bureaucrat(int grade, std::string name); Bureaucrat(const Bureaucrat& copy); ~Bureaucrat(); diff --git a/cpp05/ex01/Form.cpp b/cpp05/ex01/Form.cpp index 63c8b19..124f2f0 100644 --- a/cpp05/ex01/Form.cpp +++ b/cpp05/ex01/Form.cpp @@ -12,6 +12,13 @@ #include "Form.hpp" +Form::Form() : _name("unnamed form") +{ + this->_signedGrade = 1; + this->_executionGrade = 1; + this->_isSigned = 0; +} + Form::Form(int signedGrade, int executionGrade, std::string name) : _name(name) { this->_signedGrade = signedGrade; diff --git a/cpp05/ex01/Form.hpp b/cpp05/ex01/Form.hpp index e834d4a..d910716 100644 --- a/cpp05/ex01/Form.hpp +++ b/cpp05/ex01/Form.hpp @@ -23,6 +23,7 @@ class Bureaucrat; class Form{ public : + Form(); Form(int signedGrade, int executionGrade, std::string name); Form(const Form& copy); ~Form(); diff --git a/cpp05/ex01/main.cpp b/cpp05/ex01/main.cpp index 3f14eb3..17c68fa 100644 --- a/cpp05/ex01/main.cpp +++ b/cpp05/ex01/main.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/18 21:34:45 by apommier #+# #+# */ -/* Updated: 2022/07/19 12:42:13 by apommier ### ########.fr */ +/* Updated: 2022/08/05 13:30:03 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,14 +15,97 @@ int main() { + std::cout << "================Bureaucrat exeption test=================\n\n"; + std::cout << "---Bureaucrat grade of 151 :\n"; try { - Bureaucrat First(151, "john"); + Bureaucrat john1(151, "john"); + std::cout << "Bureaucrat become bureaucrat!\n"; + } + catch(std::exception &e) + { + std::cout << e.what(); + } + std::cout << "\n---Bureaucrat grade of -1 :\n"; + try + { + Bureaucrat john2(-1, "john"); + std::cout << "Bureaucrat become bureaucrat!\n"; + } + catch(std::exception &e) + { + std::cout << e.what(); + } + std::cout << "\n---Bureaucrat grade of 50 :\n"; + try + { + Bureaucrat john3(50, "john"); + std::cout << "Bureaucrat become bureaucrat!\n"; + std::cout << john3 << std::endl; + std::cout << "\n---Copy test :\n"; + Bureaucrat john4(john3); + std::cout << john4 << std::endl; + std::cout << "---Assignement test :\n"; + Bureaucrat john5; + john5 = john4; + std::cout << john5 << std::endl; + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + std::cout << "\n=======================Form test=======================\n\n"; + std::cout << "---Form execution grade of 151 :\n"; + try + { + Form form1(10, 151, "form_one"); + std::cout << "Form created!\n"; + } + catch(std::exception &e) + { + std::cout << e.what(); + } + std::cout << "\n---Form signed grade of -1 :\n"; + try + { + Form form2(-1, 10, "form_two"); + std::cout << "Form created!\n"; + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + + std::cout << "\n---Form signed grade of 50 :\n"; + try + { + Form form3(50, 10, "form_three"); + std::cout << "Form created!\n"; + std::cout << "trying to sign form by a 50 rank!\n"; + Bureaucrat john(50, "john"); + form3.beSigned(john); + std::cout << form3; + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + + std::cout << "\n---Form signed grade of 50 :\n"; + try + { + Bureaucrat john(51, "john"); + std::cout << john; + Form form3(50, 10, "form_three"); + std::cout << form3; + std::cout << "---trying to sign form with john---\n"; + form3.beSigned(john); } catch(std::exception &e) { std::cout << e.what(); - return (-1); } - return (0); } \ No newline at end of file diff --git a/cpp05/ex02/AForm.cpp b/cpp05/ex02/AForm.cpp index c54ef08..bacfae4 100644 --- a/cpp05/ex02/AForm.cpp +++ b/cpp05/ex02/AForm.cpp @@ -12,6 +12,13 @@ #include "AForm.hpp" +AForm::AForm() : _name("unnamed form") +{ + this->_signedGrade = 1; + this->_executionGrade = 1; + this->_isSigned = 0; +} + AForm::AForm(int signedGrade, int executionGrade, std::string name) : _name(name) { this->_signedGrade = signedGrade; @@ -91,7 +98,7 @@ void AForm::checkGrade() const throw AForm::GradeTooHighException(); } -void AForm::execute(Bureaucrat const & executor) const +void AForm::checkExecution(Bureaucrat const & executor) const { if (!this->_isSigned) throw AForm::formIsNotSignedException(); diff --git a/cpp05/ex02/AForm.hpp b/cpp05/ex02/AForm.hpp index 2ccb0e9..c395855 100644 --- a/cpp05/ex02/AForm.hpp +++ b/cpp05/ex02/AForm.hpp @@ -23,9 +23,10 @@ class Bureaucrat; class AForm{ public : + AForm(); AForm(int signedGrade, int executionGrade, std::string name); AForm(const AForm& copy); - virtual ~AForm() = 0; + virtual ~AForm(); AForm &operator=(const AForm& rhs); const std::string getName() const; @@ -36,7 +37,8 @@ class AForm{ void checkGrade() const; void beSigned(Bureaucrat &bureaucrat); - void execute(Bureaucrat const & executor) const; + virtual void execute(Bureaucrat const & executor) const = 0; + void checkExecution(Bureaucrat const & executor) const; class GradeTooLowException : public std::exception { diff --git a/cpp05/ex02/Bureaucrat.cpp b/cpp05/ex02/Bureaucrat.cpp index 9d6510e..ce3fd96 100644 --- a/cpp05/ex02/Bureaucrat.cpp +++ b/cpp05/ex02/Bureaucrat.cpp @@ -6,21 +6,26 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/18 21:34:42 by apommier #+# #+# */ -/* Updated: 2022/08/04 15:28:47 by apommier ### ########.fr */ +/* Updated: 2022/08/05 13:13:29 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" +Bureaucrat::Bureaucrat() : _name("unnamed bureaucrat") +{ + this->_grade = 150; +} + Bureaucrat::Bureaucrat(int grade, std::string name) : _name(name) { this->_grade = grade; this->checkGrade(); } -Bureaucrat::Bureaucrat(const Bureaucrat& copy) +Bureaucrat::Bureaucrat(const Bureaucrat& copy) : _name(copy.getName()) { - *this = copy; + this->_grade = copy.getGrade(); } Bureaucrat::~Bureaucrat() @@ -74,7 +79,7 @@ void Bureaucrat::checkGrade() const throw Bureaucrat::GradeTooHighException(); } -void Bureaucrat::signForm(AForm form) +void Bureaucrat::signForm(AForm &form) { try { @@ -89,4 +94,5 @@ void Bureaucrat::signForm(AForm form) void Bureaucrat::executeForm(AForm const & form) const { form.execute(*this); + std::cout << " executed
" << std::endl; } \ No newline at end of file diff --git a/cpp05/ex02/Bureaucrat.hpp b/cpp05/ex02/Bureaucrat.hpp index 00e1d0f..a53114e 100644 --- a/cpp05/ex02/Bureaucrat.hpp +++ b/cpp05/ex02/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/18 21:34:43 by apommier #+# #+# */ -/* Updated: 2022/08/04 15:26:47 by apommier ### ########.fr */ +/* Updated: 2022/08/05 12:57:35 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ class AForm; class Bureaucrat{ public: + Bureaucrat(); Bureaucrat(int grade, std::string name); Bureaucrat(const Bureaucrat& copy); ~Bureaucrat(); @@ -34,7 +35,7 @@ class Bureaucrat{ void downGrade(); void checkGrade() const; - void signForm(AForm form); + void signForm(AForm &form); void executeForm(AForm const & form) const; class GradeTooLowException : public std::exception diff --git a/cpp05/ex02/PresidentialPardonForm.cpp b/cpp05/ex02/PresidentialPardonForm.cpp index 939b654..c89780d 100644 --- a/cpp05/ex02/PresidentialPardonForm.cpp +++ b/cpp05/ex02/PresidentialPardonForm.cpp @@ -14,7 +14,7 @@ PresidentialPardonForm::PresidentialPardonForm() : AForm(25, 5, "PresidentialPardonForm") { - + this->_target = "anonymousTarget"; } PresidentialPardonForm::PresidentialPardonForm(std::string target) : AForm(25, 5, "PresidentialPardonForm") @@ -41,5 +41,6 @@ PresidentialPardonForm &PresidentialPardonForm::operator=(const PresidentialPard void PresidentialPardonForm::execute(Bureaucrat const & executor) const { - AForm::execute(executor); + AForm::checkExecution(executor); + std::cout << this->_target << " has been forgiven by Zaphod Beeblebrox\n"; } diff --git a/cpp05/ex02/RobotomyRequestForm.cpp b/cpp05/ex02/RobotomyRequestForm.cpp index e39277c..ec3e136 100644 --- a/cpp05/ex02/RobotomyRequestForm.cpp +++ b/cpp05/ex02/RobotomyRequestForm.cpp @@ -11,10 +11,11 @@ /* ************************************************************************** */ #include "RobotomyRequestForm.hpp" +#include RobotomyRequestForm::RobotomyRequestForm() : AForm(72, 45, "RobotomyRequestForm") { - + this->_target = "Unknow Target"; } RobotomyRequestForm::RobotomyRequestForm(std::string target) : AForm(72, 45, "RobotomyRequestForm") @@ -41,5 +42,10 @@ RobotomyRequestForm &RobotomyRequestForm::operator=(const RobotomyRequestForm& r void RobotomyRequestForm::execute(Bureaucrat const & executor) const { - AForm::execute(executor); + AForm::checkExecution(executor); + std::cout << "Brrrzrzrzrzzrzrzzrrzz...\n"; + if (std::rand() % 2) + std::cout << this->_target << " has been robotomized\n"; + else + std::cout << this->_target << " hasn't been robtomized\n"; } \ No newline at end of file diff --git a/cpp05/ex02/ShrubberyCreationForm.cpp b/cpp05/ex02/ShrubberyCreationForm.cpp index eed3c3a..2621c55 100644 --- a/cpp05/ex02/ShrubberyCreationForm.cpp +++ b/cpp05/ex02/ShrubberyCreationForm.cpp @@ -17,7 +17,7 @@ ShrubberyCreationForm::ShrubberyCreationForm() : AForm(145, 137, "RobotomyRequestForm") { - + this->_target = "Unknow Target"; } ShrubberyCreationForm::ShrubberyCreationForm(std::string target) : AForm(145, 137, "RobotomyRequestForm") @@ -44,9 +44,10 @@ ShrubberyCreationForm &ShrubberyCreationForm::operator=(const ShrubberyCreationF void ShrubberyCreationForm::execute(Bureaucrat const & executor) const { - std::string name = this->_target; + std::string name = this->_target + "_shrubbery"; std::cout << name << std::endl; - AForm::execute(executor); - std::ofstream outfile((std::string)name + "test"); + (void)executor; + //AForm::checkExecution(executor); + std::ofstream outfile(name.c_str()); outfile << " .\n . : \n . . :: :: \n . . ::: :: \n : : ::::. .. \n .. :: :: : ::. .:\n : ::: ::: . :: ::: .:.\n :: :::: . : :: ::: .::. \n ::: :: ::: : ::: .::.\n `::. ::: ::. `::::.::.\n `:::. :::. ::: :: :::::.\n `:::. ::bd:: :::::.\n `:::. :::. ::::. \n `::. `:::. :::: \n `:::. `::: :::: \n :::. :::: :::: \n ::bd:::bd:::: \n ::::::::::\n ::::::::\n :::(o): . . \n ::o:::(... \n `.. ::o:::: \n `):o:::: \n ::(o)::: \n .:::::: \n :::::::. \n :::::::::. \n ...::::::::::..."; } diff --git a/cpp05/ex02/main.cpp b/cpp05/ex02/main.cpp index 6f29ef1..23b782a 100644 --- a/cpp05/ex02/main.cpp +++ b/cpp05/ex02/main.cpp @@ -12,6 +12,9 @@ #include "AForm.hpp" #include "Bureaucrat.hpp" +#include "PresidentialPardonForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "ShrubberyCreationForm.hpp" int main() { @@ -22,9 +25,17 @@ int main() catch(std::exception &e) { std::cout << e.what(); - return (-1); } - //ShrubberyCreationForm test; - //test.execute() + Bureaucrat First(1, "john"); + ShrubberyCreationForm test("niceTree"); + try + { + test.execute(First); + } + catch(std::exception &e) + { + std::cout << e.what(); + } + return (0); } \ No newline at end of file diff --git a/cpp05/ex03/AForm.cpp b/cpp05/ex03/AForm.cpp new file mode 100644 index 0000000..6819028 --- /dev/null +++ b/cpp05/ex03/AForm.cpp @@ -0,0 +1,133 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* AForm.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/19 11:54:01 by apommier #+# #+# */ +/* Updated: 2022/07/19 12:54:48 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "AForm.hpp" + +AForm::AForm() : _name("unnamed form") +{ + this->_signedGrade = 1; + this->_executionGrade = 1; + this->_isSigned = 0; +} + +AForm::AForm(int signedGrade, int executionGrade, std::string name) : _name(name) +{ + this->_signedGrade = signedGrade; + this->_executionGrade = executionGrade; + this->_isSigned = 0; + this->checkGrade(); +} + +AForm::AForm(const AForm& copy) +{ + *this = copy; +} + +AForm::~AForm() +{ + +} + +AForm &AForm::operator=(const AForm& rhs) +{ + if (this != &rhs) + { + std::cout << "Only grade can be copied, name is const\n"; + this->_signedGrade = rhs.getSignedGrade(); + this->_executionGrade = rhs.getExecutionGrade(); + } + return (*this); +} + +std::ostream &operator<<(std::ostream &out, const AForm &Aform) +{ + out << Aform.getName() << "Aform need at least " << Aform.getSignedGrade() << " grade to be signed and "; + out << Aform.getExecutionGrade() << " grade to be executed, "; + if (Aform.getIsSigned()) + out << Aform.getName() << " Aform is signed\n"; + else + out << Aform.getName() << " Aform isn't signed\n"; + return (out); +} + +int AForm::getSignedGrade() const +{ + return (this->_signedGrade); +} + +int AForm::getExecutionGrade() const +{ + return (this->_executionGrade); +} + +int AForm::getIsSigned() const +{ + return (this->_isSigned); +} + +const std::string AForm::getName() const +{ + return (this->_name); +} + +void AForm::beSigned(Bureaucrat &bureaucrat) +{ + if (bureaucrat.getGrade() > this->_signedGrade) + throw AForm::signedGradeTooLowException(); + else + { + this->_isSigned = 1; + std::cout << bureaucrat.getName() << " signed " << this->_name << " form\n"; + } +} + +void AForm::checkGrade() const +{ + if (this->_signedGrade > 150 || this->_executionGrade > 150) + throw AForm::GradeTooLowException(); + else if (this->_signedGrade < 1 || this->_executionGrade < 1) + throw AForm::GradeTooHighException(); +} + +void AForm::checkExecution(Bureaucrat const & executor) const +{ + if (!this->_isSigned) + throw AForm::formIsNotSignedException(); + else if (executor.getGrade() > this->_executionGrade) + throw AForm::executionGradeTooLowException(); +} + +const char* AForm::GradeTooLowException::what() const throw() +{ + return ("Signed or Execution grade is too low\n"); +} + +const char* AForm::GradeTooHighException::what() const throw() +{ + return ("Signed or Execution grade is too high\n"); +} + +const char* AForm::signedGradeTooLowException::what() const throw() +{ + return ("Signed grade is too low\n"); +} + + +const char* AForm::executionGradeTooLowException::what() const throw() +{ + return ("Can't execute because Execution grade is too low\n"); +} + +const char* AForm::formIsNotSignedException::what() const throw() +{ + return ("Can't execute because Form isn't signed\n"); +} diff --git a/cpp05/ex03/AForm.hpp b/cpp05/ex03/AForm.hpp new file mode 100644 index 0000000..9f739b1 --- /dev/null +++ b/cpp05/ex03/AForm.hpp @@ -0,0 +1,83 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* AForm.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/19 11:54:09 by apommier #+# #+# */ +/* Updated: 2022/07/19 12:52:43 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef AFORM_HPP +# define AFORM_HPP + +# include +# include +# include +# include "Bureaucrat.hpp" + +class Bureaucrat; + +class AForm{ + public : + + AForm(); + AForm(int signedGrade, int executionGrade, std::string name); + AForm(const AForm& copy); + virtual ~AForm(); + AForm &operator=(const AForm& rhs); + + const std::string getName() const; + int getSignedGrade() const; + int getExecutionGrade() const; + int getIsSigned() const; + + void checkGrade() const; + + void beSigned(Bureaucrat &bureaucrat); + virtual void execute(Bureaucrat const & executor) const = 0; + void checkExecution(Bureaucrat const & executor) const; + + class GradeTooLowException : public std::exception + { + public : + virtual const char* what() const throw(); + }; + + class GradeTooHighException : public std::exception + { + public : + virtual const char* what() const throw(); + }; + + class signedGradeTooLowException : public std::exception + { + public : + virtual const char* what() const throw(); + }; + + class executionGradeTooLowException : public std::exception + { + public : + virtual const char* what() const throw(); + }; + + class formIsNotSignedException : public std::exception + { + public : + virtual const char* what() const throw(); + }; + + private : + + std::string const _name; + bool _isSigned; + int _signedGrade; + int _executionGrade; +}; + +std::ostream &operator<<(std::ostream &out, const AForm &Aform); + +#endif \ No newline at end of file diff --git a/cpp05/ex03/Assassin_shrubbery b/cpp05/ex03/Assassin_shrubbery new file mode 100644 index 0000000..83ba7de --- /dev/null +++ b/cpp05/ex03/Assassin_shrubbery @@ -0,0 +1,28 @@ + . + . : + . . :: :: + . . ::: :: + : : ::::. .. + .. :: :: : ::. .: + : ::: ::: . :: ::: .:. + :: :::: . : :: ::: .::. + ::: :: ::: : ::: .::. + `::. ::: ::. `::::.::. + `:::. :::. ::: :: :::::. + `:::. ::bd:: :::::. + `:::. :::. ::::. + `::. `:::. :::: + `:::. `::: :::: + :::. :::: :::: + ::bd:::bd:::: + :::::::::: + :::::::: + :::(o): . . + ::o:::(... + `.. ::o:::: + `):o:::: + ::(o)::: + .:::::: + :::::::. + :::::::::. + ...::::::::::... \ No newline at end of file diff --git a/cpp05/ex03/Bureaucrat.cpp b/cpp05/ex03/Bureaucrat.cpp new file mode 100644 index 0000000..52a7217 --- /dev/null +++ b/cpp05/ex03/Bureaucrat.cpp @@ -0,0 +1,110 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/18 21:34:42 by apommier #+# #+# */ +/* Updated: 2022/08/05 14:14:42 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat() : _name("unnamed_bureaucrat") +{ + this->_grade = 150; +} + + +Bureaucrat::Bureaucrat(int grade, std::string name) : _name(name) +{ + this->_grade = grade; + this->checkGrade(); +} + +Bureaucrat::Bureaucrat(const Bureaucrat& copy) : _name(copy.getName()) +{ + this->_grade = copy.getGrade(); +} + +Bureaucrat::~Bureaucrat() +{ + +} + +Bureaucrat &Bureaucrat::operator=(const Bureaucrat& rhs) +{ + if (this != &rhs) + { + std::cout << "Only grade can be copied, name is const\n"; + this->_grade = rhs.getGrade(); + } + return (*this); +} + +std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat) +{ + out << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade(); + return (out); +} + +const std::string Bureaucrat::getName() const +{ + return (this->_name); +} + +int Bureaucrat::getGrade() const +{ + return (this->_grade); +} + +void Bureaucrat::upGrade() +{ + this->_grade--; + this->checkGrade(); +} + +void Bureaucrat::downGrade() +{ + this->_grade++; + this->checkGrade(); +} + +void Bureaucrat::checkGrade() const +{ + if (this->_grade > 150) + throw Bureaucrat::GradeTooLowException(); + else if (this->_grade < 1) + throw Bureaucrat::GradeTooHighException(); +} + +void Bureaucrat::signForm(AForm &form) +{ + try + { + form.beSigned(*this); + } + catch (std::exception &e) + { + std::cout << this->_name << " couldn’t sign " << form.getName() << " form because "<< e.what(); + } +} + +void Bureaucrat::executeForm(AForm const & form) const +{ + form.execute(*this); + std::cout << this->_name << " executed " << form.getName() << std::endl; +} + + +const char* Bureaucrat::GradeTooLowException::what() const throw() +{ + return ("Bureaucrat grade is too low\n"); +} + +const char* Bureaucrat::GradeTooHighException::what() const throw() +{ + return ("Bureaucrat grade is too high\n"); +} \ No newline at end of file diff --git a/cpp05/ex03/Bureaucrat.hpp b/cpp05/ex03/Bureaucrat.hpp new file mode 100644 index 0000000..cfd3b24 --- /dev/null +++ b/cpp05/ex03/Bureaucrat.hpp @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/18 21:34:43 by apommier #+# #+# */ +/* Updated: 2022/08/05 12:47:03 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef BUREAUCRAT_HPP +# define BUREAUCRAT_HPP + +# include +# include +# include +# include "AForm.hpp" + +class AForm; + +class Bureaucrat{ + public: + + Bureaucrat(); + Bureaucrat(int grade, std::string name); + Bureaucrat(const Bureaucrat& copy); + ~Bureaucrat(); + Bureaucrat &operator=(const Bureaucrat& rhs); + + const std::string getName() const; + int getGrade() const; + void upGrade(); + void downGrade(); + void checkGrade() const; + + void signForm(AForm &form); + void executeForm(AForm const & form) const; + + class GradeTooLowException : public std::exception + { + public : + virtual const char* what() const throw(); + }; + + class GradeTooHighException : public std::exception + { + public : + virtual const char* what() const throw(); + }; + + private: + + std::string const _name; + int _grade; +}; + +std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat); + +#endif \ No newline at end of file diff --git a/cpp05/ex03/Intern.cpp b/cpp05/ex03/Intern.cpp new file mode 100644 index 0000000..0c5cd87 --- /dev/null +++ b/cpp05/ex03/Intern.cpp @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Intern.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/05 12:02:52 by apommier #+# #+# */ +/* Updated: 2022/08/05 12:02:54 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Intern.hpp" + + + +Intern::Intern() +{ + +} + +Intern::Intern(const Intern& copy) +{ + *this = copy; +} + +Intern::~Intern() +{ + +} + +Intern &Intern::operator=(const Intern& rhs) +{ + (void)rhs; + return (*this); +} + +AForm *Intern::makeForm(std::string formName, std::string target) +{ + std::string formNames[3] = {"shrubbery creation", "robotomy request", "presidential pardon"}; + int i = 0; + + while (i < 3 && formNames[i] != formName) + i++; + AForm* ret = NULL; + switch (i) + { + case 0: + ret = new ShrubberyCreationForm(target); + break; + case 1: + ret = new RobotomyRequestForm(target); + break; + case 2: + ret = new PresidentialPardonForm(target); + break; + default: + break; + } + if (ret) + std::cout << "Intern creates " << formName << std::endl; + else + std::cout << "Intern say that " << formName << " form doesn't exist\n"; + return (ret); +} diff --git a/cpp05/ex03/Intern.hpp b/cpp05/ex03/Intern.hpp new file mode 100644 index 0000000..60aeda6 --- /dev/null +++ b/cpp05/ex03/Intern.hpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Intern.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/05 02:25:32 by apommier #+# #+# */ +/* Updated: 2022/08/05 11:12:21 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "AForm.hpp" +#include "PresidentialPardonForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "ShrubberyCreationForm.hpp" + +class Intern{ + public: + + Intern(); + Intern(const Intern& copy); + ~Intern(); + Intern &operator=(const Intern& rhs); + + AForm *makeForm(std::string formName, std::string target); +}; \ No newline at end of file diff --git a/cpp05/ex03/Makefile b/cpp05/ex03/Makefile new file mode 100644 index 0000000..4d5562a --- /dev/null +++ b/cpp05/ex03/Makefile @@ -0,0 +1,44 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2022/07/18 21:34:54 by apommier #+# #+# # +# Updated: 2022/08/05 11:08:29 by apommier ### ########.fr # +# # +# **************************************************************************** # + +NAME = a.out +SRCS = main.cpp\ + Bureaucrat.cpp\ + AForm.cpp\ + PresidentialPardonForm.cpp\ + RobotomyRequestForm.cpp\ + ShrubberyCreationForm.cpp\ + Intern.cpp + + +OBJS = ${SRCS:.cpp=.o} +CC = c++ +CFLAGS = -Wall -Wextra -Werror -std=c++98 +RM = rm -rf + +.cpp.o: + $(CC) ${CFLAGS} -c $< -o $(<:.cpp=.o) + +${NAME}: ${OBJS} + ${CC} ${LIB} ${OBJS} -o ${NAME} + +all: ${NAME} + +clean: + @${RM} ${OBJS} + +fclean: clean + @${RM} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re \ No newline at end of file diff --git a/cpp05/ex03/PresidentialPardonForm.cpp b/cpp05/ex03/PresidentialPardonForm.cpp new file mode 100644 index 0000000..c89780d --- /dev/null +++ b/cpp05/ex03/PresidentialPardonForm.cpp @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* PresidentialPardonForm.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/23 12:16:26 by apommier #+# #+# */ +/* Updated: 2022/08/04 18:52:20 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "PresidentialPardonForm.hpp" + +PresidentialPardonForm::PresidentialPardonForm() : AForm(25, 5, "PresidentialPardonForm") +{ + this->_target = "anonymousTarget"; +} + +PresidentialPardonForm::PresidentialPardonForm(std::string target) : AForm(25, 5, "PresidentialPardonForm") +{ + this->_target = target; +} + +PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm& copy) : AForm(copy) +{ + *this = copy; +} + +PresidentialPardonForm::~PresidentialPardonForm() +{ + +} + +PresidentialPardonForm &PresidentialPardonForm::operator=(const PresidentialPardonForm& rhs) +{ + if (&rhs != this) + this->_target = rhs._target; + return (*this); +} + +void PresidentialPardonForm::execute(Bureaucrat const & executor) const +{ + AForm::checkExecution(executor); + std::cout << this->_target << " has been forgiven by Zaphod Beeblebrox\n"; +} diff --git a/cpp05/ex03/PresidentialPardonForm.hpp b/cpp05/ex03/PresidentialPardonForm.hpp new file mode 100644 index 0000000..edda022 --- /dev/null +++ b/cpp05/ex03/PresidentialPardonForm.hpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* PresidentialPardonForm.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/02 18:21:41 by apommier #+# #+# */ +/* Updated: 2022/08/04 15:07:38 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef PRESIDENTIALPARDONFORM_HPP +# define PRESIDENTIALPARDONFORM_HPP + +# include "AForm.hpp" + +class PresidentialPardonForm : public AForm{ + public : + + PresidentialPardonForm(); + PresidentialPardonForm(std::string target); + PresidentialPardonForm(const PresidentialPardonForm& copy); + ~PresidentialPardonForm(); + PresidentialPardonForm &operator=(const PresidentialPardonForm& rhs); + + void execute(Bureaucrat const & executor) const; + + private : + + std::string _target; +}; + +#endif \ No newline at end of file diff --git a/cpp05/ex03/RobotomyRequestForm.cpp b/cpp05/ex03/RobotomyRequestForm.cpp new file mode 100644 index 0000000..85a2ac6 --- /dev/null +++ b/cpp05/ex03/RobotomyRequestForm.cpp @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* RobotomyRequestForm.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/08/04 15:14:32 by apommier #+# #+# */ +/* Updated: 2022/08/05 14:30:26 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "RobotomyRequestForm.hpp" +#include + +RobotomyRequestForm::RobotomyRequestForm() : AForm(72, 45, "RobotomyRequestForm") +{ + this->_target = "Unknow Target"; +} + +RobotomyRequestForm::RobotomyRequestForm(std::string target) : AForm(72, 45, "RobotomyRequestForm") +{ + this->_target = target; +} + +RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm& copy) : AForm(copy) +{ + *this = copy; +} + +RobotomyRequestForm::~RobotomyRequestForm() +{ + +} + +RobotomyRequestForm &RobotomyRequestForm::operator=(const RobotomyRequestForm& rhs) +{ + if (&rhs != this) + this->_target = rhs._target; + return (*this); +} + +void RobotomyRequestForm::execute(Bureaucrat const & executor) const +{ + AForm::checkExecution(executor); + std::cout << "Brrrzrzrzrzzrzrzzrrzz...\n"; + if (std::rand() % 2) + std::cout << this->_target << " has been robotomized\n"; + else + std::cout << this->_target << " hasn't been robtomized\n"; +} \ No newline at end of file diff --git a/cpp05/ex03/RobotomyRequestForm.hpp b/cpp05/ex03/RobotomyRequestForm.hpp new file mode 100644 index 0000000..f66b8c5 --- /dev/null +++ b/cpp05/ex03/RobotomyRequestForm.hpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* RobotomyRequestForm.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/19 13:00:11 by apommier #+# #+# */ +/* Updated: 2022/07/23 12:30:09 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ROBOTOMYREQUESTFORM_HPP +# define ROBOTOMYREQUESTFORM_HPP + +# include "AForm.hpp" + +class RobotomyRequestForm : public AForm{ + public : + + RobotomyRequestForm(); + RobotomyRequestForm(std::string target); + RobotomyRequestForm(const RobotomyRequestForm& copy); + ~RobotomyRequestForm(); + RobotomyRequestForm &operator=(const RobotomyRequestForm& rhs); + + void execute(Bureaucrat const & executor) const; + + private : + + std::string _target; +}; + +#endif \ No newline at end of file diff --git a/cpp05/ex03/ShrubberyCreationForm.cpp b/cpp05/ex03/ShrubberyCreationForm.cpp new file mode 100644 index 0000000..5ee0d9c --- /dev/null +++ b/cpp05/ex03/ShrubberyCreationForm.cpp @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ShrubberyCreationForm.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/19 13:00:14 by apommier #+# #+# */ +/* Updated: 2022/08/05 14:33:22 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ShrubberyCreationForm.hpp" +# include +# include +# include + +ShrubberyCreationForm::ShrubberyCreationForm() : AForm(145, 137, "RobotomyRequestForm") +{ + this->_target = "Unknow Target"; +} + +ShrubberyCreationForm::ShrubberyCreationForm(std::string target) : AForm(145, 137, "RobotomyRequestForm") +{ + this->_target = target; +} + +ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm& copy) : AForm(copy) +{ + *this = copy; +} + +ShrubberyCreationForm::~ShrubberyCreationForm() +{ + +} + +ShrubberyCreationForm &ShrubberyCreationForm::operator=(const ShrubberyCreationForm& rhs) +{ + if (&rhs != this) + this->_target = rhs._target; + return (*this); +} + +void ShrubberyCreationForm::execute(Bureaucrat const & executor) const +{ + AForm::checkExecution(executor); + std::string name = this->_target + "_shrubbery"; + (void)executor; + std::ofstream outfile(name.c_str()); + outfile << " .\n . : \n . . :: :: \n . . ::: :: \n : : ::::. .. \n .. :: :: : ::. .:\n : ::: ::: . :: ::: .:.\n :: :::: . : :: ::: .::. \n ::: :: ::: : ::: .::.\n `::. ::: ::. `::::.::.\n `:::. :::. ::: :: :::::.\n `:::. ::bd:: :::::.\n `:::. :::. ::::. \n `::. `:::. :::: \n `:::. `::: :::: \n :::. :::: :::: \n ::bd:::bd:::: \n ::::::::::\n ::::::::\n :::(o): . . \n ::o:::(... \n `.. ::o:::: \n `):o:::: \n ::(o)::: \n .:::::: \n :::::::. \n :::::::::. \n ...::::::::::..."; +} diff --git a/cpp05/ex03/ShrubberyCreationForm.hpp b/cpp05/ex03/ShrubberyCreationForm.hpp new file mode 100644 index 0000000..b8c130b --- /dev/null +++ b/cpp05/ex03/ShrubberyCreationForm.hpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ShrubberyCreationForm.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/19 13:00:12 by apommier #+# #+# */ +/* Updated: 2022/08/04 18:54:10 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef SHRUBBERYCREATIONFORM_HPP +# define SHRUBBERYCREATIONFORM_HPP + +# include "AForm.hpp" + +class ShrubberyCreationForm : public AForm{ + public : + + ShrubberyCreationForm(); + ShrubberyCreationForm(std::string target); + ShrubberyCreationForm(const ShrubberyCreationForm& copy); + ~ShrubberyCreationForm(); + ShrubberyCreationForm &operator=(const ShrubberyCreationForm& rhs); + + void execute(Bureaucrat const & executor) const; + + private : + + std::string _target; +}; + +#endif \ No newline at end of file diff --git a/cpp05/ex03/jardin_shrubbery b/cpp05/ex03/jardin_shrubbery new file mode 100644 index 0000000..83ba7de --- /dev/null +++ b/cpp05/ex03/jardin_shrubbery @@ -0,0 +1,28 @@ + . + . : + . . :: :: + . . ::: :: + : : ::::. .. + .. :: :: : ::. .: + : ::: ::: . :: ::: .:. + :: :::: . : :: ::: .::. + ::: :: ::: : ::: .::. + `::. ::: ::. `::::.::. + `:::. :::. ::: :: :::::. + `:::. ::bd:: :::::. + `:::. :::. ::::. + `::. `:::. :::: + `:::. `::: :::: + :::. :::: :::: + ::bd:::bd:::: + :::::::::: + :::::::: + :::(o): . . + ::o:::(... + `.. ::o:::: + `):o:::: + ::(o)::: + .:::::: + :::::::. + :::::::::. + ...::::::::::... \ No newline at end of file diff --git a/cpp05/ex03/main.cpp b/cpp05/ex03/main.cpp new file mode 100644 index 0000000..80ddd32 --- /dev/null +++ b/cpp05/ex03/main.cpp @@ -0,0 +1,137 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/18 21:34:45 by apommier #+# #+# */ +/* Updated: 2022/08/05 14:46:57 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "AForm.hpp" +#include "Bureaucrat.hpp" +#include "PresidentialPardonForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "ShrubberyCreationForm.hpp" + +int main() +{ + std::cout << "===============================Presidential pardon=============================\n\n"; + std::cout << "Trying to execute without sign :\n"; + try + { + Bureaucrat john(150, "john"); + PresidentialPardonForm form("Assassin"); + john.executeForm(form); + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + std::cout << "\nTrying to execute without the right grade :\n"; + try + { + Bureaucrat john(25, "john"); + PresidentialPardonForm form("Assassin"); + form.beSigned(john); + john.executeForm(form); + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + std::cout << "\nAll good :\n"; + try + { + Bureaucrat john(5, "john"); + PresidentialPardonForm form("Assassin"); + form.beSigned(john); + john.executeForm(form); + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + std::cout << "\n===============================Robotomy request=============================\n\n"; + std::cout << "Trying to execute without sign :\n"; + try + { + Bureaucrat john(150, "john"); + RobotomyRequestForm form("Assassin"); + john.executeForm(form); + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + std::cout << "\nTrying to execute without the right grade :\n"; + try + { + Bureaucrat john(46, "john"); + RobotomyRequestForm form("Assassin"); + form.beSigned(john); + john.executeForm(form); + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + std::cout << "\nAll good :\n"; + try + { + Bureaucrat john(5, "john"); + RobotomyRequestForm form("Assassin"); + form.beSigned(john); + john.executeForm(form); + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + std::cout << "\n===============================Shrubbery Creation=============================\n\n"; + std::cout << "Trying to execute without sign :\n"; + try + { + Bureaucrat john(150, "john"); + ShrubberyCreationForm form("Assassin"); + john.executeForm(form); + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + std::cout << "\nTrying to execute without the right grade :\n"; + try + { + Bureaucrat john(137, "john"); + ShrubberyCreationForm form("Assassin"); + form.beSigned(john); + john.executeForm(form); + } + catch(std::exception &e) + { + std::cout << e.what(); + } + + std::cout << "\nAll good :\n"; + try + { + Bureaucrat john(5, "john"); + ShrubberyCreationForm form("Assassin"); + form.beSigned(john); + john.executeForm(form); + } + catch(std::exception &e) + { + std::cout << e.what(); + } +} \ No newline at end of file diff --git a/cpp05/ex03/niceTree_shrubbery b/cpp05/ex03/niceTree_shrubbery new file mode 100644 index 0000000..83ba7de --- /dev/null +++ b/cpp05/ex03/niceTree_shrubbery @@ -0,0 +1,28 @@ + . + . : + . . :: :: + . . ::: :: + : : ::::. .. + .. :: :: : ::. .: + : ::: ::: . :: ::: .:. + :: :::: . : :: ::: .::. + ::: :: ::: : ::: .::. + `::. ::: ::. `::::.::. + `:::. :::. ::: :: :::::. + `:::. ::bd:: :::::. + `:::. :::. ::::. + `::. `:::. :::: + `:::. `::: :::: + :::. :::: :::: + ::bd:::bd:::: + :::::::::: + :::::::: + :::(o): . . + ::o:::(... + `.. ::o:::: + `):o:::: + ::(o)::: + .:::::: + :::::::. + :::::::::. + ...::::::::::... \ No newline at end of file