d05 ex02 ok
This commit is contained in:
BIN
d05/ex02/28b_28c
BIN
d05/ex02/28b_28c
Binary file not shown.
@@ -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)
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
* *
|
||||
* * *
|
||||
* * * * *
|
||||
* * * * *
|
||||
* * * * * * *
|
||||
* * * * * .# * *
|
||||
* * * #. .# * *
|
||||
* "#. #: #" * * *
|
||||
* * * "#. ##" *
|
||||
* "###
|
||||
"##
|
||||
##.
|
||||
.##:
|
||||
:###
|
||||
;###
|
||||
,####.
|
||||
/\/\/\/\/\/.######.\/\/\/\/\
|
||||
18
d05/ex02/ascii.txt
Normal file
18
d05/ex02/ascii.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
* *
|
||||
* * *
|
||||
* * * * *
|
||||
* * * * *
|
||||
* * * * * * *
|
||||
* * * * * .# * *
|
||||
* * * #. .# * *
|
||||
* "#. #: #" * * *
|
||||
* * * "#. ##" *
|
||||
* "###
|
||||
"##
|
||||
##.
|
||||
.##:
|
||||
:###
|
||||
;###
|
||||
,####.
|
||||
/\/\/\/\/\/.######.\/\/\/\/\
|
||||
|
||||
28
d05/ex02/headers/PresidentialPardonForm.hpp
Normal file
28
d05/ex02/headers/PresidentialPardonForm.hpp
Normal 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
|
||||
|
||||
28
d05/ex02/headers/RobotomyRequestForm.hpp
Normal file
28
d05/ex02/headers/RobotomyRequestForm.hpp
Normal 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
|
||||
|
||||
@@ -19,13 +19,9 @@ public:
|
||||
|
||||
void formAction() const;
|
||||
|
||||
// std::string getTarget() const;
|
||||
|
||||
private:
|
||||
|
||||
ShrubberyCreationForm();
|
||||
// std::string const _target;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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";
|
||||
|
||||
47
d05/ex02/srcs/PresidentialPardonForm.cpp
Normal file
47
d05/ex02/srcs/PresidentialPardonForm.cpp
Normal 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";
|
||||
}
|
||||
|
||||
51
d05/ex02/srcs/RobotomyRequestForm.cpp
Normal file
51
d05/ex02/srcs/RobotomyRequestForm.cpp
Normal 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";
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user