--- /dev/null
+#include "AForm.h"
+#include "Bureaucrat.h"
+
+AForm::AForm()
+ : m_name("")
+ , m_is_signed(0)
+ , m_signatory_grade(0)
+ , m_executor_grade(0)
+{
+}
+
+AForm::AForm(const std::string &name, int signatory_grade, int executor_grade)
+ : m_name(name)
+ , m_is_signed(0)
+ , m_signatory_grade(signatory_grade)
+ , m_executor_grade(executor_grade)
+{
+ if (signatory_grade < Bureaucrat::HIGHEST_GRADE || executor_grade < Bureaucrat::HIGHEST_GRADE)
+ throw (Bureaucrat::GradeTooHighException());
+ else if (signatory_grade > Bureaucrat::LOWEST_GRADE || executor_grade > Bureaucrat::LOWEST_GRADE)
+ throw (Bureaucrat::GradeTooLowException());
+}
+
+AForm::AForm(const AForm &other)
+ : m_name(other.m_name)
+ , m_is_signed(0)
+ , m_signatory_grade(other.m_signatory_grade)
+ , m_executor_grade(other.m_executor_grade)
+{
+}
+
+AForm::~AForm() { }
+
+AForm &AForm::operator=(const AForm &other)
+{
+ if (this == &other)
+ return (*this);
+ return (*this);
+}
+
+const std::string &AForm::getName() const
+{
+ return (m_name);
+}
+
+bool AForm::isSigned() const
+{
+ return (m_is_signed);
+}
+
+int AForm::getSignatoryGrade() const
+{
+ return (m_signatory_grade);
+}
+
+int AForm::getExecutorGrade() const
+{
+ return (m_executor_grade);
+}
+
+void AForm::beSigned(const Bureaucrat &bureaucrat)
+{
+ if (bureaucrat.getGrade() > m_signatory_grade)
+ throw (Bureaucrat::GradeTooLowException());
+ if (m_is_signed)
+ throw (std::runtime_error("AForm is already signed"));
+ m_is_signed = 1;
+}
+
+void AForm::checkExecutorGrade(const Bureaucrat &bureaucrat) const
+{
+ if (bureaucrat.getGrade() > m_executor_grade)
+ throw (Bureaucrat::GradeTooLowException());
+}
+
+std::ostream &operator<<(std::ostream &ostream, const AForm &form)
+{
+ ostream << "AForm " << form.getName() << ":\n\n";
+ ostream << "\tMinimum grade of signatory:\t" << form.getSignatoryGrade() << '\n';
+ ostream << "\tMinimum grade of executor:\t" << form.getExecutorGrade() << "\n\n";
+ if (form.isSigned())
+ ostream << "\t\t\t\tBureaucrat\n";
+ else
+ ostream << "\n";
+ ostream << "\t\t\t\tSignature\n";
+ return (ostream);
+}
--- /dev/null
+#ifndef AFORM_H
+# define AFORM_H
+
+#include "Bureaucrat.h"
+#include <string>
+#include <iostream>
+
+class AForm
+{
+ private:
+ const std::string m_name;
+ bool m_is_signed;
+ const int m_signatory_grade;
+ const int m_executor_grade;
+
+ AForm();
+
+ AForm &operator=(const AForm &other);
+
+ public:
+ AForm(const std::string &name, int signatory_grade, int executor_grade);
+ AForm(const AForm &other);
+ virtual ~AForm();
+
+ const std::string &getName() const;
+ bool isSigned() const;
+ int getSignatoryGrade() const;
+ int getExecutorGrade() const;
+ void beSigned(const Bureaucrat &bureaucrat);
+ void checkExecutorGrade(const Bureaucrat &bureaucrat) const;
+ void virtual execute(const Bureaucrat &bureaucrat) const = 0;
+};
+
+std::ostream &operator<<(std::ostream &ostream, const AForm &form);
+
+#endif // AFORM_H
--- /dev/null
+#include "Bureaucrat.h"
+#include "AForm.h"
+
+Bureaucrat::Bureaucrat()
+{
+}
+
+Bureaucrat::Bureaucrat(const std::string &name, int grade)
+ : m_name(name)
+ , m_grade(grade)
+{
+ if (grade < HIGHEST_GRADE)
+ throw (Bureaucrat::GradeTooHighException());
+ else if (grade > LOWEST_GRADE)
+ throw (Bureaucrat::GradeTooLowException());
+}
+
+Bureaucrat::Bureaucrat(const Bureaucrat &other)
+{
+ *this = other;
+}
+
+Bureaucrat::~Bureaucrat()
+{
+}
+
+Bureaucrat &Bureaucrat::operator=(const Bureaucrat &other)
+{
+ if (this == &other)
+ return (*this);
+ return (*this);
+}
+
+const std::string &Bureaucrat::getName() const
+{
+ return (m_name);
+}
+
+int Bureaucrat::getGrade() const
+{
+ return (m_grade);
+}
+
+void Bureaucrat::promote()
+{
+ if (m_grade == HIGHEST_GRADE)
+ throw (Bureaucrat::GradeTooHighException());
+ --m_grade;
+}
+
+void Bureaucrat::demote()
+{
+ if (m_grade == LOWEST_GRADE)
+ throw (Bureaucrat::GradeTooLowException());
+ ++m_grade;
+}
+
+void Bureaucrat::signForm(AForm &form) const
+{
+ try
+ {
+ form.beSigned(*this);
+ std::cout << m_name << " signed the form " << form.getName() << '\n';
+ }
+ catch (const Bureaucrat::GradeTooLowException &exception)
+ {
+ std::cout << m_name << " couldn't sign the form " << form.getName()
+ << " because his grade " << m_grade << " is lower than the necessary "
+ << form.getSignatoryGrade() << '\n';
+ }
+ catch (const std::runtime_error &exception)
+ {
+ std::cout << m_name << " couldn't sign the form " << form.getName()
+ << " because it is already signed.\n";
+ }
+}
+
+void Bureaucrat::executeForm(const AForm &form) const
+{
+ try
+ {
+ form.execute(*this);
+ std::cout << m_name << " executed the form " << form.getName() << '\n';
+ }
+ catch (const Bureaucrat::GradeTooLowException &exception)
+ {
+ std::cout << m_name << " couldn't execute the form " << form.getName()
+ << " because his grade " << m_grade << " is lower than the necessary "
+ << form.getSignatoryGrade() << '\n';
+ }
+}
+
+std::ostream &operator<<(std::ostream &ostream, const Bureaucrat &bureaucrat)
+{
+ ostream << bureaucrat.getName() << ", bureaucrat of grade " << bureaucrat.getGrade();
+ return (ostream);
+}
+
+Bureaucrat::GradeTooLowException::GradeTooLowException()
+ : std::runtime_error::runtime_error("Grade cannot be lower")
+{
+}
+
+Bureaucrat::GradeTooLowException::GradeTooLowException(const Bureaucrat::GradeTooLowException &other)
+ : std::runtime_error::runtime_error(other.what())
+{
+}
+
+Bureaucrat::GradeTooLowException::~GradeTooLowException() throw()
+{
+}
+
+Bureaucrat::GradeTooLowException &Bureaucrat::GradeTooLowException::operator=(const Bureaucrat::GradeTooLowException &other)
+{
+ std::runtime_error::operator = (other);
+ return (*this);
+}
+
+Bureaucrat::GradeTooHighException::GradeTooHighException()
+ : std::runtime_error::runtime_error("Grade cannot be higher")
+{
+}
+
+Bureaucrat::GradeTooHighException::GradeTooHighException(const Bureaucrat::GradeTooHighException &other)
+ : std::runtime_error::runtime_error(other.what())
+{
+}
+
+Bureaucrat::GradeTooHighException::~GradeTooHighException() throw()
+{
+}
+
+Bureaucrat::GradeTooHighException &Bureaucrat::GradeTooHighException::operator=(const Bureaucrat::GradeTooHighException &other)
+{
+ std::runtime_error::operator = (other);
+ return (*this);
+}
--- /dev/null
+#ifndef BUREAUCRAT_H
+# define BUREAUCRAT_H
+
+#include <string>
+#include <stdexcept>
+#include <iostream>
+
+class AForm;
+
+class Bureaucrat
+{
+ private:
+ const std::string m_name;
+ int m_grade;
+
+ Bureaucrat();
+ Bureaucrat(const Bureaucrat &other);
+
+ Bureaucrat &operator=(const Bureaucrat &other);
+
+ public:
+ Bureaucrat(const std::string &name, int grade);
+ ~Bureaucrat();
+
+ static const int LOWEST_GRADE = 150;
+ static const int HIGHEST_GRADE = 1;
+
+ const std::string &getName() const;
+ int getGrade() const;
+ void promote();
+ void demote();
+ void signForm(AForm &form) const;
+ void executeForm(const AForm &form) const;
+
+ class GradeTooLowException;
+ class GradeTooHighException;
+};
+
+std::ostream &operator<<(std::ostream &ostream, const Bureaucrat &bureaucrat);
+
+class Bureaucrat::GradeTooLowException : public std::runtime_error
+{
+ public:
+ GradeTooLowException();
+ GradeTooLowException(const GradeTooLowException &other);
+ ~GradeTooLowException() throw();
+
+ GradeTooLowException &operator=(const GradeTooLowException &other);
+};
+
+class Bureaucrat::GradeTooHighException : public std::runtime_error
+{
+ public:
+ GradeTooHighException();
+ GradeTooHighException(const GradeTooHighException &other);
+ ~GradeTooHighException() throw();
+
+ GradeTooHighException &operator=(const GradeTooHighException &other);
+};
+
+#endif // BUREAUCRAT_H
--- /dev/null
+CC := c++
+CFLAGS = -std=c++98 -Wall -Wextra -Werror -Wpedantic
+
+ifneq ("$(wildcard .debug)","")
+ CFLAGS += -g
+endif
+
+RM := rm -f
+
+INCDIR := inc
+INCDIR += $(addsuffix /inc, $(SUBPROJECTS));
+ifneq ($(INCLUDE),)
+ INCLUDE := $(addprefix -I, $(INCDIR))
+endif
+
+SRCDIR := .
+
+SOURCES := main.cpp \
+ Bureaucrat.cpp \
+ AForm.cpp \
+
+SOURCES := $(addprefix $(SRCDIR)/, $(SOURCES))
+
+OBJECTS := $(SOURCES:.cpp=.o)
+
+NAME := bureaucrat
+
+all : $(NAME)
+
+debug : .debug
+ $(MAKE) all
+
+nodebug :
+ $(RM) .debug
+ $(MAKE) re
+
+.% :
+ $(MAKE) fclean
+ touch $@
+
+$(NAME) : $(OBJECTS)
+ $(CC) $(CFLAGS) -o $@ $^ $(LINKS)
+
+%.o : %.cpp
+ $(CC) $(CFLAGS) -o $@ -c $< $(INCLUDE)
+
+clean :
+ $(RM) $(OBJECTS)
+
+fclean : clean
+ $(RM) $(NAME)
+
+re : fclean
+ $(MAKE) all
--- /dev/null
+#ifndef SHRUBERRYCREATIONFORM_H
+# define SHRUBERRYCREATIONFORM_H
+
+class ShruberryCreationForm
+{
+ private:
+
+ public:
+ using l
+ ShruberryCreationForm(const ShruberryCreationForm &other);
+ ~ShruberryCreationForm();
+
+ ShruberryCreationForm &operator=(const ShruberryCreationForm &other);
+};
+
+ShruberryCreationForm::ShruberryCreationForm(const std::string &target)
+ : AForm("Shruberry Creation Form", 145, 137, target)
+{
+}
+
+ShruberryCreationForm::~ShruberryCreationForm()
+{
+}
+
+#endif // SHRUBERRYCREATIONFORM_H
--- /dev/null
+#include "Bureaucrat.h"
+#include "AForm.h"
+#include <iostream>
+
+int main(void)
+{
+ Bureaucrat boss("Boss", 1);
+ Bureaucrat employee("Employee", 110);
+
+ return (0);
+}