main.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* main.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/07/17 15:10:40 by bchanot #+# #+# */
  9. /* Updated: 2025/12/31 17:59:20 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "Bureaucrat.hpp"
  13. #include "AForm.hpp"
  14. #include "Intern.hpp"
  15. #include "PresidentialPardonForm.hpp"
  16. #include "RobotomyRequestForm.hpp"
  17. #include "ShrubberyCreationForm.hpp"
  18. #include <iostream>
  19. #include <limits>
  20. int main( void ) {
  21. srand(time(NULL));
  22. Bureaucrat* bob = new Bureaucrat("bob", 150);
  23. Bureaucrat* jimmy = new Bureaucrat("jimmy", 1);
  24. PresidentialPardonForm* form;
  25. ShrubberyCreationForm* shrubForm = new ShrubberyCreationForm("forest");
  26. RobotomyRequestForm* roboform = new RobotomyRequestForm("Bill Potts");
  27. try
  28. {
  29. form = new PresidentialPardonForm("Daphne");
  30. }
  31. catch (std::exception & e)
  32. {
  33. std::cout << "Exception " << e.what() << std::endl;
  34. }
  35. std::cout << *form << std::endl;
  36. std::cout << *shrubForm << std::endl;
  37. std::cout << *roboform << std::endl;
  38. std::cout << *bob << std::endl;
  39. std::cout << *jimmy << std::endl;
  40. try
  41. {
  42. bob->incrementGrade();
  43. jimmy->incrementGrade();
  44. }
  45. catch (std::exception & e)
  46. {
  47. std::cout << "Exception " << e.what() << std::endl;
  48. }
  49. std::cout << *bob << std::endl;
  50. std::cout << *jimmy << std::endl;
  51. try
  52. {
  53. jimmy->decrementGrade();
  54. bob->decrementGrade();
  55. bob->decrementGrade();
  56. }
  57. catch (std::exception & e)
  58. {
  59. std::cout << "Exception " << e.what() << std::endl;
  60. }
  61. std::cout << *bob << std::endl;
  62. std::cout << *jimmy << std::endl;
  63. bob->signForm(form);
  64. jimmy->signForm(form);
  65. std::cout << *form << std::endl;
  66. bob->executeForm(*form);
  67. jimmy->executeForm(*form);
  68. bob->executeForm(*roboform);
  69. jimmy->executeForm(*roboform);
  70. bob->signForm(roboform);
  71. jimmy->signForm(roboform);
  72. bob->executeForm(*shrubForm);
  73. bob->signForm(shrubForm);
  74. jimmy->signForm(shrubForm);
  75. try
  76. {
  77. int j = 0;
  78. while (j++ < 20)
  79. bob->incrementGrade();
  80. }
  81. catch (std::exception & e)
  82. {
  83. std::cout << "Exception " << e.what() << std::endl;
  84. }
  85. bob->executeForm(*shrubForm);
  86. bob->executeForm(*roboform);
  87. jimmy->executeForm(*roboform);
  88. jimmy->executeForm(*roboform);
  89. jimmy->executeForm(*roboform);
  90. jimmy->executeForm(*roboform);
  91. std::cout << "\n-------Last-Part--------\n" << std::endl;
  92. Intern* nameless = new Intern;
  93. std::cout << *nameless << std::endl;
  94. AForm* creation;
  95. try {
  96. creation = nameless->makeForm("blue", "black");
  97. } catch (std::exception & e) {
  98. e.what();
  99. }
  100. creation = nameless->makeForm("Robotomy request", "red");
  101. std::cout << *creation << std::endl;
  102. jimmy->executeForm(*creation);
  103. jimmy->signForm(creation);
  104. jimmy->executeForm(*creation);
  105. delete (bob);
  106. delete (jimmy);
  107. delete (form);
  108. delete (roboform);
  109. delete (shrubForm);
  110. delete (creation);
  111. delete (nameless);
  112. return (0);
  113. }