{"id":50338696,"url":"https://github.com/tigran-sargsyan-w/cpp-module-05","last_synced_at":"2026-05-29T15:30:21.677Z","repository":{"id":335638815,"uuid":"1146222391","full_name":"tigran-sargsyan-w/cpp-module-05","owner":"tigran-sargsyan-w","description":"This module is designed to help you understand try/catch and exceptions in C++.","archived":false,"fork":false,"pushed_at":"2026-03-03T18:37:17.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-06T11:49:04.041Z","etag":null,"topics":["42","42lyon","42school","c-plus-plus","canonical-forms","cpp","cpp98","custom-exceptions","ecole-42","exceptions","factory-pattern","object-oriented-programming","ocf","oop","operator-overloading","polymorphism","try-catch"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tigran-sargsyan-w.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-30T19:34:16.000Z","updated_at":"2026-03-03T18:44:08.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tigran-sargsyan-w/cpp-module-05","commit_stats":null,"previous_names":["tigran-sargsyan-w/cpp-module-05"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tigran-sargsyan-w/cpp-module-05","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigran-sargsyan-w%2Fcpp-module-05","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigran-sargsyan-w%2Fcpp-module-05/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigran-sargsyan-w%2Fcpp-module-05/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigran-sargsyan-w%2Fcpp-module-05/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tigran-sargsyan-w","download_url":"https://codeload.github.com/tigran-sargsyan-w/cpp-module-05/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigran-sargsyan-w%2Fcpp-module-05/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33659872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["42","42lyon","42school","c-plus-plus","canonical-forms","cpp","cpp98","custom-exceptions","ecole-42","exceptions","factory-pattern","object-oriented-programming","ocf","oop","operator-overloading","polymorphism","try-catch"],"created_at":"2026-05-29T15:30:20.842Z","updated_at":"2026-05-29T15:30:21.660Z","avatar_url":"https://github.com/tigran-sargsyan-w.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C++ Module 05 – Repetition \u0026 Exceptions 🧾⚡️\n\n✅ **Status**: Completed – all exercises  \n🏫 **School**: 42 – C++ Modules (Module 05)  \n🏅 **Score**: (100)/100\n\n\u003e *Bureaucrats, forms, abstract interfaces, and a lot of exceptions. Repetition, validation, and clean error handling.*\n\n---\n\n## 📚 Table of Contents\n\n* [Description](#-description)\n* [Goals of the Module](#-goals-of-the-module)\n* [Exercises Overview](#-exercises-overview)\n\n  * [ex00 – Bureaucrat](#ex00--bureaucrat)\n  * [ex01 – Forms](#ex01--forms)\n  * [ex02 – AForm + Concrete Forms](#ex02--aform--concrete-forms)\n  * [ex03 – Intern](#ex03--intern)\n* [Requirements](#-requirements)\n* [Build \u0026 Run](#-build--run)\n* [Repository Layout](#-repository-layout)\n* [Testing Tips](#-testing-tips)\n* [42 Notes](#-42-notes)\n\n---\n\n## 📝 Description\n\nThis repository contains my solutions to **42’s C++ Module 05 (C++98)**.\nThe main focus is **exceptions + repetition of OOP fundamentals** through a small bureaucratic system:\n\n* A `Bureaucrat` with a strict **grade range** (`1` is highest, `150` is lowest)\n* Forms that require specific grades to **sign** and **execute**\n* An abstract base class (`AForm`) with concrete derived forms\n* An `Intern` that creates forms by name (factory-like behavior)\n\nAll exercises are written in **C++98** and compiled with strict flags.\n\n---\n\n## 🎯 Goals of the Module\n\nConcepts practiced in this module include:\n\n* Designing classes in **Orthodox Canonical Form** (constructors, copy, assignment, destructor)\n* Writing and using **custom exceptions** (`GradeTooHighException`, `GradeTooLowException`, etc.)\n* Defensive checks + clear failure behavior via `throw` / `try` / `catch`\n* **Encapsulation** (private attributes, getters)\n* **Abstract classes** and polymorphism (`AForm`)\n* Separating “validation” logic from “action” logic in execution flows\n* Avoiding messy if/else chains by using cleaner patterns in `Intern::makeForm()`\n\n---\n\n## 📦 Exercises Overview\n\n### ex00 – Bureaucrat\n\n**Goal:** Implement a `Bureaucrat` class with:\n\n* `const std::string name`\n* `int grade` in range **[1..150]**\n* Grade changes:\n\n  * `incrementGrade()` (e.g., 3 → 2)\n  * `decrementGrade()` (e.g., 3 → 4)\n* Exceptions on invalid grade:\n\n  * `GradeTooHighException`\n  * `GradeTooLowException`\n* `operator\u003c\u003c` output format:\n\n  * `\u003cname\u003e, bureaucrat grade \u003cgrade\u003e.`\n\n---\n\n### ex01 – Forms\n\n**Goal:** Add a `Form` class containing:\n\n* `const std::string name`\n* `bool isSigned` (initially `false`)\n* `const int gradeToSign`\n* `const int gradeToExecute`\n\nKey behavior:\n\n* `Form::beSigned(Bureaucrat const\u0026)` signs if grade is high enough\n* `Bureaucrat::signForm(Form\u0026)` prints success/failure message with reason\n* Exceptions:\n\n  * `Form::GradeTooHighException`\n  * `Form::GradeTooLowException`\n\n---\n\n### ex02 – AForm + Concrete Forms\n\n**Goal:** Turn `Form` into an abstract base class `AForm` and implement 3 concrete forms.\n\nConcrete forms:\n\n* **`ShrubberyCreationForm`**\n  Required grades: sign **145**, exec **137**\n  Creates `\u003ctarget\u003e_shrubbery` and writes ASCII trees inside.\n\n* **`RobotomyRequestForm`**\n  Required grades: sign **72**, exec **45**\n  “Drilling noises” + **50% success** robotomy.\n\n* **`PresidentialPardonForm`**\n  Required grades: sign **25**, exec **5**\n  Announces pardon “by Zaphod Beeblebrox”.\n\nAlso required:\n\n* `AForm::execute(Bureaucrat const\u0026 executor) const`\n  Must check:\n\n  * form is signed\n  * executor grade is high enough\n    Otherwise throw appropriate exceptions.\n* `Bureaucrat::executeForm(AForm const\u0026)` prints success or explicit error.\n\n---\n\n### ex03 – Intern\n\n**Goal:** Implement an `Intern` with:\n\n* `AForm* makeForm(std::string formName, std::string target)`\n* Creates and returns the correct form based on `formName`\n* Prints:\n\n  * `Intern creates \u003cform\u003e`\n* If unknown form name:\n\n  * print explicit error message\n* **No ugly giant if/else/else-if chain** (clean mapping approach expected)\n\n---\n\n## 🛠 Requirements\n\n* **Compiler**: `c++`\n* **Flags**: `-Wall -Wextra -Werror` (+ must still compile with `-std=c++98`)\n* **OS**: Unix-like (Linux/macOS)\n* **No external libraries** (no C++11, no Boost)\n* Forbidden functions:\n\n  * `printf()`, `malloc()`, `free()` (and similar)\n* STL containers/algorithms are not allowed until later modules (08/09)\n\n---\n\n## ▶️ Build \u0026 Run\n\nClone the repository and build each exercise separately:\n\n```bash\ngit clone \u003cthis-repo-url\u003e\ncd cpp-module-05\n```\n\n### ex00\n\n```bash\ncd ex00\nmake\n./bureaucrat\n```\n\n### ex01\n\n```bash\ncd ex01\nmake\n./bureaucracy\n```\n\n### ex02\n\n```bash\ncd ex02\nmake\n./forms\n```\n\n### ex03\n\n```bash\ncd ex03\nmake\n./intern\n```\n\n\u003e Executable names may differ depending on implementation — check each `Makefile`.\n\n---\n\n## 📂 Repository Layout\n\n```text\ncpp-module-05/\n├── ex00/\n│   ├── Makefile\n│   ├── main.cpp\n│   ├── Bureaucrat.hpp\n│   └── Bureaucrat.cpp\n│\n├── ex01/\n│   ├── Makefile\n│   ├── main.cpp\n│   ├── Bureaucrat.hpp / Bureaucrat.cpp\n│   ├── Form.hpp\n│   └── Form.cpp\n│\n├── ex02/\n│   ├── Makefile\n│   ├── main.cpp\n│   ├── Bureaucrat.hpp / Bureaucrat.cpp\n│   ├── AForm.hpp / AForm.cpp\n│   ├── ShrubberyCreationForm.hpp / .cpp\n│   ├── RobotomyRequestForm.hpp / .cpp\n│   └── PresidentialPardonForm.hpp / .cpp\n│\n└── ex03/\n    ├── Makefile\n    ├── main.cpp\n    ├── Intern.hpp\n    ├── Intern.cpp\n    └── (all previous classes reused)\n```\n\n---\n\n## 🔍 Testing Tips\n\n* **Grades**\n\n  * Try constructing bureaucrats/forms with grades `0`, `151`, etc. → must throw.\n  * Test boundary values: `1` and `150`.\n\n* **Signing**\n\n  * A bureaucrat with insufficient grade must fail to sign and report why.\n  * A sufficiently ranked bureaucrat must sign successfully.\n\n* **Execution**\n\n  * Executing an **unsigned** form must throw.\n  * Executing with a too-low grade must throw.\n  * Successful executions should print the expected messages and side effects.\n\n* **Robotomy**\n\n  * Run multiple times to confirm ~50% success behavior.\n\n* **Intern**\n\n  * Try valid names (e.g. `\"robotomy request\"`) and invalid names → must show explicit error.\n\n---\n\n## 🧾 42 Notes\n\n* C++ modules don’t enforce **Norminette** style, but readability still matters.\n* **Makefile rules are still checked** during evaluation (`all/clean/fclean/re`, no unnecessary relinking, explicit file listing, etc.).\n* Don’t just “make it work”: during defense you may be asked to tweak behavior quickly, so keep your design clean and explainable.\n\n---\n\nIf you’re a 42 student working on the same module, feel free to explore the code, get inspired, but **write your own implementation** — that’s where the real learning happens. 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftigran-sargsyan-w%2Fcpp-module-05","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftigran-sargsyan-w%2Fcpp-module-05","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftigran-sargsyan-w%2Fcpp-module-05/lists"}