NPRG041: Programming in C++
Lectures [en]:
Plan |
Slides
Labs [en/cs]:
Materials |
Plan |
Small Assignments |
Big Assignments |
Files |
Deadlines |
Outcomes
Basic Information
- Annotation:
Czech |
English
- Course webpage:
Czech |
English
- Lectures
- Group 02: Tuesday 10:40 - 12:10 (S4) [English]
- Labs
- Group 06: Wednesday 10:40 - 12:10 (SW1) [Czech]
- Group 07: Wednesday 12:20 - 13:50 (SU2) [Czech]
- Group 08: Wednesday 15:40 - 17:10 (SW2) [English]
Group 09: Wednesday 17:20 - 18:50 (SU1) [English] (was merged with Group 08)
-
Table with activity points
Lectures [en]
Semester Plan
- Tuesday 30. 09. 2025 - Lecture 1 (history, literature, language features and specifics)
- Tuesday 07. 10. 2025 - Lecture 1 (language advantages, compilation process), Lecture 2 (function main, stream insertion)
- Tuesday 14. 10. 2025 - Lecture 2 (header files, definitions and declarations, inline functions, containers)
- Tuesday 21. 10. 2025 - Lecture 3 (values, pointers, and references)
Tuesday 28. 10. 2025: Not scheduled (Czechoslovak Independence Day)
- Tuesday 04. 11. 2025 - Lecture 4 (references, types of values, stealing, function parameters)
- Tuesday 11. 11. 2025 - Lecture 4 (return values, move semantics, copy elision), Lecture 5 (copy and move operations)
- Tuesday 18. 11. 2025 - Lecture 5 (special members, defaulted methods, the Rule of Five, dynamic allocation, smart pointers)
- Tuesday 25. 11. 2025 - Lecture 6 (pointers, conventions, multiple values, sequential and associative containers)
- Tuesday 02. 12. 2025 - Lecture 6 (ordered and hashed containers, functors, iterators, categories of iterators)
Tuesday 09. 12. 2025 - Self-study - Lecture 9 (classes), Lecture 10 (exceptions, noexcept, guarantees)
- Tuesday 16. 12. 2025 - Lecture 7 (algorithms, fake iterators, ranges, functors, lambdas), Lecture 9 (inheritance)
- Tuesday 06. 01. 2026
Lecture Slides
- Lecture 01 - PDF - Pros and cons of C++, compilation and header files
- Lecture 02 - PDF - Hello world, modules, declarations and definitions, references
- Lecture 03 - PDF - Values, pointers, references
- Lecture 04 - PDF - Passing arguments and returning by value and by reference, copy/move semantics, copy/move elision
- Lecture 05 - PDF - Copy/move semantics, the Rule of Five, pointers, smart pointers, observers
- Lecture 06 - PDF - References vs. pointers, conventions, containers, iterators
- Lecture 07 - PDF - Algorithms, functors, lambda expressions
- Lecture 08 - PDF - Templates, forwarding references, variadic templates
- Lecture 09 - PDF - Classes, inheritance, virtual methods, conversions
- Lecture 10 - PDF - Introduction to exceptions
Labs [en/cs]
Class Materials
Semester Plan
- Wednesday 01. 10. 2025: Class 01 - Subsets
- Wednesday 08. 10. 2025: Class 02 - Options
- Wednesday 15. 10. 2025: Class 03 - Counter
- Wednesday 22. 10. 2025: Class 04 - Movies I
- Wednesday 29. 10. 2025: Class 05 - Expressions I
- Wednesday 05. 11. 2025: Class 06 - Expressions II
- Wednesday 12. 11. 2025: Not scheduled (Dean's Sports Day)
- Wednesday 19. 11. 2025: Class 07 - Movies II
- Wednesday 26. 11. 2025: Class 08 - Matrix
- Wednesday 03. 12. 2025: Class 09 - Movies III
- Wednesday 10. 12. 2025: Class 10 - Array I
- Wednesday 17. 12. 2025: Class 11 - Array II
- Wednesday 07. 01. 2026: Class 12 - Movies IV
Small Assignments
- Tuesday 07. 10. 2025: Assignment C01 - Subsets - Czech (version 11) | English (version 9) - 1 point
- Tuesday 14. 10. 2025: Assignment C02 - Options - Czech (version 13) | English (version 8) - 1 point
- Tuesday 21. 10. 2025: Assignment C03 - Counter - Czech (version 11) | English (version 6) - 1 point
- Tuesday 28. 10. 2025: Assignment C04 - Movies I - Czech (version 11) | English (version 5) - 1 point
- Tuesday 04. 11. 2025: Assignment C05 - Expressions I - Czech (version 8) | English (version 4) - 1 point
- Tuesday 11. 11. 2025: Assignment C06 - Expressions II - Czech (version 6) | English (version 3) - 2 points - [C05 fully required]
- Tuesday 25. 11. 2025: Assignment C07 - Movies II - Czech (version 11) | English (version 6) - 2 points - [C04 fully required]
- Tuesday 02. 12. 2025: Assignment C08 - Matrix - Czech (version 7) | English (version 5) - 2 points
- Tuesday 09. 12. 2025: Assignment C09 - Movies III - Czech (version 9) | English (version 7) - 3 points - [C07 partially required]
- Tuesday 16. 12. 2025: Assignment C10 - Array I - Czech (version 7) | English (version 6) - 3 points
- Tuesday 23. 12. 2025: Assignment C11 - Array II - Czech (version 7) | English (version 6) - 3 points - [C10 fully required]
- Tuesday 13. 01. 2026: Assignment C12 - Movies IV - Czech (version 6) | English (version 6) - 3 points - [C07 partially required, C11 optionally required]
Big Assignments
- Tuesday 18. 11. 2025: Assignment A01 - Regular Expressions - Czech (version 7) | English (version 4) - 2 points
- Tuesday 06. 01. 2026: Assignment A02 - Property Graphs - Czech (version 11) | English (version 6) - 5 points - [C11 optionally required]
Auxiliary Files
Important Deadlines
- Sunday 21. 12. 2025: topic selection
- Sunday 26. 04. 2026: project submission
- Sunday 24. 05. 2026: project finalization
Learning Outcomes
- Class C01 - Subsets
- Project structure: standard C++ console application, source files (
*.cpp), header files (*.h), compilation units (legacy modules)
- Compilation process: involved programs / steps (preprocessor, compiler, assembler, linker, loader)
- Main function: function
main (program entry point, simplified interface, return value), program exit codes (convention, 0 for success, anything else error)
- Header files:
#include directive (standard libraries <...>, custom header files "..."), inclusion guards (directives #ifndef, #define, #endif, naming convention)
- Data types: primitive types (
int, size_t, char, bool, ...), user-defined types (class, struct, enum, ...), derived types (arrays [], pointers *, references &, functions)
- Custom functions: user-defined functions (interface / header, parameters, return type,
void, order of definitions), motivation (problem decomposition, ...)
- Passing parameters: pass by value (copying, read-only use, primitive types), pass by pointer (low-level approach, read / write use), pass by reference (user-friendly, read / write use)
- Constness flag:
const type qualifier (ensures value immutability), motivation (intent declaration, compiler verification), constant parameters / variables (constants)
- Control structures: conditions (
if / else if / else, ...), loops (legacy and range-based for loops, ...), jumps (break, continue, return)
- Legacy arrays: C-style arrays (illusion, pointer to the first element, array size, operator
sizeof), considerations (access before / beyond the array content)
- Standard output:
std::cout stream, stream insertion operator << (chaining), line endings (std::endl manipulator, "\n" escape sequence)
- Memory allocation: static allocation (by compiler, on the stack), dynamic allocation (at runtime, on the heap, operators
new and delete, individual / array variants)
- Naming conventions: variables, parameters, functions (
camelCase or snake_case); classes, structures (PascalCase); constants, macros (UPPER_CASE), ...
- Class C02 - Options
- Declarations and definitions: mutual separation, declarations (entities existence, basic characteristics, usually in header files), definitions (one definition rule)
- Program arguments: function main (full interface), parameters meaning (zeroth parameter, C-style array of C-style strings)
- Vector container: class
std::vector (outer wrapper, dynamically allocated content, basic methods, range-based constructor, ...)
- Strings: C-style strings (C-style array, null-terminated), standard strings (class
std::string, container, basic methods, ...), mutual conversions (including char)
- Iterators: basics (purpose, variants
iterator / const_iterator, container methods begin / end), operations (dereferencing *, access ->, movement ++, testing !=, ...)
- Named constants:
constexpr specifier, global named constants, motivation (code readability, maintainability), string constants (C-style strings only)
- Type aliases: aliases for type names (existing types only),
using construct, contexts (global, local), motivation (code refactoring, ...)
- Function parameters: default values (contiguous postfix of parameters), output parameters (modifiable references, pointers)
- Namespaces:
using construct (partial / full namespace import), contexts (global, local), irreversibility (restricted use in header files)
- Short-circuit evaluation: lazy evaluation of logical expressions (conjunction
&& and disjunction ||), practical consequences (=, &= and |= differences)
- Switch statements: structure (
case labels, fall-through behavior, default label), type limitations (integrals, enumerations, variables)
- Conditional operator: ternary operator (condition, then / else branches), considerations (same return types)
- For loops: legacy for loops (control variable, iterators, ...), range-based for loops (syntactical shortcut, container / range iteration, universal reference)
- Code comments: single-line comments (
// ...), multi-line comments (/* ... */), motivation (code description, ...)
- Class C03 - Counter
- Streams: standard input / output
std::cin / std::cout, stream insertion / extraction operators << / >>, general streams std::istream / std::ostream
- Files: input / output file streams
std::ifstream / std::ofstream, file open flags (named constants for modes in, out, app, ...)
- Stream manipulators: general (
std::endl, ...), integers (std::dec, std::hex, ...), floating point numbers (std::fixed, std::setprecision, std::defaultfloat, ...)
- Input reading: global function
std::getline (reading input lines), reading loop (termination, error states)
- Contextual conversions: principle (implicit
bool conversion), contexts (if conditions, loop termination, ...), applications (streams, ...)
- Parsing numbers: functions
std::isdigit, std::isalpha; functions std::stoi, std::stof, edge cases (std::invalid_argument, std::out_of_range, position test)
- Structures and classes:
struct / class constructs, data and function members, static members, typical use cases, default accessibility
- Function overloading: multiple functions with the same name (differ in the number and / or types of parameters, return types are irrelevant)
- Handling exceptions: basic principles (
throw, catch), throwing by value, catching by reference (three dots wildcard ...), types of exceptions (anything)
- Traditional pointers: C-style pointers (basic principles), passing parameters by pointers, operators (dereferencing
*, member access ->)
- Default values: classes (implicit construction); primitive types: global variables (numeric types
0, null pointers, other uninitialized), local variables / data members (uninitialized)
- Class C04 - Movies I
- Classes (without inheritance): declaration / definition of members, access specifiers (
public, private), naming of private members (_ postfixes), this pointer
- Constructors and destructors: implicit / parameterized / ... constructors, compiler-generated methods, construction / destruction of members, handling of exceptions
- Parameterized constructors: passing parameters (by values, constant lvalue references, modifiable rvalue references)
- Member initializer lists: legacy / modern initialization of data members, differences, advantages, declaration order rule
- Inline functions:
inline specifier, inlining rules, declaration / definition of inline methods, code availability
- Value categories:
lvalue (on the left, with name / address), rvalue (on the right, anonymous, temporary; native prvalue, marked xvalue)
- Move semantics: lvalue vs. rvalue references, function
std::move, mechanism of stealing (instead of copying, possibility only)
- Passing parameters: pass by constant lvalue reference (
const T& param, read-only use, flexibility), pass by modifiable rvalue reference (T&& param, ownership transfers)
- Construction of objects: legacy initialization via
(), uniform initialization via {}; mapping to constructors, implicit construction, narrowing conversions, initializer lists
- Set container: class
std::set (standard elements with predefined ordering, methods count / contains, binary search, time complexity)
- Emplace mechanism: in-place construction, impact (e.g.,
push_back vs. emplace_back in vector), passing constructor parameters
- String streams: class
std::stringstream (streams over std::string strings); global function std::getline (with custom separator)
- String concatenation: operator
+ (allowed operands, C-style strings, undesired pointer arithmetic), conversion of numbers to strings (function std::to_string)
- Class C05 - Expressions I
- Classes (with single inheritance): access specifiers (
public, protected, private), keyword final (for classes or virtual methods)
- Inheritance principles: inheriting data / function members, inheritance access levels (
public, protected, private)
- Virtual functions: early / late binding (differences, requirements),
virtual and override specifiers, function overriding, achieving polymorphism
- Abstract classes: pure virtual functions (provided declaration, intentionally omitted definition), constructors (may be / are present, no contradiction)
- Inheriting constructors: not automatic,
using construct (inheritance of all referenced constructors), preserved accessibility
- Virtual destructors: default behavior, destruction of members, chained destruction of ancestors in hierarchies, practical recommendations
- Enumeration classes:
enum class construct, scoped named constants, underlying type, assigned values, type safety; legacy unscoped enumerations
- Dynamic allocation: allocation on the heap, time complexity considerations, objects with a non-trivial life cycle
- Operators new and delete: operator
new (allocation, construction), operator delete (destruction, deallocation); safe deallocation (requirements, preventive measures)
- Invalid pointers: null C-style pointers (deprecated value
0 or macro NULL, recommended literal nullptr)
- Class C06 - Expressions II
- Polymorphic containers: collections of pointers to base class instances within inheritance hierarchies (C-style pointers, smart pointers)
- Stack container: class
std::stack (methods push, top, pop, and empty, separation of elements retrieval and removal)
- String views: class
std::string_view (read-only wrapper for std::string or C-style strings, manual conversion to std::string instances)
- Compiler-generated methods: constructors and destructors, declaration keywords
default and delete
- Compiler attributes: passing additional information to compilers (general mechanism, source code annotation), use cases (warnings, optimization, ...)
- Standard attributes:
[[nodiscard]] (enforced handling of return values), [[noreturn]], [[fallthrough]], [[deprecated]], [[likely]], [[unlikely]], ...
- Custom hierarchy of exceptions: class hierarchy (base, derived), catching exceptions (references), rethrowing exceptions (avoidance of slicing issues)
- Dynamic allocation: possible failures (detection,
std::bad_alloc exception)
- Memory leaks: forgotten deallocation, possible causes (inappropriately handled failures, ...), ensuring atomicity (rollback, compensation actions)
- Assignment A01 - Regular Expressions
- Unique smart pointers: class
std::unique_ptr, function std::make_unique, exclusive ownership, move semantics
- Class C07 - Movies II
- Set container: class
std::set (custom elements without predefined ordering)
- Custom operators: comparison (operator
<, ...); stream insertion << stream extraction >> (with default separator)
- Shared smart pointers: class
std::shared_ptr, function std::make_shared, allocation / deallocation principles
- Classes (with inheritance): member initializer lists (invocation of ancestor constructors)
- Friendship declarations:
friend construct, principles, levels (global function, different class / different method), granting access, private / protected members
- Helper structures: class
std::optional (function std::make_optional, constant std::nullopt, methods has_value, value, contextual conversion)
- Formatted strings: function
std::format (formatting pattern, placeholders {}, escaping {{ or }}, parameters, compile-time checking, type-safe mechanism)
- Static retyping: compile-time mechanism, no validity checks;
static_cast, function std::static_pointer_cast (for smart pointers); conversion operators (predefined, custom)
- Dynamic retyping: runtime mechanism, validity checks;
dynamic_cast, function std::dynamic_pointer_cast; failures (nullptr for pointers, std::bad_cast for references)
- Class C08 - Matrix
- Templates: general principles,
template keyword, parameters (names of types, typename keyword, values); template specialization, code availability
- Template use cases: global functions, classes / structures, member functions, inner classes, friend declarations, type aliases, variables, lambda expressions, concepts
- Template instantiation: compile-time process (general template / template specialization, substitution of parameter values, code creation, duplicates removal)
- Dependent names: names depending on template parameters (unresolved meaning before instantiation), compilation issues,
typename construct
- Array container: class
std::array (construction, self-contained storage, methods fill, ...)
- Const overloading: resolution mechanism regarding method qualifiers (ordinary,
const, ...), possible scenarios (ordinary only, constant only, both of them)
- Inner classes: embedded class name, mutual visibility of inner / outer members, independence of instances,
this pointer
- Custom operators: arithmetic operators (addition, multiplication, pre-increment, post-increment, ...)
- Two-level indexing: custom subscript
[] operators (helper request class, modifiable / read-only variants)
- Implementation of operators: possible means (member functions vs. global functions), limitations, consequences (operand conversions, ...)
- References in data members: initialization (member initializer lists only), immutability, life cycle considerations
- Constness retyping:
const_cast construct (const qualifier removal), limitations (modifiability of the original object)
- Copy-on-write mechanism: lazy copying and content detachment (use of shared smart pointers, method
use_count)
- Class C09 - Movies III
- Associative containers:
std::map, std::multimap, std::unordered_multimap, std::multiset, ...; template parameters (ordering, hashing)
- Map container methods:
insert, emplace, find, equal_range, lower_bound, upper_bound, operator []
- Helper structures: pairs
std::pair (components first / second, function std::make_pair); tuples std::tuple (functions std::make_tuple, std::tie, std::get)
- Structured binding: unfolding structure / class data members, use cases (local variables, range-based
for loops, ...)
- Functors: function / callable objects, operators
(), various signatures, typical use (standard / custom functors)
- Standard functors:
std::less (comparison, global operator <), std::equal_to (equality test, global operator ==), std::hash (hashing)
- Passing callable objects: wrapper class
std::function (unified wrapper for functions, functors, and lambda expressions)
- Template specialization: templating mechanism, redefinition of behavior, full / partial specialization
- Observer pointers: purpose, conversion of smart pointers, temporary use limitation
- Copy elision: optimization mechanism (return values from functions, avoidance of value copying)
- Class C10 - Array I
- Vector container: internal storage organization (contiguous space, reserve), reallocation (elements moving / copying), invalidation of iterators / pointers / references
- Low-level dynamic allocation: allocation without construction (function
::operator new), deallocation without destruction (function ::operator delete)
- Invocation of constructors and destructors: placement new operator
new (target) T(...), exceptions, failures; direct destructor call ∼T()
- Special member functions: copy constructor
T(const T&), copy assignment T& operator=(const T&), move constructor T(T&&), move assignment T& operator=(T&&)
- Custom special members: initial content, objectives, self-assignment, atomic behavior, shallow / deep copy, function
std::swap, custom swap functions (outside of std)
- Exception guarantees: no (absolutely no guarantees), basic (+ valid state, no resource leaks, intact invariants), strong (+ previous state rollback), nothrow (+ never throws, never fails)
- Resource stealing: intention only (optimization, copying fallback),
noexcept, new content (valid, preferably empty), further use (prohibited), feasible destruction (occurs inevitably)
- Rule of Five: any of CC/MC/CA/MA/D should imply them all; Rule of Zero: usually none needed; Rule of Three: any of CC/CA/D should imply them all, obsolete
- Implicit declarations: defaulted DC (unless any C declared), D (always), CC/CA (unless MC/MA, otherwise deleted), MC/MA (unless CC/MC/CA/MA/D, otherwise not declared)
- Defaulted functions: idea (recursively the same operation on all members), DC (defaults in parameters / members / initializer list), CC/CA (shallow copy), MC/MA (moving/copying)
- Conditional compilation: named macros, conditional sections, directives (
#define, #ifdef, #else, #endif, ...); debug exceptions
- Standard exceptions:
std::invalid_argument, std::out_of_range, std::bad_alloc, std::bad_cast, ...
- Class C11 - Array II
- Custom namespaces: standard / user-defined namespaces, construct
namespace (embedded / flat definition, reopening), naming convention
- Container requirements: motivation (standard algorithms, ranges), type aliases (
value_type, ...), member functions (begin, end, ...), named requirements
- Concepts: template parameter constraints, construct
concept, application (direct template parameter, requires clause), definition (logical expression, atomic constraints)
- Standard concepts:
std::copy_constructible, std::move_constructible, std::default_initializable, std::destructible, std::input_iterator, ...
- Requires expressions: construct
requires (parameters, body), low-level constraints (basic expression, type name existence, return type, nothrow guarantee, ...)
- Static assertions: compile-time checks,
static_assert declaration, optional message, typical conditions (concepts, requires expressions, type traits, comparisons, ...)
- Advanced container constructors: initializer (structure
std::initializer_list, wrapper), range-based (iterators, C-style pointers), ...
- Constructors overview: default, parameterized, initializer, copy, move, converting;
explicit, noexcept, constexpr; inherited, defaulted, deleted, templated; delegating
- Perfect forwarding: function
std::forward (universal reference &&), value category preservation (passing lvalue / rvalue reference), sample use (push_back, ...)
- Variadic templates: basic principles,
template<typename... Args>, entity pack, pack expansion, fold expressions, sample use (emplace_back, ...)
- Custom iterators: implementation (inner class templates, ...),
iterator / const_iterator, type aliases (iterator_category, ...), container interface (begin, end, ...)
- Iterator categories: ..., forward (basic operations
==, !=, ++, *, ->), bidirectional (also --), random access (also +, -, [] and many other), ...
- Type traits: type introspection mechanism (compile-time), structure templates (
std::conditional, ...), type aliases (*_t for *::type, ...)
- Conversion operators: custom operators (member function, no parameters, no return type, return value), analogy to constructors (direction of transformation)
- Class C12 - Movies IV
- Standard algorithms: functions
std::copy, std::copy_if, std::remove_if, std::transform, std::sort, std::for_each, std::accumulate, std::all_of, ...
- Fake iterators: function
std::back_inserter (insertion of new elements into containers), class std::ostream_iterator (writing content into output streams)
- Advanced functors: passing input parameters (data members, parameterized constructors), retrieving return values (methods)
- Lambda expressions: anonymous functors, captures (values, references), parameters, return values, storing lambdas
- Ranges and views: general abstraction, functions
std::ranges::copy and std::ranges::sort; adapters std::views::filter and std::views::transform
- Passing callable objects: class
std::function wrapper, approach via template parameters (differences, advantages)
- Regular expressions: class
std::regex (regular expression instance, case-insensitivity flag std::regex_constants::icase), matching function std::regex_match
- String literals: ordinary / raw string literals, form
R"delim(text)delim" (without standard escape sequences, configurable delimiter, even empty)
- Variant type: class
std::variant (type-safe union type, exactly one value), functions std::holds_alternative, std::get, direct assignment
- Doxygen documentation: principles, configuration, structured comments (
@file, @param, @return, @exception, @tparam, ...)