-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBureaucrat.cpp
More file actions
75 lines (62 loc) · 2.18 KB
/
Bureaucrat.cpp
File metadata and controls
75 lines (62 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Bureaucrat.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zelhajou <zelhajou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/25 11:38:47 by zelhajou #+# #+# */
/* Updated: 2024/12/30 16:16:04 by zelhajou ### ########.fr */
/* */
/* ************************************************************************** */
#include "Bureaucrat.hpp"
Bureaucrat::Bureaucrat() : _name("default"), _grade(150) {}
Bureaucrat::Bureaucrat(const std::string &name, int grade) : _name(name)
{
if (grade < 1)
throw GradeTooHighException();
if (grade > 150)
throw GradeTooLowException();
_grade = grade;
}
Bureaucrat::Bureaucrat(const Bureaucrat &src) : _name(src._name), _grade(src._grade) {}
Bureaucrat::~Bureaucrat() {}
Bureaucrat &Bureaucrat::operator=(const Bureaucrat &src)
{
if (this != &src)
_grade = src._grade;
return *this;
}
const 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++;
}
const char *Bureaucrat::GradeTooHighException::what() const throw()
{
return "Grade too high (must be between 1 and 150)";
}
const char *Bureaucrat::GradeTooLowException::what() const throw()
{
return "Grade too low (must be between 1 and 150)";
}
std::ostream &operator<<(std::ostream &os, const Bureaucrat &bureaucrat)
{
os << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade();
return os;
}