Commit b5cb8843 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

lecture notes updated after merged several corrections

parent 97e7d63c
......@@ -161,43 +161,6 @@ and the official standard
\url{http://www.open-std.org/jtc1/sc22/wg21/}
\section{Programming paradigms}
\emph{Programming paradigms}\footnote{\url{https://en.wikipedia.org/wiki/Programming_paradigm}} are a way to classify programming languages
based on their features. Languages can be classified into multiple paradigms. Some common programming paradigms include:
\begin{enumerate}
\item \emph{imperative} in which the programmer instructs the machine how to change its state,
\begin{enumerate}
\item \emph{procedural} which groups instructions into procedures, (Fortran, C, Pascal)
\item \emph{object-oriented} which groups instructions together with the part of the state they operate on, (Java, C++)
\end{enumerate}
\item \emph{declarative} in which the programmer declares properties of the desired result, but not how to compute it
\begin{enumerate}
\item \emph{functional} in which the desired result is declared as the value of a series of function applications, (Haskell, Scheme)
\item \emph{logic} in which the desired result is declared as the answer to a question about a system of facts and rules. (ALF, Curry)
\end{enumerate}
\end{enumerate}
Some programming languages are referred to as multi-paradigm programming languages. A concise reference\footnote{\url{https://en.wikipedia.org/wiki/Comparison_of_multi-paradigm_programming_languages}} for the programming
paradigms that are supported directly (or by a library implementation) of C++ include
\begin{description}
\item[Concurrent programming] have language constructs for concurrency, these may involve multi-threading, support for distributed computing, message passing, shared resources (including shared memory), or futures
\item[Constraint programming] relations between variables are expressed as constraints (or constraint networks), directing allowable solutions (uses constraint satisfaction or simplex algorithm)
\item[Dataflow programming] forced recalculation of formulas when data values change (\eg spreadsheets)
\item[Declarative programming] describes what a computation should perform, without specifying detailed state changes c.f. imperative programming (functional and logic programming are major subgroups of declarative programing)
\item[Distributed programming] have support for multiple autonomous computers that communicate via computer networks
\item[Functional programming] uses evaluation of mathematical functions and avoids state and mutable data
\item[Generic programming] uses algorithms written in terms of to-be-specified-later types that are then instantiated as needed for specific types provided as parameters
\item[Imperative programming] explicit statements that change a program state
\item[Logic programming] uses explicit mathematical logic for programming
\item[Metaprogramming] writing programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at compile time that would otherwise be done at runtime
\item[Object-oriented programming] uses data structures consisting of data fields and methods together with their interactions (objects) to design programs
\item[Pipeline programming] a simple syntax change to add syntax to nest function calls to language originally designed with none
\item[Rule-based programming] a network of rules of thumb that comprise a knowledge base and can be used for expert systems and problem deduction and resolution
\end{description}
Just a few other programming languages are listed on Wikipedia that have a similarly long list (Haskell, Julia, Mathematica).
\section{History of C++}
The programming language has a long history, that is described in the books by Bjarne Stroustrup: \emph{The Design and Evolution of C++, 1994},
\url{http://www.stroustrup.com/hopl2.pdf} (\emph{A History of C++: 1979--1991}) and \url{http://www.stroustrup.com/hopl-almost-final.pdf}
......@@ -225,12 +188,12 @@ user-controlled free-storage memory control, improved type checking. A long list
around \textbf{1986-1987}.
A first reference manual, \textit{The C++ programming language}, was written in the year \textbf{1985}, and later in \textbf{1990} the book
\textit{The Annotated C++ Reference Manual}. The language was not yet standardized. So, the book are kind of the standard reference manuals.
\textit{The Annotated C++ Reference Manual}. The language was not yet standardized. So, the books are kind of the standard reference manuals.
During these days other compiler vendors published a C++ compiler, like the \textit{Borland C++ Compiler} and in \textbf{1987} C++ was added
to the GNU Compiler Collection GCC.
\subsection{Standard C++}
The first ISO standard of C++ was published in the year \textbf{1998}, also called \cxx{98} standard. Fron that release on, the C++ versions are
The first ISO standard of C++ was published in the year \textbf{1998}, also called \cxx{98} standard. From that release on, the C++ versions are
named after the publication year of the standard document. Around \textbf{1979} an accompanying library was developed, providing standard
containers and algorithms. This library, known as the standard library, later became part of the C++ standard. During the year \textbf{1999}
the collection \emph{Boost} was founded by some standard committee members, to push the development of standard library components.
......
......@@ -307,7 +307,7 @@ Some remarks to the examples above:
top of the include file. This directive is supported by all major compilers and can be used without any problems.
\item If you want to (or have to) provide an implementation of a function or class method in a header file, it must be included together with
the corresponding declaration. Often, since is done my an include statement at the end of the header file. Or the definition is provided
the corresponding declaration. Often this is done my an include statement at the end of the header file. Or the definition is provided
together with the declaration.
\end{itemize}
......@@ -351,7 +351,7 @@ initialization:
% -------------------------------------------------------------------------------------------------
\subsection{Literals\label{sec:literal}}
A literal is a tokes directly representing a constant value of a concrete type.
A literal is a token directly representing a constant value of a concrete type.
Examples:
\begin{minted}{c++}
......@@ -383,7 +383,7 @@ where the implementer is responsible for giving those literals a meaning.
\begin{rem}
A literal is a \textit{primary expression}. Its type depends on its form (see above). A string literal is an \Index{lvalue}; all other
literals are \Index{prvalues}.
literals are \Index{prvalues} (see chapter about value categories).
\end{rem}
......@@ -426,12 +426,17 @@ A fundamental rule is that you are not allowed to define an object twice. While
type, or template.
\end{standard}
\begin{guideline}{Principle}
Declare variables as late as possible, usually right before using them the first time and whenever possible not before you can initialize them.
\end{guideline}
% -------------------------------------------------------------------------------------------------
\subsection{Fundamental Types\label{sec:fundamental-type}}
We have seen already some types in the examples above, like integer types and floating-point types. There are more fundamental data-types
available in C++. A summary can be found at \url{http://en.cppreference.com/w/cpp/language/types}.
Basic types in C++ a categorized into three groups: integral types, floating-point types, and \cpp{void}. Integral type represent integer numbers, while floating-point type might represent fractions.
Basic types in C++ are categorized into three groups: integral types, floating-point types, and \cpp{void}. Integral types represent integer numbers, while floating-point types might represent fractions.
The type \cpp{void} represents the empty set of values. No variable can be declared of type \cpp{void}. Thus, \cpp{void} is an \emph{incomplete type}. It is used as the return type for functions that do not return a value. Any expression can be explicitly converted to type \cpp{void}.
......@@ -504,7 +509,7 @@ Literals, to indicate how to interpret a number, are \texttt{F,f,L,l} for \cpp{f
\end{rem}
\begin{rem}
To do arithmetic with arbitrary precision, there a multiple libraries available. Examples include \href{https://gmplib.org/}{GNU GMP}
To do arithmetic with arbitrary precision, there are multiple libraries available. Examples include \href{https://gmplib.org/}{GNU GMP}
(Gnu MultiPrecision Arithmetic Library) and \href{https://www.boost.org/doc/libs/1_71_0/libs/multiprecision/doc/html/index.html}{Boost.Multiprecision} library.
An example of high precision calculation of the enclosed area of a circle with boost multiprecision is given below. Note, it uses templates to
......@@ -550,18 +555,13 @@ int main()
\begin{rem}
Arithmetic with floating-point number is not the same as arithmetic with real $\mathbb{R}$ numbers. There are effects of rounding,
Arithmetic with floating-point numbers is not the same as arithmetic with real $\mathbb{R}$ numbers. There are effects of rounding,
finite representation, cancellation, non-associativity, $\ldots$. Details can be found in the standard document
\href{https://standards.ieee.org/content/ieee-standards/en/standard/754-2019.html}{IEEE 754} and are explained in the lecture
\emph{Computer Arithmetics} by Prof. W. Walter.
\end{rem}
\begin{guideline}{Principle}
Declare variables as late as possible, usually right before using them the first time and whenever possible not before you can initialize them.
\end{guideline}
\subsection{Number conversion}
Whenever you initialize a variable with an expression, the value of that expression must be converted to the type of the variable.
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment