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

Vortragsfolien aktualisiert, Übungszettel

parent 2b38d87f
No related branches found
No related tags found
No related merge requests found
File moved
% ainf-uebung-20161003.pdf - Exercises on Low-Level Programming / Applied Computer Sciences
% hp-uebung-20161003.pdf - Exercises on Low-Level Programming / Applied Computer Sciences
% Copyright (C) 2013, 2015, 2016 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
......@@ -41,7 +41,8 @@
% \thispagestyle{empty}
\section*{Hardwarenahe Programmierung / Angewandte Informatik\\Übungsaufgaben -- 5.\ und 7.\ Oktober 2016}
\section*{Hardwarenahe Programmierung / Angewandte Informatik\\
Übungsaufgaben -- 5.\ und 7.\ Oktober 2016}
In den heutigen Übungsaufgaben geht es noch nicht um die
eigentlichen Inhalte (Programmieren in C), sondern darum,
......
No preview for this file type
......@@ -24,6 +24,7 @@
\usepackage{pgslides}
\usepackage{pdftricks}
\usepackage{tikz}
\newrgbcolor{orange}{0.7 0.2 0.0}
......@@ -46,7 +47,7 @@
\date{\begin{picture}(0,0)
\color{red}
\put(0.55,1.05){\makebox(0,0)[t]{$\underbrace{\rule{1.45cm}{0pt}}_{%
\put(0.65,1.05){\makebox(0,0)[t]{$\underbrace{\rule{1.45cm}{0pt}}_{%
\mbox{\emph{rerum naturalium\/} = der natürlichen Dinge (lat.)}}$}}
\end{picture}%
10.\ Oktober 2015}
......@@ -252,11 +253,11 @@
\end{frame}
\sectionnonumber{\inserttitle}
\nosectionnonumber{\inserttitle}
\begin{frame}
\showsectionnonumber
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
......@@ -275,8 +276,8 @@
\item[2.5] Verzweigungen
\item[2.6] Schleifen
\item[2.7] Seiteneffekte
\item[2.8] Strukturierte Programmierung
\item[\dots]
% \item[2.8] Strukturierte Programmierung
% \item[2.9] Funktionen
% \item[2.10] Zeiger
% \item[2.11] Arrays und Strings
......@@ -300,7 +301,6 @@
\begin{frame}[fragile]
\showsection
\pause
\showsubsection
Text ausgeben
......@@ -323,7 +323,6 @@
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{lstlisting}[style=terminal]
......@@ -337,7 +336,6 @@
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{lstlisting}[style=terminal]
......@@ -346,14 +344,27 @@
Hello, world!
$
\end{lstlisting}
\pause
\begin{picture}(0,0)
\color{red}
\put(3.0,0.5){\tikz{\draw[-latex](0.0,0.0)--(-3.0,1.0);}}
\put(4.0,0.3){\makebox(0,0)[tl]{\begin{minipage}[t]{6cm}
\begin{tabular}{ll}
\lstinline[style=cmd]{-Wall} & alle Warnungen einschalten\\
\lstinline[style=cmd]{-O} & optimieren\\
\lstinline[style=cmd]{-O3} & maximal optimieren\\
\lstinline[style=cmd]{-Os} & Codegröße optimieren\\[\smallskipamount]
\dots & gcc hat \emph{sehr viele\/} Optionen.
\end{tabular}
\end{minipage}}}
\end{picture}
\end{frame}
\subsection{Zahlenwerte ausgeben}
\subsection{Elementare Aus- und Eingabe}
\begin{frame}[fragile]
\showsection
\showsubsection
Wert ausgeben
......@@ -371,7 +382,7 @@
\end{lstlisting}
\begin{picture}(0,0)
\color{red}
\put(5.75,0.5){\vector(-1,1){0.5}}
\put(5.3,0.65){\tikz{\draw[-latex](0.0,0.0)--(-0.5,0.5);}}
\put(5.9,0.35){\begin{minipage}[t]{6cm}
Formatspezifikation "`d"': "`dezimal"'\pause\\[\smallskipamount]
Weitere Formatspezifikationen:\\
......@@ -383,11 +394,8 @@
\end{frame}
\subsection{Elementares Rechnen}
\begin{frame}[fragile]
\showsection
\showsubsection
Wert einlesen
......@@ -402,15 +410,14 @@
double a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%lf", &a);
a = 2 * a;
printf ("Das Doppelte der Zahl ist: %lf\n", a);
printf ("Ihre Antwort war: %lf\n", a);
return 0;
}
\end{lstlisting}
\begin{picture}(0,0)
\color{red}
\put(6.9,2.2){\vector(-1,0){3.5}}
\put(7.0,2.3){\begin{minipage}[t]{5cm}
\put(3.4,1.8){\tikz{\draw[-latex](0.0,0.0)--(-3.5,0);}}
\put(7.0,1.9){\begin{minipage}[t]{5cm}
Formatspezifikation "`lf"':\\
"`long floating-point"'
\end{minipage}}
......@@ -418,9 +425,10 @@
\end{frame}
\subsection{Elementares Rechnen}
\begin{frame}[fragile]
\showsection
\showsubsection
Wert an Variable zuweisen
......@@ -433,6 +441,7 @@
int main (void)
{
int a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%d", &a);
a = 2 * a;
printf ("Das Doppelte ist: %d\n", a);
......@@ -446,7 +455,6 @@
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{minipage}[t]{6cm}
......@@ -478,7 +486,6 @@
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{minipage}[t]{6cm}
......@@ -521,7 +528,6 @@
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{lstlisting}
......@@ -537,17 +543,16 @@
\pause
\begin{picture}(0,0)
\color{red}
\put(3.5,1.35){\vector(-1,0){1.7}}
\put(1.8,1.35){\tikz{\draw[-latex](0.0,0.0)--(-1.7,0);}}
\put(3.6,1.35){\makebox(0,0)[l]{Ausdruck als Anweisung: Wert wird ignoriert}}
\pause
\put(3.55,1.40){\vector(-2,1){0.4}}
\put(3.15,1.40){\tikz{\draw[-latex](0.0,0.0)--(-0.4,0.2);}}
\end{picture}
\end{frame}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{lstlisting}
......@@ -574,7 +579,6 @@
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{lstlisting}
......@@ -606,7 +610,6 @@
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{minipage}[t]{6cm}
......@@ -679,16 +682,14 @@
\end{frame}
\iftrue
\subsection{Strukturierte Programmierung}
\begin{frame}[fragile]
\showsection
\visible<2->{\showsubsection}
\visible<4->{\showsubsection}
\begin{minipage}[t]{6cm}
\begin{onlyenv}<3->
\begin{onlyenv}<2->
\begin{lstlisting}[gobble=8]
i = 0;
while (1)
......@@ -701,7 +702,7 @@
\end{onlyenv}
\strut
\bigskip
\begin{onlyenv}<4->
\begin{onlyenv}<3->
\begin{lstlisting}[gobble=8]
i = 0;
loop:
......@@ -767,383 +768,46 @@
\end{frame}
\subsection{Funktionen}
\begin{frame}[fragile]
\showsection
\showsubsection
\nosectionnonumber{\inserttitle}
\begin{minipage}[t]{6.5cm}
\vspace{-\medskipamount}
\begin{lstlisting}[gobble=6]
#include <stdio.h>
int answer (void)
{
return 42;
}
void foo (void)
{
printf ("%d\n", answer ());
}
int main (void)
{
foo ();
return 0;
}
\end{lstlisting}
\vspace*{-1cm}
\end{minipage}%
\begin{minipage}[t]{6cm}
\begin{itemize}
\pause
\item
Funktionsdeklaration:\\[\smallskipamount]
Typ Name ( Parameterliste )\\
\{\\
\quad Anweisungen\\
\}
\end{itemize}
\end{minipage}
\end{frame}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{minipage}[t]{6.5cm}
\vspace{-\medskipamount}
\begin{lstlisting}[gobble=6]
#include <stdio.h>
\begin{frame}
void add_verbose (int a, int b)
{
printf ("%d + %d = %d\n", a, b, a + b);
}
\shownosectionnonumber
int main (void)
{
add_verbose (3, 7);
return 0;
}
\end{lstlisting}
\end{minipage}%
\begin{minipage}[t]{6cm}
\begin{itemize}
\item
Funktionsdeklaration:\\[\smallskipamount]
Typ Name ( Parameterliste )\\
\{\\
\quad Anweisungen\\
\}
\pause
\bigskip
\item
Der Datentyp \lstinline{void}\\
steht für "`nichts"'\\
und \alt<3->{muß}{kann} ignoriert werden.
\end{itemize}
\end{minipage}
\end{frame}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{minipage}{6cm}
\begin{lstlisting}[gobble=6]
#include <stdio.h>
int a, b = 3;
void foo (void)
{
b++;
static int a = 5;
int b = 7;
printf ("foo(): "
"a = %d, b = %d\n",
a, b);
a++;
}
\end{lstlisting}
\end{minipage}%
\begin{minipage}{6cm}
\vspace{-1cm}
\begin{lstlisting}[gobble=6]
int main (void)
{
printf ("main(): "
"a = %d, b = %d\n",
a, b);
foo ();
printf ("main(): "
"a = %d, b = %d\n",
a, b);
a = b = 12;
printf ("main(): "
"a = %d, b = %d\n",
a, b);
foo ();
printf ("main(): "
"a = %d, b = %d\n",
a, b);
return 0;
}
\end{lstlisting}
\end{minipage}
\end{frame}
\subsection{Zeiger}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{lstlisting}
#include <stdio.h>
void calc_answer (int *a)
{
*a = 42;
}
int main (void)
{
int answer;
calc_answer (&answer);
printf ("The answer is %d.\n", answer);
return 0;
}
\end{lstlisting}
\pause
\vspace{-5cm}\hspace{5cm}%
\begin{minipage}{7cm}
\item[\textbf{1}] \textbf{Einführung}
\begin{itemize}
\item
\lstinline{*a} ist eine \lstinline{int}.
\pause
\item
unärer Operator \lstinline{*}:\\
Pointer-Dererefenzierung
\pause
\arrowitem
\lstinline{a} ist ein Zeiger (Pointer) auf eine \lstinline{int}.
\pause
\bigskip
\item
unärer Operator \lstinline{&}: Adresse
\color{medgreen}
\item[1.1] Was ist angewandte Informatik?
\item[1.2] Programmierung in C
\end{itemize}
\end{minipage}
\end{frame}
\subsection{Arrays und Strings}
\begin{frame}[fragile]
\showsection
\showsubsection
Ein Zeiger zeigt auf eine Variable\only<2->{ und deren Nachbarn}.
\bigskip
\pause
\pause
\begin{onlyenv}<1-9>
\begin{lstlisting}[gobble=6]
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11 };
int *p = prime, i = 0;
while (i < 5)
printf ("%d\n", *(p + i++));
return 0;
}
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<10->
\begin{lstlisting}[gobble=6]
#include <stdio.h>
int main (void)
{
int prime[5] = { 2, 3, 5, 7, 11 };
int i = 0;
while (i < 5)
printf ("%d\n", prime[i++]);
return 0;
}
\end{lstlisting}
\end{onlyenv}
\pause
\vspace{-3.05cm}\hspace{5.5cm}%
\begin{minipage}{6.5cm}
\item[\textbf{2}] \textbf{Einführung in C}
\begin{itemize}
\item
\lstinline{prime} ist \alt<5->{ein Array}{eine Ansammlung} von\\fünf ganzen Zahlen.
\pause
\pause
\item
\begin{picture}(0,0)
\color{medgreen}
\item[2.1] Hello, world!
\item[2.2] Programme compilieren und ausführen
\item[2.3] Zahlenwerte ausgeben
\item[2.4] Elementares Rechnen
\item[2.5] Verzweigungen
\item[2.6] Schleifen
\item[2.7] Seiteneffekte
\item[2.8] Strukturierte Programmierung
\color{red}
\put(-0.6,0.1){\vector(-1,0){1.0}}
\end{picture}%
\lstinline{prime} ist ein Zeiger auf eine \lstinline{int}.
\pause
\item
\lstinline{p + i} ist ein Zeiger\\
auf den \lstinline{i}-ten Nachbarn von \lstinline{*p}.
\pause
\item
\lstinline{*(p + i)} ist der \lstinline{i}-te Nachbar von \lstinline{*p}.
\pause
\item
Andere Schreibweise:\\
\lstinline{p[i]} statt \lstinline{*(p + i)}
\item[2.9] Funktionen
\item[2.10] Zeiger
\item[\dots]
% \item[2.11] Arrays und Strings
% \item[2.12] Strukturen
% \item[\dots]
\end{itemize}
\end{minipage}
\end{frame}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
char hello_world[] = "Hello, world!\n";
int i = 0;
while (hello_world[i] != 0)
printf ("%d", hello_world[i++]);
return 0;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
char hello_world[] = "Hello, world!\n";
int i = 0;
while (hello_world[i])
printf ("%d", hello_world[i++]);
return 0;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
char hello_world[] = "Hello, world!\n";
char *p = hello_world;
while (*p)
printf ("%d", *p++);
return 0;
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\showsection
\showsubsection
\begin{lstlisting}
#include <stdio.h>
int main (void)
{
char hello_world[] = "Hello, world!\n";
char *p = hello_world;
while (*p)
printf ("%c", *p++);
return 0;
}
\end{lstlisting}
\vspace{-1.7cm}\hspace{5cm}%
\begin{minipage}{7cm}
\begin{itemize}
\pause
\item
Ein \lstinline{char} ist eine kleinere \lstinline{int}.
\pause
\item
Ein "`String"' in C ist ein Array von \lstinline{char}s\only<4->{,\\
also ein Zeiger auf \lstinline{char}s}\only<5->{\\
also ein Zeiger auf (kleinere) Integer}.
\pause
\pause
\pause
\item
Die Formatspezifikation\\
entscheidet über die Ausgabe:\\[\smallskipamount]
\lstinline{%d}\quad dezimal\\
\lstinline{%x}\quad hexadezimal\\
\lstinline{%c}\quad Zeichen\\
\pause
\lstinline{%s}\quad String
\color{gray}
\item[\textbf{3}] \textbf{Bibliotheken}
\item[\textbf{\dots}]
% \item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
% \item[\textbf{5}] \textbf{Algorithmen}
% \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke}
\end{itemize}
\end{minipage}
\end{frame}
\fi
\sectionnonumber{Aufgaben}
\begin{frame}[c,fragile]
\showsectionnonumber
\begin{description}
\item[Aufgabe 1:] Multiplikationstabelle
Geben Sie mit Hilfe einer Schleife ein "`Einmaleins"' aus:
\begin{lstlisting}[style=terminal,gobble=8]
1 * 7 = 7
2 * 7 = 14
...
10 * 7 = 70
\end{lstlisting}
Hinweis: Verwenden Sie Formatspezifikationen wie z.\,B.\ \lstinline{%3d}\\
(siehe die Dokumentation zu \lstinline{printf()})
\item[Aufgabe 2:] Fibonacci-Zahlen berechnen
1.\ Zahl: 0\\
2.\ Zahl: 1\\
nächste Zahl = Summe der beiden vorherigen
\item[Aufgabe 3:] Schaltjahr ermitteln
Jahreszahl erfragen\\
Wenn die Zahl durch 4 teilbar ist, ist es ein Schaltjahr.\\
Wenn die Zahl durch 100 teilbar ist, ist es kein Schaltjahr.\\
Wenn die Zahl durch 400 teilbar ist,\\ist es doch wieder ein Schaltjahr.
\end{description}
\end{frame}
\end{document}
File added
% hp-uebung-20161010.pdf - Exercises on Low-Level Programming / Applied Computer Sciences
% Copyright (C) 2013, 2015, 2016 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/>.
\documentclass[a4paper]{article}
\usepackage{pgscript}
\usepackage{pdftricks}
\begin{psinputs}
\usepackage{pgscript}
\definecolor{PracticallyWhite}{rgb}{0.99 0.99 0.99}
\end{psinputs}
\newcounter{exercise}
\newcommand{\exercise}[1]{\addtocounter{exercise}{1}\subsection*{Aufgabe \arabic{exercise}: #1}}
\begin{document}
\thispagestyle{empty}
\section*{Hardwarenahe Programmierung / Angewandte Informatik\\
Übungsaufgaben -- 10.\ Oktober 2016}
\exercise{Multiplikationstabelle}
Geben Sie mit Hilfe einer Schleife ein "`Einmaleins"' aus.\\
Dabei sollen die Faktoren und Ergebnisse rechtsbündig untereinander stehen:
\begin{lstlisting}[style=terminal]
1 * 7 = 7
2 * 7 = 14
...
10 * 7 = 70
\end{lstlisting}
Hinweis: Verwenden Sie Formatspezifikationen wie z.\,B.\ \lstinline{%3d}\\
(siehe dazu die Dokumentation zu \lstinline{printf()},
z.\,B.\ \,\lstinline[style=cmd]{man 3 printf}\,)
\exercise{Fibonacci-Zahlen}
Die Folge der Fibonacci-Zahlen ist definiert durch:
\begin{quote}
1.\ Zahl: 0\\
2.\ Zahl: 1\\
nächste Zahl = Summe der beiden vorherigen
\end{quote}
Schreiben Sie ein Programm, das die ersten 50 Fibonacci-Zahlen ausgibt.
\exercise{Schaltjahr ermitteln}
Schreiben Sie ein Programm, das eine Jahreszahl erfragt
und ausgibt, ob es sich um ein Schaltjahr handelt.
\begin{itemize}
\item Wenn die Jahreszahl durch 4 teilbar ist, ist das Jahr zunächst einmal ein Schaltjahr.
\item Ausnahme: Wenn die Jahreszahl durch 100 teilbar ist, ist das Jahr kein Schaltjahr.
\item Ausnahme von der Ausnahme: Wenn die Jahreszahl durch 400 teilbar ist,\\
ist das Jahr doch wieder ein Schaltjahr.
\end{itemize}
\exercise{Hello, world!}
Unter \url{https://gitlab.cvh-server.de/pgerwinski/cpp/tree/master/20161010}
finden Sie (unter anderem)\\
die Programme \file{test-1.c} bis \file{test-5.c}.
\begin{itemize}
\item
Was bewirken diese Programme?
\item
Begründen Sie jeweils, warum sich das Programm
in der beschriebenen Weise verhält.
\end{itemize}
Formulieren Sie Ihre Beschreibungen und Begründungen so,
daß jemand, der Ihre Klausur korrigiert,
allein anhand Ihrer Texte erkennen kann,
daß Sie die Zusammenhänge verstanden haben.
\end{document}
../common/pgscript.sty
\ No newline at end of file
......@@ -207,6 +207,11 @@
\def\showsectionnonumber{\hbox{\Large\color{structure}\bf
\vtop{\secname}\par}\bigskip}
\newcommand{\nosectionnonumber}[1]{\gdef\nosectionnonumbername{#1}}
\def\shownosectionnonumber{\hbox{\Large\color{structure}\bf
\vtop{\nosectionnonumbername}\par}\bigskip}
\def\showsection{\hbox{\Large\color{structure}\bf
\vtop{\hbox{\arabic{section}}}\kern1em%
\vtop{\secname}\par}\bigskip}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment