d05 ex02 ok

This commit is contained in:
hugogogo
2022-03-05 15:59:52 +01:00
parent 0a5827f3a1
commit 6c16b9c1d6
11 changed files with 215 additions and 26 deletions

Binary file not shown.

View File

@@ -25,12 +25,16 @@ D_SRCS = srcs
SRCS = main.cpp \
Bureaucrat.cpp \
AForm.cpp \
ShrubberyCreationForm.cpp
ShrubberyCreationForm.cpp \
RobotomyRequestForm.cpp \
PresidentialPardonForm.cpp
D_HEADERS = headers
HEADERS = Bureaucrat.hpp \
AForm.hpp \
ShrubberyCreationForm.hpp
ShrubberyCreationForm.hpp \
RobotomyRequestForm.hpp \
PresidentialPardonForm.hpp
D_OBJS = builds
OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o)

View File

@@ -1,17 +0,0 @@
* *
* * *
* * * * *
* * * * *
* * * * * * *
* * * * * .# * *
* * * #. .# * *
* "#. #: #" * * *
* * * "#. ##" *
* "###
"##
##.
.##:
:###
;###
,####.
/\/\/\/\/\/.######.\/\/\/\/\

18
d05/ex02/ascii.txt Normal file
View File

@@ -0,0 +1,18 @@
* *
* * *
* * * * *
* * * * *
* * * * * * *
* * * * * .# * *
* * * #. .# * *
* "#. #: #" * * *
* * * "#. ##" *
* "###
"##
##.
.##:
:###
;###
,####.
/\/\/\/\/\/.######.\/\/\/\/\

View File

@@ -0,0 +1,28 @@
#ifndef PRESIDENTIALPARDONFORM_HPP
# define PRESIDENTIALPARDONFORM_HPP
# include "color.h"
# include <iostream>
# include <string>
# include <cstdlib>
# include "AForm.hpp"
class PresidentialPardonForm : public AForm {
public:
PresidentialPardonForm( std::string target );
PresidentialPardonForm( PresidentialPardonForm const & src );
~PresidentialPardonForm();
PresidentialPardonForm & operator=( PresidentialPardonForm const & rhs );
void formAction() const;
private:
PresidentialPardonForm();
};
#endif

View File

@@ -0,0 +1,28 @@
#ifndef ROBOTOMYREQUESTFORM_HPP
# define ROBOTOMYREQUESTFORM_HPP
# include "color.h"
# include <iostream>
# include <string>
# include <cstdlib>
# include "AForm.hpp"
class RobotomyRequestForm : public AForm {
public:
RobotomyRequestForm( std::string target );
RobotomyRequestForm( RobotomyRequestForm const & src );
~RobotomyRequestForm();
RobotomyRequestForm & operator=( RobotomyRequestForm const & rhs );
void formAction() const;
private:
RobotomyRequestForm();
};
#endif

View File

@@ -19,13 +19,9 @@ public:
void formAction() const;
// std::string getTarget() const;
private:
ShrubberyCreationForm();
// std::string const _target;
};
#endif

View File

@@ -1,6 +1,8 @@
#include "Bureaucrat.hpp"
#include "AForm.hpp"
#include "ShrubberyCreationForm.hpp"
#include "RobotomyRequestForm.hpp"
#include "PresidentialPardonForm.hpp"
#define N_TEST "5"
@@ -10,7 +12,7 @@ int main() {
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
<< "Shrubbery ok :" RESET "\n";
{
Bureaucrat b("natasha", 50);
Bureaucrat b("natasha", 1);
ShrubberyCreationForm s("sekoia");
std::cout << s << '\n';
@@ -22,7 +24,7 @@ int main() {
}
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
<< "Shrubbery too low signe and execute :" RESET "\n";
<< "Shrubbery too low sign and execute :" RESET "\n";
{
Bureaucrat b("jordan", 150);
ShrubberyCreationForm s("chemney");
@@ -72,11 +74,42 @@ int main() {
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
<< "Robotomy :" RESET "\n";
{
Bureaucrat b("romeo", 15);
RobotomyRequestForm r("oven");
std::cout << r << '\n';
std::cout << b << '\n';
std::cout << B_BLUE "b.signForm :" RESET "\n";
b.signForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
b.executeForm(r);
std::cout << r << '\n';
}
std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] "
<< "Presidential :" RESET "\n";
{
Bureaucrat b("sylvestre", 1);
PresidentialPardonForm p("queen");
std::cout << p << '\n';
std::cout << b << '\n';
std::cout << B_BLUE "b.signForm :" RESET "\n";
b.signForm(p);
b.executeForm(p);
std::cout << p << '\n';
}
std::cout << "\n";

View File

@@ -0,0 +1,47 @@
#include "PresidentialPardonForm.hpp"
#define COPLIEN_COLOR B_CYAN
/*********************************************
* CONSTRUCTORS
*********************************************/
PresidentialPardonForm::PresidentialPardonForm( std::string target )
: AForm("presidential_creation", target, 25, 5){
std::cout << COPLIEN_COLOR "RobotomyRequestForm constructor" RESET "\n";
return;
}
PresidentialPardonForm::PresidentialPardonForm( PresidentialPardonForm const & src )
: AForm("presidential_creation", this->getTarget(), 25, 5) {
std::cout << COPLIEN_COLOR "RobotomyRequestForm copy constructor" RESET "\n";
*this = src;
return;
}
/*********************************************
* DESTRUCTORS
*********************************************/
PresidentialPardonForm::~PresidentialPardonForm() {
std::cout << COPLIEN_COLOR "RobotomyRequestForm destructor" RESET "\n";
return;
}
/*********************************************
* OPERATORS
*********************************************/
PresidentialPardonForm & PresidentialPardonForm::operator=( PresidentialPardonForm const & rhs ) {
AForm::operator=(rhs);
return *this;
}
/*********************************************
* PUBLIC MEMBER FUNCTIONS
*********************************************/
void PresidentialPardonForm::formAction() const {
std::cout << "Zaphod Beeblebrox pardon " << _target << "\n";
}

View File

@@ -0,0 +1,51 @@
#include "RobotomyRequestForm.hpp"
#define COPLIEN_COLOR B_CYAN
/*********************************************
* CONSTRUCTORS
*********************************************/
RobotomyRequestForm::RobotomyRequestForm( std::string target )
: AForm("robotomy_creation", target, 72, 45){
std::cout << COPLIEN_COLOR "RobotomyRequestForm constructor" RESET "\n";
return;
}
RobotomyRequestForm::RobotomyRequestForm( RobotomyRequestForm const & src )
: AForm("robotomy_creation", this->getTarget(), 72, 45) {
std::cout << COPLIEN_COLOR "RobotomyRequestForm copy constructor" RESET "\n";
*this = src;
return;
}
/*********************************************
* DESTRUCTORS
*********************************************/
RobotomyRequestForm::~RobotomyRequestForm() {
std::cout << COPLIEN_COLOR "RobotomyRequestForm destructor" RESET "\n";
return;
}
/*********************************************
* OPERATORS
*********************************************/
RobotomyRequestForm & RobotomyRequestForm::operator=( RobotomyRequestForm const & rhs ) {
AForm::operator=(rhs);
return *this;
}
/*********************************************
* PUBLIC MEMBER FUNCTIONS
*********************************************/
void RobotomyRequestForm::formAction() const {
std::cout << "*drill sounds*\n";
if (std::rand() % 2)
std::cout << _target << " robotomized with success\n";
else
std::cout << _target << " robotomization failed\n";
}

View File

@@ -42,7 +42,8 @@ ShrubberyCreationForm & ShrubberyCreationForm::operator=( ShrubberyCreationForm
*********************************************/
void ShrubberyCreationForm::formAction() const {
std::ofstream ofs("Shrubbery.txt", std::ofstream::out);
std::string name = _target + "_shrubbery";
std::ofstream ofs(name.c_str(), std::ofstream::out);
if (!ofs)
{