Something went wrong. Try again.
Java--'s try/catch projects.intra.42.fr/projects/cpp-module-05
Something went wrong. Try again.
1.5 kB · 50 lines
C++
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051#include <RobotomyRequestForm.hpp>#include <cstdlib>#include <ctime>
RobotomyRequestForm::RobotomyRequestForm() : AForm("RobotomyRequestForm", 72, 45), target("Marvin") { std::cout << "RobotomyRequestForm default constructor called" << std::endl;}
RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm& other) : AForm(other), target(other.target) { std::cout << "RobotomyRequestForm copy constructor called" << std::endl;}
RobotomyRequestForm::RobotomyRequestForm(const std::string& target) : AForm("RobotomyRequestForm", 72, 45), target(target) { std::cout << "RobotomyRequestForm (target) constructor called" << std::endl;}
void RobotomyRequestForm::executeAction() const { static bool seeded = false;
if (!seeded) { std::srand(static_cast<unsigned int>(std::time(NULL))); seeded = true; }
std::cout << "* Bzzzzzz... Whirrrrr... Vrrrrrrrr... *" << std::endl;
if (std::rand() % 2) std::cout << target << " has been robotomized successfully" << std::endl; else std::cout << "The robotomy of " << target << " failed" << std::endl;}
const std::string& RobotomyRequestForm::getTarget() const { return target;}
RobotomyRequestForm& RobotomyRequestForm::operator=(const RobotomyRequestForm& other) { std::cout << "RobotomyRequestForm assignment operator called" << std::endl;
if (this != &other) { AForm::operator=(other); target = other.target; }
return *this;}
RobotomyRequestForm::~RobotomyRequestForm() { std::cout << "RobotomyRequestForm destructor called" << std::endl;}