⚠️ [Quan Trọng] Tài khoản không hoạt động trong vòng 01 năm sẽ bị xoá.
42 Exam: 05 |work|
The 42 Exam Rank 05 tests your proficiency in Object-Oriented Programming (OOP) using C++, with recent updates occasionally including an optional or separate C component. The exam typically follows a multi-level structure focusing on class design, polymorphism, and algorithm implementation. C++ Stream (Core Subjects)
This is the most common version of the exam, where you must implement specific classes using the Orthodox Canonical Form (default constructor, copy constructor, assignment operator, and destructor).
cpp_module00 (Warlock Basics): Create a basic Warlock class with a name, title, and introduction methods. cpp_module01 (Spells and Targets):
Warlock: Add the ability to learn, forget, and launch spells.
ASpell / ATarget: Implement abstract base classes with clone() methods.
Specific Spells/Targets: Create concrete classes like Fwoosh and Dummy. cpp_module02 (Spell Management):
SpellBook: A class to store and manage the Warlock's learned spells. TargetGenerator: A class to manage and create target types.
Advanced Spells: Implement more complex spells like Fireball, Polymorph, and targets like BrickWall. Alternative/New Subjects (C & C++)
Some newer versions of the exam split the rank into two levels or offer different algorithmic challenges: Task Description Level 1 BigInt
Implement an arbitrarily large integer class with operator overloading (arithmetic, comparison). Level 1 Vect2
Create a 2D mathematical vector class with basic arithmetic and indexing. Level 1 Polyset Implement collection classes like SearchableBag and Set. Level 2 BSQ Find the largest possible square in a given map/grid. Level 2 Life Implement Conway's Game of Life (cellular automaton). Key Technical Requirements flmarsou/42nice-exam05: New 42 Exam 05 Subjects/Solutions
To produce a "good report" (successful submission) for 42 Exam Rank 05, you must demonstrate mastery of C++ Object-Oriented Programming (OOP), specifically focusing on classes, inheritance, and polymorphism. The exam typically requires implementing specific design patterns (like the "Warlock" exercise) that test your ability to manage object lifecycles and polymorphic behavior. 1. Essential Technical Requirements
To pass the evaluation machine, your code must adhere to these strict C++ standards:
Canonical Form: Ensure every class includes a default constructor, copy constructor, copy assignment operator, and destructor.
Const Correctness: Use const for member functions that do not modify the object. Evaluation scripts often check for the specific number of const qualifiers.
Virtual Destructors: Always use virtual ~ClassName() in base classes to prevent memory leaks during polymorphic deletion. 42 exam 05
Pure Virtual Functions: For abstract base classes (like a Spell or Target class), use = 0; to define the interface. 2. Implementation Strategies Efficient coding during the exam can save critical time:
Header-Only Logic: Where permitted, you can implement small functions directly in the .hpp file to speed up the process and reduce file switching.
Vim Mastery: Use global replacements (e.g., :%s/OldClass/NewClass/g) to quickly generate repetitive boilerplate code for similar spells or targets.
Memory Management: Use std::map or similar containers if allowed by the subject to manage collections of spells, ensuring you delete pointers appropriately in the destructor to avoid leaks. 3. Subject-Specific Focus: CPP 05
The "Warlock" series is a common theme for Rank 05. A "good report" involves:
The Warlock Class: Implementing a singleton-like or strictly managed entity that can learnSpell, forgetSpell, and launchSpell.
SpellBook/TargetGenerator: Creating auxiliary classes that handle the storage and generation of spells/targets to decouple logic from the main Warlock class. 4. Preparation Resources
Simulation Tools: Practice using the 42_examshell to familiarize yourself with the automated environment.
Reference Solutions: Review community-verified solutions on GitHub to understand the expected code structure and common pitfalls.
42_examshell – Updated with New Subject Support ... - GitHub
In the context of the 42 Network's Exam 05, the common "feature" requested is the implementation of a BigInt (Big Integer) class in C++.
This exercise tests your ability to handle integers of arbitrary precision by storing digits as a string or array to bypass the limits of standard types like unsigned long long. According to the flmarsou/42nice-exam05 GitHub repository, the core features you typically need to implement include:
Constructors: A default constructor (often initializing to 0) and a copy constructor.
Arithmetic Operators: Overloading + and += to handle manual string-based addition.
Increment Operators: Implementing both prefix (++x) and postfix (x++) increments. The 42 Exam Rank 05 tests your proficiency
Bitwise/Shift Operators: Overloading << and <<= for digit shifting (often multiplying by powers of 10 in decimal representation).
Comparison Operators: Providing a full suite of comparisons: <, >, <=, >=, ==, and !=.
Ostream Overloading: Overloading the << operator to allow printing the BigInt directly to std::cout.
The 42 Exam Rank 05 is a key milestone in the 42 School Common Core curriculum, primarily focused on C++ Object-Oriented Programming (OOP) and complex system design. Core Objectives
C++ Proficiency: Mastery of advanced C++ concepts, particularly focusing on the CPP Module 05 to CPP Module 09 projects.
OOP Concepts: Deep understanding of classes, inheritance, polymorphism, and templates.
Resource Management: Efficient use of constructors, destructors, and member functions to prevent memory leaks. Exam Structure & Rules Duration: Typically 3 hours (180 minutes).
Norminette: Usually OFF for this rank, allowing more flexibility in code formatting compared to earlier C projects.
Submission System: Like other 42 exams, it uses an automated examshell for real-time grading.
Flexible Completion: Unlike some earlier exams, Rank 05 may allow you to complete part of the exam, leave, and resume remaining exercises in a subsequent session without restarting from the first one. Common Subject Themes
Warlock and Spells: A recurring theme in many versions of Exam 05 involves implementing a Warlock class that interacts with various ASpell and ATarget objects.
Vector Operations: Exercises may include creating 2D mathematical vector classes (vect2) with operator overloading for arithmetic and comparisons.
Choice of Language: Recent reports suggest that some campuses might allow students to choose between C (focusing on algorithms) and C++ at the start of the exam. Preparation Resources
The Psychological Game: 42 Exam Day
42 exam 05 is held in the school's lab. You will have exactly 4 hours. Here is a minute-by-minute strategy:
- First 10 minutes: Read ALL exercises. Do not write code yet. Identify the "easy" one (usually the first). Identify what the hardest requires (e.g., semaphores + threads + signals).
- Next 60 minutes: Solve Exercise 1 and Exercise 2 completely. Test them with edge cases. Get them to 100%. Do not move on until they are perfect.
- Next 120 minutes: Attack Exercise 3. Write the skeleton (includes, main, argument parsing, thread creation). Then add synchronization step by step. Test after each 5 lines.
- Last 50 minutes: If Exercise 3 is failing, comment it out and try Exercise 4's simplest version. Even a partial submission (e.g., a program that only initializes mutexes) can earn you 20% on that exercise.
- Last 10 minutes: Run
norminetteon all files. Fix any style errors (42 is strict about formatting). Check that you removed all debugprintfs (they slow down Moulinette and can cause false timeouts).
2. Exceptions are not optional
In normal projects, you might ignore exceptions if "it probably won't happen." In Exam 05, you must throw GradeTooHighException and GradeTooLowException. The tester specifically looks for the try/catch blocks. If a Bureaucrat with grade 150 tries to sign a grade 1 form and the program doesn't throw? Instant fail. The Psychological Game: 42 Exam Day 42 exam
Preparation strategy (8-week plan)
Week 1–2: Fundamentals
- Review C basics (or target language): pointers, arrays, strings, structs.
- Solve small algorithmic problems focusing on correctness.
Week 3: Data structures
- Implement linked lists, stacks, queues, dynamic arrays, and simple trees.
- Practice writing tests and using valgrind or sanitizers.
Week 4: Algorithms
- Study sorting, searching, traversal algorithms; implement and analyze complexity.
- Tackle coding challenges with input sizes that force algorithmic thinking.
Week 5: Systems and I/O
- Practice file parsing, buffered I/O, and basic socket programming if relevant.
- Build small utilities that read, transform, and write data.
Week 6: Concurrency and robustness
- Learn basic threading/forking models, synchronization, and avoid common pitfalls.
- Fuzz input handling and simulate abnormal conditions.
Week 7: Mock exams
- Timeboxed practice exams replicating conditions (same tools, no internet if required).
- Focus on time management: when to move on vs. debug deeply.
Week 8: Polish and review
- Fix recurring bugs, add comments, and ensure tooling (compilers, linters) passes.
- Rest, sleep well before exam day.
The Algorithm (Bubble Sort for Lists)
Because you cannot allocate an array, you must use O(n²) pointer swapping.
Step 1: Handle nulls
if (!begin_list || !*begin_list) return ;
Step 2: The swap logic
You need a temporary pointer to swap node contents. However, swapping data is easier than swapping next pointers.
(Note: In 42 exam 05, swapping data is allowed because the subject doesn't forbid it. Swapping pointers is for purists.)
Step 3: Implementation
void ft_list_sort(t_list **begin_list, int (*cmp)())
!*begin_list)
return;
swapped = 1;
while (swapped)
swapped = 0;
current = *begin_list;
while (current && current->next)
if ((*cmp)(current->data, current->next->data) > 0)
temp = current->data;
current->data = current->next->data;
current->next->data = temp;
swapped = 1;
current = current->next;
Why this passes 42 Exam 05:
- No extra
malloc→ No leaks. - Works with
NULLlists. - Handles
cmpfunction generically. - Fits within 25 lines.
Why Do Students Fail 42 Exam 05?
Understanding the failure modes is half the battle. Here are the top reasons students retake 42 exam 05:
- Forgetting to initialize mutexes/semaphores. The compiler won't warn you. The program will crash or behave erratically.
- Not handling
EINTRor unexpected returns. System calls likesem_waitcan be interrupted. Robust code checks return values. - Mixing up
sem_waitandsem_postorder. A single wrong sequence can cause a deadlock on the first test case. - Using
sleep()to synchronize. This is an instant fail. The exam expects proper synchronization primitives. - Forgetting to destroy resources.
pthread_mutex_destroy,sem_close, andsem_unlinkare required for a clean exit. Moulinette checks memory and handle leaks.
Common Pitfalls I Saw
- Const correctness: The
getName()method must be const. If you forget theconstkeyword at the end, it doesn't match the subject's expected interface, and the exam's automatic grademe script will refuse to compile. - Memory leaks in the Intern: When you
newa Form insidemakeForm, the caller (the exam checker) expects todeleteit. Don't store it in a static variable. - The Bureaucrat's
signFormoutput: The exact text matters. If the subject says it should print"<name> signed <form>", writing"signed"without the space before the name will fail the strict comparison.
1. The Norminette Nemesis
The 42 Norm dictates:
- No more than 25 lines per function.
- No more than 4 parameters.
- No
forloops (usewhile). - Variable declarations at the top of the function.
The Horror Story: A student writes a perfect ft_btree_level_count in 28 lines. The "moulinette" (autograder) rejects it. You must refactor into two static helper functions. Lose 5 minutes. Panic.
