Skip to content

Commit ca043c3

Browse files
committed
Merge commit 'README CPP01'
2 parents 9d9e97a + d7937e9 commit ca043c3

File tree

1 file changed

+96
-2
lines changed

1 file changed

+96
-2
lines changed

CPP01/README.md

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,96 @@
1-
# 42_CPP01
2-
Repositoty to CPP01 project from 42 Porto.
1+
# 🧠 42 Cursus - C++ Module 01
2+
3+
## 📌 Description
4+
5+
The C++ Module 01 is designed to introduce more advanced features of C++, focusing on the foundational topics that every C++ programmer needs to master. In this module, we learned about classes, dynamic memory allocation, constructors, destructors, and object-oriented programming principles.
6+
7+
---
8+
9+
## 🚀 Topics Covered
10+
11+
- **Classes**: Defining and using classes, constructors, destructors.
12+
- **Encapsulation**: Access control with private, public, and protected members.
13+
- **Dynamic Memory Allocation**: Using `new`, `delete`, and `new[]`.
14+
- **Copy Constructor and Assignment Operator**: How to copy objects correctly.
15+
- **Overloading**: Operator overloading and function overloading.
16+
- **Memory Management**: Smart pointers, RAII, and avoiding memory leaks.
17+
- **Object-Oriented Programming**: Principles like abstraction and inheritance.
18+
19+
---
20+
21+
## 📁 Project Structure
22+
23+
Each exercise is located in its own directory and is independent of others. You will have to compile each exercise individually using:
24+
25+
```bash
26+
c++ -Wall -Wextra -Werror <file>.cpp -o <executable>
27+
```
28+
29+
---
30+
31+
## 🧪 Exercises
32+
33+
### 📌 Exercise 00 - `BraiiiiiiinnnzzzZ`
34+
35+
In this exercise, the Zombie class manages a private name attribute and can announce itself with a specific message. It includes two functions: newZombie for creating a heap-allocated zombie, and randomChump for stack-allocated zombies that announce immediately, with destructors handling cleanup.
36+
37+
### 📌 Exercise 01 - `Moar brainz!`
38+
39+
The zombieHorde function allocates N Zombie objects in a single memory block, names them, and returns a pointer to the first zombie. The zombies should announce themselves, and proper memory management must be ensured by deleting the zombies and checking for memory leaks.
40+
41+
### 📌 Exercise 02 - `HI THIS IS BRAIN`
42+
43+
The program initializes a string and demonstrates the use of a pointer and a reference to that string. It then prints the memory addresses and values of the string, pointer, and reference, showcasing how address manipulation works.
44+
45+
### 📌 Exercise 03 - `Unnecessary violence`
46+
47+
The program involves creating a `Weapon` class with methods to get and set its type, followed by two classes, `HumanA` and `HumanB`, each equipped with a weapon and a name. The main task is to model the differences in how `HumanA` and `HumanB` manage their weapons (with `HumanA` always armed and `HumanB` potentially not), while ensuring correct memory management and handling potential memory leaks.
48+
49+
50+
### 📌 Exercise 04 - `Sed is for losers`
51+
52+
The program takes a filename and two strings, opens the file, and creates a new file with the name <filename>.replace. It then copies the content from the original file, replacing every occurrence of s1 with s2 without using C file manipulation functions or std::string::replace. Proper error handling for unexpected inputs and file operations is required.
53+
54+
### 📌 Exercise 05 - `Harl 2.0`
55+
56+
The program creates a Harl class with private member functions for each complaint level (debug, info, warning, error). The public function complain takes a level string as a parameter and calls the corresponding private function without using multiple if/else statements, but instead using pointers to member functions to automate the complaints.
57+
58+
### 📌 Exercise 06 - `Harl filter`
59+
60+
he program implements a filtering system for Harl's complaints based on a given log level. The program takes one of the four levels as a parameter and displays all complaints from that level and above. It uses a switch statement to filter out messages, and if an invalid level is passed, it displays a default message about insignificant complaints
61+
62+
## 🛠️ Compilation
63+
64+
Compile the exercises with the following command to ensure no warnings or errors:
65+
66+
```bash
67+
c++ -Wall -Wextra -Werror <file>.cpp -o <executable>
68+
```
69+
70+
---
71+
72+
## ✅ Code Guidelines
73+
74+
- [ ] Code is clean, well-organized, and properly commented.
75+
- [ ] No warnings when compiling with `-Wall -Wextra -Werror`.
76+
- [ ] Proper implementation of constructors, destructors, and copy constructors.
77+
- [ ] Use of `new` and `delete` for dynamic memory management.
78+
- [ ] Proper use of private and public members, following encapsulation principles.
79+
- [ ] Avoid memory leaks by correctly freeing allocated memory.
80+
- [ ] Consistent naming conventions: `CamelCase` for class names, `snake_case` for functions/variables.
81+
- [ ] Correct implementation of object-oriented principles (inheritance, encapsulation, abstraction).
82+
83+
---
84+
85+
## 📚 Useful References
86+
87+
- [C++ Reference - Classes](https://en.cppreference.com/w/cpp/language/classes)
88+
- [C++ Reference - Memory Management](https://en.cppreference.com/w/cpp/memory)
89+
- *Effective C++* by Scott Meyers
90+
- *C++ Primer* by Stanley B. Lippman
91+
92+
---
93+
94+
## 🏁 Conclusion
95+
96+
Module 01 builds on the concepts introduced in Module 00 and dives deeper into object-oriented programming in C++. By the end of this module, we had a good understanding of how to use classes, manage dynamic memory, and apply basic OOP principles in your C++ programs.

0 commit comments

Comments
 (0)