48 changed files with 1427 additions and 78 deletions
@ -0,0 +1,102 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Bureaucrat.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 15:03:06 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Bureaucrat.hpp" |
|||
|
|||
Bureaucrat::Bureaucrat (void) { |
|||
cout << "Bureaucrat default constructor called " << endl; |
|||
} |
|||
|
|||
Bureaucrat::Bureaucrat (const string name, int grade) |
|||
throw (Bureaucrat::GradeTooHighException, Bureaucrat::GradeTooLowException): _name(name){ |
|||
|
|||
if (grade < 1) |
|||
throw Bureaucrat::GradeTooHighException(); |
|||
if (grade > 150) |
|||
throw Bureaucrat::GradeTooLowException(); |
|||
_grade = grade; |
|||
cout << "Bureaucrat " << _name << " created grade: " << _grade << endl; |
|||
} |
|||
|
|||
Bureaucrat::Bureaucrat (Bureaucrat const & src) { |
|||
(void)src; |
|||
cout << "Bureaucrat copy constructor called" << endl; |
|||
} |
|||
|
|||
Bureaucrat & Bureaucrat::operator= (Bureaucrat const & src) { |
|||
(void)src; |
|||
cout << "Bureaucrat assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Bureaucrat::~Bureaucrat (void) { |
|||
cout << "Bureaucrat default destructor called" << endl; |
|||
} |
|||
|
|||
const string Bureaucrat::getName(void) const{ |
|||
return (_name); |
|||
} |
|||
|
|||
int Bureaucrat::getGrade(void) const{ |
|||
return (_grade); |
|||
} |
|||
|
|||
void Bureaucrat::incrGrade(int diff) |
|||
throw (Bureaucrat::GradeTooHighException) { |
|||
int new_grade = _grade - diff; |
|||
if (new_grade < 1) |
|||
throw Bureaucrat::GradeTooHighException(); |
|||
_grade = new_grade; |
|||
} |
|||
|
|||
void Bureaucrat::decrGrade(int diff) |
|||
throw (Bureaucrat::GradeTooLowException) { |
|||
int new_grade = _grade + diff; |
|||
if (new_grade > 150) |
|||
throw Bureaucrat::GradeTooLowException(); |
|||
_grade = new_grade; |
|||
} |
|||
|
|||
const char* Bureaucrat::GradeTooHighException::what(void) const throw() { |
|||
return ("Grade was too high for a bureaucrat"); |
|||
} |
|||
|
|||
const char* Bureaucrat::GradeTooLowException::what(void) const throw() { |
|||
return ("Grade was too low for a bureaucrat"); |
|||
} |
|||
|
|||
void Bureaucrat::signForm(Form &form) const { |
|||
try { |
|||
if (!form.beSigned(*this)) |
|||
cout << _name << " succesfully signed " << form.getName() << endl; |
|||
else |
|||
cout << _name << " failed to sign " << form.getName() << ": form is already signed." << endl; |
|||
} catch (std::exception &e) { |
|||
cout << _name << " failed to sign " << form.getName() << ": " << e.what() << endl; |
|||
} |
|||
} |
|||
|
|||
void Bureaucrat::executeForm(const Form &form) const { |
|||
try { |
|||
if (!form.execute(*this)) |
|||
cout << _name << " succesfully executed " << form.getName() << endl; |
|||
else |
|||
cout << _name << " failed to execute " << form.getName() << ": form is not signed" << endl; |
|||
} catch (std::exception &e) { |
|||
cout << _name << " failed to execute " << form.getName() << ": " << e.what() << endl; |
|||
} |
|||
} |
|||
|
|||
std::ostream &operator<< (std::ostream &out, Bureaucrat const &b) { |
|||
out << b.getName() << ", bureaucrat grade " << b.getGrade() << endl; |
|||
return (out); |
|||
} |
@ -0,0 +1,54 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Bureaucrat.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:47:21 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Form.hpp" |
|||
#include <string> |
|||
#include <iostream> |
|||
#include <stdexcept> |
|||
using std::cout; |
|||
using std::endl; |
|||
using std::string; |
|||
|
|||
class Form; |
|||
|
|||
class Bureaucrat{ |
|||
const string _name; |
|||
int _grade; |
|||
public: |
|||
|
|||
class GradeTooHighException: virtual public std::exception { |
|||
public: |
|||
const char *what(void) const throw (); |
|||
}; |
|||
class GradeTooLowException: virtual public std::exception { |
|||
public: |
|||
const char *what(void) const throw (); |
|||
}; |
|||
|
|||
Bureaucrat(void); |
|||
Bureaucrat(const string name, int grade) |
|||
throw (GradeTooHighException, GradeTooLowException); |
|||
Bureaucrat(Bureaucrat const & src); |
|||
~Bureaucrat(void); |
|||
Bureaucrat & operator= (Bureaucrat const & src); |
|||
|
|||
const string getName(void) const; |
|||
int getGrade(void) const; |
|||
void incrGrade(int diff = 1) throw (GradeTooHighException); |
|||
void decrGrade(int diff = 1) throw (GradeTooLowException); |
|||
void signForm(Form &form) const; |
|||
void executeForm(const Form &form) const; |
|||
}; |
|||
|
|||
std::ostream &operator<< (std::ostream &out, Bureaucrat const &b); |
@ -0,0 +1,92 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Form.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/26 16:12:05 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:56:54 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Form.hpp" |
|||
|
|||
std::ostream &operator<< (std::ostream &out, const Form &f) { |
|||
out << "Form: " << f.getName() << " - Required grade to sign: " << f.getSignGrade() << " - Required grade to execute: " << f.getExeGrade() << endl; |
|||
return (out); |
|||
}; |
|||
|
|||
/* Defaults */ |
|||
|
|||
Form & Form::operator=(Form const &f) { |
|||
(void)f; |
|||
cout << "Form assignement called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Form::Form(Form const &f) |
|||
: _name(f.getName()), _signGrade(f.getSignGrade()), _exeGrade(f.getExeGrade()) |
|||
{ |
|||
(void)f; |
|||
cout << "Form copy called" << endl; |
|||
} |
|||
|
|||
Form::~Form(void) { |
|||
cout << "Form destructor called" << endl; |
|||
} |
|||
|
|||
/* Custom constructor */ |
|||
|
|||
Form::Form(const string name, const int signGrade, const int exeGrade, const string target) |
|||
throw (Form::GradeTooHighException, Form::GradeTooLowException) |
|||
: _name(name), _signGrade(signGrade), _exeGrade(exeGrade), _target(target){ |
|||
if (signGrade < 1 || exeGrade < 1) |
|||
throw Form::GradeTooHighException(); |
|||
if (signGrade > 150 || exeGrade > 150) |
|||
throw Form::GradeTooLowException(); |
|||
} |
|||
|
|||
/* Getters */ |
|||
|
|||
const string Form::getName(void) const { |
|||
return (_name); |
|||
} |
|||
|
|||
int Form::getSignGrade(void) const { |
|||
return (_signGrade); |
|||
} |
|||
|
|||
int Form::getExeGrade(void) const { |
|||
return (_exeGrade); |
|||
} |
|||
|
|||
/* Seter */ |
|||
|
|||
int Form::beSigned(const Bureaucrat &signer) throw (Form::GradeTooLowException) { |
|||
if (_isSigned) |
|||
return (-1); |
|||
if (signer.getGrade() > _signGrade) |
|||
throw GradeTooLowException(); |
|||
_isSigned = 1; |
|||
return (0); |
|||
} |
|||
|
|||
int Form::execute(Bureaucrat const &executor) const throw (GradeTooLowException) { |
|||
if (executor.getGrade() > _exeGrade) |
|||
throw Form::GradeTooLowException(); |
|||
if (!_isSigned) |
|||
return (-1); |
|||
this->run(); |
|||
return (0); |
|||
} |
|||
|
|||
/* Except */ |
|||
|
|||
const char *Form::GradeTooHighException::what(void) const throw (){ |
|||
return ("Grade was too high for a form"); |
|||
} |
|||
|
|||
const char *Form::GradeTooLowException::what(void) const throw (){ |
|||
return ("Grade was too low for a form"); |
|||
} |
@ -0,0 +1,57 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Form.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/26 15:47:12 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:56:40 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Bureaucrat.hpp" |
|||
#include <string> |
|||
#include <iostream> |
|||
#include <fstream> |
|||
#include <stdexcept> |
|||
#include <unistd.h> |
|||
using std::cout; |
|||
using std::endl; |
|||
using std::string; |
|||
|
|||
class Bureaucrat; |
|||
|
|||
class Form { |
|||
const string _name; |
|||
const int _signGrade; |
|||
const int _exeGrade; |
|||
bool _isSigned; |
|||
public: |
|||
class GradeTooHighException: virtual public std::exception { |
|||
public: |
|||
const char *what(void) const throw (); |
|||
}; |
|||
class GradeTooLowException: virtual public std::exception { |
|||
public: |
|||
const char *what(void) const throw (); |
|||
}; |
|||
virtual ~Form(void) = 0; |
|||
const string getName(void) const; |
|||
int getSignGrade(void) const; |
|||
int getExeGrade(void) const; |
|||
int beSigned(const Bureaucrat &signer) throw (GradeTooLowException); |
|||
int execute(Bureaucrat const &executor) const throw (GradeTooLowException); |
|||
virtual void run(void) const = 0; |
|||
protected: |
|||
Form(void); |
|||
Form(const string name, const int signGrade,const int exeGrade, const string target) |
|||
throw (GradeTooHighException, GradeTooLowException); |
|||
Form & operator=(Form const &f); |
|||
Form(Form const &f); |
|||
const string _target; |
|||
}; |
|||
|
|||
std::ostream &operator<< (std::ostream &out, const Form &f); |
@ -0,0 +1,20 @@ |
|||
NAME = bureau |
|||
SRCS = main.cpp Bureaucrat.cpp Form.cpp ShrubberyCreationForm.cpp RobotomyRequestForm.cpp PresidentialPardonForm.cpp |
|||
OBJS= $(SRCS:.cpp=.o) |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME) : $(OBJS) |
|||
c++ $(OBJS) -o $(NAME) |
|||
|
|||
all : $(NAME) |
|||
|
|||
clean : |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean : clean |
|||
rm -rf $(NAME) |
|||
|
|||
re : fclean all |
|||
|
|||
.PHONY : all clean fclean re |
@ -0,0 +1,27 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* PresidentialPardonForm.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:18:34 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:43:58 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "PresidentialPardonForm.hpp" |
|||
|
|||
PresidentialPardonForm::PresidentialPardonForm (const string target): Form("PresidentialPardonForm", 25, 5, target) { |
|||
|
|||
cout << "PresidentialPardonForm parameter constructor called" << endl; |
|||
} |
|||
|
|||
PresidentialPardonForm::~PresidentialPardonForm (void) { |
|||
|
|||
cout << "PresidentialPardonForm default destructor called" << endl; |
|||
} |
|||
|
|||
void PresidentialPardonForm::run(void) const { |
|||
cout << _target << "has been pardoned by Zaphod Beeblebrox" << endl; |
|||
} |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* PresidentialPardonForm.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:18:34 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:42:14 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Form.hpp" |
|||
|
|||
class PresidentialPardonForm: public Form { |
|||
|
|||
public: |
|||
|
|||
PresidentialPardonForm(const string target); |
|||
~PresidentialPardonForm(void); |
|||
void run(void) const; |
|||
}; |
@ -0,0 +1,38 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* RobotomyRequestForm.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:17:52 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:43:34 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "RobotomyRequestForm.hpp" |
|||
|
|||
RobotomyRequestForm::RobotomyRequestForm (const string target): Form("RobotomyRequestForm", 72, 45, target) { |
|||
|
|||
cout << "RobotomyRequestForm parameter constructor called" << endl; |
|||
} |
|||
|
|||
RobotomyRequestForm::~RobotomyRequestForm (void) { |
|||
|
|||
cout << "RobotomyRequestForm default destructor called" << endl; |
|||
} |
|||
|
|||
void RobotomyRequestForm::run(void) const { |
|||
int r = rand(); |
|||
|
|||
cout << "ratatttaatata" << endl; |
|||
sleep(1); |
|||
cout << "ratata tatata" << endl; |
|||
sleep(1); |
|||
cout << "ratata" << endl; |
|||
sleep(1); |
|||
if (r % 2) |
|||
cout<< _target << " have been robotomized" << endl; |
|||
else |
|||
cout << _target << " robotomization failed" << endl; |
|||
} |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* RobotomyRequestForm.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:17:52 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:45:20 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Form.hpp" |
|||
|
|||
class RobotomyRequestForm: public Form { |
|||
|
|||
public: |
|||
|
|||
RobotomyRequestForm(const string target); |
|||
~RobotomyRequestForm(void); |
|||
void run(void) const; |
|||
}; |
@ -0,0 +1,37 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ShrubberyCreationForm.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:17:15 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:39:19 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "ShrubberyCreationForm.hpp" |
|||
|
|||
ShrubberyCreationForm::ShrubberyCreationForm (string target): Form("ShrubberyCreationForm", 147, 137, target) { |
|||
cout << "ShrubberyCreationForm parameter constructor called" << endl; |
|||
} |
|||
|
|||
ShrubberyCreationForm::~ShrubberyCreationForm (void) { |
|||
cout << "ShrubberyCreationForm default destructor called" << endl; |
|||
} |
|||
|
|||
void ShrubberyCreationForm::run(void) const { |
|||
std::ofstream file; |
|||
file.open(_target + "shrubbery"); |
|||
file << " ,@@@@@@@," << endl; |
|||
file << " ,,,. ,@@@@@@/@@, .oo8888o." << endl; |
|||
file << " ,&\%%&%&&%,@@@@@/@@@@@@,8888\\88/8o" << endl; |
|||
file << " ,%&\\%&&%&&%,@@@\\@@@/@@@88\\88888/88'" << endl; |
|||
file << " %&&%&%&/%&&%@@\\@@/ /@@@88888\\88888'" << endl; |
|||
file << " %&&%/ %&\%%&&@@\\ V /@@' `88\\8 `/88'" << endl; |
|||
file << " `&%\\ ` /%&' |.| \\ '|8'" << endl; |
|||
file << " |o| | | | |" << endl; |
|||
file << " |.| | | | |" << endl; |
|||
file << " \\\\/ ._\\//_/__/ ,\\_//__\\\\/. \\_//__/_" << endl; |
|||
file.close(); |
|||
} |
@ -0,0 +1,22 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ShrubberyCreationForm.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:17:14 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:40:37 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Form.hpp" |
|||
class ShrubberyCreationForm: public Form { |
|||
|
|||
public: |
|||
ShrubberyCreationForm(string target); |
|||
~ShrubberyCreationForm(void); |
|||
void run(void) const; |
|||
}; |
@ -0,0 +1,39 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 13:16:27 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:58:53 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "ShrubberyCreationForm.hpp" |
|||
#include "RobotomyRequestForm.hpp" |
|||
#include "PresidentialPardonForm.hpp" |
|||
#include "Bureaucrat.hpp" |
|||
|
|||
int main(void) |
|||
{ |
|||
Bureaucrat first("first", 1); |
|||
Bureaucrat mid("midle", 75); |
|||
Bureaucrat last("last", 150); |
|||
|
|||
ShrubberyCreationForm houseForm("House"); |
|||
PresidentialPardonForm gerardForm("Gerard"); |
|||
RobotomyRequestForm biduleForm("Bidule"); |
|||
last.signForm(houseForm); |
|||
last.signForm(gerardForm); |
|||
last.signForm(biduleForm); |
|||
first.signForm(houseForm); |
|||
first.signForm(gerardForm); |
|||
first.signForm(biduleForm); |
|||
last.executeForm(houseForm); |
|||
last.executeForm(gerardForm); |
|||
last.executeForm(biduleForm); |
|||
first.executeForm(houseForm); |
|||
first.executeForm(gerardForm); |
|||
first.executeForm(biduleForm); |
|||
} |
@ -0,0 +1,102 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Bureaucrat.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 15:03:06 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Bureaucrat.hpp" |
|||
|
|||
Bureaucrat::Bureaucrat (void) { |
|||
cout << "Bureaucrat default constructor called " << endl; |
|||
} |
|||
|
|||
Bureaucrat::Bureaucrat (const string name, int grade) |
|||
throw (Bureaucrat::GradeTooHighException, Bureaucrat::GradeTooLowException): _name(name){ |
|||
|
|||
if (grade < 1) |
|||
throw Bureaucrat::GradeTooHighException(); |
|||
if (grade > 150) |
|||
throw Bureaucrat::GradeTooLowException(); |
|||
_grade = grade; |
|||
cout << "Bureaucrat " << _name << " created grade: " << _grade << endl; |
|||
} |
|||
|
|||
Bureaucrat::Bureaucrat (Bureaucrat const & src) { |
|||
(void)src; |
|||
cout << "Bureaucrat copy constructor called" << endl; |
|||
} |
|||
|
|||
Bureaucrat & Bureaucrat::operator= (Bureaucrat const & src) { |
|||
(void)src; |
|||
cout << "Bureaucrat assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Bureaucrat::~Bureaucrat (void) { |
|||
cout << "Bureaucrat default destructor called" << endl; |
|||
} |
|||
|
|||
const string Bureaucrat::getName(void) const{ |
|||
return (_name); |
|||
} |
|||
|
|||
int Bureaucrat::getGrade(void) const{ |
|||
return (_grade); |
|||
} |
|||
|
|||
void Bureaucrat::incrGrade(int diff) |
|||
throw (Bureaucrat::GradeTooHighException) { |
|||
int new_grade = _grade - diff; |
|||
if (new_grade < 1) |
|||
throw Bureaucrat::GradeTooHighException(); |
|||
_grade = new_grade; |
|||
} |
|||
|
|||
void Bureaucrat::decrGrade(int diff) |
|||
throw (Bureaucrat::GradeTooLowException) { |
|||
int new_grade = _grade + diff; |
|||
if (new_grade > 150) |
|||
throw Bureaucrat::GradeTooLowException(); |
|||
_grade = new_grade; |
|||
} |
|||
|
|||
const char* Bureaucrat::GradeTooHighException::what(void) const throw() { |
|||
return ("Grade was too high for a bureaucrat"); |
|||
} |
|||
|
|||
const char* Bureaucrat::GradeTooLowException::what(void) const throw() { |
|||
return ("Grade was too low for a bureaucrat"); |
|||
} |
|||
|
|||
void Bureaucrat::signForm(Form &form) const { |
|||
try { |
|||
if (!form.beSigned(*this)) |
|||
cout << _name << " succesfully signed " << form.getName() << endl; |
|||
else |
|||
cout << _name << " failed to sign " << form.getName() << ": form is already signed." << endl; |
|||
} catch (std::exception &e) { |
|||
cout << _name << " failed to sign " << form.getName() << ": " << e.what() << endl; |
|||
} |
|||
} |
|||
|
|||
void Bureaucrat::executeForm(const Form &form) const { |
|||
try { |
|||
if (!form.execute(*this)) |
|||
cout << _name << " succesfully executed " << form.getName() << endl; |
|||
else |
|||
cout << _name << " failed to execute " << form.getName() << ": form is not signed" << endl; |
|||
} catch (std::exception &e) { |
|||
cout << _name << " failed to execute " << form.getName() << ": " << e.what() << endl; |
|||
} |
|||
} |
|||
|
|||
std::ostream &operator<< (std::ostream &out, Bureaucrat const &b) { |
|||
out << b.getName() << ", bureaucrat grade " << b.getGrade() << endl; |
|||
return (out); |
|||
} |
@ -0,0 +1,54 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Bureaucrat.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:47:21 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Form.hpp" |
|||
#include <string> |
|||
#include <iostream> |
|||
#include <stdexcept> |
|||
using std::cout; |
|||
using std::endl; |
|||
using std::string; |
|||
|
|||
class Form; |
|||
|
|||
class Bureaucrat{ |
|||
const string _name; |
|||
int _grade; |
|||
public: |
|||
|
|||
class GradeTooHighException: virtual public std::exception { |
|||
public: |
|||
const char *what(void) const throw (); |
|||
}; |
|||
class GradeTooLowException: virtual public std::exception { |
|||
public: |
|||
const char *what(void) const throw (); |
|||
}; |
|||
|
|||
Bureaucrat(void); |
|||
Bureaucrat(const string name, int grade) |
|||
throw (GradeTooHighException, GradeTooLowException); |
|||
Bureaucrat(Bureaucrat const & src); |
|||
~Bureaucrat(void); |
|||
Bureaucrat & operator= (Bureaucrat const & src); |
|||
|
|||
const string getName(void) const; |
|||
int getGrade(void) const; |
|||
void incrGrade(int diff = 1) throw (GradeTooHighException); |
|||
void decrGrade(int diff = 1) throw (GradeTooLowException); |
|||
void signForm(Form &form) const; |
|||
void executeForm(const Form &form) const; |
|||
}; |
|||
|
|||
std::ostream &operator<< (std::ostream &out, Bureaucrat const &b); |
Binary file not shown.
@ -0,0 +1,92 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Form.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/26 16:12:05 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:56:54 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Form.hpp" |
|||
|
|||
std::ostream &operator<< (std::ostream &out, const Form &f) { |
|||
out << "Form: " << f.getName() << " - Required grade to sign: " << f.getSignGrade() << " - Required grade to execute: " << f.getExeGrade() << endl; |
|||
return (out); |
|||
}; |
|||
|
|||
/* Defaults */ |
|||
|
|||
Form & Form::operator=(Form const &f) { |
|||
(void)f; |
|||
cout << "Form assignement called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Form::Form(Form const &f) |
|||
: _name(f.getName()), _signGrade(f.getSignGrade()), _exeGrade(f.getExeGrade()) |
|||
{ |
|||
(void)f; |
|||
cout << "Form copy called" << endl; |
|||
} |
|||
|
|||
Form::~Form(void) { |
|||
cout << "Form destructor called" << endl; |
|||
} |
|||
|
|||
/* Custom constructor */ |
|||
|
|||
Form::Form(const string name, const int signGrade, const int exeGrade, const string target) |
|||
throw (Form::GradeTooHighException, Form::GradeTooLowException) |
|||
: _name(name), _signGrade(signGrade), _exeGrade(exeGrade), _target(target){ |
|||
if (signGrade < 1 || exeGrade < 1) |
|||
throw Form::GradeTooHighException(); |
|||
if (signGrade > 150 || exeGrade > 150) |
|||
throw Form::GradeTooLowException(); |
|||
} |
|||
|
|||
/* Getters */ |
|||
|
|||
const string Form::getName(void) const { |
|||
return (_name); |
|||
} |
|||
|
|||
int Form::getSignGrade(void) const { |
|||
return (_signGrade); |
|||
} |
|||
|
|||
int Form::getExeGrade(void) const { |
|||
return (_exeGrade); |
|||
} |
|||
|
|||
/* Seter */ |
|||
|
|||
int Form::beSigned(const Bureaucrat &signer) throw (Form::GradeTooLowException) { |
|||
if (_isSigned) |
|||
return (-1); |
|||
if (signer.getGrade() > _signGrade) |
|||
throw GradeTooLowException(); |
|||
_isSigned = 1; |
|||
return (0); |
|||
} |
|||
|
|||
int Form::execute(Bureaucrat const &executor) const throw (GradeTooLowException) { |
|||
if (executor.getGrade() > _exeGrade) |
|||
throw Form::GradeTooLowException(); |
|||
if (!_isSigned) |
|||
return (-1); |
|||
this->run(); |
|||
return (0); |
|||
} |
|||
|
|||
/* Except */ |
|||
|
|||
const char *Form::GradeTooHighException::what(void) const throw (){ |
|||
return ("Grade was too high for a form"); |
|||
} |
|||
|
|||
const char *Form::GradeTooLowException::what(void) const throw (){ |
|||
return ("Grade was too low for a form"); |
|||
} |
@ -0,0 +1,57 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Form.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/26 15:47:12 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:56:40 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Bureaucrat.hpp" |
|||
#include <string> |
|||
#include <iostream> |
|||
#include <fstream> |
|||
#include <stdexcept> |
|||
#include <unistd.h> |
|||
using std::cout; |
|||
using std::endl; |
|||
using std::string; |
|||
|
|||
class Bureaucrat; |
|||
|
|||
class Form { |
|||
const string _name; |
|||
const int _signGrade; |
|||
const int _exeGrade; |
|||
bool _isSigned; |
|||
public: |
|||
class GradeTooHighException: virtual public std::exception { |
|||
public: |
|||
const char *what(void) const throw (); |
|||
}; |
|||
class GradeTooLowException: virtual public std::exception { |
|||
public: |
|||
const char *what(void) const throw (); |
|||
}; |
|||
virtual ~Form(void) = 0; |
|||
const string getName(void) const; |
|||
int getSignGrade(void) const; |
|||
int getExeGrade(void) const; |
|||
int beSigned(const Bureaucrat &signer) throw (GradeTooLowException); |
|||
int execute(Bureaucrat const &executor) const throw (GradeTooLowException); |
|||
virtual void run(void) const = 0; |
|||
protected: |
|||
Form(void); |
|||
Form(const string name, const int signGrade,const int exeGrade, const string target) |
|||
throw (GradeTooHighException, GradeTooLowException); |
|||
Form & operator=(Form const &f); |
|||
Form(Form const &f); |
|||
const string _target; |
|||
}; |
|||
|
|||
std::ostream &operator<< (std::ostream &out, const Form &f); |
Binary file not shown.
@ -0,0 +1,57 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Intern.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 15:07:10 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 16:28:56 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Intern.hpp" |
|||
|
|||
Intern::Intern (void) { |
|||
cout << "Intern default constructor called " << endl; |
|||
} |
|||
|
|||
Intern::Intern (Intern const & src) { |
|||
(void)src; |
|||
cout << "Intern copy constructor called" << endl; |
|||
} |
|||
|
|||
Intern & Intern::operator= (Intern const & src) { |
|||
(void)src; |
|||
cout << "Intern assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Intern::~Intern (void) { |
|||
|
|||
cout << "Intern default destructor called" << endl; |
|||
} |
|||
|
|||
Form * createRobotForm(string targ){ |
|||
return (new RobotomyRequestForm(targ)); |
|||
} |
|||
|
|||
Form * createPresidentForm(string targ) { |
|||
return (new PresidentialPardonForm(targ)); |
|||
} |
|||
|
|||
Form * createShrubberyForm(string targ) { |
|||
return (new ShrubberyCreationForm(targ)); |
|||
} |
|||
|
|||
Form * Intern::makeForm(string name, string target) |
|||
{ |
|||
string subFormsName[3] = {"robotomy request", "president pardon", "shrubbery creation"}; |
|||
Form * (*subFormsCreation[3])(string targ) =\ |
|||
{createRobotForm, createPresidentForm, createShrubberyForm}; |
|||
for (int i = 0; i < 3; i++) |
|||
if (name == subFormsName[i]) |
|||
return (subFormsCreation[i](target)); |
|||
cout << "Intern fail to create " << name << ": unknow form name" << endl; |
|||
return (NULL); |
|||
} |
@ -0,0 +1,35 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Intern.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 15:07:10 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 16:28:32 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Form.hpp" |
|||
#include "PresidentialPardonForm.hpp" |
|||
#include "RobotomyRequestForm.hpp" |
|||
#include "ShrubberyCreationForm.hpp" |
|||
#include <string> |
|||
|
|||
#include <iostream> |
|||
using std::cout; |
|||
using std::endl; |
|||
using std::string; |
|||
|
|||
class Intern{ |
|||
|
|||
public: |
|||
Intern(void); |
|||
Intern(Intern const & src); |
|||
virtual ~Intern(void); |
|||
Intern & operator= (Intern const & src); |
|||
Form * makeForm(string name, string target); |
|||
protected: |
|||
}; |
Binary file not shown.
@ -0,0 +1,20 @@ |
|||
NAME = bureau |
|||
SRCS = main.cpp Bureaucrat.cpp Form.cpp ShrubberyCreationForm.cpp RobotomyRequestForm.cpp PresidentialPardonForm.cpp Intern.cpp |
|||
OBJS= $(SRCS:.cpp=.o) |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME) : $(OBJS) |
|||
c++ $(OBJS) -o $(NAME) |
|||
|
|||
all : $(NAME) |
|||
|
|||
clean : |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean : clean |
|||
rm -rf $(NAME) |
|||
|
|||
re : fclean all |
|||
|
|||
.PHONY : all clean fclean re |
@ -0,0 +1,27 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* PresidentialPardonForm.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:18:34 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:43:58 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "PresidentialPardonForm.hpp" |
|||
|
|||
PresidentialPardonForm::PresidentialPardonForm (const string target): Form("PresidentialPardonForm", 25, 5, target) { |
|||
|
|||
cout << "PresidentialPardonForm parameter constructor called" << endl; |
|||
} |
|||
|
|||
PresidentialPardonForm::~PresidentialPardonForm (void) { |
|||
|
|||
cout << "PresidentialPardonForm default destructor called" << endl; |
|||
} |
|||
|
|||
void PresidentialPardonForm::run(void) const { |
|||
cout << _target << "has been pardoned by Zaphod Beeblebrox" << endl; |
|||
} |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* PresidentialPardonForm.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:18:34 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:42:14 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Form.hpp" |
|||
|
|||
class PresidentialPardonForm: public Form { |
|||
|
|||
public: |
|||
|
|||
PresidentialPardonForm(const string target); |
|||
~PresidentialPardonForm(void); |
|||
void run(void) const; |
|||
}; |
Binary file not shown.
@ -0,0 +1,38 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* RobotomyRequestForm.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:17:52 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:43:34 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "RobotomyRequestForm.hpp" |
|||
|
|||
RobotomyRequestForm::RobotomyRequestForm (const string target): Form("RobotomyRequestForm", 72, 45, target) { |
|||
|
|||
cout << "RobotomyRequestForm parameter constructor called" << endl; |
|||
} |
|||
|
|||
RobotomyRequestForm::~RobotomyRequestForm (void) { |
|||
|
|||
cout << "RobotomyRequestForm default destructor called" << endl; |
|||
} |
|||
|
|||
void RobotomyRequestForm::run(void) const { |
|||
int r = rand(); |
|||
|
|||
cout << "ratatttaatata" << endl; |
|||
sleep(1); |
|||
cout << "ratata tatata" << endl; |
|||
sleep(1); |
|||
cout << "ratata" << endl; |
|||
sleep(1); |
|||
if (r % 2) |
|||
cout<< _target << " have been robotomized" << endl; |
|||
else |
|||
cout << _target << " robotomization failed" << endl; |
|||
} |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* RobotomyRequestForm.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:17:52 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:45:20 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Form.hpp" |
|||
|
|||
class RobotomyRequestForm: public Form { |
|||
|
|||
public: |
|||
|
|||
RobotomyRequestForm(const string target); |
|||
~RobotomyRequestForm(void); |
|||
void run(void) const; |
|||
}; |
Binary file not shown.
@ -0,0 +1,37 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ShrubberyCreationForm.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:17:15 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 16:36:13 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "ShrubberyCreationForm.hpp" |
|||
|
|||
ShrubberyCreationForm::ShrubberyCreationForm (string target): Form("ShrubberyCreationForm", 147, 137, target) { |
|||
cout << "ShrubberyCreationForm parameter constructor called" << endl; |
|||
} |
|||
|
|||
ShrubberyCreationForm::~ShrubberyCreationForm (void) { |
|||
cout << "ShrubberyCreationForm default destructor called" << endl; |
|||
} |
|||
|
|||
void ShrubberyCreationForm::run(void) const { |
|||
std::ofstream file; |
|||
file.open(_target + "_shrubbery"); |
|||
file << " ,@@@@@@@," << endl; |
|||
file << " ,,,. ,@@@@@@/@@, .oo8888o." << endl; |
|||
file << " ,&\%%&%&&%,@@@@@/@@@@@@,8888\\88/8o" << endl; |
|||
file << " ,%&\\%&&%&&%,@@@\\@@@/@@@88\\88888/88'" << endl; |
|||
file << " %&&%&%&/%&&%@@\\@@/ /@@@88888\\88888'" << endl; |
|||
file << " %&&%/ %&\%%&&@@\\ V /@@' `88\\8 `/88'" << endl; |
|||
file << " `&%\\ ` /%&' |.| \\ '|8'" << endl; |
|||
file << " |o| | | | |" << endl; |
|||
file << " |.| | | | |" << endl; |
|||
file << " \\\\/ ._\\//_/__/ ,\\_//__\\\\/. \\_//__/_" << endl; |
|||
file.close(); |
|||
} |
@ -0,0 +1,22 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ShrubberyCreationForm.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/27 10:17:14 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 14:40:37 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Form.hpp" |
|||
class ShrubberyCreationForm: public Form { |
|||
|
|||
public: |
|||
ShrubberyCreationForm(string target); |
|||
~ShrubberyCreationForm(void); |
|||
void run(void) const; |
|||
}; |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,10 @@ |
|||
,@@@@@@@, |
|||
,,,. ,@@@@@@/@@, .oo8888o. |
|||
,&%%&%&&%,@@@@@/@@@@@@,8888\88/8o |
|||
,%&\%&&%&&%,@@@\@@@/@@@88\88888/88' |
|||
%&&%&%&/%&&%@@\@@/ /@@@88888\88888' |
|||
%&&%/ %&%%&&@@\ V /@@' `88\8 `/88' |
|||
`&%\ ` /%&' |.| \ '|8' |
|||
|o| | | | | |
|||
|.| | | | | |
|||
\\/ ._\//_/__/ ,\_//__\\/. \_//__/_ |
@ -0,0 +1,47 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 13:16:27 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/27 16:34:59 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "ShrubberyCreationForm.hpp" |
|||
#include "RobotomyRequestForm.hpp" |
|||
#include "PresidentialPardonForm.hpp" |
|||
#include "Bureaucrat.hpp" |
|||
#include "Intern.hpp" |
|||
|
|||
int main(void) |
|||
{ |
|||
Bureaucrat first("first", 1); |
|||
Bureaucrat mid("midle", 75); |
|||
Bureaucrat last("last", 150); |
|||
Intern rookie; |
|||
Form *form; |
|||
|
|||
form = rookie.makeForm("shrubbery creation", "house"); |
|||
last.signForm(*form); |
|||
first.signForm(*form); |
|||
last.executeForm(*form); |
|||
first.executeForm(*form); |
|||
delete form; |
|||
|
|||
form = rookie.makeForm("robotomy request", "bidule"); |
|||
last.signForm(*form); |
|||
first.signForm(*form); |
|||
last.executeForm(*form); |
|||
first.executeForm(*form); |
|||
delete form; |
|||
|
|||
form = rookie.makeForm("president pardon", "gerard"); |
|||
last.signForm(*form); |
|||
first.signForm(*form); |
|||
last.executeForm(*form); |
|||
first.executeForm(*form); |
|||
delete form; |
|||
} |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,62 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Converter.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/30 08:45:12 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/12 08:42:27 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Converter.hpp" |
|||
|
|||
Converter::Converter (void) { |
|||
cout << "Converter default constructor called " << endl; |
|||
} |
|||
|
|||
Converter::Converter (string str):_input(str){ |
|||
startConv(); |
|||
cout << "Converter parameter constructor called" << endl; |
|||
} |
|||
|
|||
Converter::Converter (Converter const & src) { |
|||
(void)src; |
|||
cout << "Converter copy constructor called" << endl; |
|||
} |
|||
|
|||
Converter & Converter::operator= (Converter const & src) { |
|||
(void)src; |
|||
cout << "Converter assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Converter::~Converter (void) { |
|||
|
|||
cout << "Converter default destructor called" << endl; |
|||
} |
|||
|
|||
|
|||
void Converter::startConv(void) { |
|||
if (_input[0] == '\'' || _input[0] == '"') |
|||
{ |
|||
_c = _input[1]; |
|||
_d = static_cast<double>(_c); |
|||
} |
|||
else |
|||
{ |
|||
_d = std::strtod(_input.c_str(), 0); |
|||
_c = static_cast<char>(_d); |
|||
} |
|||
_i = static_cast<int>(_d); |
|||
_f = static_cast<float>(_d); |
|||
} |
|||
|
|||
void Converter::display(void) { |
|||
cout << "Input: " << _input << endl; |
|||
cout << "Char: " << _c << endl; |
|||
cout << "Double: " << _d << endl; |
|||
cout << "Float: " << _f << endl; |
|||
cout << "Integer: " << _i << endl; |
|||
} |
@ -0,0 +1,38 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Converter.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/30 08:45:12 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/12 08:46:08 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <iostream> |
|||
#include <cstdlib> |
|||
using std::cout; |
|||
using std::endl; |
|||
using std::string; |
|||
|
|||
class Converter{ |
|||
|
|||
string _input; |
|||
char _c; |
|||
int _i; |
|||
float _f; |
|||
double _d; |
|||
int _types[4]; |
|||
public: |
|||
Converter(void); |
|||
Converter(string str); |
|||
Converter(Converter const & src); |
|||
virtual ~Converter(void); |
|||
Converter & operator= (Converter const & src); |
|||
void startConv(void); |
|||
void display(void); |
|||
}; |
Binary file not shown.
@ -0,0 +1,21 @@ |
|||
NAME = convert |
|||
SRCS = main.cpp Converter.cpp |
|||
OBJS= $(SRCS:.cpp=.o) |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME) : $(OBJS) |
|||
c++ $(OBJS) -o $(NAME) |
|||
|
|||
all : $(NAME) |
|||
|
|||
clean : |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean : clean |
|||
rm -rf $(NAME) |
|||
|
|||
re : fclean all |
|||
|
|||
.PHONY : all clean fclean re |
|||
|
Binary file not shown.
@ -0,0 +1,28 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/28 08:44:43 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/12 08:09:02 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include <iostream> |
|||
#include "Converter.hpp" |
|||
|
|||
using std::cout; |
|||
using std::endl; |
|||
using std::string; |
|||
|
|||
int main(int ac, char **av) { |
|||
|
|||
if (ac != 2) |
|||
return (EXIT_FAILURE); |
|||
string input = av[1]; |
|||
Converter raw(input); |
|||
raw.display(); |
|||
|
|||
} |
Binary file not shown.
Loading…
Reference in new issue