-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fatih Cil
committed
Sep 12, 2022
1 parent
5efd01e
commit a97828b
Showing
21 changed files
with
951 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/12 14:11:13 by fcil #+# #+# */ | ||
/* Updated: 2022/09/12 14:56:43 by fcil ### ########.fr */ | ||
/* Updated: 2022/09/12 17:14:42 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -74,7 +74,7 @@ void Form::beSigned(Bureaucrat const &b) | |
|
||
std::ostream& operator<<(std::ostream &o, Form const &f) | ||
{ | ||
o << f.getName() << "Form:" << std::endl; | ||
o << f.getName() << " Form:" << std::endl; | ||
o << "Status: " << f.getSignedResult() << std::endl; | ||
o << "Grade To Sign: " << f.getSignGrade() << std::endl; | ||
o << "Grade To Execute: " << f.getExecGrade() << std::endl; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/12 14:11:13 by fcil #+# #+# */ | ||
/* Updated: 2022/09/12 16:03:35 by fcil ### ########.fr */ | ||
/* Updated: 2022/09/12 17:14:06 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -76,7 +76,7 @@ void Form::setFormTarget(std::string target) | |
void Form::beSigned(Bureaucrat const &b) | ||
{ | ||
if (this->getSignGrade() < b.getGrade()) | ||
throw GradeTooLowException(); | ||
throw Form::GradeTooLowException(); | ||
else | ||
this->_signed = true; | ||
} | ||
|
@@ -92,11 +92,12 @@ void Form::execute(Bureaucrat const &executor) const | |
return ; | ||
} | ||
executeForm(); | ||
std::cout << executor.getName() << " executed " << this->getName() << std::endl; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream &o, Form const &f) | ||
{ | ||
o << f.getName() << "Form:" << std::endl; | ||
o << f.getName() << " Form:" << std::endl; | ||
o << "Status: " << f.getSignedResult() << std::endl; | ||
o << "Grade To Sign: " << f.getSignGrade() << std::endl; | ||
o << "Grade To Execute: " << f.getExecGrade() << std::endl; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* PresidentialPardonForm.cpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/12 16:10:36 by fcil #+# #+# */ | ||
/* Updated: 2022/09/12 16:41:53 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "PresidentialPardonForm.hpp" | ||
|
||
PresidentialPardonForm::PresidentialPardonForm() : | ||
Form("PresidentialPardonForm", 25, 5) | ||
{} | ||
|
||
PresidentialPardonForm::~PresidentialPardonForm() | ||
{} | ||
|
||
PresidentialPardonForm::PresidentialPardonForm(std::string target) : | ||
Form("PresidentialPardonForm", 25, 5) | ||
{ | ||
this->setFormTarget(target); | ||
} | ||
|
||
PresidentialPardonForm::PresidentialPardonForm(PresidentialPardonForm const &src) : | ||
Form(src.getName(), src.getSignGrade(), src.getExecGrade()) | ||
{ | ||
*this = src; | ||
} | ||
|
||
PresidentialPardonForm& PresidentialPardonForm::operator=(PresidentialPardonForm scf) | ||
{ | ||
this->setSignedResult(scf.getSignedResult()); | ||
this->setFormTarget(scf.getFormTarget()); | ||
|
||
return (*this); | ||
} | ||
|
||
void PresidentialPardonForm::executeForm() const | ||
{ | ||
std::cout << this->getFormTarget() << " has been pardoned by Zaphod Beeblebrox." << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* PresidentialPardonForm.hpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/12 16:08:24 by fcil #+# #+# */ | ||
/* Updated: 2022/09/12 16:29:59 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#pragma once | ||
|
||
#include "Form.hpp" | ||
#include <fstream> | ||
|
||
class PresidentialPardonForm : public Form | ||
{ | ||
public: | ||
PresidentialPardonForm(); | ||
virtual ~PresidentialPardonForm(); | ||
PresidentialPardonForm(std::string target); | ||
PresidentialPardonForm(PresidentialPardonForm const &src); | ||
PresidentialPardonForm &operator=(PresidentialPardonForm scf); | ||
|
||
virtual void executeForm() const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* RobotomyRequestForm.cpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/12 16:10:36 by fcil #+# #+# */ | ||
/* Updated: 2022/09/12 16:39:14 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "RobotomyRequestForm.hpp" | ||
|
||
RobotomyRequestForm::RobotomyRequestForm() : | ||
Form("RobotomyRequestForm", 72, 45) | ||
{} | ||
|
||
RobotomyRequestForm::~RobotomyRequestForm() | ||
{} | ||
|
||
RobotomyRequestForm::RobotomyRequestForm(std::string target) : | ||
Form("RobotomyRequestForm", 72, 45) | ||
{ | ||
this->setFormTarget(target); | ||
} | ||
|
||
RobotomyRequestForm::RobotomyRequestForm(RobotomyRequestForm const &src) : | ||
Form(src.getName(), src.getSignGrade(), src.getExecGrade()) | ||
{ | ||
*this = src; | ||
} | ||
|
||
RobotomyRequestForm& RobotomyRequestForm::operator=(RobotomyRequestForm scf) | ||
{ | ||
this->setSignedResult(scf.getSignedResult()); | ||
this->setFormTarget(scf.getFormTarget()); | ||
|
||
return (*this); | ||
} | ||
|
||
void RobotomyRequestForm::executeForm() const | ||
{ | ||
srand(time(NULL)); | ||
if (rand() % 2 == 0) { | ||
std::cout << "Bzzzztttt...." << std::endl; | ||
std::cout << this->getFormTarget() << " has been robotomized successfully." << std::endl; | ||
} | ||
else { | ||
std::cout << this->getFormTarget() << " robotomy failed." << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* RobotomyRequestForm.hpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/12 16:08:24 by fcil #+# #+# */ | ||
/* Updated: 2022/09/12 16:29:59 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#pragma once | ||
|
||
#include "Form.hpp" | ||
#include <fstream> | ||
|
||
class RobotomyRequestForm : public Form | ||
{ | ||
public: | ||
RobotomyRequestForm(); | ||
virtual ~RobotomyRequestForm(); | ||
RobotomyRequestForm(std::string target); | ||
RobotomyRequestForm(RobotomyRequestForm const &src); | ||
RobotomyRequestForm &operator=(RobotomyRequestForm scf); | ||
|
||
virtual void executeForm() const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/12 16:10:36 by fcil #+# #+# */ | ||
/* Updated: 2022/09/12 16:30:03 by fcil ### ########.fr */ | ||
/* Updated: 2022/09/12 16:45:12 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -61,7 +61,7 @@ void ShrubberyCreationForm::executeForm() const | |
" \\ }{\n" | ||
" }}{\n" | ||
" }}{\n" | ||
" canodis {{}\n" | ||
" fcil {{}\n" | ||
" , -=-~{ .-^- _\n" | ||
" `}\n" | ||
" {" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,52 @@ | |
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/12 11:42:20 by fcil #+# #+# */ | ||
/* Updated: 2022/09/12 16:24:32 by fcil ### ########.fr */ | ||
/* Updated: 2022/09/12 16:54:24 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "iostream" | ||
#include "Bureaucrat.hpp" | ||
#include "PresidentialPardonForm.hpp" | ||
#include "RobotomyRequestForm.hpp" | ||
#include "ShrubberyCreationForm.hpp" | ||
|
||
int main(void) | ||
{ | ||
{ | ||
PresidentialPardonForm pp("PP"); | ||
|
||
Bureaucrat fatih("fatih", 2); | ||
Bureaucrat abyerk("abyerk", 6); | ||
|
||
fatih.signForm(pp); | ||
abyerk.signForm(pp); | ||
|
||
fatih.executeForm(pp); | ||
abyerk.executeForm(pp); | ||
std::cout << "--------------------------" << std::endl; | ||
} | ||
{ | ||
RobotomyRequestForm rqf("RQF"); | ||
Bureaucrat fatih("fatih", 3); | ||
Bureaucrat abyerk("abyerk", 6); | ||
|
||
fatih.signForm(rqf); | ||
abyerk.signForm(rqf); | ||
|
||
fatih.executeForm(rqf); | ||
abyerk.executeForm(rqf); | ||
std::cout << "--------------------------" << std::endl; | ||
} | ||
{ | ||
ShrubberyCreationForm musab("SCF"); | ||
Bureaucrat fatih("fatih", 3); | ||
Bureaucrat abyerk("abyerk", 6); | ||
|
||
fatih.signForm(musab); | ||
abyerk.signForm(musab); | ||
|
||
fatih.executeForm(musab); | ||
abyerk.executeForm(musab); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* Bureaucrat.cpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: fcil <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/12 12:00:32 by fcil #+# #+# */ | ||
/* Updated: 2022/09/12 16:06:48 by fcil ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "Bureaucrat.hpp" | ||
|
||
Bureaucrat::Bureaucrat() | ||
{ | ||
this->_grade = LOWEST; | ||
} | ||
|
||
Bureaucrat::Bureaucrat(std::string name, int grade) : _name(name), _grade(grade) | ||
{ | ||
if (grade < HIGHEST) | ||
throw Bureaucrat::GradeTooHighException(); | ||
if (grade > LOWEST) | ||
throw Bureaucrat::GradeTooLowException(); | ||
} | ||
|
||
Bureaucrat::Bureaucrat(Bureaucrat const &b) : _name(b.getName()), _grade(b.getGrade()) | ||
{ | ||
*this = b; | ||
} | ||
|
||
Bureaucrat::~Bureaucrat() | ||
{} | ||
|
||
Bureaucrat& Bureaucrat::operator=(Bureaucrat const &b) | ||
{ | ||
this->_grade = b.getGrade(); | ||
|
||
return (*this); | ||
} | ||
|
||
std::string Bureaucrat::getName() const | ||
{ | ||
return (this->_name); | ||
} | ||
|
||
int Bureaucrat::getGrade() const | ||
{ | ||
return (this->_grade); | ||
} | ||
|
||
void Bureaucrat::incrementGrade() | ||
{ | ||
if (this->_grade - 1 < HIGHEST) | ||
throw Bureaucrat::GradeTooHighException(); | ||
this->_grade--; | ||
} | ||
|
||
void Bureaucrat::decrementGrade() | ||
{ | ||
if (this->_grade + 1 > LOWEST) | ||
throw Bureaucrat::GradeTooLowException(); | ||
this->_grade++; | ||
|
||
} | ||
|
||
void Bureaucrat::signForm(Form &form) | ||
{ | ||
if (form.getSignGrade() >= this->getGrade()) | ||
{ | ||
form.setSignedResult(true); | ||
std::cout << "<" << this->getName() << "> signed <" << | ||
form.getName() << ">" << std::endl; | ||
} | ||
else | ||
std::cout << "<" << this->getName() << "> cannot sign <" << | ||
form.getName() << "> because <the bureaucrat's grade is lower than " | ||
"the form's grade to sign>."<< std::endl; | ||
} | ||
|
||
void Bureaucrat::executeForm(Form const &form) | ||
{ | ||
try | ||
{ | ||
form.execute(*this); | ||
} | ||
catch(const std::exception& e) | ||
{ | ||
std::cout << this->getName() << "couldnt execute"<< form.getName() << " because " << e.what() << std::endl; | ||
} | ||
} | ||
|
||
std::ostream& operator<<(std::ostream &o, Bureaucrat const &b) | ||
{ | ||
o << b.getName() << ", bureaucrat grade " << b.getGrade() << "."; | ||
return (o); | ||
} |
Oops, something went wrong.