Programming in C++.
Lectures: Tuesday 16-18, Sal 25.
Laboratory (Marek Szykuła): Tuesday 18-20, Sal 110
Laboratory (Marek Szykuła): Tuesday 14-16, Sal 108
Laboratory (Jan Otop): Thursday 18-20, Sal 107
Laboratory (Marek Szykuła): Thursday 18-20, Sal 108
Prerequisites
Experience in one programming language, e.g.
C, Java or Python.
Exercises must be shown on Linux computers in lab 07 or 137.
YOU MUST BE WILLING TO USE LINUX!
This is an overview of the basic
commands of Linux.
Introduction
C++ is a language that starts at low level, but which is
designed in such a way that programmer can build high-level components.
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 leave the low-level programming.
Schedule
-
24.02.2016. History of C++, General Remarks.
Comparing C++ with C and Java. Memory organization in C programs.
slides.
-
02.03.2016. 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.
slides.
- 09.03.2016.
Design of data structures that use heap allocation.
Constructing/copying/destroying
an object. Difference between initialization and assignment.
Insertion of implicit operations by the compiler.
Initializers in constructors.
slides.
The string example that we made in
class. (Probably the smallest string class ever.)
- 15.03.2016.
const member functions, private field variables,
inlining, use of this,
why C-style macros should not be used anymore.
slides.
- 22.03.2016.
Explicit keyword.
User defined operators. Initializer lists.
Inlining.
-
05.04.2016. 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 associated main file.
slides.
-
12.04.2016.
Automatic generation of copy/assignment operators.
Use of noexcept in move construction.
Second part of lecture: STL containers,
vector, string and list.
slides.
- 19.04.2016.
Amortized complexity of push_back( ) on vector.
Importance of declaring Rvalue copy-constructor not throwing.
Exceptions, problems with static variables.
Slides.
-
28.04.2016.
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.)
-
10.05.2016.
Priority queues and how
to use them in search algorithms.
Slides.
-
17.05.2016.
Lambdas in C++. Slides about lambdas.
Start of template classes and functions.
These are the slides.
-
24.05.2016.
Rest of templates. Templates are checked only when they
are instantiated. That is a feature, not a bug!
-
31.05.2016.
Lecture will be given by
Andrzej Krawczyk,
dyrektor of human dialog.
Topics are: Proper use of threading,
and how to design, implement and manage large software
projects.
-
31.06.2015.
That other type of polymorphism: Derived classes.
Slides.
-
09.06.2015. Last lecture, probably also about derived classes.
Role of Laboratories
The laboratory has two goals which are somewhat in conflict
with each other: I have to teach you, and I have to check/grade you.
The balance between them depends on how much effort I believe
you put in when you made the task.
It is better that you come at the beginning of the lab:
If everyone comes at the end, I will not be able to check
(and improve, see above) your programs. Therefore, come at the
beginning. I give you a task for next week at the beginning, so
that you don't have to waste your time while waiting.
Another advantage of working/starting in the lab is that you can
ask questions.
Tasks must be shown on a Linux computer. My experience is that
in Windows, the integrated environments are not standard conforming,
use most of the screen area for showing all the fancy options of the
integrated environment instead of code, error messages and output.
In windows, it it hard to check for memory leaks, etc.
Windows is designed in such a way that the user has no control
over the computer.
The main decisions are taken by the programs, that have too much
freedom to do what they like. As a consequence, you don't know
where your files are stored, what are the access rights, what programs are
being installed, what programs are running and how much resources
they are using, what data is being sent over the internet to whom, etc.
Since this is a non-acceptable situation for a professional, we
will use Linux.
If you bring your own
laptop, try to read the screen from 1 meter distance under an angle of
45 degrees. If you cannot, you should use the computers in the lab.
Useful Sites
-
I usually use this site
for reference about STL.
-
Homepage of Bjarne Stroustrup about
C++ 11.
-
The wikipedia page about
C++ 11
is also quite good.
-
An explanation why
Java is better than C++. (These are not ordinary lies.
This text is written by professionals.)
Most of the points will be addressed in the lectures.
Exercises
-
Exercise number 1.
Basics of Linux.
Example of a makefile.
-
Exercise number 2.
You need the following files:
Makefile,
rational.h,
rational.cpp,
vector.h,
matrix.h,
matrix.cpp,
main.cpp.
-
Exercise number 3.
-
Exercise number 4.
-
Number 5.
You need the files in
nr05.
-
Number 6.
You need the files in
nr06.
This exercise changed quite a lot since last year!
-
Number 7
about usage of vector in a matching algorithm.
You need the files in
nr07.
This exercise is different from last year.
-
Number 8
about std::map and std::unordered_map.
-
Exercise 9
about solving the 15-puzzle, using unordered_map and
priority_queue.
You need these files.
-
Exercise 10
about templates.
You need these files.
-
Exercise 11
about inheritance.
-
Exercise 12
about Conway's
Game of Life.
You need these files.
Grading 2016
There were 12 exercises. Every exercise is good for 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