Skip to content

About

42 C++ Piscine modules 00-09: OOP, canonical form, casts, templates and STL in C++98

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

28 Commits

Folders and files

Repository files navigation

C++ Modules

My solutions to the 42 C++ Piscine, modules 00 to 09: a guided path from classes and references through orthodox canonical form, inheritance, exceptions and casts to templates and the STL. Every exercise compiles as C++98 with -Wall -Wextra -Werror -Wshadow -Wconversion -pedantic.

Stack: C++98 · STL · Make Context: 42 Berlin curriculum

Modules

Module Topics Exercises
00 Namespaces, classes, member functions, static members, iostreams ex00 megaphone (uppercase argv) · ex01 PhoneBook (fixed 8-contact book with formatted table output) · ex02 Account (recreate a class from its header and a log)
01 Stack vs heap allocation, references vs pointers, pointers to member functions, file streams ex00 Zombie (newZombie / randomChump) · ex01 zombieHorde · ex02 pointer and reference addresses · ex03 Weapon, HumanA (reference) vs HumanB (pointer) · ex04 sed-like replace into <file>.replace · ex05 Harl (member-function pointer table) · ex06 Harl filter (switch fallthrough by log level)
02 Orthodox canonical form, operator overloading, fixed-point numbers ex00-ex02 Fixed class (8 fractional bits, int/float conversion, comparison, arithmetic and increment operators, min/max) · ex03 BSP: point-in-triangle test with edge normals and dot products
03 Inheritance, constructor/destructor chaining, virtual inheritance ex00 ClapTrap · ex01 ScavTrap · ex02 FragTrap · ex03 DiamondTrap (diamond problem)
04 Subtype polymorphism, virtual destructors, deep copy, abstract classes, interfaces ex00 Animal / Cat / Dog vs WrongAnimal / WrongCat (with and without virtual) · ex01 Brain, deep copy of Cat and Dog · ex02 abstract Animal · ex03 Materia system: AMateria, Ice, Cure, ICharacter, IMateriaSource
05 Exceptions, nested exception classes ex00 Bureaucrat with grade bounds · ex01 Form signing · ex02 abstract AForm with Shrubbery, Robotomy and Presidential Pardon forms · ex03 Intern that creates forms by name
06 C++ casts ex00 ScalarConverter: detects char/int/float/double literals and converts with static_cast · ex01 Serializer: reinterpret_cast to uintptr_t and back · ex02 identify a Base* / Base& as A, B or C with dynamic_cast
07 Function and class templates ex00 swap / min / max · ex01 iter over an array · ex02 Array<T> with bounds-checked operator[]
08 STL containers, iterators, algorithms ex00 easyfind on any int container · ex01 Span (shortestSpan / longestSpan, range insert) · ex02 MutantStack: std::stack with iterators
09 Choosing STL containers for a task ex00 btc: bitcoin value lookup by date with std::map and closest-earlier-date lookup over data.csv · ex01 RPN calculator with std::stack · ex02 PmergeMe: merge-insertion (Ford-Johnson) sort on std::vector and std::list, timed side by side

Build & run

Each exercise is self-contained with its own Makefile:

cd module09/ex01
make            # builds ./RPN
./RPN "8 9 * 9 - 9 - 9 - 4 - 1 +"

All Makefiles support make clean, make fclean, make re, plus DEBUG=1 (debug symbols, -O0) and ASAN=1 (AddressSanitizer), e.g. make DEBUG=1 re.

A few exercises take arguments:

module00/ex00/megaphone "hello world"
module01/ex04/sed <file> <s1> <s2>        # writes <file>.replace
module06/ex00/converter 42.0f
module09/ex00/btc input.txt               # "date | value" lines, uses data.csv
module09/ex02/PmergeMe 3 5 9 7 4

Project structure

cpp_modules/
├── module00/
│   ├── ex00/            # one directory per exercise: Makefile, main.cpp, classes
│   └── ...
├── ...
└── module09/
    └── ex00/data.csv    # bitcoin price database for btc

About

42 C++ Piscine modules 00-09: OOP, canonical form, casts, templates and STL in C++98

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages