mirror of
https://github.com/Ladebeze66/cpp-partie-2.git
synced 2026-11-09 13:47:14 +01:00
modif
This commit is contained in:
@@ -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 17:30:32 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,20 +73,34 @@ void Bureaucrat::incrementGrade()
|
||||
// Décrémente le grade
|
||||
void Bureaucrat::decrementGrade()
|
||||
{
|
||||
if (grade >= 150) {
|
||||
if (grade >= 150)
|
||||
{
|
||||
throw GradeTooLowException();
|
||||
}
|
||||
++grade;
|
||||
}
|
||||
|
||||
void Bureaucrat::signForm(Form& form)
|
||||
{
|
||||
try
|
||||
{
|
||||
form.beSigned(*this);
|
||||
std::cout << this->name << " signed " << form.getName() << std::endl;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cout << this->name << " couldn’t sign " << form.getName() << " because " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
// 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 +108,3 @@ std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat)
|
||||
os << bureaucrat.getName() << " bureaucrat grade " << bureaucrat.getGrade();
|
||||
return (os);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 17:30:30 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include "Form.hpp"
|
||||
|
||||
#define RESET "\033[0m"
|
||||
#define BLACK "\033[30m"
|
||||
@@ -30,35 +31,35 @@
|
||||
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();
|
||||
void signForm(Form& form);
|
||||
|
||||
private:
|
||||
const std::string name;
|
||||
int grade;
|
||||
const std::string name;
|
||||
int grade;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -6,16 +6,17 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/11 14:39:51 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/02/11 16:05:55 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/02/16 18:19:00 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Bureaucrat.hpp"
|
||||
#include "Form.hpp"
|
||||
|
||||
Form::Form(const std::string& name)
|
||||
Form::Form()
|
||||
: name(name), isSigned(false), gradeRequiredToSign(1), gradeRequiredToExecute(1)
|
||||
{
|
||||
std::cout << GREEN << "Form default constructor called!" << RESET << std::endl;
|
||||
}
|
||||
|
||||
Form::Form(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute)
|
||||
@@ -34,15 +35,21 @@ Form::Form(const std::string &name, int gradeRequiredToSign, int gradeRequiredTo
|
||||
Form::Form(const Form& other)
|
||||
: name(other.name), isSigned(other.isSigned), gradeRequiredToSign(other.gradeRequiredToSign), gradeRequiredToExecute(other.gradeRequiredToExecute)
|
||||
{
|
||||
std::cout << CYAN << "Copy constructor called for Form " << this->name << RESET << std::endl;
|
||||
}
|
||||
|
||||
Form& Form::operator=(const Form& other)
|
||||
{
|
||||
(void)other;
|
||||
if (this != &other)
|
||||
{
|
||||
this->isSigned = other.isSigned;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Form::~Form()
|
||||
{
|
||||
std::cout << RED << "Form " << this->name << " is destroyed!" << RESET << std::endl;
|
||||
}
|
||||
|
||||
std::string Form::getName() const
|
||||
@@ -77,11 +84,21 @@ void Form::beSigned(const Bureaucrat& bureaucrat)
|
||||
}
|
||||
}
|
||||
|
||||
const char* Form::GradeTooHighException::what() const noexcept
|
||||
{
|
||||
return ("Grade too hight\n");
|
||||
}
|
||||
|
||||
const char* Form::GradeTooLowException::what() const noexcept
|
||||
{
|
||||
return ("Grade too low\n");
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Form& form)
|
||||
{
|
||||
os << "Form: " << form.getName()
|
||||
<< ", Status: " << (form.getIsSigned() ? "Signed" : "Not signed")
|
||||
<< ", Grade Required to Sign: " << form.getGradeRequiredToSign()
|
||||
<< ", Grade Required to Execute: " << form.getGradeRequiredToExecute();
|
||||
return os;
|
||||
return (os);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/11 14:37:14 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/02/12 14:43:02 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/02/16 18:26:09 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -23,14 +23,13 @@ class Form
|
||||
{
|
||||
private:
|
||||
const std::string name;
|
||||
const
|
||||
bool isSigned;
|
||||
const int gradeRequiredToSign;
|
||||
const int gradeRequiredToExecute;
|
||||
|
||||
public:
|
||||
//constructueur
|
||||
Form(const::std::string& name);
|
||||
Form();
|
||||
Form(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute);
|
||||
// Constructeur par copie
|
||||
Form(const Form& other);
|
||||
@@ -50,19 +49,13 @@ public:
|
||||
class GradeTooHighException : public std::exception
|
||||
{
|
||||
public:
|
||||
const char* what() const noexcept override
|
||||
{
|
||||
return ("Grade too high");
|
||||
}
|
||||
const char* what() const noexcept override;
|
||||
};
|
||||
|
||||
class GradeTooLowException : public std::exception
|
||||
{
|
||||
public:
|
||||
const char* what() const noexcept override
|
||||
{
|
||||
return ("Grade too low");
|
||||
}
|
||||
const char* what() const noexcept override;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user