CPP05 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
main.cpp
[詳解]
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* main.cpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/06/30 12:26:03 by kamitsui #+# #+# */
9/* Updated: 2025/07/18 02:48:08 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
21#include "AForm.hpp"
22#include "Bureaucrat.hpp"
26#include <cstdlib> // For srand
27#include <ctime> // For time
28#include <iostream>
29
30void print_header(const std::string &title) { std::cout << "\n\033[1;33m--- " << title << " ---\033[0m" << std::endl; }
31
32int main() {
33 // Seed the random number generator once for RobotomyRequestForm
34 std::srand(std::time(NULL));
35
36 // Create bureaucrats
37 Bureaucrat high("Zaphod", 1);
38 Bureaucrat mid("Ford", 50);
39 Bureaucrat low("Arthur", 148);
40
41 // Create forms
42 ShrubberyCreationForm shrub("garden");
43 RobotomyRequestForm robo("Bender");
44 PresidentialPardonForm pardon("Marvin");
45
46 print_header("Initial Status");
47 std::cout << high << std::endl;
48 std::cout << mid << std::endl;
49 std::cout << low << std::endl;
50 std::cout << shrub << std::endl;
51 std::cout << robo << std::endl;
52 std::cout << pardon << std::endl;
53
54 // --- Test Case 1: Low-level Bureaucrat ---
55 print_header("Test Case 1: Low-level Bureaucrat 'Arthur' (Grade 148)");
56 low.signForm(shrub); // Fails (needs 145)
57 low.signForm(robo); // Fails
58 low.signForm(pardon); // Fails
59 low.executeForm(shrub); // Fails (not signed)
60
61 // --- Test Case 2: Signing Shrubbery and executing ---
62 print_header("Test Case 2: Signing & Executing Shrubbery Form");
63 Bureaucrat shrubExpert("Shrub-Master", 140);
64 std::cout << shrubExpert << std::endl;
65 shrubExpert.signForm(shrub);
66 shrubExpert.executeForm(shrub); // Fails (exec grade 137 needed)
67
68 std::cout << "---" << std::endl;
69 mid.executeForm(shrub); // Mid-level can execute it
70
71 // --- Test Case 3: Signing and Executing Robotomy ---
72 print_header("Test Case 3: Signing & Executing Robotomy Form");
73 mid.signForm(robo);
74 mid.executeForm(robo); // Fails (exec grade 45 needed)
75
76 std::cout << "---" << std::endl;
77 high.executeForm(robo); // High-level can execute it
78
79 // --- Test Case 4: Signing and Executing Presidential Pardon ---
80 print_header("Test Case 4: Signing & Executing Presidential Pardon");
81 mid.signForm(pardon); // Fails (sign grade 25 needed)
82
83 std::cout << "---" << std::endl;
84 high.signForm(pardon);
85 high.executeForm(pardon);
86
87 // --- Test Case 5: Executing a form that isn't signed ---
88 print_header("Test Case 5: Executing an unsigned form");
89 RobotomyRequestForm robo2("WALL-E");
90 high.executeForm(robo2);
91
92 print_header("Tests complete.");
93 return 0;
94}
Represents a bureaucrat with a name and a grade.
void signForm(Form &form)
Attempts to sign a form. Calls the form's beSigned method and prints the result.
void executeForm(AForm const &form)
Attempts to execute a form. Calls the form's execute method and prints the result.
A concrete form that grants a presidential pardon.
A concrete form that simulates a robotomy attempt.
A concrete form that creates a file with ASCII trees.
T endl(T... args)
void print_header(const std::string &title)
Prints a formatted header to the console.
Definition main.cpp:28
int main()
Main entry point of the program.
Definition main.cpp:34
Defines the abstract base class AForm for all specific forms.
Defines the Bureaucrat class, updated to execute AForms.
Defines the PresidentialPardonForm class.
Defines the RobotomyRequestForm class.
Defines the ShrubberyCreationForm class.
T srand(T... args)
T time(T... args)