Skip to content
Snippets Groups Projects
Commit dfd85e82 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Vortragsfolien und Beispielprogramme 23.4.2018

parent 92f68773
Branches
No related tags found
No related merge requests found
Showing
with 582 additions and 0 deletions
../common/Zeichen_123.pdf
\ No newline at end of file
File added
% ad-20180423.pdf - Lecture Slides on Algorithms and Data Structures in C/C++
% Copyright (C) 2018 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Einführung in C++, Objekte
\documentclass[10pt,t]{beamer}
\usepackage{pgslides}
\usepackage{tikz}
\usepackage{soul}
\newcommand{\underconstruction}{%
\begin{picture}(0,0)
\color{black}
\put(7,-2.2){\makebox(0,0)[b]{\includegraphics[width=1.5cm]{Zeichen_123.pdf}}}
\put(7,-2.5){\makebox(0,0)[t]{\shortstack{Änderungen\\vorbehalten}}}
\end{picture}}
\title{Algorithmen und Datenstrukturen in C/C++}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{23.\ April 2018}
\begin{document}
\maketitleframe
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\underconstruction
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad.git}}}
\item[\textbf{2}] \textbf{Einführung in C++}
\item[\textbf{3}] \textbf{Datenorganisation}
\begin{itemize}
\item Listen, Bäume, Hash-Tabellen, \dots
\end{itemize}
\item[\textbf{4}] \textbf{Datenkodierung}
\begin{itemize}
\item Fehlererkennung und -korrektur
\item Kompression
\item Kryptographie
\end{itemize}
\item[\textbf{5}] \textbf{Hardwarenahe Algorithmen}
\begin{itemize}
\item FFT, CORDIC, \dots
\end{itemize}
\item[\textbf{6}] \textbf{Optimierung}
\begin{itemize}
\item Wegfindung, \dots
\end{itemize}
\color{gray}
\item[\textbf{7}] \textbf{Numerik}
\end{itemize}
\end{frame}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\underconstruction
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad.git}}}
\item[\textbf{2}] \textbf{Einführung in C++}
\begin{itemize}
\vspace*{-\smallskipamount}
\item[\dots]
\item[2.3] Referenz-Typen
\item[2.4] Überladbare Operatoren und Funktionen
\color{medgreen}
\item[2.5] Namensräume
\item[2.6] Objekte
\color{red}
\item[2.7] Strings
\item[2.8] Templates
\item[2.9] Exceptions
\end{itemize}
\item[\textbf{3}] \textbf{Datenorganisation}
% \begin{itemize}
% \item Listen, Bäume, Hash-Tabellen, \dots
% \end{itemize}
\item[\textbf{4}] \textbf{Datenkodierung}
% \begin{itemize}
% \item Fehlererkennung und -korrektur
% \item Kompression
% \item Kryptographie
% \end{itemize}
\item[\textbf{5}] \textbf{Hardwarenahe Algorithmen}
% \begin{itemize}
% \item FFT, CORDIC, \dots
% \end{itemize}
\item[\textbf{6}] \textbf{Optimierung}
% \begin{itemize}
% \item Wegfindung, \dots
% \end{itemize}
\color{gray}
\item[\textbf{7}] \textbf{Numerik}
\end{itemize}
\end{frame}
\setcounter{section}{1}
\section{Einführung in C++}
\setcounter{subsection}{4}
\subsection{Namensräume}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello, world!" << endl;
return 0;
}
\end{lstlisting}
% \pause
\bigskip
\begin{lstlisting}
namespace my_output
{
...
}
using namespace my_output;
\end{lstlisting}
\end{frame}
\subsection{Objekte}
\begin{frame}[fragile]
\showsubsection
\begin{center}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
¡struct TBase
{
};¿
\end{lstlisting}
\end{minipage}\\[0.5cm]
\begin{minipage}{6cm}
\begin{lstlisting}[gobble=8]
¡struct TInteger: public TBase
{
int content;
};¿
\end{lstlisting}
\end{minipage}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
¡struct TString: public TBase
{
char *content;
};¿
\end{lstlisting}
\end{minipage}
\end{center}
\end{frame}
\addtocounter{subsection}{-1}
\subsection{Objekte: Zugriffsrechte}
\begin{frame}[fragile]
\showsubsection
\begin{itemize}
\item
\lstinline{public}, \lstinline{private}, \lstinline{protected}\\[\smallskipamount]
nicht nur Bürokratie, sondern auch Kapselung\\
(Maßnahme gegen "`Namensraumverschmutzung"')
\medskip
\item
\lstinline{struct}: standardmäßig \lstinline{public}\\[\smallskipamount]
\lstinline{class}: standardmäßig \lstinline{private}
\medskip
\item
\lstinline{friend}-Funktionen und -Klassen
\medskip
\item
Klasse als Namensraum:\\
\lstinline{static}-"`Member"'-Variable\\
\lstinline{static}-"`Methoden"'\\
Deklarationen von z.\,B.\ Konstanten und Typen
\end{itemize}
\end{frame}
\addtocounter{subsection}{-1}
\subsection{Objekte: Konstruktoren und Destruktoren}
\begin{frame}[fragile]
\showsubsection
\begin{itemize}
\item
leerer Standard-Konstrutor
\item
\newterm{Copy-Konstruktor}
\item
Konstruktor-Aufruf als "`Initialisierung"'
\item
Konstruktor-Aufruf mit \lstinline{new}\\
Destruktor-Aufruf mit \lstinline{delete}
\item
automatischer Destruktor-Aufruf\\
beim Verlassen des Gültigkeitsbereichs
\end{itemize}
\end{frame}
\subsection{Strings}
\begin{frame}[fragile]
\showsubsection
\begin{itemize}
\item
\lstinline{#include <string>}
\item
String-Klasse
\item
String-Konstante sind \lstinline{const char *}
\item
C-kompatiblen String extrahieren: \lstinline{c_str ()}
\item
In String schreiben: \lstinline{#include <sstream>}, \lstinline{ostringstream}
\end{itemize}
\end{frame}
\subsection{Templates}
\begin{frame}[fragile]
\showsubsection
Anwendung desselben Quelltextes auf verschiedene Datentypen
\begin{itemize}
\item
\lstinline{template <typename x> ...}
\item
\lstinline{template <class x> ...}
\end{itemize}
\pause
Vorsicht: Fehler werden erst bei Instantiierung erkannt!
\pause
\begin{itemize}
\item
Template-Spezialisierung:\\
\lstinline{template <> foo <int> ...}
\end{itemize}
\end{frame}
\subsection{Exceptions}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
try
{
...
throw <value>;
...
}
catch (<type> <variable>)
{
...
}
catch ...
\end{lstlisting}
\vspace*{-4.6cm}\hspace*{5cm}
\begin{minipage}{7cm}
\begin{itemize}
\item
Nach den \lstinline{catch()}-Statements wird,
soweit nicht anders programmiert, das Programm fortgesetzt.
\medskip
\item
\lstinline{throw;} (ohne Wert):\\
an übergeordneten Exception-Handler weiterreichen
\medskip
\item
C-Äquivalent:\\
\lstinline{setjmp()}, \lstinline{longjmp()}
\medskip
\item
speziell für \lstinline{<type>}:\\
Nachfahren von \lstinline{class exception}
\medskip
\item
veraltet:\\
\newterm{dynamic exception specifications}
\end{itemize}
\end{minipage}
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\underconstruction
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad.git}}}
\item[\textbf{2}] \textbf{Einführung in C++}
\begin{itemize}
\vspace*{-\smallskipamount}
\item[\dots]
\item[2.5] Namensräume
\item[2.6] Objekte
\color{medgreen}
\item[2.7] Strings
\item[2.8] Templates
\item[2.9] Exceptions
\end{itemize}
\item[\textbf{3}] \textbf{Datenorganisation}
\begin{itemize}
\item Listen, Bäume, Hash-Tabellen, \dots
\end{itemize}
\item[\textbf{4}] \textbf{Datenkodierung}
% \begin{itemize}
% \item Fehlererkennung und -korrektur
% \item Kompression
% \item Kryptographie
% \end{itemize}
\item[\textbf{5}] \textbf{Hardwarenahe Algorithmen}
% \begin{itemize}
% \item FFT, CORDIC, \dots
% \end{itemize}
\item[\textbf{6}] \textbf{Optimierung}
% \begin{itemize}
% \item Wegfindung, \dots
% \end{itemize}
\color{gray}
\item[\textbf{7}] \textbf{Numerik}
\end{itemize}
\end{frame}
\end{document}
#include <iostream>
using namespace std;
int main ()
{
try
{
int a = 42;
int b = 0;
if (b == 0)
throw "Ganzzahldivision durch Null";
int c = a / b;
cout << "c = " << c << endl;
}
catch (const char *msg)
{
cout << "Irgendwas ist schiefgelaufen: " << msg << endl;
}
return 0;
}
#include <iostream>
using namespace std;
void check_answer (int answer)
{
if (answer != 42)
{
try
{
if (answer == 10)
throw answer;
else if (answer == 137)
throw "alpha";
}
catch (int e)
{
cout << "Yeah!" << endl;
throw;
}
throw "bullshit";
}
}
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 23)
throw answer;
else
check_answer (answer);
}
catch (const char *e)
{
cout << "caught string exception: " << e << endl;
}
cout << "And what was the question?" << endl;
return 0;
}
../common/logo-hochschule-bochum-cvh-text.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
../common/pgslides.sty
\ No newline at end of file
#include <string>
int main ()
{
string hello = "Hello, world!";
std::cout << hello << std::endl;
return 0;
}
#include <stdio.h>
#include <string>
using std::string;
void print (char *s)
{
printf ("%s\n", s);
}
int main ()
{
string hello = "Hello, world!";
print (hello.c_str ());
return 0;
}
#include <stdio.h>
#include <string>
using std::string;
void print (const char *s)
{
printf ("%s\n", s);
}
int main ()
{
string hello = "Hello, world!";
print (hello.c_str ());
return 0;
}
#include <stdio.h>
int main ()
{
char buffer[42];
sprintf (buffer, "The answer is: %d.", 42);
printf ("%s\n", buffer);
return 0;
}
#include <stdio.h>
int main ()
{
char buffer[4];
sprintf (buffer, "The answer is: %d.", 42);
printf ("%s\n", buffer);
return 0;
}
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
stringstream buffer;
int answer = 42;
buffer << "The answer is: " << answer << ".";
cout << buffer << endl;
return 0;
}
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
stringstream buffer;
int answer = 42;
buffer << "The answer is: " << answer << ".";
cout << buffer.str () << endl;
return 0;
}
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
stringstream buffer;
int answer = 42;
buffer << "The answer is: " << answer << ".";
printf ("%s\n", buffer.str ());
return 0;
}
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
stringstream buffer;
int answer = 42;
buffer << "The answer is: " << answer << ".";
printf ("%s\n", buffer.str ().c_str ());
return 0;
}
#include <stdio.h>
#include <string>
using namespace std;
int main ()
{
string HexDigit = "0123456789abcdef";
printf ("%c", HexDigit[10]);
printf ("%c", HexDigit[15]);
printf ("%c", HexDigit[15]);
printf ("%c", HexDigit[14]);
printf ("\n");
return 0;
}
#include <stdio.h>
#include <string>
using namespace std;
int main ()
{
string hello = "Hello, world!";
printf ("%s\n", hello.substr (0, 4).c_str ());
return 0;
}
#include <iostream>
#include <string>
int main ()
{
string hello = "Hello, world!";
std::cout << hello << std::endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment