示例#1
0
int			main(void)
{
	Bureaucrat			*bur;
	std::string			name;
	std::string			buffer;

	std::cout << "Please enter a name of bureaucrat" << std::endl;
	std::getline(std::cin, buffer);
	name = buffer;
	std::cout << "Please enter a grade for " << name << std::endl;
	std::getline(std::cin, buffer);
	try
	{
		bur = new Bureaucrat(name, atoi(buffer.c_str()));
		std::cout << *bur << std::endl;
		std::cout << "Try to upgrade" << std::endl;
		bur->upGrade();
		std::cout << "Try to downgrade" << std::endl;
		bur->downGrade();
		bur->downGrade();
	}
	catch (std::exception & e)
	{
		std::cout << e.what() << std::endl;
	}
}
示例#2
0
文件: main.cpp 项目: Hadopire/42
int main( void ) {

    // b essaye de signer f mais il est trop noob pour ca
    Bureaucrat b = Bureaucrat("Michel", 20);
    Form f = Form("Traite sur la peche aux moules", 19, 1);
   b.signForm(f);
    // c'est bon la il peut signer youhou
   Form f2 = Form("Traite sur les poneys", 21, 1);
   std::cout << f2 << std::endl;
   std::cout << b << std::endl;
   b.signForm(f2);
    
    // tests de creation de form interdite
   try {

        Form test("lalala", 1, 1000);
    }
    catch (std::exception & e) {
        
        std::cout << e.what() << std::endl;
    }
    try {

        Form test("lalala", 1000, 1);
    }
    catch (std::exception & e) {
        
        std::cout << e.what() << std::endl;
    }
    ShrubberyCreationForm s("test");
    b.signForm(s);
    s.execute(b);
    return (0);
}
示例#3
0
void					test1(Bureaucrat &b, Form &f)
{
	std::cout << "\033[35mtest1: \033[0m" << std::endl;
	
	std::cout << b.getName() << "(" << b.getGrade() <<
		") trying to sign " << f.getName() << "(" << f.getSGrade() <<
		")" << std::endl;
	b.signForm(f);
	std::cout << std::endl;
	return ;
}
示例#4
0
bool	Form::execute(Bureaucrat const & executor) const
{
	try
	{
		if (executor.getGrade() > this->_grade)
		{
			throw Form::GradeTooLowException();
			return (0);
		}
		else if (this->_signed == 0)
		{
			throw Form::FormNotSignedException();
			return (0);
		}
		else
		{
			this->Action();
			return (1);
		}
	}
	catch(Form::GradeTooLowException& e)
	{
		std::cout << e.what() << std::endl;
		return(0);
	}
	catch(Form::FormNotSignedException& e)
	{
		std::cout << e.what() << std::endl;
		return(0);
	}
	return (0);
}
示例#5
0
void				Form::execute(Bureaucrat const & executor) const {
	if (!this->getSigned() || executor.getGrade() > this->getExeGrade())
		throw Form::GradeTooLowException();
	else {
		this->action();
	}
}
示例#6
0
void				Form::beSigned(Bureaucrat const & bureaucrat) {

	if (bureaucrat.getGrade() <= this->_signGrade)
		this->_signed = true;
	else
		throw Form::GradeTooLowException();
}
示例#7
0
void			Form::beSigned( Bureaucrat & bureau )
{
		if (bureau.getGrade() > this->_sign_grade )
			throw Form::GradeTooLowException();
		else
			this->_status = true;
}
void			PresidentialPardonForm::execute(Bureaucrat const & executor) const
{
	if (executor.getGrade() > PresidentialPardonForm::_PresidentialExecute)
		throw Form::BureaucratNotClearForExecution();
	else
		std::cout << this->_target << " has been pardoned by Zafod Beeblebrox.\n";
}
示例#9
0
文件: Form.cpp 项目: Strade288/42
void Form::beSigned(Bureaucrat & p_bureaucrat)
{
	if (p_bureaucrat.getGrade() <= mn_gradeToSign)
		mb_isSigned = true;
	else
		throw Form::GradeTooLowException();
}
示例#10
0
文件: Form.cpp 项目: avallete/CPPool
void			Form::beSigned(Bureaucrat& b)
{
	if (b.getGrade() <= m_sgrade)
		m_sign = 1;
	else
		throw GradeTooLowException();
	return;
}
示例#11
0
文件: Form.cpp 项目: z0mbie42/42
void	Form::execute(const Bureaucrat& executor) const
{
	if (executor.getGrade() > _grade_to_execute) {
		throw Form::GradeTooLowException();
	} else if (!_is_signed) {
		throw Form::NotSignedException();
	}
}
示例#12
0
void				Form::beSigned(Bureaucrat const &b)
	throw(GradeTooLowException)
{
	if (b.getGrade() <= gradeSign)
		sign = true;
	else
		throw GradeTooLowException();
}
示例#13
0
文件: Form.cpp 项目: NegMozzie/42
void Form::beSigned(Bureaucrat &src) {
    if (src.getGrade() <= this->gradeSign) {
        this->validated = true;
    }
    else {
        throw GradeTooLowException();
    }
}
示例#14
0
void				Form::execute(Bureaucrat const &b) const
	throw(GradeTooLowException)
{
	if (b.getGrade() <= gradeExec && sign)
		action();
	else
		throw GradeTooLowException();
}
示例#15
0
文件: Form.cpp 项目: z0mbie42/42
void	Form::beSigned(Bureaucrat& b)
{
	if (b.getGrade() < _grade_to_sign) {
		_is_signed = true;
	} else {
		throw Form::GradeTooLowException();
	}
}
示例#16
0
void Form::beSigned(Bureaucrat & bureaucrat)
{
	if (bureaucrat.getGrade() > _gradeSign) // Si le bureaucrat ne peut pas sign form
	{
		throw Form::GradeTooLowException();
	}
	else
		_isSigned = true;
}
示例#17
0
void					Form::beSigned(Bureaucrat const &copy)
{
	if (this->_signGrade < copy.getGrade())
		throw Form::GradeTooLowException();

	if (this->_isSigned)
		throw std::invalid_argument("FormAlreadySigned");
    
	this->_isSigned = true;
}
示例#18
0
文件: Form.cpp 项目: Hadopire/42
void            Form::beSigned( Bureaucrat const & b) {

    if (this->_signed == true) {
        std::cout << "form already signed" << std::endl;
        return;
        }
    if (b.getGrade() > this->_signGrade)
        throw GradeTooLowException("bureaucrat grade too low to sign the form");
    else
        this->_signed = true;
}
void		PresidentialPardonForm::execute( Bureaucrat const & executor ) const
{	
	if (this->getStatus() == 1)
	{
		if (executor.getGrade() <= this->getExecGrade())
			std::cout <<  this->getTarget() << " has been pardoned by Zafod Beeblebrox !" << std::endl;
		else
			throw Form::GradeTooLowException();	
	}
	else
		throw Form::NotSignedException();
}
示例#20
0
/*------------------ Other -----------------*/
void				RobotomyRequestForm::execute(Bureaucrat const & executor) const {
	if (executor.getGrade() > 45)
		throw Form::GradeTooLowException();
	else if (this->getSigned())
	{
		int		rand = std::rand() % 2;

		if (rand == 0)
			std::cout << this->_target << " has been robotomized successfully" << std::endl;
		else
			std::cout << this->_target << " has been failure" << std::endl;
	}
}
void
ShrubberyCreationForm::execute(Bureaucrat const & f) const {
	if (this->getSign() == false)
		throw Form::FormIsNotSignedException();
	else if (this->getExecGrade() < f.getGrade())
		throw Form::GradeTooHighException();
	else {
		std::ofstream		ofs(this->_target + "_shrubbery");
		ofs << TREE << TREE << TREE << std::endl;
		ofs.close();
	}
	return ;
}
/*
** public
*/
void					ShrubberyCreationForm::execute(Bureaucrat const &executor) const
{
	this->checkExec(executor.getGrade());

	std::ofstream   wStream(this->_target.c_str());

    if (!wStream)
    {
		std::cerr << "Error: could not open file." << std::endl;
        return ;
    }
	
	wStream << "This is a tiny ascii tree with two branches : Y" << std::endl
            << "Proof I'm not so lazzy, here another one : T" << std::endl;
}
void			RobotomyRequestForm::execute(Bureaucrat const & executor) const
{
	if (executor.getGrade() > RobotomyRequestForm::_RobotomyExecute)
		throw Form::BureaucratNotClearForExecution();
	else
	{
		int fifty_fifty_chance = rand() % 2;

		std::cout << "* IIIHHHHH OOOOHHHH IIIIIIIH *\n";
		if (fifty_fifty_chance)
			std::cout << this->_target << " has been robotomized successfully\n";
		else
			std::cout << "Robotomized Form failed\n";
	}
}
void
RobotomyRequestForm::execute(Bureaucrat const & f) const {
	if (this->getSign() == false)
		throw Form::FormIsNotSignedException();
	else if (this->getExecGrade() < f.getGrade())
		throw Form::GradeTooHighException();
	else {
		std::cout << "* Drilling noises *" << std::endl;
		std::srand(std::time(0));
		int rand = std::rand();
		if (rand % 2)
			std::cout << this->_target << " has been robotomized successfully." << std::endl;
		else
			std::cout << this->_target << "'s robotomy is a failure." << std::endl;
	}
	return ;
}
示例#25
0
void ShrubberyForm::execute(Bureaucrat const & p_bureaucrat) const
{
	Form::checkGradeToExec(p_bureaucrat.getGrade());
	std::string fileName = m_target + "_shrubbery";
	std::ofstream ofs;
	ofs.open(fileName.c_str());
	std::string tree =
	"       .#.\n"
	"      .###.\n"
	"     .#%##%.\n"
	"    .%##%###.\n"
	"   .##%###%##.\n"
	"  .#%###%##%##.\n"
	"        #\n"
	"        #\n";
	ofs << tree << tree;
	ofs.close();
}
示例#26
0
int main()
{
	Bureaucrat j = Bureaucrat("Bob", 30);
	Bureaucrat k = Bureaucrat("Giselle", 150);
	Bureaucrat l = Bureaucrat("Conrad", 2);
	std::cout << j << k << l;
	j.increasesGrade();
	k.increasesGrade();
	std::cout << j << k << l;
    k.decreasesGrade();
	k.decreasesGrade();
	std::cout << j << k << l;
	return (0);
}
示例#27
0
bool	Form::beSigned(Bureaucrat const & bur)
{
	try
	{
		if (bur.getGrade() > this->_min_grade)
		{
			throw Form::GradeTooLowException();
			return (0);
		}
		else
		{
			this->_signed = 1;
			return (1);
		}
	}
	catch(Form::GradeTooLowException& e)
	{
		std::cout << e.what() << std::endl;
		return (0);
	}
	return (0);
}
/*------------------ Other -----------------*/
void				ShrubberyCreationForm::execute(Bureaucrat const & executor) const {
	if (this->getSigned())
		throw (Form::AlreadySignedException());
	else if (executor.getGrade() > 137)
		throw Form::GradeTooLowException();
	else
	{
		std::string		file = this->_target + "_shrubbery";
		std::ofstream	ofs;

		ofs.open(file);

		ofs << "       ###" << std::endl;
		ofs << "      #o###" << std::endl;
		ofs << "    #####o###" << std::endl;
		ofs << "   #o#\\#|#/###" << std::endl;
		ofs << "    ###\\|/#o#" << std::endl;
		ofs << "     # }|{  #" << std::endl;
		ofs << "       }|{" << std::endl;
		ofs.close();
	}
}
示例#29
0
Bureaucrat::Bureaucrat(Bureaucrat const &src) : Name(src.getName()), Grade(src.getGrade()) {}
示例#30
0
文件: main.cpp 项目: DylanLEBLOND/CPP
int		main(void)
{

//Bureaucrat

	Bureaucrat	*a = new Bureaucrat("Akali", 1);
	Bureaucrat  *b = new Bureaucrat("Zed", 50);
	Bureaucrat  *c = new Bureaucrat("Shaco", 150);
	Bureaucrat	*d;
	Bureaucrat	*e;

	try
	{
		d = new Bureaucrat("Dylan", 0);
	}
	catch (std::exception const &err)
	{
		std::cerr << err.what() << std::endl;
		delete d;
	}
	try
	{
		e = new Bureaucrat("Dylan", 151);
	}
	catch (std::exception const &err)
	{
		std::cerr << err.what() << std::endl;
		delete e;
	}

	std::cout << *a << *b << *c;

	b->upgrade();
	std::cout << *b;
	b->downgrade();
	std::cout << *b;

	try
	{
		a->upgrade();
	}
	catch (std::exception const &err)
	{
		std::cerr << err.what() << std::endl;
	}
	std::cout << *a;

	try
    {
        c->downgrade();
    }
    catch (std::exception const &err)
    {
		std::cerr << err.what() << std::endl;
    }
	std::cout << *c;

//Form

	Form *f0 = new Form("Got CPP Piscine", 7, 6);
	Form *f1 = new Form("Beat Math", 3, 3);
	Form *f2 = new Form("Go Eat", 140, 150);
	Form *f3;
	Form *f4;
	Form *f5;
	Form *f6;

	try
    {
		f3 = new Form("Work", 0, 15);
    }
    catch (std::exception const &err)
    {
		std::cerr << err.what() << std::endl;
        delete f3;
    }
    try
    {
        f4 = new Form("Week", 151, 15);
    }
    catch (std::exception const &err)
    {
		std::cerr << err.what() << std::endl;
        delete f4;
    }

	try
	{
		f5 = new Form("Waak", 15, 0);
	}
	catch (std::exception const &err)
	{
		std::cerr << err.what() << std::endl;
		delete f5;
	}
    try
    {
        f6 = new Form("Wuuk", 15, 151);
    }
    catch (std::exception const &err)
    {
		std::cerr << err.what() << std::endl;
        delete f6;
    }
	
	std::cout << *f0 << *f1 << *f2;

	b->signForm(*f0);
	a->signForm(*f1);
	c->signForm(*f2);

	delete a;
	delete b;
	delete c;
	delete f1;
	return 0;
}