/CPP_Modules

Contextual OOP projects, as part of the 42 Heilbronn Programming School's Core curriculum.

Primary LanguageC++

Logo

🛠 C++ (Object Oriented Programming)



CPP 00: Namespaces, classes, member functions, stdio streams, initialization lists, static, const, and some other basic stuf

ex00: Megaphone

Simple string capitalizing program. It capitalizes the string passed as parameter to the program. If no parameter is provided, it outputs a default message. Examples:

Example Output
$ ./megaphone $ * LOUD AND UNBEARABLE FEEDBACK NOISE *
$ ./megaphone "ssshh, be quiet! $ SSSHH, BE QUIET!
⬆️ Return to top

ex01: My Awesome PhoneBook

This exercise implements a simple phonebook application in C++, that allows users to store and retrieve contact information. The phonebook has a maximum capacity of 8 contacts. After reaching its full capacity, it then rewrites the oldest contact.
The application is structured into two main classes:

Contact Class:
Represents a single contact in the phonebook. Stores details such as first name, last name, nickname, phone number, and a dark secret.

Phonebook Class:
Manages a collection of max 8 Contact objects. Provides functionality to add new contacts and search for existing ones.

⬆️ Return to top

ex02: The Job Of Your Dreams

This program implements an already developed simple bank account management system, it provides functionality to manage multiple accounts, track deposits and withdrawals, and display account information.

The purpose of the exercise is to create the body of several functions that are defined in the class per the subject, in order for the program's output to match the log file provided.

⬆️ Return to top


CPP 01: Memory allocation, pointers to members, references and switch statements

ex00: BraiiiiiiinnnzzzZ

This exercise implements a simple zombie simulation. It demonstrates the ability to create zombie objects, both from the stack and the heap memory.

alt text
⬆️ Return to top

ex01: Moar brainz!

This exercise implements a zombie horde simulation. It demonstrates the ability of creating multiple zombie objects, as defined in BraiiiiiiinnnzzzZ exercise, dynamically.

⬆️ Return to top

ex02: HI THIS IS BRAIN

This exercise's purpose is to make a clear difference of the functionality between a pointer and a reference in C++, by printing both the address and the value of both a reference and a pointer to an original variable.

⬆️ Return to top

ex03: Unnecessary violence

This exercise implements a simulation of humans interacting with weapons. It demonstrates the ability of composing objects of two different classes together.

HumanA Class:
Represents a human that always has a weapon. The weapon is passed to the object at the time of construction.

HumanB Class:
Represents a human that can optionally have a weapon. The weapon can be assigned or changed dynamically after the human is created. The human can attack only if they have a weapon.

Weapon Class:
Represents a weapon of a specific type (e.g. "club", "sword", etc). Provides functionality to get and set the weapon's type dynamically. The weapon's type can be changed dynamically, and the change is reflected in the attack messages of both HumanA and HumanB.

⬆️ Return to top

ex04: Sed is for Losers

This exercise implements a simple text replacing program, where it searches a .txt file for all occurences of a specified string, replaces them with another one and saves the result into a .txt.replace file:

$ ./sed text.txt search_string replace_string
Parameters Description
text.txt input file to search in
search_string string to search for
replace_string replacement string

Example:

$ cat text.txt
Hello there! Welcome to this simple text file.
This is just a test to see if your program can find certain words.
Sometimes, people say hello in different ways.
For example, "hello" can be written as hi, hey, or even hola!
However, not every sentence will contain the word hello.
Make sure your program can detect hello no matter where it appears.
At the end, we just say goodbye instead of hello.
$ ./sed text.txt hello hi
$ cat text.txt.replace
Hello there! Welcome to this simple text file.
This is just a test to see if your program can find certain words.
Sometimes, people say hi in different ways.
For example, "hi" can be written as hi, hey, or even hola!
However, not every sentence will contain the word hi.
Make sure your program can detect hi no matter where it appears.
At the end, we just say goodbye instead of hi.
⬆️ Return to top

ex05: Harl 2.0

This exercise implements a simple program that simulates a character named "Harl" expressing complaints at different levels of severity.

The Harl class encapsulates the behavior of the character "Harl".

  • It contains four complaint levels:
    • DEBUG: Detailed debugging information.
    • INFO: General information about the program's state.
    • WARNING: A warning about potential issues.
    • ERROR: A critical error that requires immediate attention.
  • Each complaint level is implemented as a private method in the Harl class.
⬆️ Return to top

ex06: Harl Filter

Similar to Harl 2.0, this exercise simulates a program that outputs all message up to the provided level of severity. So, if the WARNING is provided, it will output the DEBUG message, the INFO message and the WARNING message.

⬆️ Return to top

CPP 02: Ad-hoc polymorphism, operator overloading and the Orthodox Canonical class form

This project demonstrates the creation of a Fixed point numbers class. It is overloading the basic mathematical operators (+, -, *, /), so that it will be able to function as a custom numeric type of variable.

A Fixed point type of number is a way of representing real numbers (numbers with fractional parts) using integers, while keeping the decimal point in a fixed position.

Our Fixed point numbers class will hold 8 bits of decimal places. This means that the true value of the number will be mulitplied by 2^8 = 256 before stored in the corresponding class's attribute.

NOTE: Every exercise builds on top of the previous one


ex00: My First Class in Orthodox Canonical Form

This exercise demonstarates the creation of 0 as a Fixed point number.

⬆️ Return to top

ex01: Towards a more useful fixed-point number class

This exercise extends the Fixed class's functionality, by adding parameterized constructors and supporting convertion of a Fixed point type to classic numberical types (int, float).

⬆️ Return to top

ex02: Now we’re talking

This exercise demonstrates the overloading functionality of most mathematical operators (+, -, *, /), as well as the creation of a min/max function.

⬆️ Return to top

ex03: BSP

This exercise demonstrates the point-in-triangle functionality of the program, using the BSP method (Barycentric Subdivion Procedure). It is a way of locating a Point inside (or around) a triangle using weights relative to the triangle's vertices. If all weights are non-negative and sum to 1, then the Point in question belongs to the triangle. If any of those weights are negative, the Point is outside.

NOTE: In this implementation, if the Point is located on any of the triangle's vertices, it is considered to be outside the triangle.

⬆️ Return to top

CPP 03: Inheritance

This projects demonstrates the functionality of the inheritance property in Object Orienting C++, where a class can be derived as a child class of a parent one, inheriting its functions. In this project, there are different types of robot classes, others functioning as parents, others as children inheriting different type of functions as the project progresses.

Every robot class is described by the same private attributes, but of different values, as seen in the corresponding exercises, as well as a special function.

Every main function is showcasing the robots interacting with each other.

⬆️ Return to top

ex00: Aaaaand... OPEN!

ClapTrap will be used as the parent class in the following exercises, inheriting its functions.

ClapTrap
⬆️ Return to top

ex01: Serena, my love!

ScavTrap is the first child class derived from ClapTrap, inheriting its functions.

ScavTrap
⬆️ Return to top

ex02: Repetitive work

FragTrap is the another child class derived from ClapTrap, ihneriting its function and also having a special function, unique to the class.

FragTrap
⬆️ Return to top

ex03: Now it’s weird!

DiamondTrap is the last child class derived from ClapTrap's children ScavTrap and FragTrap, creating a so called Diamond class. The DiamondTrap inherits different attributes from both parents and has a special function, unique to the class.

DiamondTrap
⬆️ Return to top

CPP 04: Subtype Polymorphism, Abstract Classes, and Interfaces

ex00: Polymorphism

⬆️ Return to top

ex01: I don’t want to set the world on fire

⬆️ Return to top

ex02: Abstract class

⬆️ Return to top

ex03: Interface & recap

⬆️ Return to top