Navigation
Page categories
Outline:
Last modification
2025-09-04
This is smol web. If you don't like it, fix your browser.

Infopage about the C++ lab of NPRG041.

Groups:

Zoom meeting passcodes are the same as for the lecture.

Everyone is invited to join the dedicated Slack workspace, which shall support all basic communication needs during the semester, and is the preferred way for communication. Invitation link for Slack is available in SIS noticeboard module (mail me if you can’t find it, or don’t have SIS access). If you cannot use Slack for whatever reason, please make sure to check this website for weekly updates.

Reading material:

Lab requirements#

To get the credit, you have to attend the course reasonably (at least
accordingly to your knowledge of the topic), do the homework (see below) and
finish an individual project (also below).

You will be assigned several points for finishing the homework. These will be
added to the points from the final test, therefore improving your final grade
for the whole course. Details are available in the main course slides.

Depending on many factors, students from Erasmus programs may need a completely
different set of rules to fit into different time limits.
If you are an ERASMUS student, contact us!

Homework#

There are two homework assignments. Please refer to
ReCodex. Make sure you are registered in the
correct student groups.

Project#

Each student has to create an individual project and submit it to get the
credit. Topics of the projects may vary wildly, but you should discuss your
topic before the end of November so that it is agreed upon. Size of the project
is not an issue and largely depends on the topic, around 500 lines of (neat)
C++ code is a good guideline (on the other hand, packing the same functionality
into a smaller program using e.g. advanced language features is even better).

Bad topics:

Good topics:

Deadlines:

Submission:

You must develop and submit the project using git in the corresponding MFF Gitlab group. The submission process is simplified — you just notify me that the project is ready there. Registration to Gitlab is open for all students with valid CAS UK credentials. After you register, let me know to assign you to the group.

Submission guidelines:

Useful libraries for the projects:

Lab timeline#

Source code from the labs will be available here.

CZ 1 (Sep 29th), EN 1 (Oct 5th)#

Slight introduction into C, basic data types and a bit of pointers. What does the multi-module compilation process look like (C really just spews out assembly, multiple assembly files are joined together in a linking process to create the final executable file).

CZ 2 (Oct 6th), EN 2 (Oct 12th)#

Manual memory management and pointers. (Linked lists all over again.)

How to point to a piece of actual code (aka. function pointers). Note: We did not make it thus far in English class, but you can read about function pointers e.g. here , or see the usecase in the source code from the czech lab. Anyway, this is probably the last time we used raw function pointers, so you don not need to worry about them at all.

CZ 3 (Oct 13th), EN 3 (Oct 18th)#

C++ built atop C: overloading, references, objects, custom operators. A slight hint of why format strings are not needed for C++ input/output (they are “derived” from overloading).

CZ 4 (Oct 19th), EN 4 (Oct 26th)#

Wrapping fragile resources with a programmer-friendly class interface. (Constructors, destructors, RAII, rule of three&five).

SIDE NOTE: The zoo of manual memory allocation, deallocation, object construction, and destruction:

The things above do NOT initialize the memory anyhow. If you want actual usable objects to be “created” in the memory, you need to somehow indicate that the constructors and destructors need to get called:

If you have acquired the memory in your own ways (e.g. if your operating system and libc do not have allocators) and just want to run the constructors and destructors on that memory in order to initialize/deinitialize the objects there so that they can be used safely, you can use placement new and manual destructor call:

One such case when you want to use placement new and manual destructor call is if you want to allocate a big array but only initialize (“construct”) some of its elements. That may be the case with homework assignment 1.

Also see here: cplusplus.com/operator new

CZ 5 (Oct 26th), EN 6 (Nov 3rd, moved to Tuesday)#

Using STL and containers (strings, sets, maps). We started a mergesort on lists, going to make it a bit more efficient next time.

CZ 6 (Nov 3rd), EN 6 (Nov 9th)#

A bit more about (some) STL containers, brief overview of move semantics and general “copy avoidance” hints. We read and wrote from/to files.

CZ 7 (Nov 10th), EN 7 (Nov 16th)#

OOP-style programming: Classes, inheritance hierarchies, virtual methods. Smart pointers help a lot —- run-time polymorphic data need to be “held” using a reference (ie. a pointer); smart pointers allow you to automatically destroy and deallocate these objects without much extra effort, thus preventing ugly memory issues. You should be able to deduce the reason why unique_ptr is move-only.

EN 8 (Nov 23rd), CZ 8 (Nov 24th)#

Deriving from standard classes, overloading a whole spectrum of functions at once using variadic templates. Tiny useful helper proxy classes.

EN/CZ 9 (Nov 30th, 31st)#

Postfix calculator, tricks with macros

EN/CZ 10 (Dec 7th, 8th)#

Searching through a state space (solving the reduced 15 puzzle). BFS and path backtracking tricks.

EN/CZ 11 (Dec 14th, 15th)#

Graph reduction by DFS (SMILES-like graph notation generator).

EN/CZ 12 (Dec 21st, 22nd)#

Template metaprogramming (static factorial, static debug outputs). Dynamic programming (Levenshtein distance).

EN/CZ 13 (Jan 4th, 5th 2021)#

Postfix calculator with polynomials, some operations on polynomials.

Bonus material#