{"id":24373533,"url":"https://github.com/nigeparis/42-cpp-01","last_synced_at":"2025-08-16T21:06:11.603Z","repository":{"id":268712022,"uuid":"901826545","full_name":"NigeParis/42-cpp-01","owner":"NigeParis","description":"Say hello to CPP Module 01! It’s a magical collection of exercises to transport you into the enchanted realm of C++. Here, you’ll discover the secrets of memory allocation, unlock the mysteries of pointers to members, master the art of references, and conquer the powerful switch statements.","archived":false,"fork":false,"pushed_at":"2025-01-12T09:06:34.000Z","size":66,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T11:16:35.009Z","etag":null,"topics":["cpp","cpp-learning","cpp98"],"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/NigeParis.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}},"created_at":"2024-12-11T11:42:53.000Z","updated_at":"2025-01-15T08:21:40.000Z","dependencies_parsed_at":"2024-12-18T13:35:34.369Z","dependency_job_id":"4f70f715-b175-465f-8a54-921588bfc225","html_url":"https://github.com/NigeParis/42-cpp-01","commit_stats":null,"previous_names":["nigeparis/42-cpp-01"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NigeParis%2F42-cpp-01","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NigeParis%2F42-cpp-01/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NigeParis%2F42-cpp-01/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NigeParis%2F42-cpp-01/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NigeParis","download_url":"https://codeload.github.com/NigeParis/42-cpp-01/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243205236,"owners_count":20253427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cpp","cpp-learning","cpp98"],"created_at":"2025-01-19T05:11:44.083Z","updated_at":"2025-03-12T11:16:37.693Z","avatar_url":"https://github.com/NigeParis.png","language":"C++","readme":"# 42-cpp-01\n# Welcome to the Spooky World of C++!\n\nSay hello to **CPP Module 01**! It’s a magical collection of exercises to transport you into the enchanted realm of C++. Here, you’ll discover the secrets of memory allocation, unlock the mysteries of pointers to members, master the art of references, and conquer the powerful switch statements.\n\n## Exercise 00: BraiiiiiiinnnzzzZ\n\n**Objective**: Bring the undead to life by creating a zombie class! Your mission, should you choose to accept it, includes:\n\n1. **Zombie Characteristics**:\n   - **Name**: Every zombie needs a cool (or spooky) name! This will be stored as a string attribute.\n\n2. **Zombie Announcements**:\n   - **`void announce(void)`**: Each zombie must introduce themselves with flair by saying: `NameOfTheZombie: BraiiiiiiinnnzzzZ...`\n\n3. **Zombie Creation**:\n   - **`Zombie* newZombie(std::string name)`**: This function will summon a new zombie, bestow it with a name, and return the terrifying creature to you.\n   - **`void randomChump(std::string name)`**: This function will randomly summon a zombie, name it, and have it proudly announce its arrival.\n\nThe true magic of these exercises lies in understanding how to allocate memory either on the stack or the heap. You'll become a wizard of memory management!\n\n## Files You’ll Need:\n- **Makefile**: The spellbook that compiles your code.\n- **main.cpp**: The grand stage where your zombies come to life.\n- **Zombie.cpp**: The hidden chamber where you define your zombie class.\n- **newZombie.cpp**: The secret lair where new zombies are created.\n- **randomChump.cpp**: The surprise party room where random zombies are summoned.\n- **Zombie.hpp**: The ancient scroll that contains the declarations of your zombie class.\n\n**Forbidden Spells**: None! You’re free to unleash your creativity with no restrictions!\n\n\n\n## Exercise 01: Moar Brainz!\n\n**Objective**: Summon a massive horde of zombies in this thrilling exercise! Get ready to unleash an army of the undead.\n\nTo conjure up your terrifying legion, you need to implement the following magical function:\n\n```cpp\nZombie* zombieHorde(int N, std::string name);\n```\n\n## Exercise 02: HI THIS IS BRAIN\n\n**Objective**: Dive into the fascinating world of C++ references and address pointers! Let's unravel the mysteries together.\n\n## Mission Brief:\nWe need to create a program that showcases the difference between references and address pointers. Here's what you need to include in your code:\n\n1. **String Setup**:\n   - A string initialized to `\"HI THIS IS BRAIN\"`.\n\n2. **Pointers and References**:\n   - **`stringPTR`**: A pointer to our brainy string.\n   - **`stringREF`**: A reference to the same string.\n\n## The Program's Tasks:\nOur program should print out the following:\n\n1. The **memory address** of the string variable.\n2. The **memory address** held by `stringPTR`.\n3. The **memory address** held by `stringREF`.\n4. The **value** of the string variable.\n5. The **value** pointed to by `stringPTR`.\n6. The **value** pointed to by `stringREF`.\n\n## Files You’ll Need:\n- **Makefile**: The enchanted spellbook that compiles your code.\n- **main.cpp**: The grand stage where our references and pointers perform their magic.\n\n**Forbidden Spells**: None! You have complete creative freedom.\n\n## Exercise 03: Unnecessary Violence ⚔️\n\n## Objective\nThe goal of this exercise is to master the art of implementing pointers and references, and understanding when each is most appropriate in various situations.\n\n## Step 1: Weapon Class\nFirst, we need to create a mighty **Weapon** class. This class requires:\n\n- A private string attribute **type**.\n- A `getType()` member function that returns a **const reference** to **type**.\n- A `setType()` member function that sets **type** using a new value passed as a parameter.\n\n## Step 2: HumanA and HumanB Classes\nNext, we will forge two powerful classes: **HumanA** and **HumanB**. These classes should include:\n\n- A **Weapon**.\n- A private string **name**.\n- An `attack()` member function that displays the battle cry:\n\n```cpp\n\u003cname\u003e attacks with their \u003cweapon type\u003e\n```\n\n\n### Differences Between HumanA and HumanB\nAlthough similar, **HumanA** and **HumanB** have key distinctions:\n\n- **HumanA**: Takes the **Weapon** in its constructor and will always have a weapon.\n- **HumanB**: Does not take the **Weapon** in its constructor and may not always have a weapon.\n\n## Files You’ll Need\n- **Makefile**: The enchanted spellbook that compiles your code.\n- **main.cpp**: The battlefield where your warriors come to life.\n- **Weapon.cpp**: The armory where you define your **Weapon** class.\n- **HumanA.cpp**: The training ground for **HumanA**.\n- **HumanB.cpp**: The training ground for **HumanB**.\n- **Weapon.hpp**: The ancient scroll containing the declarations of your **Weapon** class.\n- **HumanA.hpp**: The scroll for **HumanA**.\n- **HumanB.hpp**: The scroll for **HumanB**.\n\n**Forbidden Spells**: None! You're free to explore and innovate.\n\n## Exercise 04: Sed is for Losers \n\n**Objective**: Say goodbye to boring text replacements with Sed! Instead, let's create a program that takes three magical parameters: a filename and two strings, `s1` and `s2`. When executed, the program will open the file, copy its contents, and replace every occurrence of `s1` with `s2`. It's like performing a text replacement spell!\n\n## Files You’ll Need:\n- **Makefile**: The enchanted spellbook that compiles your code.\n- **main.cpp**: The mystical script where your text-replacing magic happens.\n\n**Forbidden Spells**: You must resist the temptation to use `std::string::replace`. We need to do this the old-fashioned, fun way!\n\n---\n\n## Exercise 05: Harl 2.0\n\n**Objective**: Let's bring Harl to life with a program that features a class named **Harl**. This class will include the following private incantations (member functions):\n\n- **`void debug(void)`**: For when Harl is in a mellow mood.\n- **`void info(void)`**: When Harl has something interesting to share.\n- **`void warning(void)`**: When things start to get a bit dicey.\n- **`void error(void)`**: When Harl is in full panic mode.\n\nThese functions represent the different levels of messages that Harl can communicate. Additionally, Harl will have a public spell:\n\n- **`void complain(std::string level)`**: This spell will invoke the correct function depending on the level passed as a parameter. The true magic here is learning to use pointers to member functions, so we can avoid a labyrinth of if/else statements!\n\n## Files You’ll Need:\n- **Makefile**: The enchanted spellbook that compiles your code.\n- **main.cpp**: The grand arena where Harl voices his thoughts.\n\n**Forbidden Spells**: None! Let your imagination run wild.\n\n---\n\n## Exercise 06: Harl Filter\n\n**Objective**: Get ready to filter out Harl's chatter! This exercise will help you create a refined version of Harl that only lets certain messages pass through. Details coming soon!\n\n## Files You’ll Need:\n- **Makefile**: The enchanted spellbook that compiles your code.\n- **main.cpp**: The stage where Harl's filtered messages will be revealed.\n\n**Forbidden Spells**: None! Feel free to get creative.\n\n---\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnigeparis%2F42-cpp-01","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnigeparis%2F42-cpp-01","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnigeparis%2F42-cpp-01/lists"}