Something went wrong. Try again.
Java--'s try/catch projects.intra.42.fr/projects/cpp-module-05
Something went wrong. Try again.
1.9 kB · 68 lines
C++
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869#include <Form.hpp>#include <Bureaucrat.hpp>
Form::Form() : name("Vente"), isSigned(false), gradeToSign(150), gradeToExecute(150) { std::cout << "Form default constructor called" << std::endl;}
Form::Form(const Form& other) : name(other.name), isSigned(other.isSigned), gradeToSign(other.gradeToSign), gradeToExecute(other.gradeToExecute) { std::cout << "Form copy constructor called" << std::endl;}
Form::Form(const std::string& name) : name(name), isSigned(false), gradeToSign(150), gradeToExecute(150) { std::cout << "Form (name) constructor called" << std::endl;}
Form::Form(const std::string& name, const unsigned short gradeToSign, const unsigned short gradeToExecute) : name(name), isSigned(false), gradeToSign(gradeToSign), gradeToExecute(gradeToExecute) { std::cout << "Form (name, gradeToSign, gradeToExecute) constructor called" << std::endl;
if (gradeToSign > 150 || gradeToExecute > 150) throw GradeTooLowException();
if (gradeToSign < 1 || gradeToExecute < 1) throw GradeTooHighException();}
void Form::beSigned(Bureaucrat& bureaucrat) { std::cout << "Be signed called" << std::endl;
if (bureaucrat.getGrade() > gradeToSign) throw GradeTooLowException();
isSigned = true;}
const std::string& Form::getName() const { return name;}
bool Form::getIsSigned() const { return isSigned;}
unsigned short Form::getGradeToSign() const { return gradeToSign;}
unsigned short Form::getGradeToExecute() const { return gradeToExecute;}
Form& Form::operator=(const Form& other) { std::cout << "Form assignment operator called" << std::endl;
if (this != &other) isSigned = other.isSigned;
return *this;}
Form::~Form() { std::cout << "Form destructor called" << std::endl;}
std::ostream& operator<<(std::ostream& ostream, const Form& form) { ostream << form.getName() << ", grade to sign " << form.getGradeToSign() << ", grade to execute " << form.getGradeToExecute() << "."; return ostream;}