From 9aa5e8f9c5097c51136290bedba373d6721b0b54 Mon Sep 17 00:00:00 2001 From: Ladebeze66 Date: Thu, 22 Feb 2024 16:34:34 +0100 Subject: [PATCH] ex02 --- cpp05/ex00/Bureaucrat.hpp | 6 +-- cpp05/ex01/Bureaucrat.hpp | 6 +-- cpp05/ex01/Form.cpp | 12 ++--- cpp05/ex01/Form.hpp | 7 ++- cpp05/ex01/Makefile | 8 +-- cpp05/ex02/AForm.cpp | 19 +++---- cpp05/ex02/AForm.hpp | 9 ++-- cpp05/ex02/Bureaucrat.cpp | 6 +-- cpp05/ex02/Bureaucrat.hpp | 8 +-- cpp05/ex02/Home_shrubbery | 1 - cpp05/ex02/Makefile | 8 +-- cpp05/ex02/PresidentialPardonForm.cpp | 2 +- cpp05/ex02/PresidentialPardonForm.hpp | 5 +- cpp05/ex02/RobotomyRequestForm.cpp | 18 +++++-- cpp05/ex02/RobotomyRequestForm.hpp | 8 +-- cpp05/ex02/ShrubberyCreationForm.cpp | 33 +++++++++--- cpp05/ex02/ShrubberyCreationForm.hpp | 5 +- cpp05/ex02/main.cpp | 78 +++++++++++++++++++++++---- 18 files changed, 160 insertions(+), 79 deletions(-) delete mode 100644 cpp05/ex02/Home_shrubbery diff --git a/cpp05/ex00/Bureaucrat.hpp b/cpp05/ex00/Bureaucrat.hpp index cc93394..5d6b751 100644 --- a/cpp05/ex00/Bureaucrat.hpp +++ b/cpp05/ex00/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 12:57:28 by fgras-ca #+# #+# */ -/* Updated: 2024/02/16 16:39:04 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 12:40:07 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,13 +33,13 @@ public: class GradeTooHighException : public std::exception { public: - const char* what() const throw() override; + const char* what() const throw(); }; class GradeTooLowException : public std::exception { public: - const char* what() const throw() override; + const char* what() const throw(); }; Bureaucrat(); diff --git a/cpp05/ex01/Bureaucrat.hpp b/cpp05/ex01/Bureaucrat.hpp index 99f03ed..693280a 100644 --- a/cpp05/ex01/Bureaucrat.hpp +++ b/cpp05/ex01/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 12:57:28 by fgras-ca #+# #+# */ -/* Updated: 2024/02/16 17:30:30 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 12:45:13 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,13 +34,13 @@ public: class GradeTooHighException : public std::exception { public: - const char* what() const throw() override; + const char* what() const throw(); }; class GradeTooLowException : public std::exception { public: - const char* what() const throw() override; + const char* what() const throw(); }; Bureaucrat(); diff --git a/cpp05/ex01/Form.cpp b/cpp05/ex01/Form.cpp index 93a77cd..7b143df 100644 --- a/cpp05/ex01/Form.cpp +++ b/cpp05/ex01/Form.cpp @@ -6,19 +6,13 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:39:51 by fgras-ca #+# #+# */ -/* Updated: 2024/02/16 18:19:00 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 12:48:40 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" #include "Form.hpp" -Form::Form() - : name(name), isSigned(false), gradeRequiredToSign(1), gradeRequiredToExecute(1) -{ - std::cout << GREEN << "Form default constructor called!" << RESET << std::endl; -} - Form::Form(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute) : name(name), isSigned(false), gradeRequiredToSign(gradeRequiredToSign), gradeRequiredToExecute(gradeRequiredToExecute) { @@ -84,12 +78,12 @@ void Form::beSigned(const Bureaucrat& bureaucrat) } } -const char* Form::GradeTooHighException::what() const noexcept +const char* Form::GradeTooHighException::what() const throw() { return ("Grade too hight\n"); } -const char* Form::GradeTooLowException::what() const noexcept +const char* Form::GradeTooLowException::what() const throw() { return ("Grade too low\n"); } diff --git a/cpp05/ex01/Form.hpp b/cpp05/ex01/Form.hpp index d9efcd9..c3ee743 100644 --- a/cpp05/ex01/Form.hpp +++ b/cpp05/ex01/Form.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:37:14 by fgras-ca #+# #+# */ -/* Updated: 2024/02/16 18:26:09 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 12:48:27 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,6 @@ private: public: //constructueur - Form(); Form(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute); // Constructeur par copie Form(const Form& other); @@ -49,13 +48,13 @@ public: class GradeTooHighException : public std::exception { public: - const char* what() const noexcept override; + const char* what() const throw(); }; class GradeTooLowException : public std::exception { public: - const char* what() const noexcept override; + const char* what() const throw(); }; }; diff --git a/cpp05/ex01/Makefile b/cpp05/ex01/Makefile index d41a303..ca43fe0 100644 --- a/cpp05/ex01/Makefile +++ b/cpp05/ex01/Makefile @@ -6,7 +6,7 @@ # By: fgras-ca +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# # -# Updated: 2024/02/11 14:58:41 by fgras-ca ### ########.fr # +# Updated: 2024/02/22 12:41:21 by fgras-ca ### ########.fr # # # # **************************************************************************** # @@ -29,14 +29,16 @@ SRC = Bureaucrat.cpp \ Form.cpp \ main.cpp \ -OBJS = ${SRC:.cpp=.o} - CC = c++ CFLAGS = -Wall -Werror -Wextra -std=c++98 RM = rm -f +OBJS = ${SRC:.cpp=.o} all : $(NAME) +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + $(NAME) : $(OBJS) @echo "$(RED)Compilation fixed... $(DEF_COLOR)" $(CC) $(CFLAGS) $(OBJS) -g -o $(NAME) diff --git a/cpp05/ex02/AForm.cpp b/cpp05/ex02/AForm.cpp index 52c6aa3..0b9a6b3 100644 --- a/cpp05/ex02/AForm.cpp +++ b/cpp05/ex02/AForm.cpp @@ -6,19 +6,13 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:39:51 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 14:25:05 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 14:36:36 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" #include "AForm.hpp" -AForm::AForm() - : name(name), isSigned(false), gradeRequiredToSign(1), gradeRequiredToExecute(1) -{ - std::cout << GREEN << "AForm default constructor called!" << RESET << std::endl; -} - AForm::AForm(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute) : name(name), isSigned(false), gradeRequiredToSign(gradeRequiredToSign), gradeRequiredToExecute(gradeRequiredToExecute) { @@ -84,20 +78,21 @@ void AForm::beSigned(const Bureaucrat& bureaucrat) } } -const char* AForm::GradeTooHighException::what() const noexcept +const char* AForm::GradeTooHighException::what() const throw() { - return ("Grade too hight\n"); + return ("Grade too high\n"); } -const char* AForm::GradeTooLowException::what() const noexcept +const char* AForm::GradeTooLowException::what() const throw() { return ("Grade too low\n"); } -const char* AForm::NotSignedException::what() const noexcept +const char* AForm::NotSignedException::what() const throw() { - return ("The forpm is not signed.\n"); + return ("The form is not signed.\n"); } + std::ostream& operator<<(std::ostream& os, const AForm& aform) { os << "AForm: " << aform.getName() diff --git a/cpp05/ex02/AForm.hpp b/cpp05/ex02/AForm.hpp index 56486c7..a66f1b4 100644 --- a/cpp05/ex02/AForm.hpp +++ b/cpp05/ex02/AForm.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:37:14 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 15:53:16 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 13:49:48 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,6 @@ protected: public: //constructueur - AForm(); AForm(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute); // Constructeur par copie AForm(const AForm& other); @@ -54,19 +53,19 @@ public: class GradeTooHighException : public std::exception { public: - const char* what() const noexcept override; + virtual const char* what() const throw(); }; class GradeTooLowException : public std::exception { public: - const char* what() const noexcept override; + virtual const char* what() const throw(); }; class NotSignedException : public std::exception { public: - const char* what() const noexcept override; + virtual const char* what() const throw(); }; }; // Surcharge de l'opérateur d'insertion diff --git a/cpp05/ex02/Bureaucrat.cpp b/cpp05/ex02/Bureaucrat.cpp index cc7f0ce..e08d222 100644 --- a/cpp05/ex02/Bureaucrat.cpp +++ b/cpp05/ex02/Bureaucrat.cpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 13:16:26 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 16:02:52 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 15:24:37 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -102,14 +102,14 @@ void Bureaucrat::executeForm(AForm const &form) } catch (std::exception& e) { - std::cout << name << " couldn’t execute " << RED << form.getName() << BLUE << " (" << form.getTarget() << ")" << RESET << " because: " << e.what() << std::endl; + std::cerr << name << " couldn’t execute " << RED << form.getName() << BLUE << " (" << form.getTarget() << ")" << RESET << " because: " << e.what() << std::endl; } } // Méthodes pour les exceptions const char* Bureaucrat::GradeTooHighException::what() const throw() { - return ("Grade too hight\n"); + return ("Grade too high\n"); } const char* Bureaucrat::GradeTooLowException::what() const throw() diff --git a/cpp05/ex02/Bureaucrat.hpp b/cpp05/ex02/Bureaucrat.hpp index bb47f17..794108d 100644 --- a/cpp05/ex02/Bureaucrat.hpp +++ b/cpp05/ex02/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 12:57:28 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 13:09:39 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 15:29:48 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,13 +36,13 @@ public: class GradeTooHighException : public std::exception { public: - const char* what() const throw() override; + virtual const char* what() const throw(); }; class GradeTooLowException : public std::exception { public: - const char* what() const throw() override; + virtual const char* what() const throw(); }; Bureaucrat(); @@ -56,7 +56,7 @@ public: void incrementGrade(); void decrementGrade(); void signForm(AForm& form); - void executeForm(AForm const &form); + virtual void executeForm(AForm const &form); private: const std::string name; diff --git a/cpp05/ex02/Home_shrubbery b/cpp05/ex02/Home_shrubbery deleted file mode 100644 index 6f7aa37..0000000 --- a/cpp05/ex02/Home_shrubbery +++ /dev/null @@ -1 +0,0 @@ -ASCII trees diff --git a/cpp05/ex02/Makefile b/cpp05/ex02/Makefile index 74be5d4..408d587 100644 --- a/cpp05/ex02/Makefile +++ b/cpp05/ex02/Makefile @@ -6,7 +6,7 @@ # By: fgras-ca +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# # -# Updated: 2024/02/21 13:06:08 by fgras-ca ### ########.fr # +# Updated: 2024/02/22 15:36:34 by fgras-ca ### ########.fr # # # # **************************************************************************** # @@ -32,14 +32,16 @@ SRC = Bureaucrat.cpp \ RobotomyRequestForm.cpp \ ShrubberyCreationForm.cpp \ -OBJS = ${SRC:.cpp=.o} - CC = c++ CFLAGS = -Wall -Werror -Wextra -std=c++98 RM = rm -f +OBJS = ${SRC:.cpp=.o} all : $(NAME) +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + $(NAME) : $(OBJS) @echo "$(RED)Compilation fixed... $(DEF_COLOR)" $(CC) $(CFLAGS) $(OBJS) -g -o $(NAME) diff --git a/cpp05/ex02/PresidentialPardonForm.cpp b/cpp05/ex02/PresidentialPardonForm.cpp index 4c4fcb3..0f62b6a 100644 --- a/cpp05/ex02/PresidentialPardonForm.cpp +++ b/cpp05/ex02/PresidentialPardonForm.cpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/21 11:31:13 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 15:18:45 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 15:42:00 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/cpp05/ex02/PresidentialPardonForm.hpp b/cpp05/ex02/PresidentialPardonForm.hpp index 961c6e1..f671e7c 100644 --- a/cpp05/ex02/PresidentialPardonForm.hpp +++ b/cpp05/ex02/PresidentialPardonForm.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/20 16:56:48 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 15:17:46 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 15:39:59 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #define PRESIDENTIALPARDONFORM_HPP #include "AForm.hpp" +#include "Bureaucrat.hpp" #include #define RESET "\033[0m" @@ -32,7 +33,7 @@ public: PresidentialPardonForm& operator=(const PresidentialPardonForm& other); virtual ~PresidentialPardonForm(); - void execute(Bureaucrat const &executor) const override; + void execute(Bureaucrat const &executor) const; std::string getTarget() const; }; diff --git a/cpp05/ex02/RobotomyRequestForm.cpp b/cpp05/ex02/RobotomyRequestForm.cpp index 1f22358..bde5b68 100644 --- a/cpp05/ex02/RobotomyRequestForm.cpp +++ b/cpp05/ex02/RobotomyRequestForm.cpp @@ -6,15 +6,26 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/21 11:25:21 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 16:00:03 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 16:13:37 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "RobotomyRequestForm.hpp" +void RobotomyRequestForm::initializeRandomSeed() +{ + static bool seeded = false; + if (!seeded) + { + std::srand(static_cast(std::time(NULL))); // Utilisez NULL au lieu de nullptr + seeded = true; + } +} + RobotomyRequestForm::RobotomyRequestForm(const std::string& target) : AForm("RobotomyRequestForm", 72, 45), target(target) { + initializeRandomSeed(); std::cout << GREEN << "RobotomyRequestForm constructor called for target: " << target << RESET << std::endl; } @@ -51,14 +62,15 @@ void RobotomyRequestForm::execute(Bureaucrat const &executor) const { throw GradeTooLowException(); } + std::cout << "Drilling noises... Zzzzzz..." << std::endl; if (std::rand() % 2 == 0) { - std::cout << target << " has been robotomized successfully." << std::endl; + std::cout << GREEN << target << " has been robotomized successfully." << RESET << std::endl; } else { - std::cout << "The robotomy on " << target << " failed." << std::endl; + std::cout << RED << "The robotomy on " << target << " failed." << RESET << std::endl; } } diff --git a/cpp05/ex02/RobotomyRequestForm.hpp b/cpp05/ex02/RobotomyRequestForm.hpp index 8738dae..2b44821 100644 --- a/cpp05/ex02/RobotomyRequestForm.hpp +++ b/cpp05/ex02/RobotomyRequestForm.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/20 16:55:26 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 15:58:32 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 16:10:22 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #define ROBOTOMYREQUESTFORM_HPP #include "AForm.hpp" +#include "Bureaucrat.hpp" #include #include // Pour std::rand() et std::srand() #include // Pour std::time() @@ -33,9 +34,10 @@ public: RobotomyRequestForm(const RobotomyRequestForm& other); RobotomyRequestForm& operator=(const RobotomyRequestForm& other); virtual ~RobotomyRequestForm(); + static void initializeRandomSeed(); - void execute(Bureaucrat const &executor) const override; - std::string getTarget() const override; + void execute(Bureaucrat const &executor) const; + std::string getTarget() const; }; #endif diff --git a/cpp05/ex02/ShrubberyCreationForm.cpp b/cpp05/ex02/ShrubberyCreationForm.cpp index a26d31b..7e8af2e 100644 --- a/cpp05/ex02/ShrubberyCreationForm.cpp +++ b/cpp05/ex02/ShrubberyCreationForm.cpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/20 16:54:52 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 15:39:36 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 16:33:23 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,16 +45,33 @@ void ShrubberyCreationForm::execute(Bureaucrat const &executor) const // Vérification si le formulaire est signé et si le grade de l'exécuteur est suffisant if (!getIsSigned()) throw NotSignedException(); // Assurez-vous que cette exception est correctement définie dans AForm - if (executor.getGrade() > getGradeRequiredToExecute()) + else if (executor.getGrade() > this->getGradeRequiredToExecute()) throw GradeTooLowException(); - - std::ofstream ofs(target + "_shrubbery"); - if (!ofs) + else { - std::cerr << "Failed to create file " << target << "_shrubbery" << std::endl; - return ; + std::ofstream ofs((target + "_shrubbery").c_str()); + if (!ofs) + { + std::cerr << "Failed to create file " << target << "_shrubbery" << std::endl; + return ; + } + ofs << " . 🅻🅰🅳🅴🅱🅴🆉🅴 . +" << "\n" + <<" . . . # ." << "\n" + <<" . . ### . ." << "\n" + <<" . . .#:. .:##°##:. .:#. . ." << "\n" + <<" . . ####°###°#### ." << "\n" + <<" . #:. .:#.###.#:. .:# . ." << "\n" + <<" #########°######### . ." << "\n" + <<" . #:. ####°###°#### .:# . ." << "\n" + <<" . . °#######°°##°##°°#######° ." << "\n" + <<" .°##°#####°#####°##° . ." << "\n" + <<". #:. ... .:##°###°###°##:. ... .:# ." << "\n" + <<" . #######°##°#####°##°####### . ." << "\n" + <<". . #####°°#######°°##### . ." << "\n" + <<" . 000 . ." << "\n" + <<" . . . 000 . . ." << "\n" + <<". ..................O000O................." << std::endl; } - ofs << "ASCII trees" << std::endl; } std::string ShrubberyCreationForm::getTarget() const diff --git a/cpp05/ex02/ShrubberyCreationForm.hpp b/cpp05/ex02/ShrubberyCreationForm.hpp index c464af2..f98b31d 100644 --- a/cpp05/ex02/ShrubberyCreationForm.hpp +++ b/cpp05/ex02/ShrubberyCreationForm.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/20 16:41:49 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 15:51:24 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 15:35:33 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #define SHRUBBERYCREATIONFORM_HPP #include "AForm.hpp" +#include "Bureaucrat.hpp" #include #include @@ -32,7 +33,7 @@ public: ShrubberyCreationForm& operator=(const ShrubberyCreationForm& other); virtual ~ShrubberyCreationForm(); - void execute(Bureaucrat const &executor) const override; + void execute(Bureaucrat const &executor) const; std::string getTarget() const; }; diff --git a/cpp05/ex02/main.cpp b/cpp05/ex02/main.cpp index 0e1de4a..ad66ea9 100644 --- a/cpp05/ex02/main.cpp +++ b/cpp05/ex02/main.cpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:55:46 by fgras-ca #+# #+# */ -/* Updated: 2024/02/21 15:21:24 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/22 15:54:24 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,31 +19,89 @@ int main() { + // Création des bureaucrates Bureaucrat john("John", 2); Bureaucrat doe("Doe", 150); + // Création des formulaires ShrubberyCreationForm shrub("Home"); RobotomyRequestForm robot("Robot"); PresidentialPardonForm pardon("Criminal"); - try { - john.signForm(shrub); - john.executeForm(shrub); + // Tentatives de signature et d'exécution des formulaires par John + std::cout << "\n--- John tries to sign and execute forms ---\n"; + john.signForm(shrub); + john.executeForm(shrub); - john.signForm(robot); - john.executeForm(robot); + john.signForm(robot); + john.executeForm(robot); - john.signForm(pardon); - john.executeForm(pardon); + john.signForm(pardon); + john.executeForm(pardon); - // Tester avec un bureaucrate de grade insuffisant + // Tentatives de signature et d'exécution des formulaires par Doe + std::cout << "\n--- Doe tries to sign and execute forms ---\n"; + try + { doe.signForm(shrub); + } + catch (std::exception& e) + { + std::cout << "Error: " << e.what() << std::endl; + } + + try + { doe.executeForm(shrub); } catch (std::exception& e) { - std::cout << e.what() << std::endl; + std::cout << "Error: " << e.what() << std::endl; + } + + try + { + doe.executeForm(robot); + } + catch (std::exception& e) + { + std::cout << "Error: " << e.what() << std::endl; + } + + // Tentatives de signature et d'exécution des formulaires avec gestion des exceptions + std::cout << "\n--- Additional tests with exception handling ---\n"; + try + { + doe.signForm(robot); + doe.executeForm(robot); + } + catch (std::exception& e) + { + std::cout << "Error: " << e.what() << std::endl; + } + + try + { + doe.signForm(pardon); + doe.executeForm(pardon); + } + catch (std::exception& e) + { + std::cout << "Error: " << e.what() << std::endl; + } + + // Test avec un formulaire déjà signé + std::cout << "\n--- Testing with already signed form ---\n"; + try + { + john.signForm(shrub); // shrub est déjà signé par John plus tôt + john.executeForm(shrub); + } + catch (std::exception& e) + { + std::cout << "Error: " << e.what() << std::endl; } return (0); } +