mirror of
https://github.com/Ladebeze66/cpp-partie-2.git
synced 2025-12-16 05:57:57 +01:00
61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* Bureaucrat.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/02/11 13:16:26 by fgras-ca #+# #+# */
|
|
/* Updated: 2024/02/11 13:58:43 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "Bureaucrat.hpp"
|
|
|
|
Bureaucrat::Bureaucrat(const std::string &nom, int grade) : name(nom)
|
|
{
|
|
if (grade < 1)
|
|
{
|
|
throw GradeTooHighException();
|
|
}
|
|
else if (grade > 150)
|
|
{
|
|
throw GradeTooLowException();
|
|
}
|
|
this->grade = grade;
|
|
}
|
|
|
|
std::string Bureaucrat::getName() const
|
|
{
|
|
return (name);
|
|
}
|
|
|
|
int Bureaucrat::getGrade() const
|
|
{
|
|
return (grade);
|
|
}
|
|
|
|
void Bureaucrat::incrementGrade()
|
|
{
|
|
if (grade <= 1)
|
|
{
|
|
throw GradeTooHighException();
|
|
}
|
|
--grade;
|
|
}
|
|
|
|
void Bureaucrat::decrementGrade()
|
|
{
|
|
if (grade >= 150)
|
|
{
|
|
throw GradeTooLowException();
|
|
}
|
|
++grade;
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream &os, const Bureaucrat &bureaucrat)
|
|
{
|
|
os << bureaucrat.getName() << MAGENTA << ", bureaucrat grade " << RESET << bureaucrat.getGrade();
|
|
return (os);
|
|
}
|