cpp05 end?

This commit is contained in:
kinou-p 2022-08-06 11:04:32 +02:00
parent b17f78a802
commit d6876c53bb
17 changed files with 235 additions and 91 deletions

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 21:34:42 by apommier #+# #+# */ /* Created: 2022/07/18 21:34:42 by apommier #+# #+# */
/* Updated: 2022/08/05 13:12:53 by apommier ### ########.fr */ /* Updated: 2022/08/06 10:52:11 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -79,3 +79,12 @@ void Bureaucrat::checkGrade() const
throw Bureaucrat::GradeTooHighException(); throw Bureaucrat::GradeTooHighException();
} }
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");
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 21:34:43 by apommier #+# #+# */ /* Created: 2022/07/18 21:34:43 by apommier #+# #+# */
/* Updated: 2022/07/19 11:23:31 by apommier ### ########.fr */ /* Updated: 2022/08/06 10:51:46 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -35,19 +35,13 @@ class Bureaucrat{
class GradeTooLowException : public std::exception class GradeTooLowException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Bureaucrat grade is too low\n");
}
}; };
class GradeTooHighException : public std::exception class GradeTooHighException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Bureaucrat grade is too high\n");
}
}; };
private: private:

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 21:34:42 by apommier #+# #+# */ /* Created: 2022/07/18 21:34:42 by apommier #+# #+# */
/* Updated: 2022/08/05 13:13:08 by apommier ### ########.fr */ /* Updated: 2022/08/06 10:52:58 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -45,7 +45,7 @@ Bureaucrat &Bureaucrat::operator=(const Bureaucrat& rhs)
std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat) std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat)
{ {
out << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade(); out << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade() << std::endl;
return (out); return (out);
} }
@ -90,3 +90,13 @@ void Bureaucrat::signForm(Form form)
std::cout << this->_name << " couldnt sign " << form.getName() << " form because "<< e.what(); std::cout << this->_name << " couldnt sign " << form.getName() << " form because "<< e.what();
} }
} }
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");
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 21:34:43 by apommier #+# #+# */ /* Created: 2022/07/18 21:34:43 by apommier #+# #+# */
/* Updated: 2022/07/19 12:52:52 by apommier ### ########.fr */ /* Updated: 2022/08/06 10:52:43 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,23 +36,17 @@ class Bureaucrat{
void checkGrade() const; void checkGrade() const;
void signForm(Form form); void signForm(Form form);
class GradeTooLowException : public std::exception class GradeTooLowException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Bureaucrat grade is too low\n");
}
}; };
class GradeTooHighException : public std::exception class GradeTooHighException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Bureaucrat grade is too high\n");
}
}; };
private: private:

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 11:54:01 by apommier #+# #+# */ /* Created: 2022/07/19 11:54:01 by apommier #+# #+# */
/* Updated: 2022/07/19 12:54:48 by apommier ### ########.fr */ /* Updated: 2022/08/06 10:36:48 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -50,7 +50,7 @@ Form &Form::operator=(const Form& rhs)
std::ostream &operator<<(std::ostream &out, const Form &form) std::ostream &operator<<(std::ostream &out, const Form &form)
{ {
out << form.getName() << "form need at least " << form.getSignedGrade() << " grade to be signed and "; out << form.getName() << " form need at least " << form.getSignedGrade() << " grade to be signed and ";
out << form.getExecutionGrade() << " grade to be executed, "; out << form.getExecutionGrade() << " grade to be executed, ";
if (form.getIsSigned()) if (form.getIsSigned())
out << form.getName() << " form is signed\n"; out << form.getName() << " form is signed\n";
@ -98,4 +98,17 @@ void Form::checkGrade() const
throw Form::GradeTooHighException(); throw Form::GradeTooHighException();
} }
const char* Form::GradeTooLowException::what() const throw()
{
return ("Signed or Execution grade is too low\n");
}
const char* Form::GradeTooHighException::what() const throw()
{
return ("Signed or Execution grade is too high\n");
}
const char* Form::signedGradeTooLowException::what() const throw()
{
return ("Signed grade is too low\n");
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 11:54:09 by apommier #+# #+# */ /* Created: 2022/07/19 11:54:09 by apommier #+# #+# */
/* Updated: 2022/07/19 12:52:43 by apommier ### ########.fr */ /* Updated: 2022/08/06 10:31:20 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,28 +41,19 @@ class Form{
class GradeTooLowException : public std::exception class GradeTooLowException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Signed or Execution grade is too low\n");
}
}; };
class GradeTooHighException : public std::exception class GradeTooHighException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Signed or Execution grade is too high\n");
}
}; };
class signedGradeTooLowException : public std::exception class signedGradeTooLowException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Signed grade is too low\n");
}
}; };
private : private :

View File

@ -50,7 +50,7 @@ AForm &AForm::operator=(const AForm& rhs)
std::ostream &operator<<(std::ostream &out, const AForm &Aform) 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.getName() << " Aform need at least " << Aform.getSignedGrade() << " grade to be signed and ";
out << Aform.getExecutionGrade() << " grade to be executed, "; out << Aform.getExecutionGrade() << " grade to be executed, ";
if (Aform.getIsSigned()) if (Aform.getIsSigned())
out << Aform.getName() << " Aform is signed\n"; out << Aform.getName() << " Aform is signed\n";
@ -102,8 +102,31 @@ void AForm::checkExecution(Bureaucrat const & executor) const
{ {
if (!this->_isSigned) if (!this->_isSigned)
throw AForm::formIsNotSignedException(); throw AForm::formIsNotSignedException();
else if (executor.getGrade() > this->_signedGrade) else if (executor.getGrade() > this->_executionGrade)
throw AForm::executionGradeTooLowException(); 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");
}

View File

@ -43,46 +43,31 @@ class AForm{
class GradeTooLowException : public std::exception class GradeTooLowException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Signed or Execution grade is too low\n");
}
}; };
class GradeTooHighException : public std::exception class GradeTooHighException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Signed or Execution grade is too high\n");
}
}; };
class signedGradeTooLowException : public std::exception class signedGradeTooLowException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Signed grade is too low\n");
}
}; };
class executionGradeTooLowException : public std::exception class executionGradeTooLowException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Execution grade is too low\n");
}
}; };
class formIsNotSignedException : public std::exception class formIsNotSignedException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Form isn't signed\n");
}
}; };
private : private :

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 21:34:42 by apommier #+# #+# */ /* Created: 2022/07/18 21:34:42 by apommier #+# #+# */
/* Updated: 2022/08/05 13:13:29 by apommier ### ########.fr */ /* Updated: 2022/08/06 10:55:19 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -45,7 +45,7 @@ Bureaucrat &Bureaucrat::operator=(const Bureaucrat& rhs)
std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat) std::ostream &operator<<(std::ostream &out, const Bureaucrat &bureaucrat)
{ {
out << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade(); out << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade() << std::endl;
return (out); return (out);
} }
@ -94,5 +94,15 @@ void Bureaucrat::signForm(AForm &form)
void Bureaucrat::executeForm(AForm const & form) const void Bureaucrat::executeForm(AForm const & form) const
{ {
form.execute(*this); form.execute(*this);
std::cout << "<bureaucrat> executed <form>" << std::endl; 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");
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 21:34:43 by apommier #+# #+# */ /* Created: 2022/07/18 21:34:43 by apommier #+# #+# */
/* Updated: 2022/08/05 12:57:35 by apommier ### ########.fr */ /* Updated: 2022/08/06 10:53:27 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,19 +41,13 @@ class Bureaucrat{
class GradeTooLowException : public std::exception class GradeTooLowException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Bureaucrat grade is too low\n");
}
}; };
class GradeTooHighException : public std::exception class GradeTooHighException : public std::exception
{ {
public : public :
virtual const char* what() const throw() virtual const char* what() const throw();
{
return ("Bureaucrat grade is too high\n");
}
}; };
private: private:

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/04 15:14:32 by apommier #+# #+# */ /* Created: 2022/08/04 15:14:32 by apommier #+# #+# */
/* Updated: 2022/08/04 18:54:53 by apommier ### ########.fr */ /* Updated: 2022/08/05 16:14:19 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -44,6 +44,7 @@ void RobotomyRequestForm::execute(Bureaucrat const & executor) const
{ {
AForm::checkExecution(executor); AForm::checkExecution(executor);
std::cout << "Brrrzrzrzrzzrzrzzrrzz...\n"; std::cout << "Brrrzrzrzrzzrzrzzrrzz...\n";
std::srand(time(NULL));
if (std::rand() % 2) if (std::rand() % 2)
std::cout << this->_target << " has been robotomized\n"; std::cout << this->_target << " has been robotomized\n";
else else

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 13:00:14 by apommier #+# #+# */ /* Created: 2022/07/19 13:00:14 by apommier #+# #+# */
/* Updated: 2022/08/04 19:44:50 by apommier ### ########.fr */ /* Updated: 2022/08/06 11:00:31 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -44,10 +44,8 @@ ShrubberyCreationForm &ShrubberyCreationForm::operator=(const ShrubberyCreationF
void ShrubberyCreationForm::execute(Bureaucrat const & executor) const void ShrubberyCreationForm::execute(Bureaucrat const & executor) const
{ {
AForm::checkExecution(executor);
std::string name = this->_target + "_shrubbery"; std::string name = this->_target + "_shrubbery";
std::cout << name << std::endl;
(void)executor;
//AForm::checkExecution(executor);
std::ofstream outfile(name.c_str()); 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 ...::::::::::..."; 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 ...::::::::::...";
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 21:34:45 by apommier #+# #+# */ /* Created: 2022/07/18 21:34:45 by apommier #+# #+# */
/* Updated: 2022/08/04 19:38:41 by apommier ### ########.fr */ /* Updated: 2022/08/06 11:00:04 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,24 +18,120 @@
int main() int main()
{ {
std::cout << "===============================Presidential pardon=============================\n\n";
std::cout << "Trying to execute without sign :\n";
try try
{ {
Bureaucrat First(151, "john"); Bureaucrat john(150, "john");
PresidentialPardonForm form("Assassin");
john.executeForm(form);
} }
catch(std::exception &e) catch(std::exception &e)
{ {
std::cout << e.what(); std::cout << e.what();
} }
Bureaucrat First(1, "john");
ShrubberyCreationForm test("niceTree"); std::cout << "\nTrying to execute without the right grade :\n";
try try
{ {
test.execute(First); 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(138, "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(137, "john");
ShrubberyCreationForm form("Assassin");
form.beSigned(john);
john.executeForm(form);
} }
catch(std::exception &e) catch(std::exception &e)
{ {
std::cout << e.what(); std::cout << e.what();
} }
return (0);
} }

View File

@ -50,7 +50,7 @@ AForm &AForm::operator=(const AForm& rhs)
std::ostream &operator<<(std::ostream &out, const AForm &Aform) 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.getName() << " Aform need at least " << Aform.getSignedGrade() << " grade to be signed and ";
out << Aform.getExecutionGrade() << " grade to be executed, "; out << Aform.getExecutionGrade() << " grade to be executed, ";
if (Aform.getIsSigned()) if (Aform.getIsSigned())
out << Aform.getName() << " Aform is signed\n"; out << Aform.getName() << " Aform is signed\n";
@ -121,7 +121,6 @@ const char* AForm::signedGradeTooLowException::what() const throw()
return ("Signed grade is too low\n"); return ("Signed grade is too low\n");
} }
const char* AForm::executionGradeTooLowException::what() const throw() const char* AForm::executionGradeTooLowException::what() const throw()
{ {
return ("Can't execute because Execution grade is too low\n"); return ("Can't execute because Execution grade is too low\n");

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 21:34:42 by apommier #+# #+# */ /* Created: 2022/07/18 21:34:42 by apommier #+# #+# */
/* Updated: 2022/08/05 14:14:42 by apommier ### ########.fr */ /* Updated: 2022/08/06 10:52:00 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -98,7 +98,6 @@ void Bureaucrat::executeForm(AForm const & form) const
std::cout << this->_name << " executed " << form.getName() << std::endl; std::cout << this->_name << " executed " << form.getName() << std::endl;
} }
const char* Bureaucrat::GradeTooLowException::what() const throw() const char* Bureaucrat::GradeTooLowException::what() const throw()
{ {
return ("Bureaucrat grade is too low\n"); return ("Bureaucrat grade is too low\n");

View File

@ -6,12 +6,13 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/04 15:14:32 by apommier #+# #+# */ /* Created: 2022/08/04 15:14:32 by apommier #+# #+# */
/* Updated: 2022/08/05 14:30:26 by apommier ### ########.fr */ /* Updated: 2022/08/05 16:13:44 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "RobotomyRequestForm.hpp" #include "RobotomyRequestForm.hpp"
#include <cstdlib> #include <cstdlib>
#include <time.h>
RobotomyRequestForm::RobotomyRequestForm() : AForm(72, 45, "RobotomyRequestForm") RobotomyRequestForm::RobotomyRequestForm() : AForm(72, 45, "RobotomyRequestForm")
{ {
@ -44,6 +45,7 @@ void RobotomyRequestForm::execute(Bureaucrat const & executor) const
{ {
AForm::checkExecution(executor); AForm::checkExecution(executor);
std::cout << "Brrrzrzrzrzzrzrzzrrzz...\n"; std::cout << "Brrrzrzrzrzzrzrzzrrzz...\n";
std::srand(time(NULL));
if (std::rand() % 2) if (std::rand() % 2)
std::cout << this->_target << " has been robotomized\n"; std::cout << this->_target << " has been robotomized\n";
else else

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 21:34:45 by apommier #+# #+# */ /* Created: 2022/07/18 21:34:45 by apommier #+# #+# */
/* Updated: 2022/08/05 14:46:57 by apommier ### ########.fr */ /* Updated: 2022/08/06 11:02:04 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,6 +15,7 @@
#include "PresidentialPardonForm.hpp" #include "PresidentialPardonForm.hpp"
#include "RobotomyRequestForm.hpp" #include "RobotomyRequestForm.hpp"
#include "ShrubberyCreationForm.hpp" #include "ShrubberyCreationForm.hpp"
#include "Intern.hpp"
int main() int main()
{ {
@ -112,7 +113,7 @@ int main()
std::cout << "\nTrying to execute without the right grade :\n"; std::cout << "\nTrying to execute without the right grade :\n";
try try
{ {
Bureaucrat john(137, "john"); Bureaucrat john(138, "john");
ShrubberyCreationForm form("Assassin"); ShrubberyCreationForm form("Assassin");
form.beSigned(john); form.beSigned(john);
john.executeForm(form); john.executeForm(form);
@ -125,7 +126,7 @@ int main()
std::cout << "\nAll good :\n"; std::cout << "\nAll good :\n";
try try
{ {
Bureaucrat john(5, "john"); Bureaucrat john(137, "john");
ShrubberyCreationForm form("Assassin"); ShrubberyCreationForm form("Assassin");
form.beSigned(john); form.beSigned(john);
john.executeForm(form); john.executeForm(form);
@ -134,4 +135,29 @@ int main()
{ {
std::cout << e.what(); std::cout << e.what();
} }
std::cout << "\n===============================Intern tests=============================\n\n";
Intern intern;
AForm *formPTR;
formPTR = intern.makeForm("not_a_form", "target");
std::cout << formPTR << std::endl << std::endl;
formPTR = intern.makeForm("shrubbery creation", "garden");
std::cout << *formPTR << std::endl;
formPTR = intern.makeForm("robotomy request", "ASmartGuy");
std::cout << *formPTR << std::endl;
formPTR = intern.makeForm("presidential pardon", "Sinner");
std::cout << *formPTR << std::endl;
std::cout << "Execute created form :\n";
try
{
Bureaucrat john(5, "john");
formPTR->beSigned(john);
std::cout << *formPTR;
john.executeForm(*formPTR);
}
catch(std::exception &e)
{
std::cout << e.what();
}
} }