main.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/30 18:23:16 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "Bureaucrat.hpp"
  13. #include "AForm.hpp"
  14. #include "PresidentialPardonForm.hpp"
  15. #include "RobotomyRequestForm.hpp"
  16. #include "ShrubberyCreationForm.hpp"
  17. #include <iostream>
  18. #include <limits>
  19. int main( void ) {
  20. srand(time(NULL));
  21. Bureaucrat* bob = new Bureaucrat("bob", 150);
  22. Bureaucrat* jimmy = new Bureaucrat("jimmy", 1);
  23. PresidentialPardonForm* form;
  24. ShrubberyCreationForm* shrubForm = new ShrubberyCreationForm("forest");
  25. RobotomyRequestForm* roboform = new RobotomyRequestForm("Bill Potts");
  26. try
  27. {
  28. form = new PresidentialPardonForm("Daphne");
  29. }
  30. catch (std::exception & e)
  31. {
  32. std::cout << "Exception " << e.what() << std::endl;
  33. }
  34. std::cout << *form << std::endl;
  35. std::cout << *shrubForm << std::endl;
  36. std::cout << *roboform << std::endl;
  37. std::cout << *bob << std::endl;
  38. std::cout << *jimmy << std::endl;
  39. try
  40. {
  41. bob->incrementGrade();
  42. jimmy->incrementGrade();
  43. }
  44. catch (std::exception & e)
  45. {
  46. std::cout << "Exception " << e.what() << std::endl;
  47. }
  48. std::cout << *bob << std::endl;
  49. std::cout << *jimmy << std::endl;
  50. try
  51. {
  52. jimmy->decrementGrade();
  53. bob->decrementGrade();
  54. bob->decrementGrade();
  55. }
  56. catch (std::exception & e)
  57. {
  58. std::cout << "Exception " << e.what() << std::endl;
  59. }
  60. std::cout << *bob << std::endl;
  61. std::cout << *jimmy << std::endl;
  62. bob->signForm(form);
  63. jimmy->signForm(form);
  64. std::cout << *form << std::endl;
  65. bob->executeForm(*form);
  66. jimmy->executeForm(*form);
  67. bob->executeForm(*roboform);
  68. jimmy->executeForm(*roboform);
  69. bob->signForm(roboform);
  70. jimmy->signForm(roboform);
  71. bob->executeForm(*shrubForm);
  72. bob->signForm(shrubForm);
  73. jimmy->signForm(shrubForm);
  74. try
  75. {
  76. int j = 0;
  77. while (j++ < 20)
  78. bob->incrementGrade();
  79. }
  80. catch (std::exception & e)
  81. {
  82. std::cout << "Exception " << e.what() << std::endl;
  83. }
  84. bob->executeForm(*shrubForm);
  85. bob->executeForm(*roboform);
  86. jimmy->executeForm(*roboform);
  87. jimmy->executeForm(*roboform);
  88. jimmy->executeForm(*roboform);
  89. jimmy->executeForm(*roboform);
  90. delete (bob);
  91. delete (jimmy);
  92. delete (form);
  93. delete (roboform);
  94. delete (shrubForm);
  95. return (0);
  96. }