ex02 finished
This commit is contained in:
97
ex02/RobotomyRequestForm/RobotomyRequestForm.cpp
Normal file
97
ex02/RobotomyRequestForm/RobotomyRequestForm.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* RobotomyRequestForm.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/02/15 18:00:27 by aortigos #+# #+# */
|
||||
/* Updated: 2026/02/06 02:28:09 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "RobotomyRequestForm.hpp"
|
||||
|
||||
//////////////////
|
||||
//Constructores //
|
||||
//////////////////
|
||||
|
||||
RobotomyRequestForm::RobotomyRequestForm()
|
||||
: AForm("RobotomyRequestForm", 72, 45),
|
||||
target("NULL")
|
||||
{
|
||||
//std::cout << "RobotomyRequestForm default constructor called" << std::endl;
|
||||
}
|
||||
|
||||
RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm &other)
|
||||
: AForm(other),
|
||||
target(other.getTarget())
|
||||
{
|
||||
//std::cout << "RobotomyRequestForm constructor with params called" << std::endl;
|
||||
}
|
||||
|
||||
RobotomyRequestForm& RobotomyRequestForm::operator=(const RobotomyRequestForm &other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
AForm::operator=(other);
|
||||
this->target = other.getTarget();
|
||||
}
|
||||
//std::cout << "AForm copy assigment operator called" << std::endl;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
RobotomyRequestForm::~RobotomyRequestForm()
|
||||
{
|
||||
//std::cout << "Destructor called"
|
||||
}
|
||||
|
||||
RobotomyRequestForm::RobotomyRequestForm(std::string target)
|
||||
: AForm("RobotomyRequestForm", 72, 45),
|
||||
target(target)
|
||||
{
|
||||
//std::cout << "AForm constructor with params called" << std::endl;
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// Getters //
|
||||
//////////////////
|
||||
|
||||
std::string RobotomyRequestForm::getTarget() const
|
||||
{
|
||||
return (this->target);
|
||||
}
|
||||
|
||||
|
||||
//////////////////
|
||||
// Execute //
|
||||
//////////////////
|
||||
|
||||
void RobotomyRequestForm::execute(Bureaucrat const &executor) const
|
||||
{
|
||||
if (!this->getIsSigned())
|
||||
throw FormNotSignedException();
|
||||
if (this->getGradeToExecute() < executor.getGrade())
|
||||
throw AForm::GradeTooLowException();
|
||||
|
||||
// RobotomyRequestForm form action...
|
||||
std::cout << "**bzzzzzzzzz --- **drilling noises*" << std::endl;
|
||||
|
||||
if (rand() % 2 == 0)
|
||||
{
|
||||
std::cout << this->target
|
||||
<< " has been successfully robotomized" << std::endl;
|
||||
} else {
|
||||
std::cout << "Robotomization failed :(" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// Exceptions //
|
||||
//////////////////
|
||||
|
||||
const char* RobotomyRequestForm::FormNotSignedException::what() const throw()
|
||||
{
|
||||
return ("form is not signed.");
|
||||
}
|
||||
48
ex02/RobotomyRequestForm/RobotomyRequestForm.hpp
Normal file
48
ex02/RobotomyRequestForm/RobotomyRequestForm.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* RobotomyRequestForm.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/02/15 18:00:27 by aortigos #+# #+# */
|
||||
/* Updated: 2026/02/06 02:28:09 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ROBOTOMYREQUESTFORM_HPP
|
||||
|
||||
# define ROBOTOMYREQUESTFORM_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <cstdlib>
|
||||
# include <ctime>
|
||||
# include "../AForm/AForm.hpp"
|
||||
# include "../Bureaucrat/Bureaucrat.hpp"
|
||||
|
||||
|
||||
class RobotomyRequestForm : public AForm
|
||||
{
|
||||
private:
|
||||
std::string target;
|
||||
|
||||
public:
|
||||
RobotomyRequestForm();
|
||||
RobotomyRequestForm(const RobotomyRequestForm &other);
|
||||
RobotomyRequestForm &operator=(const RobotomyRequestForm &other);
|
||||
~RobotomyRequestForm();
|
||||
|
||||
RobotomyRequestForm(std::string target);
|
||||
|
||||
std::string getTarget() const;
|
||||
|
||||
virtual void execute(Bureaucrat const &executor) const;
|
||||
|
||||
class FormNotSignedException : public std::exception {
|
||||
public:
|
||||
virtual const char* what() const throw();
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user