Browse Source

end05- start06

master^2
narnaud 3 years ago
parent
commit
fac5b9aed4
  1. 16
      CPP05/ex01/Bureaucrat.cpp
  2. 18
      CPP05/ex01/Bureaucrat.hpp
  3. 57
      CPP05/ex01/Form.cpp
  4. 27
      CPP05/ex01/Form.hpp
  5. 56
      CPP05/ex01/main.cpp
  6. 102
      CPP05/ex02/Bureaucrat.cpp
  7. 54
      CPP05/ex02/Bureaucrat.hpp
  8. 92
      CPP05/ex02/Form.cpp
  9. 57
      CPP05/ex02/Form.hpp
  10. 20
      CPP05/ex02/Makefile
  11. 27
      CPP05/ex02/PresidentialPardonForm.cpp
  12. 24
      CPP05/ex02/PresidentialPardonForm.hpp
  13. 38
      CPP05/ex02/RobotomyRequestForm.cpp
  14. 24
      CPP05/ex02/RobotomyRequestForm.hpp
  15. 37
      CPP05/ex02/ShrubberyCreationForm.cpp
  16. 22
      CPP05/ex02/ShrubberyCreationForm.hpp
  17. 39
      CPP05/ex02/main.cpp
  18. 102
      CPP05/ex03/Bureaucrat.cpp
  19. 54
      CPP05/ex03/Bureaucrat.hpp
  20. BIN
      CPP05/ex03/Bureaucrat.o
  21. 92
      CPP05/ex03/Form.cpp
  22. 57
      CPP05/ex03/Form.hpp
  23. BIN
      CPP05/ex03/Form.o
  24. 57
      CPP05/ex03/Intern.cpp
  25. 35
      CPP05/ex03/Intern.hpp
  26. BIN
      CPP05/ex03/Intern.o
  27. 20
      CPP05/ex03/Makefile
  28. 27
      CPP05/ex03/PresidentialPardonForm.cpp
  29. 24
      CPP05/ex03/PresidentialPardonForm.hpp
  30. BIN
      CPP05/ex03/PresidentialPardonForm.o
  31. 38
      CPP05/ex03/RobotomyRequestForm.cpp
  32. 24
      CPP05/ex03/RobotomyRequestForm.hpp
  33. BIN
      CPP05/ex03/RobotomyRequestForm.o
  34. 37
      CPP05/ex03/ShrubberyCreationForm.cpp
  35. 22
      CPP05/ex03/ShrubberyCreationForm.hpp
  36. BIN
      CPP05/ex03/ShrubberyCreationForm.o
  37. BIN
      CPP05/ex03/bureau
  38. 10
      CPP05/ex03/house_shrubbery
  39. 47
      CPP05/ex03/main.cpp
  40. BIN
      CPP05/ex03/main.o
  41. BIN
      CPP06/.main.cpp.swp
  42. 62
      CPP06/ex00/Converter.cpp
  43. 38
      CPP06/ex00/Converter.hpp
  44. BIN
      CPP06/ex00/Converter.o
  45. 21
      CPP06/ex00/Makefile
  46. BIN
      CPP06/ex00/convert
  47. 28
      CPP06/ex00/main.cpp
  48. BIN
      CPP06/ex00/main.o

16
CPP05/ex01/Bureaucrat.cpp

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */ /* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */
/* Updated: 2022/06/26 15:59:50 by narnaud ### ########.fr */ /* Updated: 2022/06/27 09:13:57 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -39,7 +39,7 @@ Bureaucrat & Bureaucrat::operator= (Bureaucrat const & src) {
} }
Bureaucrat::~Bureaucrat (void) { Bureaucrat::~Bureaucrat (void) {
cout << "Bureaucrat default destructor called << endl; cout << "Bureaucrat default destructor called" << endl;
} }
const string Bureaucrat::getName(void) const{ const string Bureaucrat::getName(void) const{
@ -74,8 +74,18 @@ const char* Bureaucrat::GradeTooLowException::what(void) const throw() {
return ("Grade was too low for a bureaucrat"); 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() << " form." << endl;
else
cout << _name << " failed to sign " << form.getName() << ", form is already signed." << endl;
} catch (std::exception &e) {
cout << _name << "couldn't sign form because his grade is too low" << endl;
}
}
std::ostream &operator<< (std::ostream &out, Bureaucrat const &b) { std::ostream &operator<< (std::ostream &out, Bureaucrat const &b) {
out << b.getName() << ", bureaucrat grade " << b.getGrade() << endl; out << b.getName() << ", bureaucrat grade " << b.getGrade() << endl;
return (out); return (out);
} }

18
CPP05/ex01/Bureaucrat.hpp

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */ /* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */
/* Updated: 2022/06/26 16:35:38 by narnaud ### ########.fr */ /* Updated: 2022/06/27 09:36:27 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,18 +20,18 @@ using std::cout;
using std::endl; using std::endl;
using std::string; using std::string;
class Form;
class Bureaucrat{ class Bureaucrat{
const string _name; const string _name;
int _grade; int _grade;
public: public:
class GradeTooHighException: virtual public std::exception class GradeTooHighException: virtual public std::exception {
{
public: public:
const char *what(void) const throw (); const char *what(void) const throw ();
}; };
class GradeTooLowException: virtual public std::exception class GradeTooLowException: virtual public std::exception {
{
public: public:
const char *what(void) const throw (); const char *what(void) const throw ();
}; };
@ -45,11 +45,9 @@ class Bureaucrat{
const string getName(void) const; const string getName(void) const;
int getGrade(void) const; int getGrade(void) const;
void incrGrade(int diff = 1) void incrGrade(int diff = 1) throw (GradeTooHighException);
throw (GradeTooHighException); void decrGrade(int diff = 1) throw (GradeTooLowException);
void decrGrade(int diff = 1) void signForm(Form &form) const;
throw (GradeTooLowException);
}; };
std::ostream &operator<< (std::ostream &out, Bureaucrat const &b); std::ostream &operator<< (std::ostream &out, Bureaucrat const &b);

57
CPP05/ex01/Form.cpp

@ -6,32 +6,77 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/26 16:12:05 by narnaud #+# #+# */ /* Created: 2022/06/26 16:12:05 by narnaud #+# #+# */
/* Updated: 2022/06/27 01:05:27 by narnaud ### ########.fr */ /* Updated: 2022/06/27 09:40:11 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "Form.hpp" #include "Form.hpp"
Form::Form(const string name, const int signGrade, const int exeGrade) 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) {
(void)f;
cout << "Form copy called" << endl;
}
Form::~Form(void) {
cout << "Form desctructor called" << endl;
}
/* Custom constructor */
Form::Form(const string name, int signGrade, int exeGrade)
throw (Form::GradeTooHighException, Form::GradeTooLowException): _name(name){ throw (Form::GradeTooHighException, Form::GradeTooLowException): _name(name){
if (signGrade < 1 || exeGrade < 1) if (signGrade < 1 || exeGrade < 1)
throw Form::GradeTooHighException; throw Form::GradeTooHighException();
if (signGrade > 150 || exeGrade > 150) if (signGrade > 150 || exeGrade > 150)
throw Form::GradeTooLowException; throw Form::GradeTooLowException();
_signGrade = signGrade; _signGrade = signGrade;
_exeGrade = exeGrade; _exeGrade = exeGrade;
} }
/* Getters */
const string Form::getName(void) const { const string Form::getName(void) const {
return (_name); return (_name);
} }
const int Form::getSignGrade(void) const { int Form::getSignGrade(void) const {
return (_signGrade); return (_signGrade);
} }
const int Form::getExeGrade(void) const { int Form::getExeGrade(void) const {
return (_exeGrade); return (_exeGrade);
} }
/* Seter */
bool Form::beSigned(const Bureaucrat &b) throw (Form::GradeTooLowException) {
if (_isSigned)
return (1);
if (b.getGrade() > _signGrade)
throw GradeTooLowException();
_isSigned = 1;
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");
}

27
CPP05/ex01/Form.hpp

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/26 15:47:12 by narnaud #+# #+# */ /* Created: 2022/06/26 15:47:12 by narnaud #+# #+# */
/* Updated: 2022/06/27 01:05:27 by narnaud ### ########.fr */ /* Updated: 2022/06/27 09:36:10 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,33 +20,32 @@ using std::cout;
using std::endl; using std::endl;
using std::string; using std::string;
class Bureaucrat;
class Form { class Form {
const string _name; const string _name;
const int _signGrade; int _signGrade;
const int _exeGrade; int _exeGrade;
bool _isSigned; bool _isSigned;
public: public:
class GradeTooHighException: virtual public std::exception { class GradeTooHighException: virtual public std::exception {
public: public:
const char *what(void) const throw (); const char *what(void) const throw ();
} };
class GradeTooLowException: virtual public std::exception { class GradeTooLowException: virtual public std::exception {
public: public:
const char *what(void) const throw (); const char *what(void) const throw ();
} };
Form(void); Form(void);
Form(const string name, const int signGrade,const int exeGrade) Form(const string name, const int signGrade,const int exeGrade)
throw (GradeTooHighException, GradeTooLowException); throw (GradeTooHighException, GradeTooLowException);
Form & operator=(Form const &f); Form & operator=(Form const &f);
Form(Form const &f); Form(Form const &f);
~Form(); ~Form(void);
const string getName(void) const; const string getName(void) const;
const int getSignGrade(void) const; int getSignGrade(void) const;
const int getExeGrade(void) const; int getExeGrade(void) const;
beSigned(Bureaucrat); bool beSigned(const Bureaucrat &b) throw (GradeTooLowException);
} };
std::ostream &operator<< (std::ostream &out, const Form &f) { 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();
return (out);
}

56
CPP05/ex01/main.cpp

@ -6,59 +6,25 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/24 13:16:27 by narnaud #+# #+# */ /* Created: 2022/06/24 13:16:27 by narnaud #+# #+# */
/* Updated: 2022/06/26 16:34:45 by narnaud ### ########.fr */ /* Updated: 2022/06/27 09:40:50 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "Form.hpp" #include "Form.hpp"
#include "Bureaucrat.hpp"
void create_too_low(void) {
try {
Bureaucrat b("trash", 151);
} catch (std::exception &e) {
cout << "Grade 151 creation: " << e.what() << endl;
}
}
void create_too_high(void) {
try {
Bureaucrat b("god", 0);
} catch (std::exception &e) {
cout << "Grade 0 creation: " << e.what() << endl;
}
}
void first_evolve(Bureaucrat &b) {
try {
b.incrGrade();
} catch (std::exception &e) {
cout << "Grade 1 increase: "<< e.what() << endl;
}
}
void last_dismiss(Bureaucrat &b) {
try {
b.decrGrade();
} catch (std::exception &e) {
cout << "Grade 150 decrease: "<< e.what() << endl;
}
}
int main(void) int main(void)
{ {
Bureaucrat first("first", 1); Bureaucrat first("first", 1);
Bureaucrat last("last", 150); Bureaucrat mid("midle", 75);
Bureaucrat last("last", 150);
Form garb("garbage", 75, 75);
cout << first; cout << first << mid << last << garb;
cout << last;
create_too_low(); last.signForm(garb);
create_too_high(); mid.signForm(garb);
first_evolve(first); first.signForm(garb);
last_dismiss(last);
cout << first;
cout << last;
} }

102
CPP05/ex02/Bureaucrat.cpp

@ -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);
}

54
CPP05/ex02/Bureaucrat.hpp

@ -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);

92
CPP05/ex02/Form.cpp

@ -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");
}

57
CPP05/ex02/Form.hpp

@ -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);

20
CPP05/ex02/Makefile

@ -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

27
CPP05/ex02/PresidentialPardonForm.cpp

@ -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;
}

24
CPP05/ex02/PresidentialPardonForm.hpp

@ -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;
};

38
CPP05/ex02/RobotomyRequestForm.cpp

@ -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;
}

24
CPP05/ex02/RobotomyRequestForm.hpp

@ -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;
};

37
CPP05/ex02/ShrubberyCreationForm.cpp

@ -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();
}

22
CPP05/ex02/ShrubberyCreationForm.hpp

@ -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;
};

39
CPP05/ex02/main.cpp

@ -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);
}

102
CPP05/ex03/Bureaucrat.cpp

@ -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);
}

54
CPP05/ex03/Bureaucrat.hpp

@ -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);

BIN
CPP05/ex03/Bureaucrat.o

Binary file not shown.

92
CPP05/ex03/Form.cpp

@ -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");
}

57
CPP05/ex03/Form.hpp

@ -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);

BIN
CPP05/ex03/Form.o

Binary file not shown.

57
CPP05/ex03/Intern.cpp

@ -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);
}

35
CPP05/ex03/Intern.hpp

@ -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:
};

BIN
CPP05/ex03/Intern.o

Binary file not shown.

20
CPP05/ex03/Makefile

@ -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

27
CPP05/ex03/PresidentialPardonForm.cpp

@ -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;
}

24
CPP05/ex03/PresidentialPardonForm.hpp

@ -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;
};

BIN
CPP05/ex03/PresidentialPardonForm.o

Binary file not shown.

38
CPP05/ex03/RobotomyRequestForm.cpp

@ -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;
}

24
CPP05/ex03/RobotomyRequestForm.hpp

@ -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;
};

BIN
CPP05/ex03/RobotomyRequestForm.o

Binary file not shown.

37
CPP05/ex03/ShrubberyCreationForm.cpp

@ -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();
}

22
CPP05/ex03/ShrubberyCreationForm.hpp

@ -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;
};

BIN
CPP05/ex03/ShrubberyCreationForm.o

Binary file not shown.

BIN
CPP05/ex03/bureau

Binary file not shown.

10
CPP05/ex03/house_shrubbery

@ -0,0 +1,10 @@
,@@@@@@@,
,,,. ,@@@@@@/@@, .oo8888o.
,&%%&%&&%,@@@@@/@@@@@@,8888\88/8o
,%&\%&&%&&%,@@@\@@@/@@@88\88888/88'
%&&%&%&/%&&%@@\@@/ /@@@88888\88888'
%&&%/ %&%%&&@@\ V /@@' `88\8 `/88'
`&%\ ` /%&' |.| \ '|8'
|o| | | | |
|.| | | | |
\\/ ._\//_/__/ ,\_//__\\/. \_//__/_

47
CPP05/ex03/main.cpp

@ -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;
}

BIN
CPP05/ex03/main.o

Binary file not shown.

BIN
CPP06/.main.cpp.swp

Binary file not shown.

62
CPP06/ex00/Converter.cpp

@ -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;
}

38
CPP06/ex00/Converter.hpp

@ -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);
};

BIN
CPP06/ex00/Converter.o

Binary file not shown.

21
CPP06/ex00/Makefile

@ -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

BIN
CPP06/ex00/convert

Binary file not shown.

28
CPP06/ex00/main.cpp

@ -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();
}

BIN
CPP06/ex00/main.o

Binary file not shown.
Loading…
Cancel
Save