ex02 finished

This commit is contained in:
2026-02-18 00:16:54 +01:00
parent c233d14af7
commit f96fb516ff
10 changed files with 314 additions and 10 deletions

View File

@@ -67,7 +67,7 @@ std::string ShrubberyCreationForm::getTarget() const
// Execute //
//////////////////
void ShrubberyCreationForm::execute(Bureaucrat const &executor)
void ShrubberyCreationForm::execute(Bureaucrat const &executor) const
{
if (!this->getIsSigned())
throw FormNotSignedException();
@@ -75,8 +75,16 @@ void ShrubberyCreationForm::execute(Bureaucrat const &executor)
throw AForm::GradeTooLowException();
// ShrubberyCreation form action...
std::string filename = this->target + "_shrubbery";
std::ofstream file(filename.c_str());
if (!file.is_open())
{
std::cerr << "Error: could not create file "
<< filename << std::endl;
return ;
}
file << " _-_\n";
file << " /~~ ~~\\\n";
@@ -88,6 +96,7 @@ void ShrubberyCreationForm::execute(Bureaucrat const &executor)
file << " _ - | | -_\n";
file << " // \\";
file.close();
}
//////////////////

View File

@@ -16,7 +16,9 @@
# include <iostream>
# include <fstream>
# include <string>
# include "../AForm/AForm.hpp"
# include "../Bureaucrat/Bureaucrat.hpp"
class ShrubberyCreationForm : public AForm
{
@@ -33,7 +35,7 @@ class ShrubberyCreationForm : public AForm
std::string getTarget() const;
void execute(Bureaucrat const &executor);
virtual void execute(Bureaucrat const &executor) const;
class FormNotSignedException : public std::exception {
public: