Programming in C++.
Lectures: Tuesday 16-18, Room 140.
Laboratory: Tuesday 18-20, Thursday 10-12
On Friday June 27th, there is lab from 10.15 to 11.30 in room 137.
Prerequisites
Knowledge of programming in C or Python.
During the exercises,
I will be using Linux in lab 137 or 07.
YOU MUST BE WILLING TO USE LINUX.
I will explain the basics
of Linux in the first lecture. You don't need advance
knowledge but you must be willing to learn it.
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
-
25.02.2014. History of C++, General Remarks.
Comparing C++ with C and Java. Memory organization in C programs.
slides.
-
04.03.2014. 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.
- 11.03.2014.
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.)
- 18.03.2014.
const member functions, private field variables,
inlined member functions, use of this,
overloading resolution rules, operator overloading,
initializer_list.
slides.
(I corrected the overloading rules.)
- 25.03.2014. Probably the last lecture about basic data structure design:
Hidden temporary objects in expressions,
move semantics, R-value references,
sharing with reference counting. Adding iterators to your classes.
C++ filosophy on checking preconditions.
slides.
-
01.04.2014. Some more remarks about Rvalue references and move
semantics. I will demonstrate on the
string class that we made before,
that all these things (temporaries, Rvalues, return value
optimization) really exist.
After that, we continue with STL, which I think will be
easier than the previous topics,
list, vector, string:
slides.
- 08.04.2014.
STL: map and hashmap. slides.
(If you downloaded these slides before 9 april, 10.00, download them again.)
-
15.04.2014.
A bit more about map and hashmap. Priority queues and how
to use them in search algorithms.
Slides.
Exceptions.
-
22.04.2014.
No lecture.
On 24.04.2014, there will be no lab.
-
29.04.2014.
Derived classes and inheritance. Slides.
-
06.05.2014.
Rest of derived classes and inheritance. Problems with derived classes and
polymorphic ownership. The solution is to define a wrapper class,
or to use unique_ptr< >.
I will not give a new task, because there will be no lab on thursday,
and many people are behind with exercises.
Try to catch up!
-
13.05.2014. Templates.
Slides.
-
20.05.2014. More about templates. Slides are the same
as last week. (But you should reload them , because I repaired
some mistakes on 20.05.2014, 20.25.)
(Defining flexible operators, issues with friendship,
specialization.)
-
27.05.2014.
Basics of 2D-computer graphics using OpenGL. A pixel contains
color + depth information. Clearing the screen is giving
every pixel the same color and depth. Selecting a
color. Drawing a line. Transformations.
A link to the red book.
-
03.06.2014.
Lambda Expressions: Slides.
-
10.06.2014.
Timing and threading.
Slides (somewhat unfinished).
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, but there is not much info on C++ 11 yet.
-
Homepage of Bjarne Stroustrup about
C++ 11.
I will freely use C++ 11 in exercises, because it is already 2014.
-
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,
assert.h,
main.cpp.
-
Exercise number 3.
-
Exercise number 4.
-
Number 5 .
You need the files in
nr05.
-
Exercise 6.
The main containers of STL (vector and list).
Use of iterators.
-
Exercise 7
about map and unordered_map.
-
Exercise 8
about solving the 15-puzzle, using unordered_map and
priority_queue.
You need these files.
On 22-24.04, there is no lab.
-
Exercise 9 about
inheritance.
-
Exercise 10 about templates.
-
Exercise 11 about polymorphic functions.
.
-
Exercise 12 about Conway's Game of Life.
You need these files.
(The printed version had the rules wrong.)
Grading
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