Skip to content

itsiros/CPP_Learning_Path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Learning Path (CPP00 - CPP09)

A comprehensive collection of C++ exercises covering fundamental to advanced concepts. This progression builds from basic syntax to advanced template usage, object-oriented design patterns, and algorithmic problem-solving.

Overview

10 modules (CPP00–CPP09) with multiple exercises per module:

  • CPP00–CPP04: Core OOP concepts (classes, inheritance, polymorphism)
  • CPP05: Exception handling and form validation
  • CPP06: Type casting and serialization
  • CPP07: Templates (generic functions and classes)
  • CPP08: STL containers and algorithms
  • CPP09: Advanced algorithms and data structures

Project Structure

CPP/
├── CPP00/  # Basics (classes, constructors, getters/setters)
├── CPP01/  # Memory management (pointers, heap allocation)
├── CPP02/  # Operator overloading (Fixed-point numbers)
├── CPP03/  # Inheritance (multiple inheritance, diamond problem)
├── CPP04/  # Polymorphism (virtual functions, abstract classes)
├── CPP05/  # Exception handling (try-catch, custom exceptions)
├── CPP06/  # Type casting (static_cast, dynamic_cast, reinterpret_cast)
├── CPP07/  # Templates (function templates, class templates)
├── CPP08/  # STL containers and algorithms
└── CPP09/  # Advanced algorithms (Bitcoin exchange, RPN, merge sort)

CPP00 — Basics

Exercises

  • ex00: megaphone — converts input to uppercase
  • ex01: phonebook — simple contact management (max 8 contacts)
  • ex02: Account — bank account simulation with static logging

Build & Run

cd CPP00/ex00 && make && ./megaphone "hello world"
cd CPP00/ex01 && make && ./phonebook
cd CPP00/ex02 && make && ./account

Key Concepts

  • Classes and object construction
  • Getters/setters and encapsulation
  • Static members and methods
  • Basic file I/O and string handling

CPP01 — Memory Management & Pointers

Exercises

  • ex00: Zombie — stack vs. heap allocation
  • ex01: zombieHorde — array allocation on heap
  • ex02: fileReplace — read file, replace string, write output
  • ex03: Weapon — pointer references between objects
  • ex04: sed — file search/replace (like sed)
  • ex05: Harl — function pointers for logging levels
  • ex06: Harl Filter — switch-case on string (filter log level)

Build & Run

cd CPP01/ex00 && make && ./zombie
cd CPP01/ex02 && make && ./sed input_file.txt "search" "replace"
cd CPP01/ex05 && make && ./harl

Key Concepts

  • Stack vs. heap allocation
  • Pointer arithmetic and references
  • File I/O streams
  • Function pointers

CPP02 — Operator Overloading

Implements a Fixed-point number class with custom operators.

Exercises

  • ex00: Basic Fixed class (constructor, copy, assignment)
  • ex01: Overload arithmetic operators (+, -, *, /)
  • ex02: Overload comparison operators (<, >, ==, etc.) and increment
  • ex03: bsp() — point-in-triangle test using cross products

Build & Run

cd CPP02/ex02 && make && ./fixed
cd CPP02/ex03 && make && ./bsp

Key Concepts

  • Copy constructor and assignment operator
  • Operator overloading (arithmetic, comparison, pre/post-increment)
  • const correctness
  • Insertion operator (<<)

CPP03 — Inheritance

Exercises

  • ex00: Basic inheritance (ClapTrap)
  • ex01: Multiple levels (ScavTrap inherits ClapTrap)
  • ex02: Multiple inheritance (FragTrap inherits ClapTrap)
  • ex03: Diamond problem (DiamondTrap from ScavTrap + FragTrap)

Build & Run

cd CPP03/ex00 && make && ./clapTrap
cd CPP03/ex03 && make && ./diamondTrap

Key Concepts

  • Single and multiple inheritance
  • Constructor/destructor chaining
  • Diamond problem and virtual inheritance
  • Protected vs. private members

CPP04 — Polymorphism & Abstract Classes

Exercises

  • ex00: Animal hierarchy (Animal → Dog/Cat, WrongAnimal for comparison)
  • ex01: Brain deep copy (fix resource leaks)
  • ex02: Brain with array of ideas (100 ideas per animal)
  • ex03: Materia system — abstract base, Ice/Cure implementations, inventory

Build & Run

cd CPP04/ex00 && make && ./animal
cd CPP04/ex03 && make && ./materia

Key Concepts

  • Virtual functions and pure virtual (abstract) classes
  • Polymorphic behavior via pointers/references
  • Deep copy semantics
  • Factory pattern (MateriaSource)

CPP05 — Exception Handling

Exercises

  • ex00: Bureaucrat with grades (1–150), throw exceptions on invalid grade
  • ex01: Form class with sign conditions, Bureaucrat signs forms
  • ex02: AForm (abstract) with PresidentialPardonForm, RobotomyRequestForm, ShrubberyCreationForm
  • ex03: Intern creates forms from name string (factory pattern)

Build & Run

cd CPP05/ex00 && make && ./bureaucrat
cd CPP05/ex03 && make && ./intern

Key Concepts

  • Custom exceptions (inherit from std::exception)
  • Try-catch blocks
  • Exception safety and re-throw
  • Const correctness in exception handling

CPP06 — Type Casting

Exercises

  • ex00: ScalarConverter — parse scalar string, detect type (int/float/double/char), convert & print
  • ex01: Serializer — serialize/deserialize pointer to Data struct (reinterpret_cast)
  • ex02: Base — identify object type via RTTI (dynamic_cast)

Build & Run

cd CPP06/ex00 && make && ./convert "42"
cd CPP06/ex01 && make && ./serialize
cd CPP06/ex02 && make && ./identify

Key Concepts

  • static_cast — safe conversions (e.g., int to float)
  • reinterpret_cast — low-level bit reinterpretation (pointers)
  • dynamic_cast — RTTI for polymorphic types
  • Type detection via typeid()

CPP07 — Templates

Generic programming with templates.

Exercises

  • ex00: template<T> void swap(T &a, T &b) — generic swap function
  • ex01: template<T> T iter(...) — iterate and apply function to array
  • ex02: template<typename T> class Array — generic dynamic array

Build & Run

cd CPP07/ex00 && make && ./whatever
cd CPP07/ex01 && make && ./iter
cd CPP07/ex02 && make && ./array

Key Concepts

  • Function templates with deduction
  • Class templates and member function definitions
  • Template specialization
  • Non-type template parameters

CPP08 — STL Containers & Algorithms

Exercises

  • ex00: easyfind() — template function to find element in container via STL find()
  • ex01: Span — container storing up to N integers, addNumber(), shortestSpan(), longestSpan()
  • ex02: MutantStack — stack with iterator support (template + inheritance)

Build & Run

cd CPP08/ex00 && make && ./easyfind
cd CPP08/ex01 && make && ./span
cd CPP08/ex02 && make && ./mutantstack

Key Concepts

  • STL containers (vector, list, stack, map)
  • STL algorithms (find, sort, transform)
  • Iterators (forward, bidirectional, random-access)
  • Adapter patterns (stack wrapping deque)

CPP09 — Advanced Algorithms

Exercises

ex00: BitcoinExchange

Parse CSV historical Bitcoin prices, read input file with dates/amounts, output exchange values.

Files:

  • data.csv — historical Bitcoin prices (date, price)
  • input — list of dates and amounts
  • main.cpp — parse and compute

Build & Run:

cd CPP09/ex00 && make && ./btc input

Output:

2011-01-03 => 1.2 = 11.6
2011-01-03 => 1 = 9.67
2012-01-11 => 7.1 = 4.9971
...

Key Concepts:

  • File parsing and CSV handling
  • Map (key-value) data structure
  • Binary search (lower_bound())
  • Date validation

ex01: RPN (Reverse Polish Notation)

Evaluate mathematical expressions in RPN using a stack.

Example:

Input: "5 1 2 + 4 * + 3 -"
Output: 32
# (5 + (1 + 2) * 4) - 3 = 32

Build & Run:

cd CPP09/ex01 && make && ./RPN "5 1 2 + 4 * + 3 -"

Key Concepts:

  • Stack-based computation
  • Postfix notation evaluation
  • String tokenization
  • Operator handling

ex02: PmergeMe

Merge-insert sort (Ford-Johnson algorithm) using two different containers (vector + deque).

Build & Run:

cd CPP09/ex02 && make && ./PmergeMe 5 2 8 1 9

Output:

Before:  5 2 8 1 9
After:   1 2 5 8 9
Time to process a range of 5 elements with std::vector: 0.001 ms
Time to process a range of 5 elements with std::deque:  0.001 ms

Key Concepts:

  • Merge-insert sort algorithm
  • Container comparison (vector vs. deque performance)
  • High-order element tracking
  • Timing measurements (gettimeofday())

Build Instructions

Each exercise has its own Makefile. General build:

cd CPP<XX>/ex<YY>
make              # compile
make run          # compile and run (if main exists)
make clean        # remove .o files
make fclean       # remove executable and .o
make re           # clean + compile

Compilation Flags

Standard compilation with:

  • -Wall -Wextra -Werror — strict warnings
  • -std=c++98 or -std=c++11 (project-specific)
  • -O2 or -O3 (optimization)

Example Makefile snippet:

CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -std=c++98
LDFLAGS =

SRC = $(wildcard *.cpp)
OBJ = $(SRC:.cpp=.o)
TARGET = program_name

all: $(TARGET)

$(TARGET): $(OBJ)
    $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

%.o: %.cpp
    $(CXX) $(CXXFLAGS) -c $< -o $@

clean:
    rm -f $(OBJ)

fclean: clean
    rm -f $(TARGET)

re: fclean all

.PHONY: all clean fclean re

Learning Path Summary

Module Focus Difficulty
CPP00 Classes & basics
CPP01 Pointers & memory ⭐⭐
CPP02 Operator overloading ⭐⭐
CPP03 Inheritance ⭐⭐
CPP04 Polymorphism ⭐⭐⭐
CPP05 Exceptions ⭐⭐
CPP06 Type casting ⭐⭐
CPP07 Templates ⭐⭐⭐
CPP08 STL & algorithms ⭐⭐⭐⭐
CPP09 Advanced algorithms ⭐⭐⭐⭐

Key Takeaways

  • OOP fundamentals: classes, inheritance, polymorphism
  • Memory safety: pointers, references, RAII, smart pointers (C++11)
  • Operator overloading: custom behavior for built-in operators
  • Exception safety: try-catch, custom exceptions
  • Generic programming: function & class templates
  • STL mastery: containers, iterators, algorithms
  • Algorithmic thinking: sorting, searching, optimization

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors