Starting ex03
This commit is contained in:
91
ex03/PresidentialPardonForm/PresidentialPardonForm.cpp
Normal file
91
ex03/PresidentialPardonForm/PresidentialPardonForm.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* PresidentialPardonForm.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 "PresidentialPardonForm.hpp"
|
||||
|
||||
//////////////////
|
||||
//Constructores //
|
||||
//////////////////
|
||||
|
||||
PresidentialPardonForm::PresidentialPardonForm()
|
||||
: AForm("PresidentialPardonForm", 25, 5),
|
||||
target("NULL")
|
||||
{
|
||||
//std::cout << "PresidentialPardonForm default constructor called" << std::endl;
|
||||
}
|
||||
|
||||
PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm &other)
|
||||
: AForm(other),
|
||||
target(other.getTarget())
|
||||
{
|
||||
//std::cout << "PresidentialPardonForm constructor with params called" << std::endl;
|
||||
}
|
||||
|
||||
PresidentialPardonForm& PresidentialPardonForm::operator=(const PresidentialPardonForm &other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
AForm::operator=(other);
|
||||
this->target = other.getTarget();
|
||||
}
|
||||
//std::cout << "AForm copy assigment operator called" << std::endl;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
PresidentialPardonForm::~PresidentialPardonForm()
|
||||
{
|
||||
//std::cout << "Destructor called"
|
||||
}
|
||||
|
||||
PresidentialPardonForm::PresidentialPardonForm(std::string target)
|
||||
: AForm("PresidentialPardonForm", 25, 5),
|
||||
target(target)
|
||||
{
|
||||
//std::cout << "AForm constructor with params called" << std::endl;
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// Getters //
|
||||
//////////////////
|
||||
|
||||
std::string PresidentialPardonForm::getTarget() const
|
||||
{
|
||||
return (this->target);
|
||||
}
|
||||
|
||||
|
||||
//////////////////
|
||||
// Execute //
|
||||
//////////////////
|
||||
|
||||
void PresidentialPardonForm::execute(Bureaucrat const &executor) const
|
||||
{
|
||||
if (!this->getIsSigned())
|
||||
throw FormNotSignedException();
|
||||
if (this->getGradeToExecute() < executor.getGrade())
|
||||
throw AForm::GradeTooLowException();
|
||||
|
||||
// PresidentialPardonForm form action...
|
||||
std::cout << this->target
|
||||
<< " has been pardoned by Zaphod Beeblebrox."
|
||||
<< std::endl;
|
||||
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// Exceptions //
|
||||
//////////////////
|
||||
|
||||
const char* PresidentialPardonForm::FormNotSignedException::what() const throw()
|
||||
{
|
||||
return ("form is not signed.");
|
||||
}
|
||||
45
ex03/PresidentialPardonForm/PresidentialPardonForm.hpp
Normal file
45
ex03/PresidentialPardonForm/PresidentialPardonForm.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* PresidentialPardonForm.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 PRESIDENTIALPARDONFORM_HPP
|
||||
|
||||
# define PRESIDENTIALPARDONFORM_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include "../AForm/AForm.hpp"
|
||||
# include "../Bureaucrat/Bureaucrat.hpp"
|
||||
|
||||
class PresidentialPardonForm : public AForm
|
||||
{
|
||||
private:
|
||||
std::string target;
|
||||
|
||||
public:
|
||||
PresidentialPardonForm();
|
||||
PresidentialPardonForm(const PresidentialPardonForm &other);
|
||||
PresidentialPardonForm &operator=(const PresidentialPardonForm &other);
|
||||
~PresidentialPardonForm();
|
||||
|
||||
PresidentialPardonForm(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