Skip to content

madebypixel02/CPP-Module-01

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPP-Module-01 | 42 Madrid

BraiiiiiiinnnzzzZ 🧠

Table of Contents

Introduction

This second set of exercises is a bit more interesting. We'll be learning the basics of memory allocation in C++, references, pointers, and a rough look at switches.

ex00. BraiiiiiiinnnzzzZ

This first exercise asks us to simply create a bunch of classes with basic methods we will use in future exercises in the module. We must have two ways of allocating instances of the class: either on the stack or on the heap, and free the allocated space at the right time.

Example

This is an example output given my main.

ex01. Moar brainz!

This second exercise consists of creating a method that will summon N zombies in one go, without naming each one of them. Then they all announce themselves and are properly destroyed.

Example

ex02. HI THIS IS BRAIN

This next exercise is super simple, it only aims to differentiate between pointers and references

Example

ex03. Unnecessary violence

This one extends the concepts of references and pointers from the previous exercise, creating two types of humans in two classes that can attack each other with different weapons.

Example

ex04. Sed is for losers

This exercise aims to replicate the basic performance of the sed command (stream editor), receiving a file and a string to replace with another. It saves the output to a file with the same name ending in .replace. This exercise helps us understand file streams and strings in C++.

Example

Note: the example above shows how the replace operation is reversible (unsurprisingly).

ex05. Karen 2.0

The next two exercises expand on the idea of refernces a bit further. We create a Karen class that can give various messages of types DEBUG, INFO, WARNING and ERROR. We are asked to create that outputs the proper message depending message type.

Example

ex06. Karen-filter

This last exercise is an extension of the previous one. However this time we receive the message type from the user and output that type's message and all the message types above it (order is DEBUG < INFO < WARNING < ERROR). We must coordinate the responses using switches for this exercise.

Example

Note how the DEBUG message is not shown because it is below INFO.

Installation

For this project and fututre C++ projects it is only required to have clang and/or gcc, which provide their respective compilers clang++ and g++. It is also recommended to install the valgrind package on Linux for debugging purposes. Every exercise (unless specified otherwise) includes its own Makefile with the necessary instructions. In some cases certain tweaks needed to be made to ensure the most similar results in both Linux and MacOS.

Summary

This one was definitely harder than the previous one, but it was still pretty fun.

June 13th, 2022