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

Vorbereitung 19.11.2018

parent 0b9ec04b
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Bibliotheken, Differentialgleichungen
% README: Einführung: Bibliotheken, Differentialgleichungen
\documentclass[10pt,t]{beamer}
......
#include <stdio.h>
void f (int *s0, int *s1)
{
while (*s0 >= 0)
{
int *s = s1;
while (*s >= 0)
if (*s0 == *s++)
printf ("%d ", *s0);
s0++;
}
printf ("\n");
}
int main (void)
{
int a[] = { 10, 4, 3, 7, 12, 0, 1, -1 };
int b[] = { 7, 14, 0, 8, 9, 22, 10, -1 };
f (a, b);
return 0;
}
#include <stdio.h>
void f (int *s0, int *s1)
{
while (*s0 >= 0)
{
int *s = s1;
while (*s >= 0)
if (*s0 == *s++)
printf ("%d ", *s0);
s0++;
}
printf ("\n");
}
int main (void)
{
int a[] = { 10, 4, 3, 7, 12, 0, 1 };
int b[] = { 7, 14, 0, 8, 9, 22, 10 };
f (a, b);
return 0;
}
#include <gtk/gtk.h>
#define WIDTH 320
#define HEIGHT 240
double t = 0.0;
double dt = 0.2;
int r = 5;
double x = 10;
double y = 200;
double vx = 20;
double vy = -60;
double g = 9.81;
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
gdk_cairo_set_source_rgba (c, &blue);
cairo_arc (c, x, y, r, 0, 2 * G_PI);
cairo_fill (c);
return FALSE;
}
gboolean timer (GtkWidget *widget)
{
t += dt;
x += vx * dt;
y += vy * dt;
vx = vx;
vy = 0.5 * g * (t * t);
if (y + r >= HEIGHT)
vy = -vy * 0.9;
if (x + r >= WIDTH)
vx = -vx * 0.9;
if (x - r <= 0)
vx = -vx * 0.9;
gtk_widget_queue_draw_area (widget, 0, 0, WIDTH, HEIGHT);
g_timeout_add (50, (GSourceFunc) timer, widget);
return FALSE;
}
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_show (drawing_area);
gtk_container_add (GTK_CONTAINER (window), drawing_area);
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
gtk_main ();
return 0;
}
File added
% hp-20181119.pdf - Lecture Slides on Low-Level Programming
% Copyright (C) 2012, 2013, 2015, 2016, 2017, 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: Vertiefung: Bibliotheken, Differentialgleichungen
\documentclass[10pt,t]{beamer}
\usepackage{pgslides}
\usepackage{pdftricks}
\usepackage{tikz}
\begin{psinputs}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage{pstricks,pst-grad}
\end{psinputs}
\title{Hardwarenahe Programmierung}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{19.\ November 2018}
\begin{document}
\maketitleframe
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/hp.git}}}
\item[\textbf{2}] \textbf{Einführung in C}
\begin{itemize}
% \item[2.1] Hello, world!
\vspace*{-0.1cm}
\item[\dots]
\item[2.15] String-Operationen
\end{itemize}
\item[\textbf{3}] \textbf{Bibliotheken}
\begin{itemize}
\color{orange}
\item[3.1] Der Präprozessor
\color{medgreen}
\item[3.2] Bibliotheken einbinden
\color{orange}
\item[3.3] Bibliotheken verwenden
\color{red}
\item[3.4] Projekt organisieren: make
\end{itemize}
\item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
\item[\textbf{5}] \textbf{Algorithmen}
\begin{itemize}
\color{medgreen}
\item[5.1] Differentialgleichungen
\color{black}
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\item[\textbf{\dots}]
% \item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
% \item[\textbf{5}] \textbf{Algorithmen}
% \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke}
\end{itemize}
\vspace*{-1cm}
\end{frame}
\setcounter{section}{2}
\section{Bibliotheken}
\subsection{Der Präprozessor}
\begin{frame}[fragile]
\showsection
\showsubsection
\lstinline{#include}: %\pause:
Text einbinden
\begin{itemize}
% \pause
\item
\lstinline{#include <stdio.h>}: Standard-Verzeichnisse -- Standard-Header
% \pause
\item
\lstinline{#include "answer.h"}: auch aktuelles Verzeichnis -- eigene Header
\end{itemize}
\pause
\bigskip
\lstinline{#define VIER 4}: Text ersetzen lassen -- Konstante definieren
\begin{itemize}
\pause
\item
Kein Semikolon!
\pause
\item
Berechnungen in Klammern setzen:\\
\lstinline{#define VIER (2 + 2)}
\pause
\item
Konvention: Großbuchstaben
\end{itemize}
\end{frame}
\subsection{Bibliotheken einbinden}
\begin{frame}[fragile]
\showsection
\showsubsection
Inhalt der Header-Datei: externe Deklarationen
% \pause
\smallskip
\lstinline{extern int answer (void);}
% \pause
\smallskip
\lstinline{extern int printf (__const char *__restrict __format, ...);}
% \pause
\bigskip
Funktion wird "`anderswo"' definiert
\begin{itemize}
% \pause
\item
separater C-Quelltext: mit an \lstinline[style=terminal]{gcc} übergeben
% \pause
\item
Zusammenfügen zu ausführbarem Programm durch den \newterm{Linker}
% \pause
\item
vorcompilierte Bibliothek: \lstinline[style=terminal]{-lfoo}\\
% \pause
= Datei \file{libfoo.a} in Standard-Verzeichnis
\end{itemize}
\end{frame}
\subsection{Bibliothek verwenden (Beispiel: GTK+)}
\begin{frame}[fragile]
\showsubsection
\begin{itemize}
\item
\lstinline{#include <gtk/gtk.h>}
\pause
\smallskip
\item
Mit \lstinline[style=cmd]{pkg-config --cflags --libs} erfährt man,\\
welche Optionen und Bibliotheken man an \lstinline[style=cmd]{gcc}
übergeben muß\alt<4->{.}{:}
\pause
\begin{onlyenv}<3>
\begin{lstlisting}[style=terminal,gobble=10]
$ ¡pkg-config --cflags --libs gtk+-3.0¿
-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-
atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1
.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/
include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/inc
lude/cairo -I/usr/include/pango-1.0 -I/usr/include/harf
buzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I
/usr/include/cairo -I/usr/include/pixman-1 -I/usr/inclu
de/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk
-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib
-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtk
-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcai
ro-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject
-2.0 -lglib-2.0
\end{lstlisting}
\vspace*{-1cm}
\end{onlyenv}
\pause
\arrowitem
Compiler-Aufruf:
\begin{onlyenv}<4>
\begin{lstlisting}[style=terminal,gobble=10]
$ ¡gcc -Wall -O hello-gtk.c -pthread -I/usr/include/gtk
-3.0 -I/usr/include/at-spi2- atk/2.0 -I/usr/include/at-
spi-2.0 -I/usr/include/dbus-1 .0 -I/usr/lib/x86_64-linu
x-gnu/dbus-1.0/include -I/usr/ include/gtk-3.0 -I/usr/i
nclude/gio-unix-2.0/ -I/usr/inc lude/cairo -I/usr/inclu
de/pango-1.0 -I/usr/include/harf buzz -I/usr/include/pa
ngo-1.0 -I/usr/include/atk-1.0 -I /usr/include/cairo -I
/usr/include/pixman-1 -I/usr/inclu de/freetype2 -I/usr/
include/libpng16 -I/usr/include/gdk -pixbuf-2.0 -I/usr/
include/libpng16 -I/usr/include/glib -2.0 -I/usr/lib/x8
6_64-linux-gnu/glib-2.0/include -lgtk -3 -lgdk-3 -lpang
ocairo-1.0 -lpango-1.0 -latk-1.0 -lcai ro-gobject -lcai
ro -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject -2.0 -lglib-2.0
-o hello-gtk¿
\end{lstlisting}
\vspace*{-1cm}
\end{onlyenv}
\begin{onlyenv}<5->
\begin{lstlisting}[style=terminal,gobble=10]
$ ¡gcc -Wall -O hello-gtk.c $(pkg-config --cflags --libs)
-o hello-gtk¿
\end{lstlisting}
\end{onlyenv}
\end{itemize}
\pause[6]
\begin{picture}(0,0)
\color{red}
\put(6.6,-0.6){\makebox(0,0)[bl]{\tikz{\draw[-latex](0,0)--(3,1.5);}}}
\put(6.3,-0.7){\makebox(0,0)[t]{\shortstack{\strut Optionen:\\
\strut u.\,a.\ viele Include-Verzeichnisse:\\
\lstinline[style=cmd]{-I/usr/include/gtk-3.0}}}}
\put(10.0,-2.1){\makebox(0,0)[bl]{\tikz{\draw[-latex](0,0)--(1.5,3);}}}
\put(10.3,-2.2){\makebox(0,0)[t]{\shortstack{\strut Bibliotheken:\\
\strut u.\,a.\ \lstinline[style=cmd]{-lgtk-3 -lcairo}}}}
\end{picture}
\end{frame}
\begin{frame}[fragile]
\showsubsection
Selbst geschriebene Funktion übergeben: \newterm{Callback}
\bigskip
\begin{lstlisting}[xleftmargin=1em]
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
/* Zeichenbefehle */
...
return FALSE;
}
...
g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL);
\end{lstlisting}
\medskip
\begin{itemize}
\arrowitem
GTK+ ruft immer dann, wenn es etwas zu zeichnen gibt,\\
die Funktion \lstinline{draw} auf.
\end{itemize}
\pause
\begin{picture}(0,0)
\color{red}
\put(5.3,4.8){\makebox(0,0)[bl]{\tikz{\draw[-latex](0,0)--(1.90,1.15);}}}
\put(5.0,4.7){\makebox(0,0)[t]{\shortstack{\strut repräsentiert den\\
\strut Bildschirm, auf den\\
\strut gezeichnet werden soll}}}
\pause
\put(9.7,5.1){\makebox(0,0)[br]{\tikz{\draw[-latex](0,0)--(-0.2,0.85);}}}
\put(9.7,5.0){\makebox(0,0)[t]{\shortstack{\strut optionale Zusatzinformationen\\
\strut für draw(), typischerweise\\
\strut ein Zeiger auf ein struct}}}
\put(10.0,3.5){\makebox(0,0)[tl]{\tikz{\draw[-latex](0,0)--(0.6,-1.25);}}}
\end{picture}
\end{frame}
\begin{frame}[fragile]
\showsubsection
Selbst geschriebene Funktion übergeben: \newterm{Callback}
\bigskip
\begin{lstlisting}[xleftmargin=1em]
gboolean timer (GtkWidget *widget)
{
/* Rechenbefehle */
...
gtk_widget_queue_draw_area (widget, 0, 0, WIDTH, HEIGHT);
g_timeout_add (50, (GSourceFunc) timer, widget);
return FALSE;
}
...
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
\end{lstlisting}
\medskip
\begin{itemize}
\arrowitem
GTK+ ruft nach 50 Millisekunden
die Funktion \lstinline{timer} auf.
\end{itemize}
\pause
\begin{picture}(0,0)
\color{red}
\put(9.7,6.7){\makebox(0,0)[t]{\shortstack{\strut Dieser Bereich soll\\
\strut neu gezeichnet werden.}}}
\put(9.7,5.7){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-0.6,-0.8);}}}
\pause
\put(4.3,3.2){\makebox(0,0)[br]{\tikz{\draw[-latex](0,0)--(-0.7,0.6);}}}
\put(4.3,3.1){\makebox(0,0)[t]{\shortstack{\strut In weiteren 50 Millisekunden soll\\
\strut die Funktion erneut aufgerufen werden.}}}
\pause
\put(9.3,2.9){\makebox(0,0)[br]{\tikz{\draw[-latex](0,0)--(-3.3,0.9);}}}
\put(9.8,2.8){\makebox(0,0)[t]{\shortstack{\strut Explizite Typumwandlung\\
\strut eines Zeigers (später)}}}
\end{picture}
\end{frame}
\setcounter{section}{4}
\section{Algorithmen}
\subsection{Differentialgleichungen}
\begin{frame}[fragile]
\showsection
\showsubsection
\textbf{Beispiel 1: Gleichmäßig beschleunigte Bewegung}
\begin{center}
\includegraphics[width=\textwidth,trim={0cm 7cm 0cm 0cm},clip]{../20181112/photo-20181112-173737.jpg}
\end{center}
\end{frame}
\begin{frame}[fragile]
\showsection
\showsubsection
\textbf{Beispiel 1: Gleichmäßig beschleunigte Bewegung}
\strut\hfill
\begin{minipage}{2.5cm}
\vspace*{0.6cm}
\begin{align*}
x'(t) &= v_x(t) \\[0.65cm]
y'(t) &= v_y(t) \\[0.75cm]
v_x'(t) &= 0 \\[0.65cm]
v_y'(t) &= -g
\end{align*}
\vspace*{0.0cm}
\end{minipage}%
\only<1>{\hspace*{9.49cm}}\strut
\only<2->{\hfill$\Rightarrow$\hfill}%
\begin{onlyenv}<2-8>
\begin{minipage}{8.3cm}
\begin{align*}
x(t) &= \int v_x(t)\,dt
\visible<4->{= \int v_{0x}\,dt}
\visible<5->{= x_0 + v_{0x}\cdot t}\\[\medskipamount]
y(t) &= \int v_y(t)\,dt
\visible<7->{= \int v_{0y} + g\cdot t\,dt}
\visible<8->{= y_0 + v_{0y}\cdot t
- {\textstyle\frac12}gt^2}\\[\bigskipamount]
v_x(t) &= \int 0\,dt
\visible<3->{= v_{0x}} \\[\medskipamount]
v_y(t) &= \int -g\,dt
\visible<6->{= v_{0y} - g\cdot t}
\end{align*}
\end{minipage}%
\end{onlyenv}%
\begin{onlyenv}<9->
\begin{minipage}{3.5cm}
\vspace*{0.5cm}
\begin{lstlisting}[gobble=8,xleftmargin=0.5em]
¡x += vx * dt;¿
\end{lstlisting}
\vspace{0.75cm}
\begin{lstlisting}[gobble=8,xleftmargin=0.5em]
¡y += vy * dt;¿
\end{lstlisting}
\vspace{0.90cm}
\begin{lstlisting}[gobble=8,xleftmargin=0.5em]
¡vx += 0 * dt;¿
\end{lstlisting}
\vspace{0.75cm}
\begin{lstlisting}[gobble=8,xleftmargin=0.5em]
¡vy += -g * dt;¿
\end{lstlisting}
\end{minipage}%
\begin{minipage}{5.13cm}
Siehe: \file{gtk-13.c}
\end{minipage}
\end{onlyenv}%
\hfill\strut
\end{frame}
\begin{frame}[fragile]
\showsection
\showsubsection
\textbf{Beispiel 1: Gleichmäßig beschleunigte Bewegung}
\medskip
\textbf{Beispiel 2: Mathematisches Pendel}
\vspace*{-2\bigskipamount}
\begin{picture}(0,0)
\put(8,-6.5){\includegraphics{pendulum.pdf}}
\end{picture}
\begin{eqnarray*}
\varphi'(t) &=& \omega(t) \\[\smallskipamount]
\omega'(t) &=& -\frac{g}{l}\cdot\sin\varphi(t)\hspace*{7.1cm}
\end{eqnarray*}
\vspace*{-1.5\medskipamount}
\begin{itemize}
\item
Von Hand (analytisch):\\
Lösung raten (Ansatz), Parameter berechnen
\item
Mit Computer (numerisch):\\
Eulersches Polygonzugverfahren
\end{itemize}
\smallskip
\begin{lstlisting}[gobble=0]
phi += dt * omega;
omega += - dt * g / l * sin (phi);
\end{lstlisting}
\pause
\bigskip
\textbf{Beispiel 3: Weltraum-Simulation}
Praktikumsaufgabe
\vspace*{-1cm}
\end{frame}
\setcounter{section}{2}
\section{Bibliotheken}
\setcounter{subsection}{3}
\subsection{Projekt organisieren: make}
\begin{frame}[fragile]
\showsubsection
\begin{itemize}
\item
\only<4->{explizite und implizite} Regeln
\begin{onlyenv}<2>
\smallskip
\begin{lstlisting}[language=make,gobble=10]
philosophy: philosophy.o answer.o
gcc philosophy.o answer.o -o philosophy
answer.o: answer.c answer.h
gcc -Wall -O answer.c -c
philosophy.o: philosophy.c answer.h
gcc -Wall -O philosophy.c -c
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<4>
\smallskip
\begin{lstlisting}[language=make,gobble=10]
TARGET = philosophy
OBJECTS = philosophy.o answer.o
HEADERS = answer.h
CFLAGS = -Wall -O
$(TARGET): $(OBJECTS)
gcc $(OBJECTS) -o $(TARGET)
%.o: %.c $(HEADERS)
gcc $(CFLAGS) $< -c
clean:
rm -f $(OBJECTS) $(TARGET)
\end{lstlisting}
\end{onlyenv}
\item
Makros
\begin{onlyenv}<3>
\smallskip
\begin{lstlisting}[language=make,gobble=10]
TARGET = philosophy
OBJECTS = philosophy.o answer.o
HEADERS = answer.h
CFLAGS = -Wall -O
$(TARGET): $(OBJECTS)
gcc $(OBJECTS) -o $(TARGET)
answer.o: answer.c $(HEADERS)
gcc $(CFLAGS) answer.c -c
philosophy.o: philosophy.c $(HEADERS)
gcc $(CFLAGS) philosophy.c -c
clean:
rm -f $(OBJECTS) $(TARGET)
\end{lstlisting}
\vspace*{-1cm}
\end{onlyenv}
\begin{onlyenv}<5->
\smallskip
\arrowitem
3 Sprachen: C, Präprozessor, make
\end{onlyenv}
\end{itemize}
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/hp.git}}}
\item[\textbf{2}] \textbf{Einführung in C}
\item[\textbf{3}] \textbf{Bibliotheken}
\begin{itemize}
\color{medgreen}
\item[3.1] Der Präprozessor
\item[3.2] Bibliotheken einbinden
\item[3.3] Bibliotheken verwenden
\item[3.4] Projekt organisieren: make
\end{itemize}
\item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
\begin{itemize}
\color{red}
\item[4.1] Bit-Operationen
\item[4.2] I/O-Ports
\item[4.3] Interrupts
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\item[\textbf{5}] \textbf{Algorithmen}
\begin{itemize}
\color{medgreen}
\item[5.1] Differentialgleichungen
\color{black}
\vspace*{-0.1cm}
\item[\dots]
\end{itemize}
\item[\textbf{\dots}]
% \item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
% \item[\textbf{5}] \textbf{Algorithmen}
% \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke}
\end{itemize}
\vspace*{-1cm}
\end{frame}
\end{document}
File added
% hp-uebung-20181119.pdf - Exercises on Low-Level Programming / Applied Computer Sciences
% Copyright (C) 2013, 2015, 2016, 2017, 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: Arrays mit Zahlen, hüpfender Ball
\documentclass[a4paper]{article}
\usepackage{pgscript}
\begin{document}
% \thispagestyle{empty}
\section*{Hardwarenahe Programmierung\\
Übungsaufgaben -- 19.\ November 2018}
Diese Übung enthält Punkteangaben wie in einer Klausur.
Um zu "`bestehen"', müssen Sie innerhalb von 60 Minuten
unter Verwendung ausschließlich zugelassener Hilfsmittel
10 Punkte (von insgesamt \totalpoints) erreichen.
\exercise{Arrays mit Zahlen}
\begin{minipage}[t]{0.5\textwidth}
Wir betrachten das folgende Programm\\
(Datei: \gitfile{hp}{20181119}{aufgabe-1.c}):
\begin{lstlisting}[gobble=6]
#include <stdio.h>
void f (int *s0, int *s1)
{
while (*s0 >= 0)
{
int *s = s1;
while (*s >= 0)
if (*s0 == *s++)
printf ("%d ", *s0);
s0++;
}
printf ("\n");
}
int main (void)
{
int a[] = { 10, 4, 3, 7, 12, 0, 1, -1 };
int b[] = { 7, 14, 0, 8, 9, 22, 10, -1 };
f (a, b);
return 0;
}
\end{lstlisting}
\end{minipage}\hfill
\begin{minipage}[t]{0.5\textwidth}
\vspace*{-\bigskipamount}
\begin{enumerate}[\quad(a)]
\item
Was bewirkt die Funktion \lstinline{f},\\
und wie funktioniert sie?
\points{4}
% \item
% Von welcher Ordnung (Landau-Symbol) ist die Funktion und warum?
%
% Wir beziehen uns hierbei auf die Anzahl der Vergleiche
% in Abhängigkeit von der Länge der Eingabedaten \lstinline{s0} und \lstinline{s1}.
% Für die Rechnung dürfen Sie beide Längen mit $n$ gleichsetzen,
% obwohl sie normalerweise nicht gleich sind.
% \points{2}
\item
Was passiert, wenn Sie beim Aufruf der Funktion für einen der
Parameter den Wert \lstinline{NULL} übergeben und warum?
\points{2}
\item
Was kann passieren, wenn Sie das Hauptprogramm wie folgt abändern
(\gitfile{hp}{20181119}{aufgabe-1d.c}) und warum?
\begin{lstlisting}[gobble=8]
int main (void)
{
int a[] = { 10, 4, 3, 7, 12, 0, 1 };
int b[] = { 7, 14, 0, 8, 9, 22, 10 };
f (a, b);
return 0;
}
\end{lstlisting}
\points{2}
% \item
% Beschreiben Sie -- in Worten und/oder als C-Quelltext --, wie
% sich die Funktion \lstinline{f} effizienter gestalten läßt,
% wenn man die ihr übergebenen Arrays \lstinline{s0} und
% \lstinline{s1} als sortiert voraussetzt.
% \points{5}
%
% Hinweis: Wie würden Sie als Mensch die Aufgabe erledigen?
% \item
% Von welcher
% Ordnung (Landau-Symbol) ist Ihre effizientere Version der Funktion und warum?
% \points{2}
\end{enumerate}
\end{minipage}
\exercise{Fehlerhaftes Programm: Hüpfender Ball}
Das auf der nächsten Seite abgedruckte GTK+-Programm
(Datei: \gitfile{hp}{20181119}{aufgabe-2.c}) soll einen
hüpfenden Ball darstellen, ist jedoch fehlerhaft.
\begin{enumerate}[\quad(a)]
\item
Warum sieht man lediglich ein leeres Fenster?
Welchen Befehl muß man ergänzen, um diesen Fehler zu beheben?
\points{3}
\item
Nach der Fehlerbehebung in Aufgabenteil (a)
zeigt das Programm einen unbeweglichen Ball.
Welchen Befehl muß man ergänzen, um diesen Fehler zu beheben, und warum?
\points{2}
\item
Erklären Sie das merkwürdige Hüpfverhalten des Balls.
Wie kommt es zustande?
Was an diesem Verhalten ist korrekt, und was ist fehlerhaft? \points{5}
\item
Welche Befehle muß man in welcher Weise ändern,
um ein realistischeres Hüpf-Verhalten zu bekommen? \points{2}
\end{enumerate}
Hinweis: Das Hinzuziehen von Beispiel-Programmen aus der Vorlesung
ist ausdrücklich erlaubt -- auch in der Klausur.
Allgemeiner Hinweis:
Wenn Sie die Übungsaufgaben zu dieser Lehrveranstaltung
als PDF-Datei betrachten und darin auf die Dateinamen klicken,
können Sie die Beispiel-Programme direkt herunterladen.
Dadurch vermeiden Sie Übertragungsfehler.
\bigskip
\begin{flushright}
\textit{Viel Erfolg!}
\end{flushright}
\clearpage
\vbox to \textheight{\vspace*{-0.5cm}\begin{lstlisting}
#include <gtk/gtk.h>
#define WIDTH 320
#define HEIGHT 240
double t = 0.0;
double dt = 0.2;
int r = 5;
double x = 10;
double y = 200;
double vx = 20;
double vy = -60;
double g = 9.81;
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
gdk_cairo_set_source_rgba (c, &blue);
cairo_arc (c, x, y, r, 0, 2 * G_PI);
cairo_fill (c);
return FALSE;
}
gboolean timer (GtkWidget *widget)
{
t += dt;
x += vx * dt;
y += vy * dt;
vx = vx;
vy = 0.5 * g * (t * t);
if (y + r >= HEIGHT)
vy = -vy * 0.9;
if (x + r >= WIDTH)
vx = -vx * 0.9;
if (x - r <= 0)
vx = -vx * 0.9;
gtk_widget_queue_draw_area (widget, 0, 0, WIDTH, HEIGHT);
g_timeout_add (50, (GSourceFunc) timer, widget);
return FALSE;
}
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_show (drawing_area);
gtk_container_add (GTK_CONTAINER (window), drawing_area);
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_main ();
return 0;
}
\end{lstlisting}\vss}
\makeatletter
\immediate\write\@mainaux{\string\gdef\string\totalpoints{\arabic{points}}}
\makeatother
\end{document}
../common/logo-hochschule-bochum-cvh-text-v2.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
../common/pendulum.pdf
\ No newline at end of file
../common/pgscript.sty
\ No newline at end of file
../common/pgslides.sty
\ No newline at end of file
......@@ -22,7 +22,8 @@ Vortragsfolien:
* [22.10.2018: Zeiger, Arrays und Strings, Strukturen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20181022/hp-20181022.pdf)
* [29.10.2018: Dateien und Fehlerbehandlung, Parameter des Hauptprogramms](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20181029/hp-20181029.pdf)
* [05.11.2018: String-Operationen, Bibliotheken](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20181105/hp-20181105.pdf)
* [12.11.2018: Bibliotheken, Differentialgleichungen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20181112/hp-20181112.pdf)
* [12.11.2018: Einführung: Bibliotheken, Differentialgleichungen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20181112/hp-20181112.pdf)
* [19.11.2018: Vertiefung: Bibliotheken, Differentialgleichungen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20181119/hp-20181119.pdf)
* [alle in 1 Datei](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/hp-slides-2017ws.pdf)
Übungsaufgaben:
......@@ -33,6 +34,7 @@ Vortragsfolien:
* [29.10.2018: Strings, Primzahlen, Datum-Bibliothek](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20181029/hp-uebung-20181029.pdf)
* [05.11.2018: Ausgabe von Hexadezimalzahlen, Einfügen in Strings, Länge von Strings](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20181105/hp-uebung-20181105.pdf)
* [12.11.2018: Text-Grafik-Bibliothek, Datum-Bibliothek, Kondensator](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20181112/hp-uebung-20181112.pdf)
* [19.11.2018: Arrays mit Zahlen, hüpfender Ball](https://gitlab.cvh-server.de/pgerwinski/hp/raw/master/20181119/hp-uebung-20181119.pdf)
Musterlösungen:
---------------
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment