return (m_executor_grade);
}
+const std::string &AForm::getTarget() const
+{
+ return (m_target);
+}
+
void AForm::beSigned(const Bureaucrat &bureaucrat)
{
if (bureaucrat.getGrade() > m_signatory_grade)
bool isSigned() const;
int getSignatoryGrade() const;
int getExecutorGrade() const;
+ const std::string &getTarget() const;
void beSigned(const Bureaucrat &bureaucrat);
void checkExecutorGrade(const Bureaucrat &bureaucrat) const;
void virtual execute(const Bureaucrat &bureaucrat) const = 0;
#include "RobotomyRequestForm.h"
+#include <iostream>
+#include <cstdlib>
+#include <ctime>
RobotomyRequestForm::RobotomyRequestForm()
: AForm()
void RobotomyRequestForm::execute(Bureaucrat const &executor) const
{
checkExecutorGrade(executor);
+ if (getRandomBit())
+ std::cout << "The robotomy on " << getTarget() << " was successful.\n";
+ else
+ std::cout << "The robotomy on " << getTarget() << " failed.\n";
+}
+
+bool RobotomyRequestForm::getRandomBit()
+{
+ static bool is_seeded = 0;
+
+ if (!is_seeded)
+ {
+ std::srand(std::time(0));
+ is_seeded = 1;
+ }
+ return (std::rand() > (RAND_MAX / 2));
}
class RobotomyRequestForm : public AForm
{
+ private:
+ static bool getRandomBit();
// These are protected only so that inheriting classes can use them
// in their "non implementations" of there functions
protected:
employee1.executeForm(pres);
std::cout << '\n';
employee2.executeForm(shrub);
+ std::cout << '\n';
+ employee1.executeForm(robot);
+ employee1.executeForm(robot);
+ employee1.executeForm(robot);
+ employee1.executeForm(robot);
+ employee1.executeForm(robot);
employee1.executeForm(robot);
+ employee1.executeForm(robot);
+ employee1.executeForm(robot);
+ employee1.executeForm(robot);
+ employee1.executeForm(robot);
+ std::cout << '\n';
employee0.executeForm(pres);
return (0);
}