Programming in C++.
Lecture: Wednesday 16-18, Sal 25.
Laboratory (Hans de Nivelle): Wednesday 18-20, Sal 7
Laboratory (Marek Szykuła): Tuesday 16-18, Sal 110
Laboratory (Marek Szykuła): Tuesday 18-20, Sal 110
Laboratory (Jan Otop): Friday 10-12, Sal 7
Experience in at least one programming language, e.g.
C, Java or Python.
Exercises have two goals which are in conflict
with each other: We have to teach you, and we have to check/grade you.
The balance between them depends on how much effort we believe
invested in your solution. This will be is a subjective judgement.
Exercises must be shown on Linux computers in lab 7 or 137.
We believe that ability to use Linux is a fundamental skill,
that every developer should possess, so don't argue about this.
If it is difficult for you, you will have problems in other
We have to check and improve
up to 20 solutions in 105 minutes, most of them need some
improvement, some of them have bugs which need to corrected.
On a lab computer this goes much quicker than on somebody's
cheap laptop, with bad screen and bad keyboard. We don't want
to negatiote with you if your laptop is good enough.
That is a waste of our time.
Coincidentally, the students that are unable to use a lab computer,
are also the ones that have the most problems in other areas.
You must attend lectures. We have no
time to repeat things that you could have known if you would
have come to the lectures. As above, lab time is short,
and it must be used efficiently.
Don't rush to finish your task on the same day that you get them.
This is childish. We are a university, not a Kindergarten.
You have one week, and try to make the tasks as good
as you can. You learn nothing from a fast, bad solution, and
it wastes our time.
Come at the beginning of the lab:
If everyone comes at the end, we will not be able to check
(and improve, see above) your programs. Just be there from
We give you a task for next week at the beginning, so
that you don't have to waste your time while waiting.
Code must be presented in reasonable lay out.
It is not difficult at all to format code, so the only possible
reason for bad code lay out is lazyness on the side of the
We accept every reasonable indentation style, see
C++ is a language that starts at low level, but which is
designed in such a way that a programmer can build high-level components
inside the language.
When you are working on a large project, you build your components,
and after that do not use the low-level features anymore in
the rest of the project.
If you are joining an existing project or using libraries, you
probably never have to deal with the low-level aspects of the language.
If you are working on a large project, and after half a year still
doing low-level programming, then you are doing something wrong.
The bad reputation of C++ is caused by programmers and teachers
that never manage to escape from the low-level programming.
22.02.2017. History of C++, General Remarks.
Comparing C++ with C and Java. Memory organization in C programs.
01.03.2017. Editing, compiling, linking. Separate compilation.
How to use make. Different types of references
and why they are needed.
Basics of class design.
Class = representation + invariants + equivalences.
Design of data structures that use heap allocation.
an object. Difference between initialization and assignment.
Insertion of implicit operations by the compiler.
Initializers in constructors.
The string example that we made in
class. (Probably the smallest string class ever.)
Private vs. public fields, inlining,
use of this in member functions,
why C-style macros should not be used anymore.
User defined operators. Initializer lists.
Slides are the same.
29.03.2017. Move semantics, temporaries, the
return value optimization, and rvalue references.
I will demonstrate on the
string class that we made before,
that all these things (temporaries, Rvalues, return value
optimization) exist in real.
This is the associated main file.
Automatic generation of copy/assignment operators.
Use of noexcept in move construction.
Second part of lecture: STL containers,
vector, string and list.
Amortized complexity of push_back( ) on vector.
Importance of declaring Rvalue copy-constructor noexcept.
Exceptions, static variables, and constexpr.
19.04.2017. No lecture, because it is Tuesday.
STL: map and hashmap. Slides.
The standard way of passing a function in C++.
(As a type with a default constructor and an application operator.)
Priority queues and how
to use them in search algorithms.
(I corrected the slides after the lecture.
I corrected printpath on 05.12.2017.)
03.05.2017. No lecture.
Lambdas in C++. Slides about lambdas.
Start of template classes and functions.
These are the slides.
More about templates. Templates are checked only when they
are instantiated. That is a feature, not a bug!
24.05.2017. Templates, and start of derived classes.
That other type of polymorphism: Derived classes.
More about derived classes.
Threading in C++.
Example. (Super inefficient calculation
of pi on four cores using pi/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 ...)
14.06.2017. Multiple Inheritance.
I usually use this site
for reference about STL. Make sure to select C++-11 whenever possible.
Homepage of Bjarne Stroustrup about
The wikipedia page about
is also quite good.
An explanation why
Java is better than C++. (These are not ordinary lies or misunderstandings.
This text is written by professionals.)
Most of the points will be addressed in the lectures.
Discussion of C++-17.
of interaction between template instantiation, std::forward, and move
Exercise number 1.
Basics of Linux.
Example of a makefile.
Exercise number 2.
You need the following files:
Exercise number 3.
Exercise number 4.
You need these additional files.
You need the files in
(Note that there are problems with task 5. The non-const
operator cannot be made robust against assignments of form
t = t, when t is not shared. Method replacesubtree( ) in
task 7 is OK. )
You need the files in
about usage of std::map and std::unordered_map.
This exercise is different from last year.
about solving the 15-puzzle, using unordered_map and
You need these files.
(If you have a version with 5 tasks, reload it, because there
are now only 3.)
Note that the task uses exceptions in an improper way.
Next year, the task will be without exceptions, and
there will be some more chances.
about computer algebra using templates.
You need these files.
about use of templates for physical units.
You need these files.
(I made some changes on 25.05 in the morning, please reload.)
Exercise 12 has two versions:
Game of Life
There were 12 exercises. Every exercise counts as 10 points. This means
that there are 120 points in total. Exercises 1,2,3,4,5 must be
made in all cases. Grades are obtained from the
points as follows:
70 => 3.0
80 => 3.5
90 => 4.0
100 => 4.5
110 => 5.0