This commit is contained in:
2024-02-20 15:37:45 +01:00
parent 8ad95969ba
commit bb9b81c53f
15 changed files with 341 additions and 203 deletions

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 13:16:26 by fgras-ca #+# #+# */
/* Updated: 2024/02/14 14:38:10 by fgras-ca ### ########.fr */
/* Updated: 2024/02/16 16:48:16 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,7 +15,7 @@
// Constructeur par défaut
Bureaucrat::Bureaucrat() : name("Default"), grade(150)
{
std::cout << GREEN << "Bureaucrat default constructor called!\n" << RESET << std::endl;
std::cout << GREEN << "Bureaucrat default constructor called!" << RESET << std::endl;
}
// Constructeur avec paramètres
Bureaucrat::Bureaucrat(const std::string& name, int grade) :name(name), grade(grade)
@@ -73,7 +73,8 @@ void Bureaucrat::incrementGrade()
// Décrémente le grade
void Bureaucrat::decrementGrade()
{
if (grade >= 150) {
if (grade >= 150)
{
throw GradeTooLowException();
}
++grade;
@@ -81,12 +82,12 @@ void Bureaucrat::decrementGrade()
// Méthodes pour les exceptions
const char* Bureaucrat::GradeTooHighException::what() const throw()
{
return "Grade too hight\n";
return ("Grade too hight\n");
}
const char* Bureaucrat::GradeTooLowException::what() const throw()
{
return "Grade too low\n";
return ("Grade too low\n");
}
// Surcharge de l'opérateur <<
std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat)
@@ -94,4 +95,3 @@ std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat)
os << bureaucrat.getName() << " bureaucrat grade " << bureaucrat.getGrade();
return (os);
}

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 12:57:28 by fgras-ca #+# #+# */
/* Updated: 2024/02/14 14:32:41 by fgras-ca ### ########.fr */
/* Updated: 2024/02/16 16:39:04 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -30,35 +30,34 @@
class Bureaucrat
{
public:
class GradeTooHighException : public std::exception
class GradeTooHighException : public std::exception
{
public:
const char* what() const throw() override;
};
public:
const char* what() const throw() override;
};
class GradeTooLowException : public std::exception
class GradeTooLowException : public std::exception
{
public:
const char* what() const throw() override;
};
public:
const char* what() const throw() override;
};
Bureaucrat();
Bureaucrat(const std::string& name, int grade);
Bureaucrat(const Bureaucrat& other);
Bureaucrat& operator=(const Bureaucrat& other);
~Bureaucrat();
Bureaucrat();
Bureaucrat(const std::string& name, int grade);
Bureaucrat(const Bureaucrat& other);
Bureaucrat& operator=(const Bureaucrat& other);
~Bureaucrat();
std::string getName() const;
int getGrade() const;
void incrementGrade();
void decrementGrade();
std::string getName() const;
int getGrade() const;
void incrementGrade();
void decrementGrade();
private:
const std::string name;
int grade;
const std::string name;
int grade;
};
std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat);
#endif

Binary file not shown.

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 13:28:49 by fgras-ca #+# #+# */
/* Updated: 2024/02/14 14:37:10 by fgras-ca ### ########.fr */
/* Updated: 2024/02/16 16:48:36 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */