diff --git a/20220926/hello-01-O.s b/20220926/hello-01-O.s deleted file mode 100644 index cb01acba7d1f0e09cf72a12a32af03fc5c685059..0000000000000000000000000000000000000000 --- a/20220926/hello-01-O.s +++ /dev/null @@ -1,24 +0,0 @@ - .file "hello-01.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "Hello, world!" - .text - .globl main - .type main, @function -main: -.LFB11: - .cfi_startproc - subq $8, %rsp - .cfi_def_cfa_offset 16 - leaq .LC0(%rip), %rdi - call puts@PLT - movl $0, %eax - addq $8, %rsp - .cfi_def_cfa_offset 8 - ret - .cfi_endproc -.LFE11: - .size main, .-main - .ident "GCC: (Debian 8.3.0-6) 8.3.0" - .section .note.GNU-stack,"",@progbits diff --git a/20220926/hello-01.c b/20220926/hello-01.c deleted file mode 100644 index b19d80e9bd0bd7c5ed8f54b20c6a50d9166f03ac..0000000000000000000000000000000000000000 --- a/20220926/hello-01.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Hello, world!\n"); - return 0; -} diff --git a/20220926/hello-01.s b/20220926/hello-01.s deleted file mode 100644 index b147da2a77ec8409c9906775295072971eb48f9a..0000000000000000000000000000000000000000 --- a/20220926/hello-01.s +++ /dev/null @@ -1,27 +0,0 @@ - .file "hello-01.c" - .text - .section .rodata -.LC0: - .string "Hello, world!" - .text - .globl main - .type main, @function -main: -.LFB0: - .cfi_startproc ; .cfi_startproc - pushq %rbp ; subq $8, %rsp - .cfi_def_cfa_offset 16 ; .cfi_def_cfa_offset 16 - .cfi_offset 6, -16 ; leaq .LC0(%rip), %rdi - movq %rsp, %rbp ; call puts@PLT - .cfi_def_cfa_register 6 ; movl $0, %eax - leaq .LC0(%rip), %rdi ; addq $8, %rsp - call puts@PLT ; .cfi_def_cfa_offset 8 - movl $0, %eax ; ret - popq %rbp ; .cfi_endproc - .cfi_def_cfa 7, 8 - ret - .cfi_endproc -.LFE0: - .size main, .-main - .ident "GCC: (Debian 8.3.0-6) 8.3.0" - .section .note.GNU-stack,"",@progbits diff --git a/20220926/hello-02.c b/20220926/hello-02.c deleted file mode 100644 index 2dbbad99d102df43d00779483f789f03274353ca..0000000000000000000000000000000000000000 --- a/20220926/hello-02.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Hello, world!"); - return 0; -} diff --git a/20220926/hello-03.c b/20220926/hello-03.c deleted file mode 100644 index ae37ad290203e4e490e3e2fac5a8080f7dfa0364..0000000000000000000000000000000000000000 --- a/20220926/hello-03.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Die Antwort lautet: "); - printf (42); - printf ("\n"); - return 0; -} diff --git a/20220926/hello-04.c b/20220926/hello-04.c deleted file mode 100644 index 6a9b1daa3162c4b25d0a9eeaa93910c4625d1234..0000000000000000000000000000000000000000 --- a/20220926/hello-04.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Die Antwort lautet: "); - printf ("42"); - printf ("\n"); - return 0; -} diff --git a/20220926/hello-05.c b/20220926/hello-05.c deleted file mode 100644 index 8df53c4c95e8c3ae959324a1b7fa4f058aafc7ef..0000000000000000000000000000000000000000 --- a/20220926/hello-05.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Die Antwort lautet: %d\n", 42); - return 0; -} diff --git a/20220926/hello-06.c b/20220926/hello-06.c deleted file mode 100644 index c6946c2a4faf6b6bbd6a0e9148f15fe58cf76367..0000000000000000000000000000000000000000 --- a/20220926/hello-06.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int answer = 42; - printf ("Die Antwort lautet: %d\n", answer); - return 0; -} diff --git a/20220926/hello-gtk.c b/20220926/hello-gtk.c deleted file mode 100644 index 016867d41e42de57390a21653de467c061e5ded0..0000000000000000000000000000000000000000 --- a/20220926/hello-gtk.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <gtk/gtk.h> - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); - GtkWidget *label = gtk_label_new ("Hello, world!"); - gtk_container_add (GTK_CONTAINER (vbox), label); - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - gtk_widget_show (button); - gtk_widget_show (label); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20220926/hello.c b/20220926/hello.c deleted file mode 100644 index b19d80e9bd0bd7c5ed8f54b20c6a50d9166f03ac..0000000000000000000000000000000000000000 --- a/20220926/hello.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Hello, world!\n"); - return 0; -} diff --git a/20220926/hp-uebung-20220926.pdf b/20220926/hp-uebung-20220926.pdf deleted file mode 100644 index 849ca3df582a3b8847019670eb96192886fb2a11..0000000000000000000000000000000000000000 Binary files a/20220926/hp-uebung-20220926.pdf and /dev/null differ diff --git a/20220926/hp-uebung-20220926.tex b/20220926/hp-uebung-20220926.tex deleted file mode 100644 index 15b74e5a4d3725a3de57bdd72ecbc58834d826d3..0000000000000000000000000000000000000000 --- a/20220926/hp-uebung-20220926.tex +++ /dev/null @@ -1,93 +0,0 @@ -% hp-uebung-20220926.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Hello-World-Programme, Schaltjahr ermitteln, Maximum berechnen - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\thispagestyle{empty} - -\begin{document} - - \thispagestyle{empty} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 26.\ September 2022} - - \exercise{Hello, world!} - - Unter \url{https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20220926} - können Sie - \href{https://gitlab.cvh-server.de/pgerwinski/hp/raw/2021ws/20211004/hp-uebung-20220926.pdf}% - {diesen Übungszettel als PDF-Datei} - herunterladen sowie die folgenden Beispielprogramme: - \begin{enumerate}[\quad(a)] - \item \gitfile{hp}{2022ws/20220926}{hello.c} - \item \gitfile{hp}{2022ws/20220926}{hello-gtk.c} - \end{enumerate} - Bringen Sie diese Programme auf Ihrem eigenen Rechner - und/oder auf einem Rechner der Hochschule - unter einem Betriebssystem Ihrer Wahl zum Laufen. - - \file{hello.c} ist das klassische "`Hello, world!"'-Programm; - \file{hello-gtk} erzeugt ein Fenster mit einem Button zum Schließen. - (Wie diese Programme im einzelnen funktionieren, - wird im Laufe der Lehrveranstaltung erklärt werden. - In dieser Übung geht es nur darum, - sich mit dem Compilieren von C-Programmen vertraut zu machen.) - - \textbf{Hinweis 0:} Diese PDF-Datei enthält Links zu den jeweiligen Dateien. - Durch Anklicken können Sie diese direkt herunterladen. - - \textbf{Hinweis 1:} Für (b) benötigen Sie die Bibliothek GTK+. - Diese finden Sie -- einschließlich Dokumentation -- als freie Software im Internet. - - \textbf{Hinweis 2:} Unter Unix mit \lstinline[style=cmd]{gcc} - funktioniert das Compilieren und Starten der Programme folgendermaßen: - \begin{lstlisting}[style=cmd] - gcc -Wall -O hello.c -o hello - ./hello - gcc -Wall -O $(pkg-config --cflags gtk+-3.0) hello-gtk.c \ - $(pkg-config --libs gtk+-3.0) -o hello-gtk - ./hello-gtk - \end{lstlisting} - - \exercise{Schaltjahr ermitteln} - - Schreiben Sie ein Programm in einer beliebigen Programmiersprache - (z.\,B.\ C, Java, Python, Shell-Skript), - 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{Maximum berechnen} - - Schreiben Sie ein Programm in einer beliebigen Programmiersprache, - das 5 Zahlen erfragt und anschließend die größte dieser Zahlen ausgibt. - -\end{document} diff --git a/20220926/if-01.c b/20220926/if-01.c deleted file mode 100644 index a7eb40b2a3e446de27bdf2ba0a54d70cedeea941..0000000000000000000000000000000000000000 --- a/20220926/if-01.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 9; - int b = 2; - if (b != 0) - printf ("%d\n", a / b); - return 0; -} diff --git a/20220926/if-02.c b/20220926/if-02.c deleted file mode 100644 index ebc8469b845706113cceb4a382c1e1b84edebc9c..0000000000000000000000000000000000000000 --- a/20220926/if-02.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 9; - int b = 2; - if (b != 0) - printf ("%d\n", a % b); - return 0; -} diff --git a/20220926/if-03.c b/20220926/if-03.c deleted file mode 100644 index a5c87d8a502ca4c09924759da0dd8f93add008d0..0000000000000000000000000000000000000000 --- a/20220926/if-03.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 9; - int b = 2; - if (b) - printf ("%d\n", a / b); - return 0; -} diff --git a/20220926/if-04.c b/20220926/if-04.c deleted file mode 100644 index 1d22ec8c394d2e0fbb48f4bf81156f1e06a19e2c..0000000000000000000000000000000000000000 --- a/20220926/if-04.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 9; - int b = 0; - if (b) - printf ("%d\n", a / b); - else - printf ("Bitte nicht durch 0 dividieren.\n"); - return 0; -} diff --git a/20220926/if-05.c b/20220926/if-05.c deleted file mode 100644 index 4b00da885ad6205a2d542434bbc0e62a15a2e344..0000000000000000000000000000000000000000 --- a/20220926/if-05.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 9; - int b = 0; - if (b) - printf ("%d\n", a / b); - else - printf ("Bitte nicht durch 0 dividieren.\n"); - printf ("Das tut man nicht.\n"); - return 0; -} diff --git a/20220926/if-06.c b/20220926/if-06.c deleted file mode 100644 index 38d4ff547eba41a550f31688f595d8588d12c056..0000000000000000000000000000000000000000 --- a/20220926/if-06.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 9; - int b = 2; - if (b) - printf ("%d\n", a / b); - else - printf ("Bitte nicht durch 0 dividieren.\n"); - printf ("Das tut man nicht.\n"); - return 0; -} diff --git a/20220926/if-07.c b/20220926/if-07.c deleted file mode 100644 index 61e765c74f893e99639ee2d5203e912837132ac5..0000000000000000000000000000000000000000 --- a/20220926/if-07.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 9; - int b = 2; - if (b) - printf ("%d\n", a / b); - else - { - printf ("Bitte nicht durch 0 dividieren.\n"); - printf ("Das tut man nicht.\n"); - } - return 0; -} diff --git a/20220926/if-08.c b/20220926/if-08.c deleted file mode 100644 index 98cc3f3575dc64ca04faa0b8c06a06cd85911439..0000000000000000000000000000000000000000 --- a/20220926/if-08.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 9; - int b = 2; - if (b) { - printf ("%d\n", a / b); - } else { - printf ("Bitte nicht durch 0 dividieren.\n"); - printf ("Das tut man nicht.\n"); - } - return 0; -} diff --git a/20220926/if-09.c b/20220926/if-09.c deleted file mode 100644 index a46f9c5ce258de2bc3a861a990de2b418fc8304c..0000000000000000000000000000000000000000 --- a/20220926/if-09.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 9; - int b = 2; - if (b) { - printf ("%d\n", a / b); - } else { - printf ("Bitte nicht durch 0 dividieren.\n"); - printf ("Das tut man nicht.\n"); -} - return 0; - } diff --git a/20220926/if-10.c b/20220926/if-10.c deleted file mode 100644 index 29f1ca7fa398dfe736fcd6b0320c3535c4f67039..0000000000000000000000000000000000000000 --- a/20220926/if-10.c +++ /dev/null @@ -1,4 +0,0 @@ -#include <stdio.h> -int main (void) { int a = 9; int b = 2; if (b) { printf ("%d\n", a / b); } -else { printf ("Bitte nicht durch 0 dividieren.\n"); printf ("Das tut man nicht.\n"); -} return 0; } diff --git a/20220926/if-11.c b/20220926/if-11.c deleted file mode 100644 index 115016e9207c760d3e7605c9bfc9336a0595785c..0000000000000000000000000000000000000000 --- a/20220926/if-11.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 9; - int b = 2; - if (b) - { - printf ("%d\n", a / b); - } - else - { - printf ("Bitte nicht durch 0 dividieren.\n"); - printf ("Das tut man nicht.\n"); - } - return 0; -} diff --git a/20220926/if-12.c b/20220926/if-12.c deleted file mode 100644 index e291f4225be4d4d444e6c1895a2839041c39119d..0000000000000000000000000000000000000000 --- a/20220926/if-12.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("%d\n", 1 > 0); - return 0; -} diff --git a/20220926/if-13.c b/20220926/if-13.c deleted file mode 100644 index d615f4821814b5cbc6a15d925310e9c0b5083a93..0000000000000000000000000000000000000000 --- a/20220926/if-13.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1 > 0; - printf ("%d\n", a); - return 0; -} diff --git a/20220926/input-01.c b/20220926/input-01.c deleted file mode 100644 index 5ca4c8c63cf313591a5a57e18c915329a3c71162..0000000000000000000000000000000000000000 --- a/20220926/input-01.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - double a; - printf ("Bitte eine Zahl eingeben: "); - scanf ("%lf", &a); - printf ("Ihre Antwort war: %lf\n", a); - return 0; -} diff --git a/20220926/input-02.c b/20220926/input-02.c deleted file mode 100644 index 3c8912a1210787f322016cd6b611a3dd1bcaced3..0000000000000000000000000000000000000000 --- a/20220926/input-02.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - double a; - printf ("Bitte eine Zahl eingeben: "); - scanf ("%lf", a); - printf ("Ihre Antwort war: %lf\n", a); - return 0; -} diff --git a/20220926/input-03.c b/20220926/input-03.c deleted file mode 100644 index cf2a21d8fccc2150610486374efa0d8c0606240d..0000000000000000000000000000000000000000 --- a/20220926/input-03.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - double a; - printf ("Bitte eine Zahl eingeben: "); - scanf ("%lf", &a); - a = 2 * a; - printf ("Das Doppelte ist: %lf\n", a); - return 0; -} diff --git a/20220926/input-04.c b/20220926/input-04.c deleted file mode 100644 index b8c58a39a39f78c4417b98f5a4bad118280de434..0000000000000000000000000000000000000000 --- a/20220926/input-04.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - double a = 3.14; - printf ("Das Doppelte von %lf ist: %lf\n", a, 2 * a); - return 0; -} diff --git a/20220926/input-05.c b/20220926/input-05.c deleted file mode 100644 index b6b01519b4b48c2448e88280ca79d02a789c8dd6..0000000000000000000000000000000000000000 --- a/20220926/input-05.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - double a; - a = 3.14; - printf ("Das Doppelte von %lf ist: %lf\n", a, 2 * a); - return 0; -} diff --git a/20220926/side-effects-01.c b/20220926/side-effects-01.c deleted file mode 100644 index 61c4abb82e369b17b5acc83107b9baa598f371d2..0000000000000000000000000000000000000000 --- a/20220926/side-effects-01.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Hello, world!\n"); - "Hello, world!\n"; - return 0; -} diff --git a/20220926/side-effects-02.c b/20220926/side-effects-02.c deleted file mode 100644 index 275a28e55e4568ff0e7f135bfaae8de819d224f7..0000000000000000000000000000000000000000 --- a/20220926/side-effects-02.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Hello, world!\n"); - 42; - return 0; -} diff --git a/20220926/side-effects-03.c b/20220926/side-effects-03.c deleted file mode 100644 index 41bf3a1f90ea07ada508c6dc4fe2b6f7afed0a9b..0000000000000000000000000000000000000000 --- a/20220926/side-effects-03.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = printf ("Hello, world!\n"); - printf ("a = %d\n", a); - return 0; -} diff --git a/20220926/side-effects-04.c b/20220926/side-effects-04.c deleted file mode 100644 index a0154b80d373b2e3789ecbf849eac931e28d1a13..0000000000000000000000000000000000000000 --- a/20220926/side-effects-04.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 3; - printf ("-a = %d\n", -a); - return 0; -} diff --git a/20220926/side-effects-05.c b/20220926/side-effects-05.c deleted file mode 100644 index 05d6e19e9cc6107dd0d092f428c89987e179bcf4..0000000000000000000000000000000000000000 --- a/20220926/side-effects-05.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 3; - int b = 7; - printf ("a + b = %d\n", a + b); - return 0; -} diff --git a/20220926/side-effects-06.c b/20220926/side-effects-06.c deleted file mode 100644 index d18e48f9870275341c3d00de9fe92db735aa3a64..0000000000000000000000000000000000000000 --- a/20220926/side-effects-06.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 3; - int b = 7; - printf ("a += b = %d\n", a += b); - return 0; -} diff --git a/20220926/side-effects-07.c b/20220926/side-effects-07.c deleted file mode 100644 index 62d6041a140ac96e1d77452bd79dd4f3389e6d4d..0000000000000000000000000000000000000000 --- a/20220926/side-effects-07.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 3; - int b = 7; - printf ("a += b = %d\n", a += b); - printf ("a = %d\n", a); - return 0; -} diff --git a/20220926/side-effects-08.c b/20220926/side-effects-08.c deleted file mode 100644 index 69eea137842d66df11f7b2053984b733a3e69c61..0000000000000000000000000000000000000000 --- a/20220926/side-effects-08.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 3; - int b = 7; - printf ("a + b = %d\n", a + b); - printf ("a = %d\n", a); - return 0; -} diff --git a/20220926/side-effects-09.c b/20220926/side-effects-09.c deleted file mode 100644 index 070e7d71afd2cff9dedf86d8b754588fe20b8362..0000000000000000000000000000000000000000 --- a/20220926/side-effects-09.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int pi = 3,14; - printf ("pi = %d\n", pi); - return 0; -} diff --git a/20220926/side-effects-10.c b/20220926/side-effects-10.c deleted file mode 100644 index 51fef72c094324dabe42b212d0fc0a9d79284789..0000000000000000000000000000000000000000 --- a/20220926/side-effects-10.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int pi; - pi = 3,14; - printf ("pi = %d\n", pi); - return 0; -} diff --git a/20220926/side-effects-11.c b/20220926/side-effects-11.c deleted file mode 100644 index 3faa6221bb149da7b17fad7b68905fcba26e6131..0000000000000000000000000000000000000000 --- a/20220926/side-effects-11.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int pi; - pi = (3,14); - printf ("pi = %d\n", pi); - return 0; -} diff --git a/20220926/side-effects-12.c b/20220926/side-effects-12.c deleted file mode 100644 index af3ea2bb093bb7f2478a12965713a3cfc7dabab2..0000000000000000000000000000000000000000 --- a/20220926/side-effects-12.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int pi; - pi = 3.14; - printf ("pi = %d\n", pi); - return 0; -} diff --git a/20220926/side-effects-13.c b/20220926/side-effects-13.c deleted file mode 100644 index 3706b07714088ee94340dc1141e3633baecb098f..0000000000000000000000000000000000000000 --- a/20220926/side-effects-13.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int i = 3; - i++; - printf ("i = %d\n", i); - return 0; -} diff --git a/20220926/side-effects-14.c b/20220926/side-effects-14.c deleted file mode 100644 index eaf2ea37bb48a3f9fec536ca4a9d2d838007cee9..0000000000000000000000000000000000000000 --- a/20220926/side-effects-14.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int i = 3; - printf ("i = %d\n", i++); - return 0; -} diff --git a/20220926/side-effects-15.c b/20220926/side-effects-15.c deleted file mode 100644 index a417fabb96ea00231138b219536d2c0593b0a25e..0000000000000000000000000000000000000000 --- a/20220926/side-effects-15.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int i = 3; - printf ("i = %d\n", i++); - printf ("i = %d\n", i++); - return 0; -} diff --git a/20220926/side-effects-16.c b/20220926/side-effects-16.c deleted file mode 100644 index d5c8f724f2d8766385aef983f06d142435e31018..0000000000000000000000000000000000000000 --- a/20220926/side-effects-16.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int i = 3; - printf ("i = %d\n", ++i); - printf ("i = %d\n", ++i); - return 0; -} diff --git a/20220926/while-01.c b/20220926/while-01.c deleted file mode 100644 index 84912102488878cd3ad2ee11cf84551de8403fc1..0000000000000000000000000000000000000000 --- a/20220926/while-01.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a; - a = 1; - while (a <= 10) - { - printf ("%d\n", a); - a = a + 1; - } - return 0; -} diff --git a/20220926/while-02.c b/20220926/while-02.c deleted file mode 100644 index ad1323b373fdb5ea197fc9f53b8c0a388b6e6c19..0000000000000000000000000000000000000000 --- a/20220926/while-02.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a; - for (a = 1; a <= 10; a = a + 1) - printf ("%d\n", a); - return 0; -} diff --git a/20220926/while-03.c b/20220926/while-03.c deleted file mode 100644 index d3fc45ff1ca0b85e01282a7c2bf473c85f071862..0000000000000000000000000000000000000000 --- a/20220926/while-03.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a; - a = 1; - do - { - printf ("%d\n", a); - a = a + 1; - } - while (a <= 10); - return 0; -} diff --git a/20220926/while-04.c b/20220926/while-04.c deleted file mode 100644 index 0fda44ad08fa963bc6229f32329e11d9f79109b2..0000000000000000000000000000000000000000 --- a/20220926/while-04.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a; - for (a = 1; a > 10; a = a + 1) - printf ("%d\n", a); - return 0; -} diff --git a/20220926/while-05.c b/20220926/while-05.c deleted file mode 100644 index ab32889936d61b2fdaec641cf8ea453c4ca27711..0000000000000000000000000000000000000000 --- a/20220926/while-05.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - while (a <= 10) - printf ("%d\n", a++); - return 0; -} diff --git a/20220926/while-06.c b/20220926/while-06.c deleted file mode 100644 index eb77790700657077a683f33d339f42f26982a1b2..0000000000000000000000000000000000000000 --- a/20220926/while-06.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - for (int a = 1; a <= 10; printf ("%d\n", a++)); - return 0; -} diff --git a/20220926/while-07.c b/20220926/while-07.c deleted file mode 100644 index e39422e7523a6d72641954db79ffbc460ebb8708..0000000000000000000000000000000000000000 --- a/20220926/while-07.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - while (1) - { - if (a > 10) - break; - printf ("%d\n", a); - a++; - } - return 0; -} diff --git a/20220926/while-08.c b/20220926/while-08.c deleted file mode 100644 index ea5d22f70221add949ee0ee09acf5726afa29c06..0000000000000000000000000000000000000000 --- a/20220926/while-08.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - while (1) - { - if (a > 10) - { - printf ("Eintrag gefunden: %d\n", a); - if (a > 42) - printf ("Eintrag ist größer als 42.\n"); - break; - } - printf ("%d\n", a); - a++; - } - return 0; -} diff --git a/20220926/while-09.c b/20220926/while-09.c deleted file mode 100644 index 8b7d3fe155b64db30c2a90993ce8a83a205d1292..0000000000000000000000000000000000000000 --- a/20220926/while-09.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - while (a <= 10) - { - printf ("%d\n", a); - a++; - } - if (a > 10) - { - printf ("Eintrag gefunden: %d\n", a); - if (a > 42) - printf ("Eintrag ist größer als 42.\n"); - } - return 0; -} diff --git a/20220926/while-10.c b/20220926/while-10.c deleted file mode 100644 index 490c4b3bcd52cb615eb2296ea1fcb39659abcdfa..0000000000000000000000000000000000000000 --- a/20220926/while-10.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - loop: - if (a > 10) - goto endloop; - printf ("%d\n", a++); - goto loop; - endloop: - return 0; -} diff --git a/20220926/while-11.c b/20220926/while-11.c deleted file mode 100644 index 5c1ece5438affbf59b22e7cd24e3fee6fb57f3f6..0000000000000000000000000000000000000000 --- a/20220926/while-11.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - loop: - if (a > 10) - goto endloop; - printf ("%d\n", a++); - goto loop; - int i = 7; - endloop: - printf ("i = %d\n", i); - return 0; -} diff --git a/20221006/hp-2022ws-p1.pdf b/20221006/hp-2022ws-p1.pdf deleted file mode 100644 index 891ed5f47d0a862ae3e81fbcb986aaadd5fced4a..0000000000000000000000000000000000000000 Binary files a/20221006/hp-2022ws-p1.pdf and /dev/null differ diff --git a/20221006/hp-2022ws-p1.tex b/20221006/hp-2022ws-p1.tex deleted file mode 100644 index bf2129cb96f751d7ee5543ca12e028ec3b5d923f..0000000000000000000000000000000000000000 --- a/20221006/hp-2022ws-p1.tex +++ /dev/null @@ -1,204 +0,0 @@ -% hp-2022ws-p1.pdf - Labor Notes on Low-Level Programming -% Copyright (C) 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Versuch 1: RSA-Verschlüsselung - -\documentclass[a4paper]{article} - -\usepackage{pgscript} -\usepackage{multicol} -\usepackage{sfmath} - -\sloppy -\pagestyle{empty} -\addtolength{\textheight}{1cm} -\newcommand{\sep}{~$\cdot$~} -\newcommand{\mylicense}{CC BY-SA (Version 4.0) oder GNU GPL (Version 3 oder höher)} - -\begin{document} - - \makebox(0,0.005)[tl]{\includegraphics[scale=0.72]{logo-hochschule-bochum-cvh-text-v2.pdf}}\hfill - \makebox(0,0)[tr]{\includegraphics[scale=0.5]{logo-hochschule-bochum.pdf}} - \par\bigskip\bigskip - \begin{center} - \Large\textbf{Praktikumsversuch 1: RSA-Verschlüsselung} - \par\medskip - \normalsize Hardwarenahe Programmierung\sep - Wintersemester 2022/23\sep - Prof.~Dr.~Peter Gerwinski - \end{center} - - Aufgabe: Schreiben Sie ein Programm, das - die Verschlüsselung nach Rivest, Shamir und Adleman (RSA) - sowie die Schwierigkeiten beim Brechen ("`Knacken"') der - Verschlüsselung demonstriert. - - \begin{multicols}{2} - - Schreiben Sie ein C-Programm (oder mehrere), - das folgendes durchführt: - - \begin{itemize} - \item - \textbf{Schlüsselerzeugung} - - Bestimmen Sie drei verschiedene Primzahlen $p$, $q$ und $e$, wobei $e$ - kleiner als $(\kern0.5pt p-1)\cdot(q-1)$ und teilerfremd zu $(\kern0.5pt p-1)\cdot(q-1)$ sei. - (Dies ist z.\,B.\ der Fall, wenn $e$ größer als $p$ und $q$ ist.) - - Berechnen Sie $N = p \cdot q$ - sowie eine natürliche Zahl $d$ mit der Eigenschaft: - \begin{displaymath} - (e \cdot d) \,\%\, \bigl((\kern0.5pt p-1)\cdot(q-1)\bigr) = 1 - \end{displaymath} - ("`$x \,\%\, y\/$"' wird "`x modulo y"' gesprochen und steht - für den Rest, der bei Division von $x$ durch $y$ verbleibt.) - - $N$ und $e$ sind der \newterm{öffentliche Schlüssel}. \\ - $p$, $q$ und $d$ sind der \newterm{geheime Schlüssel}. - - \item - \textbf{Verschlüsselung} - - Wählen Sie eine geheime Botschaft $m$ eine Zahl kleiner als $N$, - die Sie verschlüsseln wollen. - - $m$ muß teilerfremd zu $N$ sein. - (Dies ist der Fall, wenn $m$ weder durch $p$ noch durch $q$ teilbar ist.) - - Schreiben Sie ein Programm, das aus $m$ die verschlüsselte - Nachricht $c$ berechnet: - \begin{displaymath} - c = m^e ~\%\, N - \end{displaymath} - - \textbf{Hinweis:} - \begin{displaymath} - m^e ~\%\, N - = \underbrace{(m \cdot m \cdot \dots \cdot m)}_{\mbox{$e$ Faktoren}} \,\%\, N - \hspace*{2cm} - \end{displaymath} - \vspace*{-\medskipamount} - \begin{displaymath} - = \underbrace{\Bigl(\dots\bigl((m \cdot m) \,\%\, N \cdot m\bigr) \,\%\, N \cdot \dots \cdot m\Bigr) \,\%\, N}_{\mbox{$e$ Faktoren}} - \end{displaymath} - - Dies bedeutet: Multiplizieren Sie die Zahl $m$ $e$-mal mit sich selbst, - wobei Sie \emph{nach jeder Multiplikation\/} modulo $N$ rechnen. - - \item - \textbf{Entschlüsselung} - - Rekonstruieren Sie aus der verschlüsselten Botschaft $c$ - wieder die geheime Botschaft $m$: - \begin{displaymath} - m = c^d ~\%\, N - \end{displaymath} - - \item - \textbf{Verschlüsselung brechen} - - Rekonstruieren Sie aus der verschlüsselten Botschaft $c$ - wieder die geheime Botschaft $m$, - \emph{ohne\/} den geheimen Schlüssel zu kennen, - d.\,h.\ Sie kennen nur $N$ und $e$, nicht jedoch $p$, $q$ und $d$. - - \textbf{Hinweis:} - Sie können z.\,B.\ versuchen, $N$ in seine Primfaktoren zu zerlegen. - Auf diese Weise können Sie zunächst $p$ und $q$ berechnen und danach $d$. - - \item - \textbf{Rechenzeit vergleichen} - - Vergleichen Sie nun - die für das Brechen der Verschlüsselung benötigte Rechenzeit - mit der Zeit, die das reguläre Ver- und Entschlüsseln dauert. - (Auf diesem Schwierigkeitsunterschied - beruht die Sicherheit der RSA-Verschlüsselung.) - - \textbf{Hinweis 1:} -% Wenn Sie ein Programm per Kommandozeile mit \lstinline[style=cmd]{time ./programm} starten, -% wird Ihnen angezeigt, wieviel Rechenzeit das Programm benötigt hat. -% Die drei angezeigten Werte stehen hierbei für die -% tatsächlich verstrichene Gesamtzeit (\lstinline[style=terminal]{real}), -% für die mit Rechnen verbrachte Zeit (\lstinline[style=terminal]{user}) -% und für die mit Systemaufrufen (z.\,B.\ Ein- und Ausgabe) -% verbrachte Zeit (\lstinline[style=terminal]{sys}). - Ein einfacher Weg, die von Ihrem Programm benötigte Rechenzeit zu messen, - ist die Verwendung der Funktion \lstinline{clock()}. - Diese gibt zurück, wieviel Rechenzeit seit Programmstart aufgewendet wurde. - Der Typ dieses Rückgabewerts ist ein ganzzahliger Typ, \lstinline{clock_t}, - mit dem man rechnen und den man mit \lstinline{%ld} ausgeben kann. - Pro Sekunde wächst der Zähler um \lstinline{CLOCKS_PER_SEC} Einheiten. - Typischerweise hat \lstinline{CLOCKS_PER_SEC} den Wert \lstinline{1000000} - oder \lstinline{1000}, die Zeiteinheit ist also eine Mikrosekunde - bzw.\ eine Millisekunde. - - \textbf{Hinweis 2:} - Die mit der o.\,a.\ Methode meßbaren Zeiten sind eigentlich zu ungenau, - um damit die sehr kurzen Rechenzeiten erfassen zu können -- - etwa so, als wollten Sie mit einem Lineal mit Millimetereinteilung - die Dicke eines Blatts Papier messen. Beides ist jedoch möglich. - -% \item -% Die \textbf{Abgabe} erfolgt auf einem zur Verfügung gestellten USB-Stick. -% Legen Sie dort ein Verzeichnis gemäß Ihrem Namen an, -% wie er in Ihrer Hochschul-E-Mail-Adresse auftaucht -% (z.\,B.\ \file{hans-joerg.mueller-mustermann} -% und speichern Sie darin Ihre \emph{Quelltexte} -% mit den Lösungen der Praktikumsaufgabe -% (und insbesondere \emph{nicht} die ausführbaren Dateien). -% Vermerken Sie bitte außerdem die folgenden Angaben -% entweder als Kommentar im Quelltext oder in einer separaten Textdatei: -% Name in korrekter Schreibweise, Matrikel-Nummer, -% Studiengang (MI/MP/TI) und Studienmodell (KIA/KIS/GS). - - \end{itemize} - - \end{multicols} - - \vspace*{-\bigskipamount} - - \strut\hfill\emph{Viel Erfolg!} - - \vfill - - \begingroup - - \small - - \setlength{\leftskip}{3cm} - - Stand: 4.\ Oktober 2022 - -% Soweit nicht anders angegeben:\\ - Copyright \copyright\ 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022\quad Peter Gerwinski\\ - Lizenz: \mylicense - - Sie können diese Praktikumsunterlagen einschließlich \LaTeX-Quelltext -%% und Beispielprogramme\\ - herunterladen unter:\\ - \url{https://gitlab.cvh-server.de/pgerwinski/hp} - - \endgroup - -\end{document} diff --git a/20221006/logo-hochschule-bochum-cvh-text-v2.pdf b/20221006/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221006/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221006/logo-hochschule-bochum.pdf b/20221006/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221006/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221006/pgscript.sty b/20221006/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221006/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221010/arrays-01.c b/20221010/arrays-01.c deleted file mode 100644 index 35cf856c63942234116544ac721ff0a47d797b09..0000000000000000000000000000000000000000 --- a/20221010/arrays-01.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int prime[5] = { 2, 3, 5, 7, 11 }; - int *p = prime; - for (int i = 0; i < 5; i++) - printf ("%d\n", *(p + i)); - return 0; -} diff --git a/20221010/arrays-02.c b/20221010/arrays-02.c deleted file mode 100644 index d206e6c3296fe7f7e48febd10893a5be65fca67a..0000000000000000000000000000000000000000 --- a/20221010/arrays-02.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int prime[5] = { 2, 3, 5, 7, 11 }; - int *p = prime; - for (int i = 0; i < 5; i++) - printf ("%d\n", p[i]); - return 0; -} diff --git a/20221010/arrays-03.c b/20221010/arrays-03.c deleted file mode 100644 index 83a03a4fe9425d684db38f0219cd9e9e19b405ba..0000000000000000000000000000000000000000 --- a/20221010/arrays-03.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int prime[5] = { 2, 3, 5, 7, 11 }; - for (int i = 0; i < 5; i++) - printf ("%d\n", prime[i]); - return 0; -} diff --git a/20221010/arrays-04.c b/20221010/arrays-04.c deleted file mode 100644 index 2015ffc6cd5057daaa755294ab4af602559eefa4..0000000000000000000000000000000000000000 --- a/20221010/arrays-04.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int prime[5] = { 2, 3, 5, 7, 11 }; - for (int *p = prime; p < prime + 5; p++) - printf ("%d\n", *p); - return 0; -} diff --git a/20221010/arrays-05.c b/20221010/arrays-05.c deleted file mode 100644 index a24238adf6daadf18acfa27e1da7881802c7ed75..0000000000000000000000000000000000000000 --- a/20221010/arrays-05.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int prime[5] = { 2, 3, 5, 7, 11 }; - for (int *p = prime; p <= prime + 5; p++) - printf ("%d\n", *p); - return 0; -} diff --git a/20221010/arrays-06.c b/20221010/arrays-06.c deleted file mode 100644 index 82ab32dfc4fc73c3a700a6e88a50202029934ca1..0000000000000000000000000000000000000000 --- a/20221010/arrays-06.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int prime[5] = { 2, 3, 5, 7, 11 }; - for (int i = 0; i <= 5; i++) - printf ("%d\n", prime[i]); - return 0; -} diff --git a/20221010/arrays-07.c b/20221010/arrays-07.c deleted file mode 100644 index dcf32170d4658f2eafdf436809e9a9aa0e56379b..0000000000000000000000000000000000000000 --- a/20221010/arrays-07.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int prime[6] = { 2, 3, 5, 7, 11, 0 }; - for (int *p = prime; *p; p++) - printf ("%d\n", *p); - return 0; -} diff --git a/20221010/arrays-08.c b/20221010/arrays-08.c deleted file mode 100644 index 3437adea44f78176745a1d1b6be31c9cb4a63dfc..0000000000000000000000000000000000000000 --- a/20221010/arrays-08.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int prime[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 0 }; - for (int *p = prime; *p; p++) - printf ("%d\n", *p); - return 0; -} diff --git a/20221010/arrays-09.c b/20221010/arrays-09.c deleted file mode 100644 index 0bd5cbdc7de1ff9a37a649772bab6bb0b99666b4..0000000000000000000000000000000000000000 --- a/20221010/arrays-09.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int prime[15] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 0 }; - for (int *p = prime; *p; p++) - printf ("%d\n", *p); - prime[9] = 29; - prime[10] = 0; - for (int *p = prime; *p; p++) - printf ("%d\n", *p); - return 0; -} diff --git a/20221010/aufgabe-4.c b/20221010/aufgabe-4.c deleted file mode 100644 index b8b3de796fbef94bd4a86f944e1269b97e97982b..0000000000000000000000000000000000000000 --- a/20221010/aufgabe-4.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - for (int i = 10; i = 0; i - 1) - printf ("%d\n", i); - return 0; -} diff --git a/20221010/functions-01.c b/20221010/functions-01.c deleted file mode 100644 index e1adaf78b6f48b158980dccbb9f5fe378a4c89d5..0000000000000000000000000000000000000000 --- a/20221010/functions-01.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -void hello () -{ - printf ("Hello, world!\n"); -} - -int main () -{ - hello (); - return 0; -} diff --git a/20221010/functions-02.c b/20221010/functions-02.c deleted file mode 100644 index 16f2559f5d08a624c26270963e371dd3c6e03219..0000000000000000000000000000000000000000 --- a/20221010/functions-02.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -void hello () -{ - printf ("Hello, world!\n"); -} - -int main () -{ - hello ("Hallo, Welt!\n"); - return 0; -} diff --git a/20221010/functions-03.c b/20221010/functions-03.c deleted file mode 100644 index 53b28487f1c20f717520b2469a1aeb4906eba6d6..0000000000000000000000000000000000000000 --- a/20221010/functions-03.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -void hello (void) -{ - printf ("Hello, world!\n"); -} - -int main (void) -{ - hello ("Hallo, Welt!\n"); - return 0; -} diff --git a/20221010/functions-04.c b/20221010/functions-04.c deleted file mode 100644 index b1c31984589edfe971ddf8c24357338314706237..0000000000000000000000000000000000000000 --- a/20221010/functions-04.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -void philosophy (a) - int a; -{ - printf ("The answer is: %d.\n", a); -} - -int main (void) -{ - philosophy (137); - return 0; -} diff --git a/20221010/functions-05.c b/20221010/functions-05.c deleted file mode 100644 index d9ef21add0b8698a83e7684392480742d822bf36..0000000000000000000000000000000000000000 --- a/20221010/functions-05.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -void philosophy (a) - int a; -{ - printf ("The answer is: %d.\n", a); -} - -int main (void) -{ - philosophy ("Hello, world!\n"); - return 0; -} diff --git a/20221010/functions-05.txt b/20221010/functions-05.txt deleted file mode 100644 index 8a6213744eefbe1e1b60e91521b55ff3863f9063..0000000000000000000000000000000000000000 --- a/20221010/functions-05.txt +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> - -void philosophy (a) - int a; -{ - printf ("The answer is: %d.\n", a); -} - -int main (void) -{ - philosophy ("Hello, world!\n"); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221010> gcc -Wall -O functions-05.c -o functions-05 -cassini/home/peter/bo/2022ws/hp/20221010> ./functions-05 -The answer is: -1434640360. -cassini/home/peter/bo/2022ws/hp/20221010> ./functions-05 -The answer is: -402571240. -cassini/home/peter/bo/2022ws/hp/20221010> ./functions-05 -The answer is: 588369944. -cassini/home/peter/bo/2022ws/hp/20221010> ./functions-05 -The answer is: 97824792. -cassini/home/peter/bo/2022ws/hp/20221010> diff --git a/20221010/functions-06.c b/20221010/functions-06.c deleted file mode 100644 index 6d849e0dc18e8c2e37bedaa7a2628800581fffce..0000000000000000000000000000000000000000 --- a/20221010/functions-06.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -void philosophy (int a) -{ - printf ("The answer is: %d.\n", a); -} - -int main (void) -{ - philosophy ("Hello, world!\n"); - return 0; -} diff --git a/20221010/functions-07.c b/20221010/functions-07.c deleted file mode 100644 index d44829bf9a4659c294eaec84db8395fe834962ed..0000000000000000000000000000000000000000 --- a/20221010/functions-07.c +++ /dev/null @@ -1,24 +0,0 @@ -#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++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - return 0; - 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); -} diff --git a/20221010/functions-08.c b/20221010/functions-08.c deleted file mode 100644 index 48446d7ff20fc63e8ed827e5db0fed48e51e4315..0000000000000000000000000000000000000000 --- a/20221010/functions-08.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdio.h> - -int a; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - return 0; - 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); -} diff --git a/20221010/functions-09.c b/20221010/functions-09.c deleted file mode 100644 index 77b42dfdd943a2a5fd266f7782434fe1b5f3b5ab..0000000000000000000000000000000000000000 --- a/20221010/functions-09.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - return 0; - 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); -} diff --git a/20221010/functions-10.c b/20221010/functions-10.c deleted file mode 100644 index f132d2e86b139f742568178b2eaad1364e9b09b8..0000000000000000000000000000000000000000 --- a/20221010/functions-10.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - return 0; - 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); -} diff --git a/20221010/functions-11.c b/20221010/functions-11.c deleted file mode 100644 index b42cee93f5be7620a55bb685796ae30a122883ed..0000000000000000000000000000000000000000 --- a/20221010/functions-11.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - return 0; - a = b = 12; - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); -} diff --git a/20221010/functions-12.c b/20221010/functions-12.c deleted file mode 100644 index 3e707373990ea2e59dd1a529eca5ef8adfd2daa0..0000000000000000000000000000000000000000 --- a/20221010/functions-12.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; -} - -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); - return 0; - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); -} diff --git a/20221010/functions-13.c b/20221010/functions-13.c deleted file mode 100644 index 5ec0af58c608791fa2e1ca5f93668003219b8199..0000000000000000000000000000000000000000 --- a/20221010/functions-13.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - b = 12; - a = b; - printf ("main(): " "a = %d, b = %d\n", a, b); - return 0; - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); -} diff --git a/20221010/functions-14.c b/20221010/functions-14.c deleted file mode 100644 index 6ea1d0da07e6f8479b0f0dc6cbabc1fde99e5a5d..0000000000000000000000000000000000000000 --- a/20221010/functions-14.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - b = 12; - a = b; - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - return 0; - printf ("main(): " "a = %d, b = %d\n", a, b); -} diff --git a/20221010/functions-15.c b/20221010/functions-15.c deleted file mode 100644 index 6b60de937312f89db3402a5a744ac810a5b8590d..0000000000000000000000000000000000000000 --- a/20221010/functions-15.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - int a = 5; - int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - b = 12; - a = b; - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - return 0; - printf ("main(): " "a = %d, b = %d\n", a, b); -} diff --git a/20221010/functions-16.c b/20221010/functions-16.c deleted file mode 100644 index ffa82861602224ce227bfbbbc802dea3a8f20fab..0000000000000000000000000000000000000000 --- a/20221010/functions-16.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - b = 12; - a = b; - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - return 0; -} diff --git a/20221010/functions-17.c b/20221010/functions-17.c deleted file mode 100644 index a123a3acade411d6a0f01879de3a10e1b537aa12..0000000000000000000000000000000000000000 --- a/20221010/functions-17.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - static int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - b = 12; - a = b; - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - return 0; -} diff --git a/20221010/functions-18.c b/20221010/functions-18.c deleted file mode 100644 index 4b1034683b7129fdc619c1b67b037fa8cbad8357..0000000000000000000000000000000000000000 --- a/20221010/functions-18.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - static int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; - b++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - b = 12; - a = b; - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - return 0; -} diff --git a/20221010/functions-19.c b/20221010/functions-19.c deleted file mode 100644 index 37610ed19254f2086900a71d5ac8cbf69a5c37c4..0000000000000000000000000000000000000000 --- a/20221010/functions-19.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <stdio.h> - -int a = 0; -int b = 3; - -void foo (void) -{ - b++; - static int a = 5; - int b = 7; - printf ("foo(): " "a = %d, b = %d\n", a, b); - a++; - b++; -} - -int main (void) -{ - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - b = 12; - a = b; - printf ("main(): " "a = %d, b = %d\n", a, b); - foo (); - printf ("main(): " "a = %d, b = %d\n", a, b); - return 0; -} diff --git a/20221010/gitlab.png b/20221010/gitlab.png deleted file mode 100644 index 5724da8b8338534857e5e845f1f1a9b67f0fab1a..0000000000000000000000000000000000000000 Binary files a/20221010/gitlab.png and /dev/null differ diff --git a/20221010/hp-20221010-fig1.pdf b/20221010/hp-20221010-fig1.pdf deleted file mode 100644 index 2e878f1026f04f8363df3339f30f5cb936734baf..0000000000000000000000000000000000000000 Binary files a/20221010/hp-20221010-fig1.pdf and /dev/null differ diff --git a/20221010/hp-20221010-fig1.tex b/20221010/hp-20221010-fig1.tex deleted file mode 100644 index 9993254ede0128398967c2a56ca2898533e2b861..0000000000000000000000000000000000000000 --- a/20221010/hp-20221010-fig1.tex +++ /dev/null @@ -1,60 +0,0 @@ -\documentclass{article} -\input tmp.inputs -\pagestyle{empty} -\begin{document} - \psscalebox{0.79}{% - \begin{pspicture}(-5,0)(12,12) - \small - \psset{unit=0.5cm} - \psline[arrows=<->](-1,0)(-1,22) - \rput(-1.3,0){\makebox(0,0)[br]{\textbf{gegenständlich}}} - \rput(-1.3,22){\makebox(0,0)[tr]{\textbf{abstrakt}}} - \rput(-1.3,2){\makebox(0,0)[r]{Elektromagnetismus, Halbleiter}} - \rput(-1.3,4){\makebox(0,0)[r]{Elektronische Bauelemente}} - \rput(-1.3,6){\makebox(0,0)[r]{Logik-Schaltkreise}} - \rput(-1.3,8){\makebox(0,0)[r]{Prozessoren}} - \rput(-1.3,9){\makebox(0,0)[r]{Maschinensprache}} - \rput(-1.3,10){\makebox(0,0)[r]{Assembler}} - \rput(-1.3,11){\makebox(0,0)[r]{Ein-/Ausgabe}} - \rput(-1.3,12.35){\makebox(0,0)[r]{\textbf{hardwarenahe Programmierung} (z.\,B.\ in C)}} - \rput(-1.3,14){\makebox(0,0)[r]{\shortstack[r]{abstrahierende Programmierung\\(z.\,B.\ in C++, Java)}}} -% \rput(-1.3,15){\makebox(0,0)[r]{Programmierung}} - \rput(-1.3,16){\makebox(0,0)[r]{Algorithmen, Datenstrukturen, Software-Entwurf}} - \rput(-1.3,17){\makebox(0,0)[r]{Requirements Engineering}} - \rput(-1.3,18){\makebox(0,0)[r]{formale Sprachen, Berechenbarkeit}} - \rput(-1.3,19){\makebox(0,0)[r]{mathematische Strukturen}} - \rput(-1.3,20){\makebox(0,0)[r]{mathematische Beweise}} - \rput(2.1,0.5){\makebox(0,0)[l]{Physik}} - \rput(4.1,4){\makebox(0,0)[l]{Elektrotechnik}} - \rput(6.1,8){\makebox(0,0)[l]{Rechnertechnik}} - \rput(8.1,12.35){\makebox(0,0)[l]{angewandte Informatik}} - \rput(10.1,16){\makebox(0,0)[l]{\shortstack[l]{Softwaretechnik und\\theoretische Informatik}}} - \rput(12.1,21){\makebox(0,0)[l]{Mathematik}} - \psset{linewidth=0.001,linestyle=none,fillstyle=gradient,gradmidpoint=1.0,gradlines=1000} - \definecolor{RGBwhite}{rgb}{1.0,1.0,1.0} - \definecolor{RGBblue}{rgb}{0.0,0.0,1.0} - \definecolor{RGBred}{rgb}{1.0,0.0,0.0} - \definecolor{RGBgreen}{rgb}{0.0,1.0,0.0} - \definecolor{RGByellow}{rgb}{1.0,1.0,0.0} - \definecolor{RGBorange}{rgb}{1.0,0.7,0.0} - \definecolor{RGBgrey}{rgb}{0.7,0.7,0.7} - \rput(0,2){\psframe[gradbegin=RGBwhite,gradend=RGBblue](2,2)} - \rput(0,0){\psframe[fillstyle=solid,fillcolor=RGBblue](2,2.01)} - \rput(2,6){\psframe[gradbegin=RGBwhite,gradend=RGBred](2,2)} - \rput(2,2){\psframe[gradbegin=RGBred,gradend=RGBwhite](2,2)} - \rput(2,3.99){\psframe[fillstyle=solid,fillcolor=RGBred](2,2.02)} - \rput(4,10){\psframe[gradbegin=RGBwhite,gradend=RGBgreen](2,2)} - \rput(4,6){\psframe[gradbegin=RGBgreen,gradend=RGBwhite](2,2)} - \rput(4,7.99){\psframe[fillstyle=solid,fillcolor=RGBgreen](2,2.02)} - \rput(6,14){\psframe[gradbegin=RGBwhite,gradend=RGByellow](2,2)} - \rput(6,10){\psframe[gradbegin=RGByellow,gradend=RGBwhite](2,2)} - \rput(6,11.99){\psframe[fillstyle=solid,fillcolor=RGByellow](2,2.02)} - \rput(8,18){\psframe[gradbegin=RGBwhite,gradend=RGBorange](2,2)} - \rput(8,14){\psframe[gradbegin=RGBorange,gradend=RGBwhite](2,2)} - \rput(8,15.99){\psframe[fillstyle=solid,fillcolor=RGBorange](2,2.02)} - \rput(10,18){\psframe[gradbegin=RGBgrey,gradend=RGBwhite](2,2)} - \rput(10,19.99){\psframe[fillstyle=solid,fillcolor=RGBgrey](2,2.01)} - \end{pspicture} - } - -\end{document} diff --git a/20221010/hp-20221010.pdf b/20221010/hp-20221010.pdf deleted file mode 100644 index bf79bfec030b97fe2b8e3e320c272701ac0b3d0a..0000000000000000000000000000000000000000 Binary files a/20221010/hp-20221010.pdf and /dev/null differ diff --git a/20221010/hp-20221010.tex b/20221010/hp-20221010.tex deleted file mode 100644 index 313aa41741cee49dcc6bf002baedd6e321d18497..0000000000000000000000000000000000000000 --- a/20221010/hp-20221010.tex +++ /dev/null @@ -1,1582 +0,0 @@ -% hp-20221010.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Funktionen, Zeiger, Arrays und Strings - -\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} - -\newcommand{\redurl}[1]{\href{#1}{\color{red}\nolinkurl{#1}}} - -\title{Hardwarenahe Programmierung} -\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{10.\ Oktober 2022} - -\begin{document} - -\maketitleframe - -\sectionnonumber{Vorab: Online-Werkzeuge} - -\begin{frame} - - \showsectionnonumber - \begin{itemize} - \item - Diese Veranstaltung findet \textbf{in Präsenz} statt.\\ - Wir versuchen aber, auch eine Online-Teilnahme zu ermöglichen. - \medskip - \item - \textbf{Mumble}: Seminarraum 2\\ - Fragen: Mikrofon einschalten oder über den Chat\\ - Umfragen: über den Chat -- \textbf{auch während der Präsenz-Veranstaltung} - \smallskip - \item - \textbf{VNC}: Kanal 6, Passwort: \lstinline[style=cmd]{testcvh}\\ - Eigenen Bildschirm freigeben: VNC-Software oder Web-Interface \emph{yesVNC}\\ - Eigenes Kamerabild übertragen: Web-Interface \emph{CVH-Camera} - \smallskip - \item - Allgemeine Informationen: - \url{https://www.cvh-server.de/online-werkzeuge/} - \smallskip - \item - Notfall-Schnellzugang: \url{https://www.cvh-server.de/virtuelle-raeume/}\\ - Seminarraum 2, VNC-Passwort: \lstinline[style=cmd]{testcvh} - \smallskip - \item - Bei Problemen: bitte notieren:\\ - Art des Problems, genaue Uhrzeit, eigener Internet-Zugang - \bigskip - \item - GitLab: \url{https://gitlab.cvh-server.de/pgerwinski/hp} - \end{itemize} - -\end{frame} - -\begin{frame}[fragile] - - \vspace{-0.6cm} - \begin{pdfpic} - \psscalebox{0.79}{% - \begin{pspicture}(-5,0)(12,12) - \small - \psset{unit=0.5cm} - \psline[arrows=<->](-1,0)(-1,22) - \rput(-1.3,0){\makebox(0,0)[br]{\textbf{gegenständlich}}} - \rput(-1.3,22){\makebox(0,0)[tr]{\textbf{abstrakt}}} - \rput(-1.3,2){\makebox(0,0)[r]{Elektromagnetismus, Halbleiter}} - \rput(-1.3,4){\makebox(0,0)[r]{Elektronische Bauelemente}} - \rput(-1.3,6){\makebox(0,0)[r]{Logik-Schaltkreise}} - \rput(-1.3,8){\makebox(0,0)[r]{Prozessoren}} - \rput(-1.3,9){\makebox(0,0)[r]{Maschinensprache}} - \rput(-1.3,10){\makebox(0,0)[r]{Assembler}} - \rput(-1.3,11){\makebox(0,0)[r]{Ein-/Ausgabe}} - \rput(-1.3,12.35){\makebox(0,0)[r]{\textbf{hardwarenahe Programmierung} (z.\,B.\ in C)}} - \rput(-1.3,14){\makebox(0,0)[r]{\shortstack[r]{abstrahierende Programmierung\\(z.\,B.\ in C++, Java)}}} -% \rput(-1.3,15){\makebox(0,0)[r]{Programmierung}} - \rput(-1.3,16){\makebox(0,0)[r]{Algorithmen, Datenstrukturen, Software-Entwurf}} - \rput(-1.3,17){\makebox(0,0)[r]{Requirements Engineering}} - \rput(-1.3,18){\makebox(0,0)[r]{formale Sprachen, Berechenbarkeit}} - \rput(-1.3,19){\makebox(0,0)[r]{mathematische Strukturen}} - \rput(-1.3,20){\makebox(0,0)[r]{mathematische Beweise}} - \rput(2.1,0.5){\makebox(0,0)[l]{Physik}} - \rput(4.1,4){\makebox(0,0)[l]{Elektrotechnik}} - \rput(6.1,8){\makebox(0,0)[l]{Rechnertechnik}} - \rput(8.1,12.35){\makebox(0,0)[l]{angewandte Informatik}} - \rput(10.1,16){\makebox(0,0)[l]{\shortstack[l]{Softwaretechnik und\\theoretische Informatik}}} - \rput(12.1,21){\makebox(0,0)[l]{Mathematik}} - \psset{linewidth=0.001,linestyle=none,fillstyle=gradient,gradmidpoint=1.0,gradlines=1000} - \definecolor{RGBwhite}{rgb}{1.0,1.0,1.0} - \definecolor{RGBblue}{rgb}{0.0,0.0,1.0} - \definecolor{RGBred}{rgb}{1.0,0.0,0.0} - \definecolor{RGBgreen}{rgb}{0.0,1.0,0.0} - \definecolor{RGByellow}{rgb}{1.0,1.0,0.0} - \definecolor{RGBorange}{rgb}{1.0,0.7,0.0} - \definecolor{RGBgrey}{rgb}{0.7,0.7,0.7} - \rput(0,2){\psframe[gradbegin=RGBwhite,gradend=RGBblue](2,2)} - \rput(0,0){\psframe[fillstyle=solid,fillcolor=RGBblue](2,2.01)} - \rput(2,6){\psframe[gradbegin=RGBwhite,gradend=RGBred](2,2)} - \rput(2,2){\psframe[gradbegin=RGBred,gradend=RGBwhite](2,2)} - \rput(2,3.99){\psframe[fillstyle=solid,fillcolor=RGBred](2,2.02)} - \rput(4,10){\psframe[gradbegin=RGBwhite,gradend=RGBgreen](2,2)} - \rput(4,6){\psframe[gradbegin=RGBgreen,gradend=RGBwhite](2,2)} - \rput(4,7.99){\psframe[fillstyle=solid,fillcolor=RGBgreen](2,2.02)} - \rput(6,14){\psframe[gradbegin=RGBwhite,gradend=RGByellow](2,2)} - \rput(6,10){\psframe[gradbegin=RGByellow,gradend=RGBwhite](2,2)} - \rput(6,11.99){\psframe[fillstyle=solid,fillcolor=RGByellow](2,2.02)} - \rput(8,18){\psframe[gradbegin=RGBwhite,gradend=RGBorange](2,2)} - \rput(8,14){\psframe[gradbegin=RGBorange,gradend=RGBwhite](2,2)} - \rput(8,15.99){\psframe[fillstyle=solid,fillcolor=RGBorange](2,2.02)} - \rput(10,18){\psframe[gradbegin=RGBgrey,gradend=RGBwhite](2,2)} - \rput(10,19.99){\psframe[fillstyle=solid,fillcolor=RGBgrey](2,2.01)} - \end{pspicture} - } - \end{pdfpic} - -\end{frame} - -\sectionnonumber{Hardwarenahe Programmierung} -\subsectionnonumber{Programmierung in C} - -\begin{frame} - - \showsectionnonumber - - Man kann Computer vollständig beherrschen. - -% \begin{onlyenv}<1> -% -% \vspace*{2cm} -% -% {\Large\color{structure}\textbf{Rechnertechnik}} -% -% \bigskip -% -% Man kann vollständig verstehen, wie Computer funktionieren. -% -% \vspace*{-3cm} -% -% \end{onlyenv} - -% \pause - - \bigskip - \bigskip - - \showsubsectionnonumber - - \vspace{-\medskipamount} - - \begin{itemize} -% \item -% kleinster gemeinsamer Nenner für viele Plattformen\\ -% \pause -% \begin{picture}(0,1) -% \color{red} -% \put(7.2,0.6){\vector(0,1){0.4}} -% \put(7.2,0.5){\makebox(0,0)[t]{\color{black}Hardware und/oder Betriebssystem}} -% \end{picture} -% \pause -% \medskip - \item - Hardware direkt ansprechen und effizient einsetzen - \medskip - \item - \dots\ bis hin zu komplexen Software-Projekten - \medskip - \item - Programmierkenntnisse werden nicht vorausgesetzt,\\ - aber schnelles Tempo - \end{itemize} - -\end{frame} - -\iffalse - -\subsectionnonumber{Programmierung in C und C++} - -\begin{frame} - - \showsectionnonumber - - Man kann Computer vollständig beherrschen. - - \bigskip - - \showsubsectionnonumber - - Etabliertes Profi-Werkzeug - \begin{itemize} - \item - kleinster gemeinsamer Nenner für viele Plattformen\\ - \begin{picture}(0,1) - \color{red} - \put(7.2,0.6){\vector(0,1){0.4}} - \put(7.2,0.5){\makebox(0,0)[t]{\color{black}Hardware und/oder Betriebssystem}} - \end{picture} - \medskip - \item - Programmierkenntnisse werden nicht vorausgesetzt,\\ - aber schnelles Tempo - \bigskip - \item - Hardware direkt ansprechen und effizient einsetzen - \bigskip - \item - \dots\ bis hin zu komplexen Software-Projekten - \end{itemize} - -\end{frame} - -\fi - -\subsectionnonumber{Was ist C?} - -\begin{frame} - - \showsectionnonumber - \showsubsectionnonumber - - Etabliertes Profi-Werkzeug - \begin{itemize} - \item - kleinster gemeinsamer Nenner für viele Plattformen -% \pause - \begin{picture}(0,0) - \color{red} - \put(-1.0,-0.8){\vector(0,1){0.7}} - \put(-1.0,-0.9){\makebox(0,0)[t]{\color{black}Hardware und/oder Betriebssystem}} - \end{picture} -% \pause - \item - leistungsfähig, aber gefährlich - \end{itemize} - -% \pause - \medskip - "`High-Level-Assembler"' - \begin{itemize} -% \pause - \item - kein "`Fallschirm"' -% \pause - \item - kompakte Schreibweise - \end{itemize} - -% \pause - \medskip - Unix-Hintergrund - \begin{itemize} -% \pause - \item - Baukastenprinzip -% \pause - \item - konsequente Regeln -% \pause - \item - kein "`Fallschirm"' - \end{itemize} - -\end{frame} - -\sectionnonumber{Zu dieser Lehrveranstaltung} - -\begin{frame} - - \showsectionnonumber - - \begin{itemize} - \item - \textbf{Lehrmaterialien:}% - \hfill\makebox(0,0)[r]{\includegraphics[width=3.5cm]{gitlab.png}}\\ - \url{https://gitlab.cvh-server.de/pgerwinski/hp} - \item - \textbf{Klausur:} - - Zeit: 150 Minuten - - Zulässige Hilfsmittel: - \begin{itemize} - \item Schreibgerät - \item beliebige Unterlagen in Papierform und/oder auf Datenträgern - \item elektronische Rechner (Notebook, Taschenrechner o.\,ä.) - \item \emph{kein\/} Internet-Zugang - \end{itemize} - \item - \textbf{Übungen}\\ - sind mit der Vorlesung integriert. - \item - Das \textbf{Praktikum}\\ - findet jede Woche statt.\\ - Diese Woche: vorbereitende Maßnahmen,\\ - Kennenlernen der verwendeten Werkzeuge - \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}}} - \begin{itemize} - \color{medgreen} - \item[1.1] Was ist hardwarenahe Programmierung? - \item[1.2] Programmierung in C - \item[1.3] Zu dieser Lehrveranstaltung - \end{itemize} - \item[\textbf{2}] \textbf{Einführung in C} - \begin{itemize} - \color{medgreen} - \item[2.1] Hello, world! - \item[2.2] Programme compilieren und ausführen - \item[2.3] Elementare Aus- und Eingabe - \item[2.4] Elementares Rechnen - \item[2.5] Verzweigungen - \item[2.6] Schleifen - \item[2.7] Strukturierte Programmierung - \item[2.8] Seiteneffekte - \color{red} - \item[2.9] Funktionen - \item[\dots] -% \item[2.10] Zeiger -% \item[2.11] Arrays und Strings -% \item[2.12] Strukturen -% \item[\dots] - \end{itemize} - \color{gray} - \item[\textbf{3}] \textbf{Bibliotheken} - \vspace*{-\smallskipamount} - \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{frame} - -\section{Einführung} -\section{Einführung in C} -\subsection{Hello, world!} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - Text ausgeben - - \bigskip - - \begin{lstlisting} - #include <stdio.h> - - int main (void) - { - printf ("Hello, world!\n"); - return 0; - } - \end{lstlisting} -% \pause - \begin{picture}(0,0) - \color{red} - \put(5.0,1.5){\makebox(0,0)[bl]{printf = "`print formatted"'}} -% \pause - \put(4.0,0.4){\makebox(0,0)[br]{\tikz{\draw[-latex](0.0,0.0)--(-0.3,0.7);}}} - \put(4.0,0.3){\makebox(0,0)[t]{\textbackslash n: Zeilenschaltung}} - \end{picture} - -\end{frame} - -\subsection{Programme compilieren und ausführen} - -\begin{frame}[fragile] - - \showsubsection - - \begin{onlyenv}<1-3> - \begin{lstlisting}[style=terminal,gobble=6] - $ ¡gcc hello-1.c -o hello-1¿ - $ ¡./hello-1¿ - Hello, world! - $ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<4-> - \begin{lstlisting}[style=terminal,gobble=6] - $ ¡gcc -Wall -O hello-1.c -o hello-1¿ - $ ¡./hello-1¿ - Hello, world! - $ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<2> - \bigskip - Hier: Kommandozeilen-Interface (CLI) - \begin{itemize} - \item - Der C-Compiler (hier: \lstinline[style=cmd]{gcc}) - muß installiert sein und sich im \lstinline[style=terminal]{PATH} befinden. - \item - Der Quelltext (hier: \file{hello-1.c}) - muß sich im aktuellen Verzeichnis befinden. - \item - aktuelles Verzeichnis herausfinden: \lstinline[style=cmd]{pwd} - \item - aktuelles Verzeichnis wechseln: \lstinline[style=cmd]{cd foobar}, \lstinline[style=cmd]{cd ..} - \item - Inhalt des aktuellen Verzeichnisses ausgeben: \lstinline[style=cmd]{ls}, \lstinline[style=cmd]{ls -l} - \item - Ausführen des Programms (\file{hello-1}) im aktuellen Verzeichnis (\file{.}):\\ - \lstinline[style=cmd]{./hello-1} - \end{itemize} - - Alternative: Integrierte Entwicklungsumgebung (IDE)\\ - mit graphischer Benutzeroberfläche (GUI) - \begin{itemize} - \item - Das können Sie bereits. - \end{itemize} - \vspace*{-1cm} - \end{onlyenv} - \begin{onlyenv}<3> - \bigskip - GNU Compiler Collection (GCC) für verschiedene Plattformen: - \begin{itemize} - \item - GNU/Linux: \file{gcc} - \item - Apple Mac OS: \file{Xcode} - \item - Microsoft Windows: \file{Cygwin}\\ - oder \file{MinGW} mit \file{MSYS}\\ - oder \file{WSL} mit darin installiertem \file{GNU/Linux} - \medskip - \item - außerdem: Texteditor\\ - \file{vi}(\file{m}), \file{nano}, - \file{Emacs}, \file{Notepad++}, \dots\\ - (Microsoft Notepad ist \emph{nicht} geeignet!) - \end{itemize} - \end{onlyenv} - \begin{onlyenv}<1> - \begin{picture}(0,0) - \color{red} - \put(4.0,0.5){\tikz{\draw[-latex](0.0,0.0)--(-2.0,1.0);}} - \put(4.0,0.3){\makebox(0,0)[tl]{\begin{minipage}[t]{8cm} - \begin{tabular}{ll} - \lstinline[style=cmd]{-o hello-1} - & Name für Ausgabe-Datei ("`output"') \\ - & unter Unix: ohne Endung \\ - & unter MS-Windows: Endung \lstinline[style=cmd]{.exe} - \end{tabular} - \end{minipage}}} - \end{picture} - \end{onlyenv} - \begin{onlyenv}<4-> - \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{onlyenv} - -\end{frame} - -\subsection{Elementare Aus- und Eingabe} - -\begin{frame}[fragile] - - \showsubsection - - Wert ausgeben - - \bigskip - - \begin{lstlisting} - #include <stdio.h> - - int main (void) - { - printf ("Die Antwort lautet: "); - printf (42); - printf ("\n"); - return 0; - } - \end{lstlisting} -% \pause - \medskip - \textarrow\ Absturz - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Wert ausgeben - - \bigskip - - \begin{lstlisting} - #include <stdio.h> - - int main (void) - { - printf ("Die Antwort lautet: %d\n", 42); - return 0; - } - \end{lstlisting} - \begin{picture}(0,0) - \color{red} - \put(5.3,0.65){\tikz{\draw[-latex](0.0,0.0)--(-0.5,0.5);}} - \put(5.9,0.35){\begin{minipage}[t]{6.5cm} - Formatspezifikation "`d"': "`dezimal"'%\pause - \\[\smallskipamount] - Weitere Formatspezifikationen:\\ - siehe Dokumentation (z.\,B.\ man 3 printf),\\ - Internet-Recherche oder Literatur - \end{minipage}} - \end{picture} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Wert einlesen - - \bigskip - - \begin{lstlisting} - #include <stdio.h> - - int main (void) - { - double a; - printf ("Bitte eine Zahl eingeben: "); - scanf ("%lf", &a); - printf ("Ihre Antwort war: %lf\n", a); - return 0; - } - \end{lstlisting} - \begin{picture}(0,0) - \color{red} - \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"'\\[\smallskipamount] - Das "`\&"' nicht vergessen! - \end{minipage}} - \end{picture} - -\end{frame} - -\subsection{Elementares Rechnen} - -\begin{frame}[fragile] - - \showsubsection - - Wert an Variable zuweisen - - \bigskip - - \begin{lstlisting} - #include <stdio.h> - - int main (void) - { - int a; - printf ("Bitte eine Zahl eingeben: "); - scanf ("%d", &a); - a = 2 * a; - printf ("Das Doppelte ist: %d\n", a); - return 0; - } - \end{lstlisting} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Variable bei Deklaration initialisieren - - \bigskip - - \begin{lstlisting} - int a = 42; - a = 137; - \end{lstlisting} - - \bigskip - - \textbf{Achtung:} Initialisierung $\ne$ Zuweisung - - \smallskip - - Die beiden Gleichzeitszeichen haben\\ - \emph{subtil unterschiedliche\/} Bedeutungen! - -\end{frame} - -\subsection{Verzweigungen} - -\begin{frame}[fragile] - - \showsubsection - - \begin{minipage}[t]{6cm} - \lstinline{if}-Verzweigung - - \bigskip - - \begin{lstlisting}[gobble=6] - if (b != 0) - printf ("%d\n", a / b); - \end{lstlisting} - \end{minipage}%\pause - \begin{minipage}[t]{6cm} - \textbf{Wahrheitswerte} in C: \textbf{numerisch}\\[\medskipamount] - 0 steht für \emph{falsch (false)},\\ - $\ne 0$ steht für \emph{wahr (true)}. - - \bigskip - - \begin{lstlisting}[gobble=6] - if (b) - printf ("%d\n", a / b); - \end{lstlisting} - \end{minipage} - -\end{frame} - -\subsection{Schleifen} - -\begin{frame}[fragile] - - \showsubsection - - \begin{minipage}[t]{6cm} - \lstinline{while}-Schleife - \bigskip - \begin{lstlisting}[gobble=6] - a = 1; - while (a <= 10) - { - printf ("%d\n", a); - a = a + 1; - } - \end{lstlisting} - \end{minipage}%\pause - \begin{minipage}[t]{6cm} - \lstinline{for}-Schleife - \bigskip - \begin{lstlisting}[gobble=6] - for (a = 1; a <= 10; a = a + 1) - printf ("%d\n", a); - \end{lstlisting} - \vspace{1.5cm} -% \pause - \lstinline{do}-\lstinline{while}-Schleife - \bigskip - \begin{lstlisting}[gobble=6] - a = 1; - do - { - printf ("%d\n", a); - a = a + 1; - } - while (a <= 10); - \end{lstlisting} - \end{minipage} - -\end{frame} - -\subsection{Strukturierte Programmierung} - -\begin{frame}[fragile] - - \visible<1->{\showsubsection} - - \begin{minipage}[t]{6cm} - \begin{onlyenv}<1-> - \begin{lstlisting}[gobble=8] - ¡i = 0; - while (1) - { - if (i >= 10) - break; - printf ("%d\n", i++); - }¿ - \end{lstlisting} - \end{onlyenv} - \strut - \bigskip - \begin{onlyenv}<1-> - \begin{lstlisting}[gobble=8] - ¡i = 0; - loop: - if (i >= 10) - goto endloop; - printf ("%d\n", i++); - goto loop; - endloop:¿ - \end{lstlisting} - \end{onlyenv} - \end{minipage} - \begin{minipage}[t]{6cm} - \vspace{-\bigskipamount} - \begin{lstlisting} - ¡int i; - \end{lstlisting} - \bigskip - \begin{lstlisting} - ¡i = 0; - while (i < 10) - { - printf ("%d\n", i); - i++; - }¿ - \end{lstlisting} - \bigskip - \begin{lstlisting} - ¡for (i = 0; i < 10; i++) - printf ("%d\n", i);¿ - \end{lstlisting} - \bigskip - \begin{lstlisting} - ¡i = 0; - while (i < 10) - printf ("%d\n", i++);¿ - \end{lstlisting} - \bigskip - \begin{lstlisting} - ¡for (i = 0; i < 10; printf ("%d\n", i++));¿ - \end{lstlisting} - \end{minipage}% - \begin{onlyenv}<1-> - \begin{picture}(0,0) - \put(-1.9,-3.0){\mbox{\color{medgreen}gut}} - \put(-1.9,-5.2){\begin{minipage}{5cm} - \color{orange} - nur, wenn\\ - Sie wissen,\\ - was Sie tun - \end{minipage}} - - \put(-10,-0.5){\mbox{\color{red}fragwürdig}} - \put(-9.3,-4.2){\begin{minipage}[t]{5cm} - \color{red} - sehr fragwürdig\\[\smallskipamount] - \footnotesize(siehe z.\,B.:\\ - http://xkcd.com/292/) - \end{minipage}} - \end{picture} - \end{onlyenv} - \vspace*{-1cm} - -\end{frame} - -\subsection{Seiteneffekte} - -\begin{frame}[fragile] - - \showsubsection - - \begin{lstlisting} - #include <stdio.h> - - int main (void) - { - printf ("Hello, world!\n"); - "Hello, world!\n"; - return 0; - } - \end{lstlisting} -% \pause - \begin{picture}(0,0) - \color{red} - \put(3.1,1.35){\tikz{\draw[-latex](0.0,0.0)--(-0.8,0);}} - \put(4.0,1.35){\makebox(0,0)[l]{Ausdruck als Anweisung: Wert wird ignoriert}} - \pause - \put(3.55,1.40){\tikz{\draw[-latex](0.0,0.0)--(-0.4,0.2);}} - \end{picture} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \begin{lstlisting} - #include <stdio.h> - - int main (void) - { - int a = printf ("Hello, world!\n"); - printf ("%d\n", a); - return 0; - } - \end{lstlisting} -% \pause - \bigskip - \begin{lstlisting}[style=terminal] - $ ¡gcc -Wall -O side-effects-1.c -o side-effects-1¿ - $ ¡./side-effects-1¿ - Hello, world! - 14 - $ - \end{lstlisting} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \begin{lstlisting} - #include <stdio.h> - - int main (void) - { - int a = printf ("Hello, world!\n"); - printf ("%d\n", a); - return 0; - } - \end{lstlisting} - \begin{itemize} - \item - \lstinline{printf()} ist eine Funktion. -% \pause - \item - "`Haupteffekt"': Wert zurückliefern\\ - (hier: Anzahl der ausgegebenen Zeichen) -% \pause - \item - \newterm{Seiteneffekt\/}: Ausgabe - \end{itemize} - -\end{frame} - -\addtocounter{subsection}{-1} -\subsection{Seiteneffekte \protect\color{gray}bei Operatoren} - -\begin{frame}[fragile] - - \showsubsection - - \begin{minipage}[t]{6cm} - Unäre Operatoren: - \begin{itemize} - \item - Negation: \lstinline{-foo} - \item - {\only<1->{\color{red}}Funktionsaufruf}: \lstinline{foo ()} - \item - {\only<1->{\color{red}}Post-Inkrement}: \lstinline{foo++} - \item - {\only<1->{\color{red}}Post-Dekrement}: \lstinline{foo--} - \item - {\only<1->{\color{red}}Prä-Inkrement}: \lstinline{++foo} - \item - {\only<1->{\color{red}}Prä-Dekrement}: \lstinline{--foo} - \end{itemize} - \medskip - Binäre Operatoren: - \begin{itemize} - \item - Rechnen: \lstinline{+ - * / %} - \item - Vergleich: \lstinline{== != < > <= >=} - \item - {\only<1->{\color{red}}Zuweisung}: \lstinline{= += -= *= /= %=} - \item - Ignorieren: \lstinline{,}\quad \lstinline{a, b}: berechne \lstinline{a}, ignoriere es, nimm stattdessen \lstinline{b} - \end{itemize} -% \pause - \medskip - {\color{red}rot = mit Seiteneffekt} - \end{minipage} -% \pause - \begin{minipage}[t]{6cm} - \vspace{-\bigskipamount} - \begin{lstlisting} - ¡int i;¿ - \end{lstlisting} - \bigskip - \begin{lstlisting} - ¡i = 0; - while (i < 10) - { - printf ("%d\n", i); - i++; - }¿ - \end{lstlisting} - \bigskip -% \pause - \begin{lstlisting} - ¡for (i = 0; i < 10; i++) - printf ("%d\n", i);¿ - \end{lstlisting} - \bigskip -% \pause - \begin{lstlisting} - ¡i = 0; - while (i < 10) - printf ("%d\n", i++);¿ - \end{lstlisting} - \bigskip -% \pause - \begin{lstlisting} - ¡for (i = 0; i < 10; printf ("%d\n", i++));¿ - \end{lstlisting} - \end{minipage} - \vspace*{-1cm} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \begin{itemize} - \color{medgreen} - \item[2.1] Hello, world! - \item[2.2] Programme compilieren und ausführen - \item[2.3] Elementare Aus- und Eingabe - \item[2.4] Elementares Rechnen - \item[2.5] Verzweigungen - \item[2.6] Schleifen - \item[2.7] Strukturierte Programmierung - \item[2.8] Seiteneffekte - \color{red} - \item[2.9] Funktionen - \item[2.10] Zeiger - \item[2.11] Arrays und Strings - \color{black} - \item[2.12] Strukturen - \item[\dots] - \end{itemize} - \color{gray} - \item[\textbf{3}] \textbf{Bibliotheken} - \vspace*{-\smallskipamount} - \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} - -\subsection{Funktionen} - -\begin{frame}[fragile] - - \showsubsection - - \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] - - \showsubsection - - \begin{minipage}[t]{6.5cm} - \vspace{-\medskipamount} - \begin{lstlisting}[gobble=6] - ¡#include <stdio.h> - - void add_verbose (int a, int b) - { - printf ("%d + %d = %d\n", a, b, a + b); - } - - 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] - - \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] - \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} - \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 - \end{itemize} - \end{minipage} -\end{frame} - -\subsection{Arrays und Strings} - -\begin{frame}[fragile] - \showsubsection - - Ein Zeiger zeigt auf eine Variable\only<2->{ und deren Nachbarn}. - -% \bigskip - \pause - \pause - - \begin{onlyenv}<1-8> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[5] = { 2, 3, 5, 7, 11 }; - int *p = prime; - for (int i = 0; i < 5; i++) - printf ("%d\n", *(p + i)); - return 0; - } - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<9> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[5] = { 2, 3, 5, 7, 11 }; - int *p = prime; - for (int i = 0; i < 5; i++) - 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 }; - for (int i = 0; i < 5; i++) - printf ("%d\n", prime[i]); - return 0; - } - ¡ ¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<11> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[5] = { 2, 3, 5, 7, 11 }; - for (int *p = prime; - p < prime + 5; p++) - printf ("%d\n", *p); - return 0; - } - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<12> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[6] = { 2, 3, 5, 7, 11, 0 }; - for (int *p = prime; *p; p++) - printf ("%d\n", *p); - return 0; - } - ¡ ¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<13-> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[] = { 2, 3, 5, 7, 11, 0 }; - for (int *p = prime; *p; p++) - printf ("%d\n", *p); - return 0; - } - ¡ ¿ - \end{lstlisting} - \end{onlyenv} - - \pause - \vspace{-3.05cm}\hspace{5.5cm}% - \begin{minipage}{6.5cm} - \begin{itemize} - \item - \lstinline{prime} ist \alt<5->{ein Array}{eine Ansammlung} von\\fünf ganzen Zahlen. - \pause - \pause - \item - \only<6-9>{\begin{picture}(0,0) - \color{red} - \put(-1.6,0.1){\tikz{\draw[-latex](0.0,0.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)} - \pause - \pause - \item - Zeiger-Arithmetik:\\ - \lstinline{p++} rückt den Zeiger \lstinline{p}\\ - um eine \lstinline{int} weiter. - \pause - \pause - \item - Array ohne \only<14->{explizite }Längenangabe:\\ - Compiler zählt selbst - \vspace*{-1cm} - \pause - \begin{picture}(0,0) - \put(-5.2,1.0){\makebox(0,0)[br]{\color{red}\bf\shortstack{Die Länge des Arrays\\ist \emph{nicht\/} veränderlich!}}} - \end{picture} - \end{itemize} - \end{minipage} -\end{frame} - -% \begin{frame}[fragile] -% \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] -% \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] -% \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} -% \end{frame} - -\begin{frame}[fragile] - \showsubsection - - \begin{onlyenv}<1-6> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - char hello[] = "Hello, world!\n"; - for (char *p = hello; *p; p++) - printf ("%d", *p); - return 0; - } - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<7> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - char hello[] = "Hello, world!\n"; - for (char *p = hello; *p; p++) - printf ("%c", *p); - return 0; - } - \end{lstlisting} - \end{onlyenv} -% \begin{onlyenv}<8> -% \begin{lstlisting}[gobble=6] -% #include <stdio.h> -% -% int main (void) -% { -% char hello[] = "Hello, world!\n"; -% printf ("%s", hello); -% return 0; -% } -% ¡ ¿ -% \end{lstlisting} -% \end{onlyenv} -% \begin{onlyenv}<9> -% \begin{lstlisting}[gobble=6] -% #include <stdio.h> -% -% int main (void) -% { -% char *hello = "Hello, world!\n"; -% printf ("%s", hello); -% return 0; -% } -% ¡ ¿ -% \end{lstlisting} -% \end{onlyenv} -% \begin{onlyenv}<10> -% \begin{lstlisting}[gobble=6] -% #include <stdio.h> -% -% int main (void) -% { -% char *hello = "Hello, world!\n"; -% while (*hello) -% printf ("%c", *hello++); -% return 0; -% } -% \end{lstlisting} -% \end{onlyenv} - - \vspace{-1.7cm}\hfill - \begin{minipage}{6.8cm} - \begin{itemize} - \pause[2] - \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 - Der letzte \lstinline{char} muß 0 sein.\\ - Er kennzeichnet das Ende des Strings. - \pause - \item - Die Formatspezifikation\\ - entscheidet über die Ausgabe:\\[\smallskipamount] - \begin{tabular}{ll} - \lstinline|%d|\hspace*{0.5em}dezimal - & \lstinline|%c|\hspace*{0.5em}Zeichen\\ - \lstinline|%x|\hspace*{0.5em}hexadezimal -% \pause -% & \lstinline|%s|\hspace*{0.5em}String - \end{tabular} - \vspace*{-1cm} - \end{itemize} - \end{minipage} -\end{frame} - -\addtocounter{subsection}{-1} -\subsection{Arrays und Strings \protect\color{gray}und Zeichen} - -\begin{frame}[fragile] - \showsubsection - - \emph{"`Alles ist Zahl."'\/} -- Schule der Pythagoreer, 6.\ Jh.\ v.\,Chr. - - \medskip - - \begin{center} - \renewcommand{\arraystretch}{1.5} - \begin{tabular}{r} - \lstinline|"Hello"|\\ - \lstinline|'H'|\\ - \lstinline|'a' + 4| - \end{tabular} - \renewcommand{\arraystretch}{1.0} - \begin{tabular}{c} - ist nur eine andere\\ - Schreibweise für - \end{tabular} - \renewcommand{\arraystretch}{1.5} - \begin{tabular}{l} - \lstinline|{ 72, 101, 108, 108, 111, 0 }|\\ - \lstinline|72|\\ - \lstinline|'e'| - \end{tabular} - \renewcommand{\arraystretch}{1.0} - \end{center} - - \begin{itemize} - \item - Welchen Zahlenwert hat \lstinline{'*'} im Zeichensatz? - - \smallskip - - \begin{lstlisting}[gobble=8] - printf ("%d\n", '*'); - \end{lstlisting} - - \smallskip - - (normalerweise: ASCII) - \medskip - \item - Ist \lstinline{char ch} ein Großbuchstabe? - - \smallskip - - \begin{lstlisting}[gobble=8] - if (ch >= 'A' && ch <= 'Z') - ... - \end{lstlisting} - \medskip - \item - Groß- in Kleinbuchstaben umwandeln - - \smallskip - - \begin{lstlisting}[gobble=8] - ch += 'a' - 'A'; - \end{lstlisting} - \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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \begin{itemize} - \item[2.1] Hello, world! - \item[2.2] Programme compilieren und ausführen - \item[2.3] Elementare Aus- und Eingabe - \item[2.4] Elementares Rechnen - \item[2.5] Verzweigungen - \item[2.6] Schleifen - \item[2.7] Strukturierte Programmierung - \item[2.8] Seiteneffekte - \color{medgreen} - \item[2.9] Funktionen - \item[2.10] Zeiger - \item[2.11] Arrays und Strings - \color{red} - \item[2.12] Strukturen - \item[\dots] - \end{itemize} - \color{gray} - \item[\textbf{3}] \textbf{Bibliotheken} - \vspace*{-\smallskipamount} - \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} diff --git a/20221010/hp-musterloesung-20221010.pdf b/20221010/hp-musterloesung-20221010.pdf deleted file mode 100644 index 702cba8bda0bb7341f4963f472a7f677ffc05ccc..0000000000000000000000000000000000000000 Binary files a/20221010/hp-musterloesung-20221010.pdf and /dev/null differ diff --git a/20221010/hp-musterloesung-20221010.tex b/20221010/hp-musterloesung-20221010.tex deleted file mode 100644 index 0e03af9727dbc70e4e939df693623e54c2beab1c..0000000000000000000000000000000000000000 --- a/20221010/hp-musterloesung-20221010.tex +++ /dev/null @@ -1,375 +0,0 @@ -% hp-musterloesung-20221010.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Schaltjahr ermitteln, Multiplikationstabelle, Fibonacci-Zahlen, fehlerhaftes Programm - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 10.\ Oktober 2022} - - \exercise{Schaltjahr ermitteln} - - Schreiben Sie ein C-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} - - \solution - - Am einfachsten ist es, die Aufgabenstellung in geschachtelte - \lstinline{if}-Verzweigungen zu übersetzen. - Im folgenden finden Sie eine Funktion \lstinline{is_leap_year()}, - der man das Jahr übergibt und die für Schaltjahre \lstinline{1} - zurückgibt und für Nicht-Schaltjahre \lstinline{0}. - \begin{lstlisting} - #include <stdio.h> - - int is_leap_year (int year) - { - int leap_year = 0; - if (year % 4 == 0) - { - leap_year = 1; - if (year % 100 == 0) - { - leap_year = 0; - if (year % 400 == 0) - leap_year = 1; - } - } - return leap_year; - } - \end{lstlisting} - (In C steht \lstinline{0} für den Wahrheitswert "`falsch"' - und jeder Wert ungleich \lstinline{0} für den Wahrheitswert "`wahr'"; - die Zeile \lstinline{leap_year = 0} steht daher wörtlich und - selbsterklärend für "`ist kein Schaltjahr"'.) - - Unter Verwendung von \lstinline{else} läßt sich dies verkürzen zu: - \begin{lstlisting} - #include <stdio.h> - - int is_leap_year (int year) - { - if (year % 4 == 0) - { - if (year % 100 == 0) - { - if (year % 400 == 0) - return 1; - else - return 0; - } - else - return 1; - } - else - return 0; - } - \end{lstlisting} - - Eine andere Möglichkeit ist es, die Schaltjahr-Bedingung in eine - Kette von "`und"'- und "`oder"'-Verknüpfungen - (C-Operatoren \lstinline{&&} und \lstinline{||}) zu übersetzen: - \begin{lstlisting} - int is_leap_year (int year) - { - if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) - return 1; - else - return 0; - } - \end{lstlisting} - Dies ist zwar kürzer, aber nicht unbedingt übersichtlicher. - Der erzeugte Code ist übrigens \emph{nicht\/} kürzer und/oder - effizienter als bei der Verwendung mehrerer - \lstinline{if}-Verzweigungen. - Wir empfehlen, daß Sie immer so programmieren, - daß Sie selbst den maximalen Überblick über Ihr Programm behalten. - - \goodbreak - - Ein Hauptprogramm, das die o.\,a.\ Funktion aufruft, - könnte dann wie folgt aussehen: - \begin{lstlisting} - int main (void) - { - int year; - printf ("Bitte geben Sie eine Jahreszahl ein: "); - scanf ("%d", &year); - if (is_leap_year (year)) - printf ("Das Jahr %d ist ein Schaltjahr.\n", year); - else - printf ("Das Jahr %d ist kein Schaltjahr.\n", year); - return 0; - } - \end{lstlisting} - In den Dateien \gitfile{hp}{2022ws/20221010}{loesung-1-1.c} bis \gitfile{hp}{2022ws/20221010}{loesung-1-3.c} - finden Sie lauffähige Programme, die die o.\,a.\ Funktionen aufrufen. - Beachten Sie, daß die Funktion \emph{vor\/} dem Hauptprogramm - deklariert werden muß, damit das Hauptprogramm sie kennt. - (Es gibt Tricks, mit denen es auch anders geht, - aber was hätten wir in diesem Zusammenhang davon?) - - In \gitfile{hp}{2022ws/20221010}{loesung-1-4.c} und \gitfile{hp}{2022ws/20221010}{loesung-1-5.c} - findet die Schaltjahr-Prüfung direkt im Hauptprogramm statt. - Dies ist ebenfalls eine richtige Lösung der Aufgabe, - schränkt aber die Wiederverwertbarkeit des Codes ein. - - Die Datei \gitfile{hp}{2022ws/20221010}{loesung-1-4.c} enthält darüberhinaus Codeverdopplungen, - nämlich mehrere identische \lstinline{printf()}-Auf"-rufe - an unterschiedlichen Stellen. - Dies ist schlechter Programmierstil ("`Cut-and-paste-Programmierung"'). - - Die besten Lösungen sind \gitfile{hp}{2022ws/20221010}{loesung-1-2.c} - und \gitfile{hp}{2022ws/20221010}{loesung-1-3.c}. - - \goodbreak - - Zum Testen:\vspace*{-\medskipamount} - \begin{itemize}\itemsep0pt - \item 1900 ist kein Schaltjahr. - \item 1902 ist kein Schaltjahr. - \item 1904 ist ein Schaltjahr. - \item 1996 ist ein Schaltjahr. - \item 1998 ist kein Schaltjahr. - \item 2000 ist ein Schaltjahr. - \item 2002 ist kein Schaltjahr. - \item 2004 ist ein Schaltjahr. - \item 2019 ist kein Schaltjahr. - \item 2020 ist ein Schaltjahr. - \item 2021 ist kein Schaltjahr. - \item 2022 ist kein Schaltjahr. - \end{itemize} - - \goodbreak - - Hier noch ein Hinweis für Unix-Shell-Experten: - \begin{lstlisting}[style=cmd] - for y in 1 2 3 4 5; do - clear - for x in 1900 1902 1904 1996 1998 2000 2002 2004 2019 2020 2021 2022; do - echo $x | ./loesung-1-$y - done - sleep 2s - done - \end{lstlisting} - - \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}\,) - - \solution - - Drei verschiedene richtige Lösungen finden Sie in den Dateien - \gitfile{hp}{2022ws/20221010}{loesung-2-1.c}, \gitfile{hp}{2022ws/20221010}{loesung-2-2.c} und \gitfile{hp}{2022ws/20221010}{loesung-2-3.c}. - (Zum Compilieren von \gitfile{hp}{2022ws/20221010}{loesung-2-2.c} und \gitfile{hp}{2022ws/20221010}{loesung-2-3.c} - ist mindestens der C99-Standard erforderlich; bitte nötigenfalls - in \file{gcc} die Option \lstinline[style=cmd]{-std=c99} mit angeben.) - - Die Lösung in \gitfile{hp}{2022ws/20221010}{loesung-2-3.c} ist zwar richtig, - aber unnötig kompliziert und daher nicht empfohlen. - - Eine \textbf{falsche} Lösung finden Sie in der Datei \gitfile{hp}{2022ws/20221010}{loesung-2-f4.c}: - In der Ausgabe dieses Programms stehen die Faktoren und Ergebnisse - nicht rechtsbündig untereinander. - - \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. - - Falls Ihnen dabei irgendwelche Besonderheiten auffallen - und/oder Sie irgendwelche besondere Maßnahmen treffen, - dokumentieren Sie diese. - - (Wem dies zu einfach ist, kann auch gerne - die ersten 100 Fibonacci-Zahlen ausgeben.) - - \solution - - Zwei verschiedene richtige Lösungen finden Sie in den Dateien - \gitfile{hp}{2022ws/20221010}{loesung-3-1.c} und \gitfile{hp}{2022ws/20221010}{loesung-3-2.c}. - - Die Lösung in \gitfile{hp}{2022ws/20221010}{loesung-3-2.c} - speichert alle berechneten Zahlen in einem Array, - die in \gitfile{hp}{2022ws/20221010}{loesung-3-1.c} hingegen - speichert immer nur maximal drei Zahlen gleichzeitig. - Sofern nicht alle berechneten Zahlen später noch benötigt werden, - ist daher \gitfile{hp}{2022ws/20221010}{loesung-3-1.c} zu bevorzugen. - - Wichtig in \gitfile{hp}{2022ws/20221010}{loesung-3-1.c} ist, daß \lstinline{f0 + f1} berechnet wird, - \emph{bevor\/} \lstinline{f0} oder \lstinline{f1} ein neuer Wert zugewiesen wird. - Dies ist nur möglich, weil das Programm - eine zusätzliche Variable (hier: \lstinline{f2}) verwendet. - - \goodbreak - - Eine "`Besonderheit"' besteht darin, daß das Ergebnis - ab der Fibonacci-Zahl Nr.~47 \textbf{falsch} ist: - \begin{lstlisting}[style=terminal] - f[45] = 1134903170 - f[46] = 1836311903 - f[47] = -1323752223 - f[48] = 512559680 - f[49] = -811192543 - \end{lstlisting} - Die Summe zweier positiver Zahlen darf keine negative Zahl sein. - - (Mit der Dokumentation dieser Beobachtung - ist die Aufgabenstellung bereits erfüllt.) - - Der Grund für diese fehlerhafte Rechnung - ist die begrenzte Rechengenauigkeit unserer Rechner, - in diesem Fall ein sogenannter \newterm{Integer-Überlauf}. - Details dazu sind Gegenstand von Kapitel~5 der Lehrveranstaltung. - - Eine "`besondere Maßnahme"' besteht darin, - anstelle des "`normalen"' Ganzzahl-Datentyps \lstinline{int} - "`lange"' ganze Zahlen (\lstinline{long int}) zu verwenden -- - siehe \gitfile{hp}{2022ws/20221010}{loesung-3-3.c}. - Damit nicht nur die Rechnung, sondern auch die Ausgabe funktioniert, - muß die Formatspezifikation in \lstinline{printf()} - von \lstinline{%d} zu \lstinline{%ld} angepaßt werden -- - siehe \gitfile{hp}{2022ws/20221010}{loesung-3-4.c}. - (Anstelle von \lstinline{long int} verwendet man üblicherweise - abkürzend \lstinline{long} -- siehe \gitfile{hp}{2022ws/20221010}{loesung-3-5.c}.) - - Wenn die genaue Rechengenauigkeit wichtig ist, sind die Definitionen - der Datentypen \lstinline{int} und \lstinline{long} zu unpräzise. - Für derartige Fälle gibt es spezielle Datentypen, - z.\,B.\ \lstinline{uint64_t} für vorzeichenlose 64-Bit-Ganzzahlen. - Für die Ausgabe derartiger Datentypen sind spezielle Formatspezifikationen - erforderlich. Die Beispiel-Lösungen \gitfile{hp}{2022ws/20221010}{loesung-3-5.c} - und \gitfile{hp}{2022ws/20221010}{loesung-3-6.c} funktionieren zwar, - zeigen aber \emph{noch nicht\/} die bestmögliche Lösung. - - \textbf{Achtung:} Die Verwendung von Fließkommazahlen - für ganzzahlige Berechnungen wie bei den Fibonacci-Zahlen - ist \textbf{nicht} zielführend! - Die in \gitfile{hp}{2022ws/20221010}{loesung-3-7f.c} - bis \gitfile{hp}{2022ws/20221010}{loesung-3-12f.c} vorgestellte "`Lösung"' - ist \textbf{falsch}. - - \bigskip - - \exercise{Fehlerhaftes Programm} - - \begin{minipage}[t]{0.65\textwidth} - Wir betrachten das nebenstehende C-Programm - (Datei: \gitfile{hp}{2022ws/20221010}{aufgabe-4.c}). - \begin{itemize} - \item[(a)] - Was bewirkt dieses Programm? Begründen Sie Ihre Antwort. - - Schreiben Sie Ihre Begründung so auf, - daß man sie auch dann versteht, - wenn man gerade nicht die Möglichkeit hat, - bei Ihnen persönlich nachzufragen - (z.\,B.\ weil man gerade eine Klausur korrigiert). - - Die Schwierigkeit dieser Aufgabe besteht - nicht allein darin, die Problematik zu verstehen, - sondern auch darin, dieses Verständnis für andere aufzuschreiben. - \item[(b)] - Ändern Sie das Programm so um, - daß es einen "`Countdown"' von 10 bis 0 ausgibt. - \end{itemize} - \end{minipage}\hfill - \begin{minipage}[t]{0.3\textwidth} - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - for (int i = 10; i = 0; i - 1) - printf ("%d\n", i); - return 0; - } - \end{lstlisting} - \end{minipage} - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Was bewirkt dieses Programm? Begründen Sie Ihre Antwort.} - - Dieses Programm bewirkt nichts. - Die \lstinline{for}-Schleife wird nicht ausgeführt. - - Begründung: Die \lstinline{for}-Bedingung ist eine Zuweisung - des Werts \lstinline{0} an die Variable \lstinline{i}. - Neben dem Seiteneffekt der Zuweisung liefert der Ausdruck - einen Wert zurück, nämlich den zugewiesenen Wert - \lstinline{0}. Dieser wird von \lstinline{for} als eine - Bedingung mit dem konstanten Wert "`falsch"' interpretiert. - - (Hinweis: Ohne diese Begründung ist die Aufgabe nur zu einem - kleinen Teil gelöst.) - - Darüberhinaus ist die Zähl-Anwendung unwirksam: Sie berechnet - den Wert \lstinline{i - 1} und vergißt ihn wieder, ohne ihn - einer Variablen (z.\,B.\ \lstinline{i}) zuzuweisen. - - \goodbreak - \item[(b)] - \textbf{Ändern Sie das Programm so, daß es einen "`Countdown"' von 10 bis 0 ausgibt.} - - Datei \gitfile{hp}{2022ws/20221010}{loesung-4.c}: - \begin{lstlisting}[gobble=8] - #include <stdio.h> - - int main (void) - { - for (int i = 10; i >= 0; i--) - printf ("%d\n", i); - return 0; - } - \end{lstlisting} - \end{itemize} - -\end{document} diff --git a/20221010/hp-uebung-20221010.pdf b/20221010/hp-uebung-20221010.pdf deleted file mode 100644 index cbaa3880ee4a1c3e3e24807f501ee07d22c63bf3..0000000000000000000000000000000000000000 Binary files a/20221010/hp-uebung-20221010.pdf and /dev/null differ diff --git a/20221010/hp-uebung-20221010.tex b/20221010/hp-uebung-20221010.tex deleted file mode 100644 index ab3dca92ebc752ea7e3eb336e666d38d745cf3d9..0000000000000000000000000000000000000000 --- a/20221010/hp-uebung-20221010.tex +++ /dev/null @@ -1,114 +0,0 @@ -% hp-uebung-20221010.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Schaltjahr ermitteln, Multiplikationstabelle, Fibonacci-Zahlen, fehlerhaftes Programm - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \thispagestyle{empty} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 10.\ Oktober 2022} - - \exercise{Schaltjahr ermitteln} - - Schreiben Sie ein C-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{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} - \textbf{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. - - Falls Ihnen dabei irgendwelche Besonderheiten auffallen - und/oder Sie irgendwelche besondere Maßnahmen treffen, - dokumentieren Sie diese. - - (Wem dies zu einfach ist, kann auch gerne - die ersten 100 Fibonacci-Zahlen ausgeben.) - - \exercise{Fehlerhaftes Programm} - - \begin{minipage}[t]{0.65\textwidth} - Wir betrachten das nebenstehende C-Programm - (Datei: \gitfile{hp}{2022ws/20221010}{aufgabe-4.c}). - \begin{itemize} - \item[(a)] - Was bewirkt dieses Programm? Begründen Sie Ihre Antwort. - - Schreiben Sie Ihre Begründung so auf, - daß man sie auch dann versteht, - wenn man gerade nicht die Möglichkeit hat, - bei Ihnen persönlich nachzufragen - (z.\,B.\ weil man gerade eine Klausur korrigiert). - - Die Schwierigkeit dieser Aufgabe besteht - nicht allein darin, die Problematik zu verstehen, - sondern auch darin, dieses Verständnis für andere aufzuschreiben. - \item[(b)] - Ändern Sie das Programm so um, - daß es einen "`Countdown"' von 10 bis 0 ausgibt. - \end{itemize} - \end{minipage}\hfill - \begin{minipage}[t]{0.3\textwidth} - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - for (int i = 10; i = 0; i - 1) - printf ("%d\n", i); - return 0; - } - \end{lstlisting} - \end{minipage} - -\end{document} diff --git a/20221010/if-14.c b/20221010/if-14.c deleted file mode 100644 index 5223dbd7e5a29bc624505c1f492aaedd6ef1e174..0000000000000000000000000000000000000000 --- a/20221010/if-14.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 42; - if (a = 0) - printf ("a ist gleich 0.\n"); - else - printf ("a ist ungleich 0, nämlich %d.\n", a); - return 0; -} diff --git a/20221010/if-15.c b/20221010/if-15.c deleted file mode 100644 index c11ce599bf9a0b77f19f65007455398c84f8a7e4..0000000000000000000000000000000000000000 --- a/20221010/if-15.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 42; - if ((a = 0) != 0) - printf ("a ist gleich 0.\n"); - else - printf ("a ist ungleich 0, nämlich %d.\n", a); - return 0; -} diff --git a/20221010/if-16.c b/20221010/if-16.c deleted file mode 100644 index eb9a1b0201bef2c3ac8a1356c32a020f3dbb2648..0000000000000000000000000000000000000000 --- a/20221010/if-16.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 42; - if (a == 0) - printf ("a ist gleich 0.\n"); - else - printf ("a ist ungleich 0, nämlich %d.\n", a); - return 0; -} diff --git a/20221010/if-17.c b/20221010/if-17.c deleted file mode 100644 index ed40dafb79e72bd97b7e447a23ad1bc75358e668..0000000000000000000000000000000000000000 --- a/20221010/if-17.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 42; - if (a += 0) - printf ("a ist gleich 0.\n"); - else - printf ("a ist ungleich 0, nämlich %d.\n", a); - return 0; -} diff --git a/20221010/if-18.c b/20221010/if-18.c deleted file mode 100644 index 6084990ba45dcbf61c4f5d916ade9fe449e6dae7..0000000000000000000000000000000000000000 --- a/20221010/if-18.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 42; - if (a += 0) - printf ("a += 0 ist ungleich 0, nämlich %d.\n", a); - else - printf ("a += 0 ist gleich 0.\n"); - return 0; -} diff --git a/20221010/loesung-1-1.c b/20221010/loesung-1-1.c deleted file mode 100644 index ea41b8ea35bf871389c8be15779a58c293c81049..0000000000000000000000000000000000000000 --- a/20221010/loesung-1-1.c +++ /dev/null @@ -1,29 +0,0 @@ -#include <stdio.h> - -int is_leap_year (int year) -{ - int leap_year = 0; - if (year % 4 == 0) - { - leap_year = 1; - if (year % 100 == 0) - { - leap_year = 0; - if (year % 400 == 0) - leap_year = 1; - } - } - return leap_year; -} - -int main (void) -{ - int year; - printf ("Bitte geben Sie eine Jahreszahl ein: "); - scanf ("%d", &year); - if (is_leap_year (year)) - printf ("Das Jahr %d ist ein Schaltjahr.\n", year); - else - printf ("Das Jahr %d ist kein Schaltjahr.\n", year); - return 0; -} diff --git a/20221010/loesung-1-2.c b/20221010/loesung-1-2.c deleted file mode 100644 index d9e4df8a36238875e0b46398b21f93e7f4f98792..0000000000000000000000000000000000000000 --- a/20221010/loesung-1-2.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdio.h> - -int is_leap_year (int year) -{ - if (year % 4 == 0) - { - if (year % 100 == 0) - { - if (year % 400 == 0) - return 1; - else - return 0; - } - else - return 1; - } - else - return 0; -} - -int main (void) -{ - int year; - printf ("Bitte geben Sie eine Jahreszahl ein: "); - scanf ("%d", &year); - if (is_leap_year (year)) - printf ("Das Jahr %d ist ein Schaltjahr.\n", year); - else - printf ("Das Jahr %d ist kein Schaltjahr.\n", year); - return 0; -} diff --git a/20221010/loesung-1-3.c b/20221010/loesung-1-3.c deleted file mode 100644 index 97051b3bb5e6620ff771d6b3f5949687130abea8..0000000000000000000000000000000000000000 --- a/20221010/loesung-1-3.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <stdio.h> - -int is_leap_year (int year) -{ - if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) - return 1; - else - return 0; -} - -int main (void) -{ - int year; - printf ("Bitte geben Sie eine Jahreszahl ein: "); - scanf ("%d", &year); - if (is_leap_year (year)) - printf ("Das Jahr %d ist ein Schaltjahr.\n", year); - else - printf ("Das Jahr %d ist kein Schaltjahr.\n", year); - return 0; -} diff --git a/20221010/loesung-1-4.c b/20221010/loesung-1-4.c deleted file mode 100644 index 3a0d218e6c03f326ad73bad55ad3e29ea882eb2d..0000000000000000000000000000000000000000 --- a/20221010/loesung-1-4.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int year; - printf ("Bitte geben Sie eine Jahreszahl ein: "); - scanf ("%d", &year); - if (year % 4 == 0) - { - if (year % 100 == 0) - { - if (year % 400 == 0) - printf ("Das Jahr %d ist ein Schaltjahr.\n", year); - else - printf ("Das Jahr %d ist kein Schaltjahr.\n", year); - } - else - printf ("Das Jahr %d ist ein Schaltjahr.\n", year); - } - else - printf ("Das Jahr %d ist kein Schaltjahr.\n", year); - return 0; -} diff --git a/20221010/loesung-1-5.c b/20221010/loesung-1-5.c deleted file mode 100644 index 999d9f2030e29f1c961b12d647d2e82592b637bf..0000000000000000000000000000000000000000 --- a/20221010/loesung-1-5.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int year; - printf ("Bitte geben Sie eine Jahreszahl ein: "); - scanf ("%d", &year); - if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) - printf ("Das Jahr %d ist ein Schaltjahr.\n", year); - else - printf ("Das Jahr %d ist kein Schaltjahr.\n", year); - return 0; -} diff --git a/20221010/loesung-2-1.c b/20221010/loesung-2-1.c deleted file mode 100644 index 5ec9dd3caf6639d22bf770ef4b6bb779a3d7c714..0000000000000000000000000000000000000000 --- a/20221010/loesung-2-1.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - int b = 7; - while (a <= 10) - { - printf ("%2d * %d = %2d\n", a, b, a * b); - a++; - } - return 0; -} diff --git a/20221010/loesung-2-1a.c b/20221010/loesung-2-1a.c deleted file mode 100644 index 8acad25cdce91f7f1dec5e2d8607a08f709cff2a..0000000000000000000000000000000000000000 --- a/20221010/loesung-2-1a.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - int b = 7; - while (a <= 10) - { - printf ("%*d * %d = %*d\n", a, 2, b, a * b, 2); - a++; - } - return 0; -} diff --git a/20221010/loesung-2-1b.c b/20221010/loesung-2-1b.c deleted file mode 100644 index b739818db5ea8ecb13a18a1700bce9d9d4f85140..0000000000000000000000000000000000000000 --- a/20221010/loesung-2-1b.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - int b = 7; - while (a <= 10) - { - printf ("%*d * %d = %*d\n", 2, a, b, 2, a * b); - a++; - } - return 0; -} diff --git a/20221010/loesung-2-1c.c b/20221010/loesung-2-1c.c deleted file mode 100644 index f09dc57abf6efa82ab7918590126e721e1c7dd4d..0000000000000000000000000000000000000000 --- a/20221010/loesung-2-1c.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - int b = 7; - char format[42]; - sprintf (format, "%%%dd * %%d = %%%dd\n", 2, 2); - printf ("format = %s\n", format); - while (a <= 10) - { - printf (format, a, b, a * b); - a++; - } - return 0; -} diff --git a/20221010/loesung-2-1d.c b/20221010/loesung-2-1d.c deleted file mode 100644 index 8d4aa51b4ad32fd32bb2a62e31255f089bd3991e..0000000000000000000000000000000000000000 --- a/20221010/loesung-2-1d.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 1; - int b = 7; - char format[42]; - snprintf (format, 42, "%%%dd * %%d = %%%dd\n", 2, 2); - format[41] = 0; - printf ("format = %s\n", format); - while (a <= 10) - { - printf (format, a, b, a * b); - a++; - } - return 0; -} diff --git a/20221010/loesung-2-2.c b/20221010/loesung-2-2.c deleted file mode 100644 index 8f9319ee596a52f38531a2cefb376b54e7ec3ec0..0000000000000000000000000000000000000000 --- a/20221010/loesung-2-2.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int x = 7; - for (int i = 1; i <= 10; i++) - printf ("%2d *%2d =%3d\n", i, x, i * x); - return 0; -} diff --git a/20221010/loesung-2-3.c b/20221010/loesung-2-3.c deleted file mode 100644 index 71fca2538b991397ac5f046a33ff0f9130b2980f..0000000000000000000000000000000000000000 --- a/20221010/loesung-2-3.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int x = 7; - for (int i = 1; i <= 10; i++) - { - if (i >= 10) - printf ("%d", i); - else - printf (" %d", i); - printf (" * %d = ", x); - int y = i * x; - if (y >= 10) - printf ("%d", y); - else - printf (" %d", y); - printf ("\n"); - } - return 0; -} diff --git a/20221010/loesung-2-f4.c b/20221010/loesung-2-f4.c deleted file mode 100644 index 8520d438f654856a74c22ffd01b9c5815741efbc..0000000000000000000000000000000000000000 --- a/20221010/loesung-2-f4.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int x = 7; - for (int i = 1; i <= 10; i++) - printf ("%d * %d = %d\n", i, x, i * x); - return 0; -} diff --git a/20221010/loesung-3-1.c b/20221010/loesung-3-1.c deleted file mode 100644 index ec5f4d9f93985577246eefccdd0f6003403795ab..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-1.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int f0 = 0; - int f1 = 1; - for (int i = 0; i < 50; i++) - { - printf ("f[%d] = %d\n", i, f0); - int f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-10f.c b/20221010/loesung-3-10f.c deleted file mode 100644 index 7bb464e8490084edbe8f388e1e6cf2bfd0b5c4be..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-10f.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - long double f0 = 0; - long double f1 = 1; - for (int i = 0; i < 200; i++) - { - printf ("f[%d] = %.0Lf\n", i, f0); - long double f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-11f.c b/20221010/loesung-3-11f.c deleted file mode 100644 index def1256c1aaa78d07234bf73be485077e5e68270..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-11f.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - long double f0 = 0; - long double f1 = 1; - for (int i = 0; i < 200; i++) - { - printf ("f[%d] = %30.0Lf\n", i, f0); - long double f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-12f.c b/20221010/loesung-3-12f.c deleted file mode 100644 index 7ca898622fd72bac0cf074b947f0e0f8810d3689..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-12f.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - long double f0 = 0; - long double f1 = 1; - for (int i = 0; i < 200; i++) - { - printf ("f[%3d] = %60.0Lf\n", i, f0); - long double f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-2.c b/20221010/loesung-3-2.c deleted file mode 100644 index 7043f66e6b73894be9547a5562de8cad43cf0e71..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-2.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int f[50]; - f[0] = 0; - f[1] = 1; - for (int i = 2; i < 50; i++) - f[i] = f[i - 2] + f[i - 1]; - for (int i = 0; i < 50; i++) - printf ("f[%d] = %d\n", i, f[i]); - return 0; -} diff --git a/20221010/loesung-3-3.c b/20221010/loesung-3-3.c deleted file mode 100644 index c27f4717a14c244d609c4c2d86a21c1026679d3e..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-3.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - long int f0 = 0; - long int f1 = 1; - for (int i = 0; i < 50; i++) - { - printf ("f[%d] = %d\n", i, f0); - long int f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-4.c b/20221010/loesung-3-4.c deleted file mode 100644 index c3c0dbe62bffce9adfc49cadb1c747e2e932c04e..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-4.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - long int f0 = 0; - long int f1 = 1; - for (int i = 0; i < 50; i++) - { - printf ("f[%d] = %ld\n", i, f0); - long int f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-5.c b/20221010/loesung-3-5.c deleted file mode 100644 index 119125542cf5fdca1289cf5918428f1634c4f2ee..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-5.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - long f0 = 0; - long f1 = 1; - for (int i = 0; i < 50; i++) - { - printf ("f[%d] = %ld\n", i, f0); - long f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-6.c b/20221010/loesung-3-6.c deleted file mode 100644 index 339217e92fb44da2e667dc15c5bbd839b9f579c2..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-6.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -int main (void) -{ - uint64_t f0 = 0; - uint64_t f1 = 1; - for (int i = 0; i < 100; i++) - { - printf ("f[%d] = %lu\n", i, f0); - uint64_t f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-6a.c b/20221010/loesung-3-6a.c deleted file mode 100644 index 685ba9744a1fe3104459a75c9f534887b8ad4cd9..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-6a.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -int main (void) -{ - uint128_t f0 = 0; - uint128_t f1 = 1; - for (int i = 0; i < 100; i++) - { - printf ("f[%d] = %lu\n", i, f0); - uint128_t f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-7f.c b/20221010/loesung-3-7f.c deleted file mode 100644 index 11a9e200a07e1e7c368b014f659f3c5f55196ff3..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-7f.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - long double f0 = 0; - long double f1 = 1; - for (int i = 0; i < 100; i++) - { - printf ("f[%d] = %llf\n", i, f0); - long double f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-8f.c b/20221010/loesung-3-8f.c deleted file mode 100644 index d6aff68d21c4aa754fa94a434f5bb17235d6535e..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-8f.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - long double f0 = 0; - long double f1 = 1; - for (int i = 0; i < 100; i++) - { - printf ("f[%d] = %Lf\n", i, f0); - long double f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-3-9f.c b/20221010/loesung-3-9f.c deleted file mode 100644 index e1d95dc56e72da5a203548ff0907c6c128004a28..0000000000000000000000000000000000000000 --- a/20221010/loesung-3-9f.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - long double f0 = 0; - long double f1 = 1; - for (int i = 0; i < 100; i++) - { - printf ("f[%d] = %.0Lf\n", i, f0); - long double f2 = f0 + f1; - f0 = f1; - f1 = f2; - } - return 0; -} diff --git a/20221010/loesung-4.c b/20221010/loesung-4.c deleted file mode 100644 index f8481e994c02ac8e581244713756c9e9be7c7fd6..0000000000000000000000000000000000000000 --- a/20221010/loesung-4.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - for (int i = 10; i >= 0; i--) - printf ("%d\n", i); - return 0; -} diff --git a/20221010/logo-hochschule-bochum-cvh-text-v2.pdf b/20221010/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221010/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221010/logo-hochschule-bochum.pdf b/20221010/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221010/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221010/pgscript.sty b/20221010/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221010/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221010/pgslides.sty b/20221010/pgslides.sty deleted file mode 120000 index 5be1416f4216f076aa268901f52a15d775e43f64..0000000000000000000000000000000000000000 --- a/20221010/pgslides.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgslides.sty \ No newline at end of file diff --git a/20221010/pointers-01.c b/20221010/pointers-01.c deleted file mode 100644 index 421153a64907b61eebbacec398ed4f1fcb487cc6..0000000000000000000000000000000000000000 --- a/20221010/pointers-01.c +++ /dev/null @@ -1,14 +0,0 @@ -#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; -} diff --git a/20221010/pointers-02.c b/20221010/pointers-02.c deleted file mode 100644 index 0a67f323100640643892d28f8675e725215b849b..0000000000000000000000000000000000000000 --- a/20221010/pointers-02.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> - -void calc_answer (int a) -{ - printf ("1: a = %d\n", a); - a = 42; - printf ("2: a = %d\n", a); -} - -int main (void) -{ - int answer; - calc_answer (answer); - printf ("The answer is %d.\n", answer); - return 0; -} diff --git a/20221010/pointers-03.c b/20221010/pointers-03.c deleted file mode 100644 index 25e3c5698f86e558c8dfc33b55387d2ec9816e17..0000000000000000000000000000000000000000 --- a/20221010/pointers-03.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> - -void calc_answer (int a) -{ - printf ("1: a = %d\n", a); - a = 42; - printf ("2: a = %d\n", a); -} - -int main (void) -{ - int answer; - calc_answer (&answer); - printf ("The answer is %d.\n", answer); - return 0; -} diff --git a/20221010/pointers-04.c b/20221010/pointers-04.c deleted file mode 100644 index 3bd2e86c08fbe05eb8eb9b42d886e30f8f0be286..0000000000000000000000000000000000000000 --- a/20221010/pointers-04.c +++ /dev/null @@ -1,14 +0,0 @@ -#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; -} diff --git a/20221010/pointers-05.c b/20221010/pointers-05.c deleted file mode 100644 index 8ed7f9367ad4757f48f81193e41b12b6b730b69a..0000000000000000000000000000000000000000 --- a/20221010/pointers-05.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int answer = 42; - int *a = &answer; - int *b = a; - *b = 137; - printf ("The answer is %d.\n", answer); - return 0; -} diff --git a/20221010/pointers-06.c b/20221010/pointers-06.c deleted file mode 100644 index bdd6a1fd48cdfbb41f418a038e87c9cc600613e7..0000000000000000000000000000000000000000 --- a/20221010/pointers-06.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -void calc_answers (int *a, int *b) -{ - *a = 42; - *b = 127; -} - -int main (void) -{ - int answer; - calc_answers (&answer, &answer); - printf ("The answer is %d.\n", answer); - return 0; -} diff --git a/20221010/strings-01.c b/20221010/strings-01.c deleted file mode 100644 index 81bc3cda8affb6268786ac989dd2907d9a84783a..0000000000000000000000000000000000000000 --- a/20221010/strings-01.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "Hello, world!\n"; - for (char *p = hello; *p; p++) - printf ("%d", *p); - return 0; -} diff --git a/20221010/strings-02.c b/20221010/strings-02.c deleted file mode 100644 index 0e62e1e346091fab3da99c27973f54552eca2b5e..0000000000000000000000000000000000000000 --- a/20221010/strings-02.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "Hello, world!\n"; - for (char *p = hello; *p; p++) - printf ("%x", *p); - return 0; -} diff --git a/20221010/strings-03.c b/20221010/strings-03.c deleted file mode 100644 index ca99a886dc567e2ec28391d6284697298f996fd9..0000000000000000000000000000000000000000 --- a/20221010/strings-03.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "Hello, world!\n"; - for (char *p = hello; *p; p++) - printf ("%02x", *p); - return 0; -} diff --git a/20221010/strings-04.c b/20221010/strings-04.c deleted file mode 100644 index 4df32974a15ef2752512cc8b9889381b5a0917cd..0000000000000000000000000000000000000000 --- a/20221010/strings-04.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "Hello, world!\n"; - for (char *p = hello; *p; p++) - printf ("%c", *p); - return 0; -} diff --git a/20221010/strings-05.c b/20221010/strings-05.c deleted file mode 100644 index 5c36db92dac8129b66d1f0ff6b709534b9e1bdb3..0000000000000000000000000000000000000000 --- a/20221010/strings-05.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = { 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 10, 0 }; - for (char *p = hello; *p; p++) - printf ("%c", *p); - return 0; -} diff --git a/20221010/strings-06.c b/20221010/strings-06.c deleted file mode 100644 index efd6ac33660fc6ae2a53077739760e0e59fbc768..0000000000000000000000000000000000000000 --- a/20221010/strings-06.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "Hell0, w0rld!\n"; - for (char *p = hello; *p; p++) - printf ("%c", *p); - return 0; -} diff --git a/20221010/strings-07.c b/20221010/strings-07.c deleted file mode 100644 index 5c76dfd93c25c3241db4e12cd18738e0c11cd258..0000000000000000000000000000000000000000 --- a/20221010/strings-07.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "Hell0, w0rld!\n"; - for (char *p = hello; *p; p++) - printf ("%d ", *p); - return 0; -} diff --git a/20221010/strings-08.c b/20221010/strings-08.c deleted file mode 100644 index fefbc1e4bc1e73c3160f4d6a8cfa438d26a04fbf..0000000000000000000000000000000000000000 --- a/20221010/strings-08.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = { 72, 101, 49, 49, 48, 44, 32, 119, 48, 114, 49, 100, 33, 10, 0 }; - for (char *p = hello; *p; p++) - printf ("%c", *p); - return 0; -} diff --git a/20221010/strings-09.c b/20221010/strings-09.c deleted file mode 100644 index 809ffebea4c1421100dcef5ce5e055fb2fe5e62f..0000000000000000000000000000000000000000 --- a/20221010/strings-09.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Die Antwort lautet: %d.\n", '*'); - return 0; -} diff --git a/20221010/strings-10.c b/20221010/strings-10.c deleted file mode 100644 index 72b828a90ee844229d0c6d07c8fe59d7ce8dd7a5..0000000000000000000000000000000000000000 --- a/20221010/strings-10.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Die Antwort lautet: %d.\n", ' ' + 10); - return 0; -} diff --git a/20221010/strings-11.c b/20221010/strings-11.c deleted file mode 100644 index 10f1cf13094d8c5c1bc7cb362bc8c3d9140dbfb4..0000000000000000000000000000000000000000 --- a/20221010/strings-11.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char x = '4'; - if (x >= 48 && x <= 57) - printf ("%c ist eine Ziffer.\n", x); - else - printf ("%c ist keine Ziffer.\n", x); - return 0; -} diff --git a/20221010/strings-12.c b/20221010/strings-12.c deleted file mode 100644 index 75dd7d07f6aa64bd87763935984ea18e8e407551..0000000000000000000000000000000000000000 --- a/20221010/strings-12.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char x = '4'; - if (x >= '0' && x <= '9') - printf ("%c ist eine Ziffer.\n", x); - else - printf ("%c ist keine Ziffer.\n", x); - return 0; -} diff --git a/20221010/strings-13.c b/20221010/strings-13.c deleted file mode 100644 index 073b57dbc6415f165428369df3f6ef04e356308a..0000000000000000000000000000000000000000 --- a/20221010/strings-13.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char x = 'ä'; - if (x >= '0' && x <= '9') - printf ("%c ist eine Ziffer.\n", x); - else - printf ("%c ist keine Ziffer.\n", x); - return 0; -} diff --git a/20221010/strings-14.c b/20221010/strings-14.c deleted file mode 100644 index d627a0f382f711a82f499ba4d1637be397a6709b..0000000000000000000000000000000000000000 --- a/20221010/strings-14.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char x = 'ä'; - if (x >= '0' && x <= '9') - printf ("%02x ist eine Ziffer.\n", x); - else - printf ("%02x ist keine Ziffer.\n", x); - return 0; -} diff --git a/20221010/strings-15.c b/20221010/strings-15.c deleted file mode 100644 index 30fb1f10d5df083f9b623d36ae600fff6e3b624a..0000000000000000000000000000000000000000 --- a/20221010/strings-15.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char x = 'ä'; - if (x >= '0' && x <= '9') - printf ("%02x wäre eine Ziffer.\n", x); - else - printf ("%02x wäre keine Ziffer.\n", x); - return 0; -} diff --git a/20221010/strings-16.c b/20221010/strings-16.c deleted file mode 100644 index 674b096c8abb968c5de1057233bda9cd3710dc25..0000000000000000000000000000000000000000 --- a/20221010/strings-16.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "ä"; - for (char *p = hello; *p; p++) - printf ("%02hhx", *p); - printf ("\n"); - return 0; -} diff --git a/20221010/strings-17.c b/20221010/strings-17.c deleted file mode 100644 index 952681bf1c382c1e69e44db29aa175f2445aa5b4..0000000000000000000000000000000000000000 --- a/20221010/strings-17.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "ä"; - for (char *p = hello; *p; p++) - printf ("%hhd ", *p); - printf ("\n"); - return 0; -} diff --git a/20221010/strings-18.c b/20221010/strings-18.c deleted file mode 100644 index 2f651cea98a0010fe2fff3937d150ad25d69eb1c..0000000000000000000000000000000000000000 --- a/20221010/strings-18.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "ä"; - for (char *p = hello; *p; p++) - printf ("%hhu ", *p); - printf ("\n"); - return 0; -} diff --git a/20221010/strings-19.c b/20221010/strings-19.c deleted file mode 100644 index ad8a7aa046e5ae2a635ab2548b967efbccc3e0d1..0000000000000000000000000000000000000000 --- a/20221010/strings-19.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "HELLO"; - for (char *p = hello; *p; p++) - printf ("%c", *p - 'A' + 'a'); - printf ("\n"); - return 0; -} diff --git a/20221017/aufgabe-3.c b/20221017/aufgabe-3.c deleted file mode 100644 index ad9d80416bad5c7c0edf9c9d4f175146c92a2755..0000000000000000000000000000000000000000 --- a/20221017/aufgabe-3.c +++ /dev/null @@ -1,8 +0,0 @@ -int fun_1 (char *s1, char *s2) -{ - int result = 1; - for (int i = 0; s1[i] && s2[i]; i++) - if (s1[i] != s2[i]) - result = 0; - return result; -} diff --git a/20221017/aufgabe-4.c b/20221017/aufgabe-4.c deleted file mode 100644 index dc58b6e8ee4a7a023654aa0eb3a9715a5b9f75cf..0000000000000000000000000000000000000000 --- a/20221017/aufgabe-4.c +++ /dev/null @@ -1 +0,0 @@ -char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c";main(){printf(f,34,f,34,10);} diff --git a/20221017/ausgabe.txt b/20221017/ausgabe.txt deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/20221017/fhello.txt b/20221017/fhello.txt deleted file mode 100644 index 95e75d98dbaf42c1efc9be0405e079f97aa24888..0000000000000000000000000000000000000000 --- a/20221017/fhello.txt +++ /dev/null @@ -1,2 +0,0 @@ -Hello, world! -Hello, world! diff --git a/20221017/files-01.c b/20221017/files-01.c deleted file mode 100644 index 6548d9c81c73a7f3da8b1b2e62290bc8029d11f0..0000000000000000000000000000000000000000 --- a/20221017/files-01.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - FILE *f = fopen ("fhello.txt", "w"); - fprintf (f, "Hello, world!\n"); - fclose (f); - return 0; -} diff --git a/20221017/files-02.c b/20221017/files-02.c deleted file mode 100644 index 988cb71488e7b9c32771cf8c9305e9ca3b142faa..0000000000000000000000000000000000000000 --- a/20221017/files-02.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - FILE *f = fopen ("fhello.txt", "a"); - fprintf (f, "Hello, world!\n"); - fclose (f); - return 0; -} diff --git a/20221017/files-03.c b/20221017/files-03.c deleted file mode 100644 index a65c5c766b07f09ea4b002fd28369e51271b2fca..0000000000000000000000000000000000000000 --- a/20221017/files-03.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - FILE *f = fopen ("bla/blubb", "w"); - fprintf (f, "Hello, world!\n"); - fclose (f); - return 0; -} diff --git a/20221017/files-04.c b/20221017/files-04.c deleted file mode 100644 index d6fea32f7c9d53e85813ef51a306411c8ce8adf4..0000000000000000000000000000000000000000 --- a/20221017/files-04.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - FILE *f = fopen ("bla/blubb", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - return 0; -} diff --git a/20221017/files-05.c b/20221017/files-05.c deleted file mode 100644 index 4367f987813c0fb4780867123f788c54fa1c0775..0000000000000000000000000000000000000000 --- a/20221017/files-05.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - FILE *f = fopen ("bla/blubb", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - fprintf (stderr, "Konnte Datei nicht öffnen. :-(\n"); - return 0; -} diff --git a/20221017/files-06.c b/20221017/files-06.c deleted file mode 100644 index 41e67d4d4e5718e6712286ea87480d105c00112c..0000000000000000000000000000000000000000 --- a/20221017/files-06.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <errno.h> - -int main (void) -{ - FILE *f = fopen ("bla/blubb", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - fprintf (stderr, "Konnte Datei nicht öffnen. :-( Grund: %d\n", errno); - return 0; -} diff --git a/20221017/files-07.c b/20221017/files-07.c deleted file mode 100644 index 67f97d6d1a990a0e6e8423caddd23bdb5b60dc24..0000000000000000000000000000000000000000 --- a/20221017/files-07.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <errno.h> - -int main (void) -{ - FILE *f = fopen ("/fhello.txt", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - fprintf (stderr, "Konnte Datei nicht öffnen. :-( Grund: %d\n", errno); - return 0; -} diff --git a/20221017/files-08.c b/20221017/files-08.c deleted file mode 100644 index 18a331edff6b4e8d8e40362ac9365bdd763cad40..0000000000000000000000000000000000000000 --- a/20221017/files-08.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <errno.h> -#include <string.h> - -int main (void) -{ - FILE *f = fopen ("/fhello.txt", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - { - char *msg = strerror (errno); - fprintf (stderr, "Konnte Datei nicht öffnen. :-( Grund: %s\n", msg); - } - return 0; -} diff --git a/20221017/files-09.c b/20221017/files-09.c deleted file mode 100644 index 1ab0b5e4e22cbfee74af0e7d3bd0a2854e8de925..0000000000000000000000000000000000000000 --- a/20221017/files-09.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <errno.h> -#include <string.h> - -int main (void) -{ - FILE *f = fopen ("bla/blubb", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - { - char *msg = strerror (errno); - fprintf (stderr, "Konnte Datei nicht öffnen. :-( Grund: %s\n", msg); - } - return 0; -} diff --git a/20221017/files-10.c b/20221017/files-10.c deleted file mode 100644 index 0e718a693947d403329586fc86bca4c043abf7d2..0000000000000000000000000000000000000000 --- a/20221017/files-10.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <stdio.h> -#include <errno.h> -#include <string.h> - -int main (void) -{ - FILE *f = fopen ("bla/blubb", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - { - char *msg = strerror (errno); - fprintf (stderr, "Konnte Datei nicht öffnen. :-( Grund: %s\n", msg); - return 1; - } - return 0; -} diff --git a/20221017/files-11.c b/20221017/files-11.c deleted file mode 100644 index ce0cbb5c900ba6fbc0b179301ae63e74a183eae7..0000000000000000000000000000000000000000 --- a/20221017/files-11.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <stdio.h> -#include <errno.h> -#include <string.h> - -int main (void) -{ - FILE *f = fopen ("bla/blubb", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - { - char *msg = strerror (errno); - fprintf (stderr, "Konnte Datei nicht öffnen. :-( Grund: %s\n", msg); - return errno; - } - return 0; -} diff --git a/20221017/files-12.c b/20221017/files-12.c deleted file mode 100644 index 47a8e4035b9eb9303ed5eda50546a4cc49476c37..0000000000000000000000000000000000000000 --- a/20221017/files-12.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> - -int main (void) -{ - FILE *f = fopen ("bla/blubb", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - { - char *msg = strerror (errno); - fprintf (stderr, "Konnte Datei nicht öffnen. :-( Grund: %s\n", msg); - exit (errno); - } - return 0; -} diff --git a/20221017/files-13.c b/20221017/files-13.c deleted file mode 100644 index 62ae60e998a6a4af74a1d858ee4153e8b2b0486a..0000000000000000000000000000000000000000 --- a/20221017/files-13.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> -#include <errno.h> -#include <error.h> - -int main (void) -{ - FILE *f = fopen ("bla/blubb", "w"); - if (!f) - error (errno, errno, "cannot open file"); - fprintf (f, "Hello, world!\n"); - fclose (f); - return 0; -} diff --git a/20221017/files-14.c b/20221017/files-14.c deleted file mode 100644 index 299b52ac2592b5a829ace1fc5964c114e409d9f9..0000000000000000000000000000000000000000 --- a/20221017/files-14.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> -#include <errno.h> -#include <error.h> - -int main (void) -{ - FILE *f = fopen ("bla/blubb", "w"); - if (!f) - error (0, errno, "cannot open file"); - fprintf (f, "Hello, world!\n"); - fclose (f); - return 0; -} diff --git a/20221017/hp-20221017.pdf b/20221017/hp-20221017.pdf deleted file mode 100644 index 48829fe532924d9efcfe41e1c4e7fac1a637383e..0000000000000000000000000000000000000000 Binary files a/20221017/hp-20221017.pdf and /dev/null differ diff --git a/20221017/hp-20221017.tex b/20221017/hp-20221017.tex deleted file mode 100644 index 7bd34ca2aeac191847e684b08313cd62e60586ca..0000000000000000000000000000000000000000 --- a/20221017/hp-20221017.tex +++ /dev/null @@ -1,1137 +0,0 @@ -% hp-20221017.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Strukturen, Dateien und Fehlerbehandlung, Parameter des Hauptprogramms, String-Operationen - -\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} - -\newcommand{\redurl}[1]{\href{#1}{\color{red}\nolinkurl{#1}}} - -\title{Hardwarenahe Programmierung} -\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{17.\ Oktober 2022} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \begin{itemize} - \item[2.1] Hello, world! - \item[2.2] Programme compilieren und ausführen - \item[2.3] Elementare Aus- und Eingabe - \item[2.4] Elementares Rechnen - \item[2.5] Verzweigungen - \item[2.6] Schleifen - \item[2.7] Strukturierte Programmierung - \item[2.8] Seiteneffekte - \color{medgreen} - \item[2.9] Funktionen - \item[2.10] Zeiger - \item[2.11] Arrays und Strings - \color{red} - \item[2.12] Strukturen - \item[\dots] - \end{itemize} - \color{gray} - \item[\textbf{3}] \textbf{Bibliotheken} - \vspace*{-\smallskipamount} - \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{frame} - -\setcounter{section}{1} -\section{Einführung in C} -\setcounter{subsection}{8} -\subsection{Funktionen} - -\begin{frame}[fragile] - - \showsubsection - - \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] - - \showsubsection - - \begin{minipage}[t]{6.5cm} - \vspace{-\medskipamount} - \begin{lstlisting}[gobble=6] - ¡#include <stdio.h> - - void add_verbose (int a, int b) - { - printf ("%d + %d = %d\n", a, b, a + b); - } - - 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] - - \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] - \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} - \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 - \end{itemize} - \end{minipage} -\end{frame} - -\subsection{Arrays und Strings} - -\begin{frame}[fragile] - \showsubsection - - Ein Zeiger zeigt auf eine Variable\only<1->{ und deren Nachbarn}. - -% \bigskip -% \pause -% \pause - - \begin{onlyenv}<1> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[5] = { 2, 3, 5, 7, 11 }; - int *p = prime; - for (int i = 0; i < 5; i++) - printf ("%d\n", *(p + i)); - return 0; - } - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<2> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[5] = { 2, 3, 5, 7, 11 }; - int *p = prime; - for (int i = 0; i < 5; i++) - printf ("%d\n", p[i]); - return 0; - } - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<3> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[5] = { 2, 3, 5, 7, 11 }; - for (int i = 0; i < 5; i++) - printf ("%d\n", prime[i]); - return 0; - } - ¡ ¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<4> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[5] = { 2, 3, 5, 7, 11 }; - for (int *p = prime; - p < prime + 5; p++) - printf ("%d\n", *p); - return 0; - } - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<5> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[6] = { 2, 3, 5, 7, 11, 0 }; - for (int *p = prime; *p; p++) - printf ("%d\n", *p); - return 0; - } - ¡ ¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<6-> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int prime[] = { 2, 3, 5, 7, 11, 0 }; - for (int *p = prime; *p; p++) - printf ("%d\n", *p); - return 0; - } - ¡ ¿ - \end{lstlisting} - \end{onlyenv} - -% \pause - \vspace{-3.05cm}\hspace{5.5cm}% - \begin{minipage}{6.5cm} - \begin{itemize} - \item - \lstinline{prime} ist \alt<1->{ein Array}{eine Ansammlung} von\\fünf ganzen Zahlen. -% \pause -% \pause - \item - \only<1>{\begin{picture}(0,0) - \color{red} - \put(-1.6,0.1){\tikz{\draw[-latex](0.0,0.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)} - \pause - \pause - \item - Zeiger-Arithmetik:\\ - \lstinline{p++} rückt den Zeiger \lstinline{p}\\ - um eine \lstinline{int} weiter. - \pause - \pause - \item - Array ohne \only<1->{explizite }Längenangabe:\\ - Compiler zählt selbst - \vspace*{-1cm} -% \pause - \begin{picture}(0,0) - \put(-5.2,1.0){\makebox(0,0)[br]{\color{red}\bf\shortstack{Die Länge des Arrays\\ist \emph{nicht\/} veränderlich!}}} - \end{picture} - \end{itemize} - \end{minipage} -\end{frame} - -% \begin{frame}[fragile] -% \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] -% \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] -% \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} -% \end{frame} - -\begin{frame}[fragile] - \showsubsection - - \begin{onlyenv}<1> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - char hello[] = "Hello, world!\n"; - for (char *p = hello; *p; p++) - printf ("%d", *p); - return 0; - } - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<2> - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - char hello[] = "Hello, world!\n"; - for (char *p = hello; *p; p++) - printf ("%c", *p); - return 0; - } - \end{lstlisting} - \end{onlyenv} -% \begin{onlyenv}<8> -% \begin{lstlisting}[gobble=6] -% #include <stdio.h> -% -% int main (void) -% { -% char hello[] = "Hello, world!\n"; -% printf ("%s", hello); -% return 0; -% } -% ¡ ¿ -% \end{lstlisting} -% \end{onlyenv} -% \begin{onlyenv}<9> -% \begin{lstlisting}[gobble=6] -% #include <stdio.h> -% -% int main (void) -% { -% char *hello = "Hello, world!\n"; -% printf ("%s", hello); -% return 0; -% } -% ¡ ¿ -% \end{lstlisting} -% \end{onlyenv} -% \begin{onlyenv}<10> -% \begin{lstlisting}[gobble=6] -% #include <stdio.h> -% -% int main (void) -% { -% char *hello = "Hello, world!\n"; -% while (*hello) -% printf ("%c", *hello++); -% return 0; -% } -% \end{lstlisting} -% \end{onlyenv} - - \vspace{-1.7cm}\hfill - \begin{minipage}{6.8cm} - \begin{itemize} -% \pause[2] - \item - Ein \lstinline{char} ist eine kleinere \lstinline{int}. -% \pause - \item - Ein "`String"' in C ist ein Array von \lstinline{char}s\only<1->{,\\ - also ein Zeiger auf \lstinline{char}s}\only<1->{\\ - also ein Zeiger auf (kleinere) Integer}. -% \pause -% \pause -% \pause - \item - Der letzte \lstinline{char} muß 0 sein.\\ - Er kennzeichnet das Ende des Strings. -% \pause - \item - Die Formatspezifikation\\ - entscheidet über die Ausgabe:\\[\smallskipamount] - \begin{tabular}{ll} - \lstinline|%d|\hspace*{0.5em}dezimal - & \lstinline|%c|\hspace*{0.5em}Zeichen\\ - \lstinline|%x|\hspace*{0.5em}hexadezimal -% \pause - & \lstinline|%s|\hspace*{0.5em}{\color{red}String} - \end{tabular} - \vspace*{-1cm} - \end{itemize} - \end{minipage} -\end{frame} - -\addtocounter{subsection}{-1} -\subsection{Arrays und Strings \protect\color{gray}und Zeichen} - -\begin{frame}[fragile] - \showsubsection - - \emph{"`Alles ist Zahl."'\/} -- Schule der Pythagoreer, 6.\ Jh.\ v.\,Chr. - - \medskip - - \begin{center} - \renewcommand{\arraystretch}{1.5} - \begin{tabular}{r} - \lstinline|"Hello"|\\ - \lstinline|'H'|\\ - \lstinline|'a' + 4| - \end{tabular} - \renewcommand{\arraystretch}{1.0} - \begin{tabular}{c} - ist nur eine andere\\ - Schreibweise für - \end{tabular} - \renewcommand{\arraystretch}{1.5} - \begin{tabular}{l} - \lstinline|{ 72, 101, 108, 108, 111, 0 }|\\ - \lstinline|72|\\ - \lstinline|'e'| - \end{tabular} - \renewcommand{\arraystretch}{1.0} - \end{center} - - \begin{itemize} - \item - Welchen Zahlenwert hat \lstinline{'*'} im Zeichensatz? - - \smallskip - - \begin{lstlisting}[gobble=8] - printf ("%d\n", '*'); - \end{lstlisting} - - \smallskip - - (normalerweise: ASCII) - \medskip - \item - Ist \lstinline{char ch} ein Großbuchstabe? - - \smallskip - - \begin{lstlisting}[gobble=8] - if (ch >= 'A' && ch <= 'Z') - ... - \end{lstlisting} - \medskip - \item - Groß- in Kleinbuchstaben umwandeln - - \smallskip - - \begin{lstlisting}[gobble=8] - ch += 'a' - 'A'; - \end{lstlisting} - \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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \begin{itemize} - \vspace*{-\smallskipamount} - \item[\dots] - \item[2.5] Verzweigungen - \item[2.6] Schleifen - \item[2.7] Strukturierte Programmierung - \item[2.8] Seiteneffekte - \color{medgreen} - \item[2.9] Funktionen - \item[2.10] Zeiger - \item[2.11] Arrays und Strings - \color{red} - \item[2.12] Strukturen - \item[2.13] Dateien und Fehlerbehandlung - \item[2.14] Parameter des Hauptprogramms - \item[2.15] String-Operationen - \end{itemize} - \color{gray} - \item[\textbf{3}] \textbf{Bibliotheken} - \vspace*{-\smallskipamount} - \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} - -\subsection{Strukturen} - -\begin{frame}[fragile] - \showsubsection - - \begin{lstlisting} - #include <stdio.h> - - typedef struct - { - char day, month; - int year; - } - date; - - int main (void) - { - date today = { 17, 10, 2022 }; - printf ("%d.%d.%d\n", today.day, today.month, today.year); - return 0; - } - \end{lstlisting} -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - \vspace*{0.9mm} - \begin{minipage}[b]{6cm} - \begin{lstlisting}[gobble=6] - ¡#include <stdio.h> - - typedef struct - { - char day, month; - int year; - } - date; - - void set_date (date *d) - { - (*d).day = 17; - (*d).month = 10; - (*d).year = 2022; - }¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[b]{6cm} - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - date today; - set_date (&today); - printf ("%d.%d.%d\n", today.day, - today.month, today.year); - return 0; - }¿ - \end{lstlisting} - \end{minipage} -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - \vspace*{0.9mm} - \begin{minipage}[b]{6cm} - \begin{lstlisting}[gobble=6] - ¡#include <stdio.h> - - typedef struct - { - char day, month; - int year; - } - date; - - void set_date (date *d) - { - d->day = 17; - d->month = 10; - d->year = 2022; - }¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[b]{6cm} - \hspace*{-1cm}% - \lstinline{foo->bar} - ist Abkürzung für - \lstinline{(*foo).bar} - - \bigskip - - \visible<2->{% - \hspace*{-1cm}% - Eine Funktion, die mit einem \lstinline{struct} arbeitet,\\ - \hspace*{-1cm}% - kann man eine \newterm{Methode\/} des \lstinline{struct} nennen.} - - \bigskip - \bigskip - - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - date today; - set_date (&today); - printf ("%d.%d.%d\n", today.day, - today.month, today.year); - return 0; - }¿ - \end{lstlisting} - \end{minipage} - -\end{frame} - -\subsection{Dateien und Fehlerbehandlung} - -\begin{frame}[fragile] - \showsubsection - \vspace*{-0.2925cm} - \begin{minipage}[t]{6cm} - \begin{onlyenv}<1> - \begin{lstlisting}[gobble=8] - ¡#include <stdio.h> - - int main (void) - { - FILE *f = fopen ("fhello.txt", "w"); - fprintf (f, "Hello, world!\n"); - fclose (f); - return 0; - }¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<2> - \begin{lstlisting}[gobble=8] - ¡#include <stdio.h> - - int main (void) - { - FILE *f = fopen ("fhello.txt", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - return 0; - }¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<3> - \begin{lstlisting}[gobble=8] - ¡#include <stdio.h> - #include <errno.h> - - int main (void) - { - FILE *f = fopen ("fhello.txt", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - fprintf (stderr, "error #%d\n", errno); - return 0; - }¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<4> - \begin{lstlisting}[gobble=8] - ¡#include <stdio.h> - #include <errno.h> - #include <string.h> - - int main (void) - { - FILE *f = fopen ("fhello.txt", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - { - char *msg = strerror (errno); - fprintf (stderr, "%s\n", msg); - } - return 0; - }¿ - \end{lstlisting} - \vspace*{-1cm} - \end{onlyenv} - \begin{onlyenv}<5-> - \begin{lstlisting}[gobble=8] - ¡#include <stdio.h> - #include <errno.h> - #include <er¡ror.h> - - int main (void) - { - FILE *f = fopen ("fhello.txt", "w"); - if (!f) - error (errno, errno, "cannot open file"); - fprintf (f, "Hello, world!\n"); - fclose (f); - return 0; - } - \end{lstlisting} - \end{onlyenv} - \end{minipage}\pause\hspace*{-1.5cm}% - \begin{minipage}[t]{8.5cm} - \bigskip - \only<3->{\bigskip} - \begin{itemize} - \item - Wenn die Datei nicht geöffnet werden kann,\\ - gibt \lstinline{fopen()} den Wert \lstinline{NULL} zurück. - \pause - \medskip - \item - \addtolength{\leftskip}{1cm} - Die globale Variable \lstinline{int errno}\\ - enthält dann die Nummer des Fehlers.\\ - Benötigt: \lstinline{#include <errno.h>} - \pause - \medskip - \only<5->{\bigskip} - \item - Die Funktion \lstinline{strerror()} wandelt \lstinline{errno}\\ - in einen Fehlermeldungstext um.\\ - Benötigt: \lstinline{#include <string.h>} - \pause - \medskip - \item - \addtolength{\leftskip}{-1.5cm} - Die Funktion \lstinline{error()} gibt eine Fehlermeldung aus\\ - und beendet das Programm.\\ - Benötigt: \lstinline{#include <er¡¿ror.h>} - \pause - \medskip - \item - \textbf{Niemals Fehler einfach ignorieren!} - \end{itemize} - \addtolength{\leftskip}{0.5cm} - \end{minipage} -\end{frame} - -\subsection{Parameter des Hauptprogramms} - -\begin{frame}[fragile] - - \showsubsection - - \begin{lstlisting} - #include <stdio.h> - - int main (int argc, char **argv) - { - printf ("argc = %d\n", argc); - for (int i = 0; i < argc; i++) - printf ("argv[%d] = \"%s\"\n", i, argv[i]); - return 0; - } - \end{lstlisting} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \begin{lstlisting} - #include <stdio.h> - - int main (int argc, char **argv) - { - printf ("argc = %d\n", argc); - for (int i = 0; *argv; i++, argv++) - printf ("argv[%d] = \"%s\"\n", i, *argv); - return 0; - } - \end{lstlisting} - -\end{frame} - -\subsection{String-Operationen} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char hello[] = "Hello, world!\n"; - - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); - - printf ("%s\n", hello + 7); - printf ("%zd\n", strlen (hello + 7)); - - hello[5] = 0; - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); - - return 0; - } - \end{lstlisting} - \vspace*{-1cm} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char *anton = "Anton"; - char *zacharias = "Zacharias"; - - printf ("%d\n", strcmp (anton, zacharias)); - printf ("%d\n", strcmp (zacharias, anton)); - printf ("%d\n", strcmp (anton, anton)); - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); - - return 0; - } - \end{lstlisting} - \vspace*{-1cm} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char buffer[100] = ""; - sprintf (buffer, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - return 0; - } - \end{lstlisting} - \vspace*{-1cm} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char buffer[100] = ""; - snprintf (buffer, 100, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - return 0; - } - \end{lstlisting} - -\end{frame} - -\iffalse - -\begin{frame} - - \showsection - - Sprachelemente weitgehend komplett - - \bigskip - Es fehlen: - \begin{itemize} - \item - Ergänzungen (z.\,B.\ ternärer Operator, \lstinline{union}, \lstinline{unsigned}, \lstinline{volatile}) - \item - Bibliotheksfunktionen (z.\,B.\ \lstinline{malloc()}) - \arrowitem - werden eingeführt, wenn wir sie brauchen - \bigskip - \item - Konzepte (z.\,B.\ rekursive Datenstrukturen, Klassen selbst bauen) - \arrowitem - werden eingeführt, wenn wir sie brauchen, oder: - \arrowitem - Literatur\\[\smallskipamount] - (z.\,B.\ Wikibooks: C-Programmierung,\\ - Dokumentation zu Compiler und Bibliotheken) - \bigskip - \item - Praxiserfahrung - \arrowitem - Übung und Praktikum: nur Einstieg - \arrowitem - selbständig arbeiten - \end{itemize} -\end{frame} - -\fi - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \begin{itemize} - \vspace*{-\smallskipamount} - \item[\dots] - \item[2.5] Verzweigungen - \item[2.6] Schleifen - \item[2.7] Strukturierte Programmierung - \item[2.8] Seiteneffekte - \item[2.9] Funktionen - \item[2.10] Zeiger - \item[2.11] Arrays und Strings - \color{medgreen} - \item[2.12] Strukturen - \item[2.13] Dateien und Fehlerbehandlung - \item[2.14] Parameter des Hauptprogramms - \item[2.15] String-Operationen - \end{itemize} - \item[\textbf{3}] \textbf{Bibliotheken} - \vspace*{-\smallskipamount} - \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{frame} - -\end{document} diff --git a/20221017/hp-musterloesung-20221017.pdf b/20221017/hp-musterloesung-20221017.pdf deleted file mode 100644 index 682b51a374a737deb4eef50681b0740524e3a6a4..0000000000000000000000000000000000000000 Binary files a/20221017/hp-musterloesung-20221017.pdf and /dev/null differ diff --git a/20221017/hp-musterloesung-20221017.tex b/20221017/hp-musterloesung-20221017.tex deleted file mode 100644 index 0069168a76a638d0ccf4e799e26668a16d9136db..0000000000000000000000000000000000000000 --- a/20221017/hp-musterloesung-20221017.tex +++ /dev/null @@ -1,523 +0,0 @@ -% hp-musterloesung-20221017.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Seltsame Programme, Kalender-Berechnung, Strings, Programm analysieren - -\documentclass[a4paper]{article} - -\usepackage{pgscript} -\renewcommand{\breath}{\bigskip} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 17.\ Oktober 2022} - - \exercise{Seltsame Programme} - - Unter \url{https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221017} - finden Sie (unter anderem)\\ - die Programme \gitfile{hp}{2022ws/20221017}{test-1.c}, - \gitfile{hp}{2022ws/20221017}{test-2.c} und \gitfile{hp}{2022ws/20221017}{test-3.c}. - - Was bewirken diese Programme, und warum verhalten sie sich so? - - \solution - - \begin{itemize} - \item - \gitfile{hp}{2022ws/20221017}{test-1.c} - - Hinter \lstinline{return} steht ein Ausdruck mit dem - Komma-Operator. Dieser bewirkt, daß der Wert vor dem Komma - berechnet und ignoriert und danach der Wert nach dem Komma - zurückgegeben wird. - - In diesem Fall wird vor dem Komma der Wert des - \lstinline{printf()}-Aufrufs berechnet und ignoriert. - Als Seiteneffekt gibt das Programm die Zeile - \lstinline[style=terminal]{Hello, world!} aus. - Anschließend wird der Wert \lstinline{0} an \lstinline{return} - übergeben und daher \lstinline{return 0} ausgeführt. - - \item - \gitfile{hp}{2022ws/20221017}{test-2.c} - - Das Programm gibt die Zeile - \lstinline[style=terminal]{Die Antwort lautet: 42} aus. - - Die \lstinline{if}-Bedingung ist eine Zuweisung \lstinline{b = 42}, - die den zugewiesenen Wert \lstinline{42} zurückgibt. - Weil dieser Wert ungleich Null ist, interpretiert - \lstinline{if} ihn als Wahrheitswert "`wahr"', führt also den - \lstinline{if}-Zweig aus und überspringt den - \lstinline{else}-Zweig. - - \item - \gitfile{hp}{2022ws/20221017}{test-3.c} - - Das Programm stürzt mit einer Fehlermeldung - "`Speicherzugriffsfehler"' oder "`Schutzverletzung"' ab. - - Der Funktionsaufruf \lstinline{printf (42)} übergibt den - Zahlenwert \lstinline{42} als String, also als einen Zeiger - auf \lstinline{char}-Variable, an die Funktion - \lstinline{printf()}. Diese versucht, auf den Speicher ab - Adresse 42 zuzugreifen, wofür aber das Programm keine - Zugriffsrechte hat. Das Betriebssystem beendet daraufhin das - Programm mit der o.\,a.\ Fehlermeldung. - - Der String \lstinline{"Die Antwort lautet: "} wird nicht - ausgegeben, weil Schreiboperationen aus Effizienzgründen - erst nach einer abgeschlossenen Zeile (\lstinline{"\n"}) - durchgeführt werden. - \end{itemize} - - \clearpage - - \exercise{Kalender-Berechnung} - - Am 3.\,1.\,2009 meldete \emph{heise online\/}: - \begin{quote} - Kunden des ersten mobilen Media-Players von Microsoft - erlebten zum Jahresende eine böse Überraschung: - Am 31.\ Dezember 2008 fielen weltweit alle Zune-Geräte der ersten Generation aus. - Ursache war ein interner Fehler bei der Handhabung von Schaltjahren. - - \strut\hfill\url{http://heise.de/-193332}, - \end{quote} - Der Artikel verweist auf ein Quelltextfragment (Datei: \gitfile{hp}{2022ws/20221017}{aufgabe-2.c}), - das für einen gegebenen Wert \lstinline{days} - das Jahr und den Tag innerhalb des Jahres - für den \lstinline{days}-ten Tag nach dem 1.\,1.\,1980 berechnen soll: - \begin{lstlisting} - year = ORIGINYEAR; /* = 1980 */ - - while (days > 365) - { - if (IsLeapYear (year)) - { - if (days > 366) - { - days -= 366; - year += 1; - } - } - else - { - days -= 365; - year += 1; - } - } - \end{lstlisting} - Dieses Quelltextfragment enthält schlechten Programmierstil, - nämlich mehrere Code-Verdopplungen: - \begin{itemize} - \item - Die Anweisung \lstinline{year += 1} taucht an zwei Stellen auf. - \item - Es gibt zwei unabhängige Abfragen \lstinline{days > 365} und \lstinline{days > 366}:\\ - eine in einer \lstinline{while}- und die andere in einer \lstinline{if}-Bedingung. - \item - Die Länge eines Jahres wird nicht durch eine Funktion berechnet oder in einer Variablen gespeichert; - stattdessen werden an mehreren Stellen die expliziten numerischen Konstanten 365 und 366 verwendet. - \end{itemize} - Diese Probleme führten am 31.\ Dezember 2008 zu einer Endlosschleife. - - Gut hingegen ist die Verwendung einer Konstanten \lstinline{ORIGINYEAR} - anstelle der Zahl 1980 - sowie die Kapselung der Berechnung der Schaltjahr-Bedingung - in einer Funktion \lstinline{IsLeapYear()}. - - \begin{itemize} - \item[(a)] - Erklären Sie das Zustandekommen der Endlosschleife. - \item[(b)] - Schreiben Sie das Quelltextfragment so um, daß es die beschriebenen Probleme - nicht mehr enthält. - \end{itemize} - - \textbf{Hinweis 1:} Verwenden Sie Ihre eigene Funktion \lstinline{IsLeapYear()}. - - \textbf{Hinweis 2}: Schreiben Sie zusätzlich eine Funktion \lstinline{DaysInYear()}. - - \clearpage - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Erklären Sie das Zustandekommen der Endlosschleife.} - - Das Programm startet mit demjenigen Wert für \lstinline{days}, - der der Anzahl der Tage vom 1.\,1.\,1980 bis zum - 31.\,12.\,2008 entspricht. Die \lstinline{while}-Schleife - läuft zunächst solange korrekt durch, bis \lstinline{year} den - Wert \lstinline{2008} und \lstinline{days} den Wert - \lstinline{366} hat. (Der 31.\,12.\ des Schaltjahres 2008 ist - der 366.\ Tag seines Jahres.) - - Die Bedingung der \lstinline{while}-Schleife ist damit - weiterhin erfüllt; das Programm läuft weiter. - - Da 2008 ein Schaltjahr ist, ist auch die Bedingung der äußeren - \lstinline{if}-Anweisung erfüllt. - - Da \lstinline{days} den Wert 366 hat und dieser nicht größer - als 366 ist, ist die innere \lstinline{if}-Bedingung nicht - erfüllt. Somit wird innerhalb der \lstinline{while}-Schleife - kein weiterer Code ausgeführt, die \lstinline{while}-Bedingung - bleibt erfüllt, und das Programm führt eine Endlosschleife - aus. - - \item[(b)] - \textbf{Schreiben Sie das Quelltextfragment so um, daß es die beschriebenen Probleme - nicht mehr enthält.} - - Um das Programm zu testen, genügt es, das Datum auf den - 31.\,12.\,1980 zu stellen, also \lstinline{days} auf den Wert - 366 zu setzen. Darüberhinaus muß man die Funktion - \lstinline{IsLeapYear()} bereitstellen (vgl.\ Aufgabe 1 vom 11.\,10.\,2021). - - Der Quelltext \gitfile{hp}{2022ws/20221017}{loesung-2-f1.c} ist eine lauffähige - Version des Programms, die den Fehler (Endlosschleife) - reproduziert. - - \breath - - Es liegt nahe, den Fehler in der \lstinline{while}-Bedingung - zu korrigieren, so daß diese Schaltjahre berücksichtigt. Der - Quelltext \gitfile{hp}{2022ws/20221017}{loesung-2-f2.c} behebt den Fehler auf diese - Weise mit Hilfe von Und- (\lstinline{&&}) und - Oder-Verknüpfungen (\lstinline{||}) in der - \lstinline{while}-Bedingung. - - Der Quelltext \gitfile{hp}{2022ws/20221017}{loesung-2-f3.c} vermeidet die umständliche - Formulierung mit \lstinline{&&} und \lstinline{||} durch - Verwendung des ternären Operators \lstinline{?:}. Dieser - stellt eine "`\lstinline{if}-Anweisung für Ausdrücke"' bereit. - In diesem Fall liefert er für die rechte Seite des Vergleichs - \lstinline{days >} den Wert 366 im Falle eines Schaltjahrs - bzw.\ ansonsten den Wert 365. - - Beide Lösungen \gitfile{hp}{2022ws/20221017}{loesung-2-f2.c} und \gitfile{hp}{2022ws/20221017}{loesung-2-f3.c} - sind jedoch im Sinne der Aufgabenstellung \textbf{falsch}. - Diese lautet: "`Schreiben Sie das Quelltextfragment so um, - daß es die beschriebenen Probleme nicht mehr enthält."' - Mit den beschriebenen Problemen sind die genannten drei - Code-Verdopplungen gemeint, und diese befinden sich weiterhin - im Quelltext. Damit ist der Fehler zwar "`korrigiert"', aber - das Programm ist eher noch unübersichtlicher geworden, so daß - nicht klar ist, ob es nicht noch weitere Fehler enthält. - - \breath - - Eine richtige Lösung liefert \gitfile{hp}{2022ws/20221017}{loesung-2-4.c}. Dieses - Programm speichert den Wert der Tage im Jahr in einer - Variablen \lstinline{DaysInYear}. Damit erübrigen sich die - \lstinline{if}-Anweisungen innerhalb der - \lstinline{while}-Schleife, und die damit verbundenen - Code-Verdopplungen verschwinden. - - Etwas unschön ist hierbei die neu hinzugekommene - Code-Verdopplung bei der Berechnung von \lstinline{DaysInYear}. - Diese ist allerdings weniger kritisch als die vorherigen, da - sie nur einmal innerhalb der \lstinline{while}-Schleife - vorkommt und das andere Mal außerhalb derselben. - - Um diese Code-Verdopplung loszuwerden, kann man das - \lstinline{if} durch den \lstinline{?:}-Operator ersetzen und - die Zuweisung innerhalb der \lstinline{while}-Bedingung - vornehmen -- siehe \gitfile{hp}{2022ws/20221017}{loesung-2-5.c}. Dies ist einer der - seltenen Fälle, in denen ein Programm \emph{übersichtlicher\/} - wird, wenn eine Zuweisung innerhalb einer Bedingung - stattfindet. - - Alternativ kann \lstinline{DaysInYear()} auch eine Funktion - sein -- siehe \gitfile{hp}{2022ws/20221017}{loesung-2-6.c}. Diese Version ist - wahrscheinlich die übersichtlichste, hat jedoch den Nachteil, - daß die Berechnung von \lstinline{DaysInYear()} zweimal statt - nur einmal pro Schleifendurchlauf erfolgt, wodurch Rechenzeit - verschwendet wird. - - \gitfile{hp}{2022ws/20221017}{loesung-2-7.c} und \gitfile{hp}{2022ws/20221017}{loesung-2-8.c} beseitigen - dieses Problem durch eine Zuweisung des Funktionsergebnisses - an eine Variable -- einmal innerhalb der - \lstinline{while}-Bedingung und einmal außerhalb. - Der zweimalige Aufruf der Funktion \lstinline{DaysInYear()} in - \gitfile{hp}{2022ws/20221017}{loesung-2-8.c} zählt nicht als Code-Verdopplung, denn - der Code ist ja in einer Funktion gekapselt. (Genau dazu sind - Funktionen ja da: daß man sie mehrfach aufrufen kann.) - - \breath - - Fazit: Wenn Sie sich beim Programmieren bei - Cut-And-Paste-Aktionen erwischen, sollten Sie die Struktur - Ihres Programms noch einmal überdenken. - - Wahrscheinlich gibt es dann eine elegantere Lösung, deren - Korrektheit man auf den ersten Blick sieht. - - \end{itemize} - - \exercise{Strings} - - Strings werden in der Programmiersprache C - durch Zeiger auf \lstinline{char}-Variable realisiert. - - Wir betrachten die folgende Funktion (Datei: \gitfile{hp}{2022ws/20221017}{aufgabe-3.c}): - \begin{center} - \begin{minipage}{8cm} - \begin{lstlisting}[gobble=8] - int fun_1 (char *s1, char *s2) - { - int result = 1; - for (int i = 0; s1[i] && s2[i]; i++) - if (s1[i] != s2[i]) - result = 0; - return result; - } - \end{lstlisting} - \end{minipage}% - \end{center} - \begin{itemize} - \item[(a)] - Was bewirkt die Funktion? % \points{3} - \item[(b)] - Welchen Sinn hat die Bedingung "`\lstinline{s1[i] && s2[i]}"' - in der \lstinline{for}-Schleife? % \points{2} - \item[(c)] - Was würde sich ändern, wenn die Bedingung "`\lstinline{s1[i] && s2[i]}"' - in der \lstinline{for}-Schleife\\ - zu "`\lstinline{s1[i]}"' verkürzt würde? % \points{3} -% \item[(d)] -% Von welcher Ordnung (Landau-Symbol) ist die Funktion \lstinline{fun_1()} -% hinsichtlich der Anzahl ihrer Zugriffe auf die Zeichen in den Strings -% -- und warum? % \points{2} - \item[(d)] - Schreiben Sie eine eigene Funktion, - die dieselbe Aufgabe erledigt wie \lstinline{fun_1()}, nur effizienter. -% und geben Sie die Ordnung (Landau-Symbol) der von Ihnen geschriebenen Funktion an. % \points{5} - \end{itemize} - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Was bewirkt die Funktion?} - - Sie vergleicht zwei Strings miteinander bis zur Länge des kürzeren Strings - und gibt bei Gleichheit 1 zurück, ansonsten 0. - - Alternative Formulierung: - Die Funktion prüft, ob zwei Strings bis zur Länge des kürzeren übereinstimmen, - und gibt bei Gleichheit 1 zurück, ansonsten 0. - - Die Funktion prüft insbesondere \textbf{nicht} zwei Strings auf Gleichheit, - und sie ist \textbf{nicht} funktionsgleich zur - Standard-Bibliotheksfunktion \lstinline{strcmp()}. - - \item[(b)] - \textbf{Welchen Sinn hat die Bedingung "`\lstinline{s1[i] && s2[i]}"' - in der \lstinline{for}-Schleife?} - - Die Bedingung prüft, ob \emph{bei einem der beiden Strings\/} - die Ende-Markierung (Null-Symbol) erreicht ist. - Falls ja, wird die Schleife beendet. - - \item[(c)] - \textbf{Was würde sich ändern, wenn die Bedingung "`\lstinline{s1[i] && s2[i]}"' - in der \lstinline{for}-Schleife\\ - zu "`\lstinline{s1[i]}"' verkürzt würde?} - - In diesem Fall würde nur für \lstinline{s1} geprüft, - ob das Ende erreicht ist. - Wenn \lstinline{s1} länger ist als \lstinline{s2}, - würde \lstinline{s2} über sein Ende hinaus ausgelesen. - Dies kann zu Lesezugriffen auf Speicher außerhalb des Programms - und damit zu einem Absturz führen - ("`Speicherzugriffsfehler"', "`Schutzverletzung"'). - - \item[(d)] - \textbf{Schreiben Sie eine eigene Funktion, - die dieselbe Aufgabe erledigt wie \lstinline{fun_1()}, nur effizienter.} - - Die Effizienz läßt sich steigern, indem man die Schleife abbricht, - sobald das Ergebnis feststeht. - Es folgen drei Möglichkeiten, dies zu realisieren. - \end{itemize} - - \begin{center} - \begin{minipage}[t]{8cm} - Erweiterung der Schleifenbedingung: - - \begin{lstlisting}[gobble=8] - int fun_2 (char *s1, char *s2) - { - int result = 1; - for (int i = 0; s1[i] && s2[i] && result; i++) - if (s1[i] != s2[i]) - result = 0; - return result; - } - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{6cm} - Verwendung von \lstinline{return}: - - \begin{lstlisting}[gobble=8] - int fun_3 (char *s1, char *s2) - { - for (int i = 0; s1[i] && s2[i]; i++) - if (s1[i] != s2[i]) - return 0; - return 1; - } - \end{lstlisting} - \end{minipage} - \end{center} - \vspace*{-1cm}\goodbreak - - \begin{center} - \begin{minipage}{9cm} - Die nebenstehende Lösung unter Verwendung von \lstinline{break} - ist zwar ebenfalls richtig, aber länger und weniger übersichtlich - als die beiden anderen Lösungen. - - \smallskip - - Die Datei \gitfile{hp}{2022ws/20221017}{loesung-3.c} enthält ein Testprogramm - für alle o.\,a.\ Lösungen. - Das Programm testet nur die offensichtlichsten Fälle; - für den Einsatz der Funktionen in einer Produktivumgebung - wären weitaus umfassendere Tests erforderlich. - - \smallskip - - Das Testprogramm enthält String-Zuweisungen wie z.\,B.\ - \lstinline{s2 = "Apfel"}. - Dies funktioniert, weil wir damit einen Zeiger (\lstinline{char *s2}) - auf einen neuen Speicherbereich (\lstinline{"Apfel"}) zeigen lassen. - Eine entsprechende Zuweisung zwischen Arrays - (\lstinline{char s3[] = "Birne"; s3 = "Pfirsich";)} - funktioniert \emph{nicht}. - - \end{minipage}\hspace*{1cm}% - \begin{minipage}{6cm} - \begin{lstlisting}[gobble=8] - int fun_4 (char *s1, char *s2) - { - int result = 1; - for (int i = 0; s1[i] && s2[i]; i++) - if (s1[i] != s2[i]) - { - result = 0; - break; - } - return result; - } - \end{lstlisting} - \end{minipage} - \end{center} - - \exercise{Programm analysieren} - - Wir betrachten das folgende C-Programm (Datei: \gitfile{hp}{2022ws/20221017}{aufgabe-4.c}): - \begin{lstlisting} - char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c";main(){printf(f,34,f,34,10);} - \end{lstlisting} - \vspace{-\medskipamount} - \begin{itemize} - \item[(a)] - Was bewirkt dieses Programm? - \item[(b)] - Wofür stehen die Zahlen? - \item[(c)] - Ergänzen Sie das Programm derart, daß seine \lstinline{main()}-Funktion - \lstinline{int main (void)} lautet und eine \lstinline{return}-Anweisung hat, - wobei die in Aufgabenteil (a) festgestellte Eigenschaft erhalten bleiben soll. - \end{itemize} - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Was bewirkt dieses Programm?} - - Es gibt \emph{seinen eigenen Quelltext\/} aus. - - (Wichtig ist die Bezugnahme auf den eigenen Quelltext. - Die Angabe\\ - "`Es gibt - \lstinline|char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c";main(){printf(f,34,f,34,10);}| - aus"'\\ - genügt insbesondere nicht.) - - \item[(b)] - \textbf{Wofür stehen die Zahlen?} - - Die 34 steht für ein Anführungszeichen und die 10 für ein - Zeilenendezeichen (\lstinline{\n}). - - Hintergrund: Um den eigenen Quelltext ausgeben zu können, muß - das Programm auch Anführungszeichen und Zeilenendezeichen - ausgeben. Dies geschieht normalerweise mit vorangestelltem - Backslash: \lstinline{\"} bzw.\ \lstinline{\n}. Um dann aber - den Backslash ausgeben zu können, müßte man diesem ebenfalls - einen Backslash voranstellen: \lstinline{\\}. Damit dies nicht - zu einer Endlosschleife wird, verwendet der Programmierer - dieses Programms den Trick mit den Zahlen, die durch - \lstinline{%c} als Zeichen ausgegeben werden. - - \item[(c)] - \textbf{Ergänzen Sie das Programm derart, daß seine \lstinline{main()}-Funktion - \lstinline{int main (void)} lautet und eine \lstinline{return}-Anweisung hat, - wobei die in Aufgabenteil (a) festgestellte Eigenschaft erhalten bleiben soll.} - - Datei: \gitfile{hp}{2022ws/20221017}{loesung-4.c} - \begin{lstlisting}[gobble=8] - char*f="char*f=%c%s%c;int main(void){printf(f,34,f,34,10);return 0;}%c"; - int main(void){printf(f,34,f,34,10);return 0;} - \end{lstlisting} - Das Programm ist eine einzige, lange Zeile, die hier nur aus - Platzgründen als zwei Zeilen abgedruckt wird. Auf das - Semikolon am Ende der "`ersten Zeile"' folgt unmittelbar -- ohne Leerzeichen -- - das Schlüsselwort \lstinline{int} am Anfang der "`zweiten Zeile"'. - - Mit "`die in Aufgabenteil (a) festgestellte Eigenschaft"' ist - gemeint, daß das Programm weiterhin seinen eigenen Quelltext - ausgeben soll. Die Herausforderung dieser Aufgabe besteht - darin, das Programm zu modifizieren, ohne diese Eigenschaft zu - verlieren. - - Zusatzaufgabe für Interessierte: Ergänzen Sie das Programm so, - daß es auch mit \lstinline[style=cmd]{-Wall} ohne Warnungen - compiliert werden kann. - - Hinweis dazu: \lstinline{#include<stdio.h>} - (ohne Leerzeichen, um Platz zu sparen) - - Lösung der Zusatzaufgabe: \gitfile{hp}{2022ws/20221017}{loesung-4x.c} - - \end{itemize} - -\end{document} diff --git a/20221017/hp-uebung-20221017.pdf b/20221017/hp-uebung-20221017.pdf deleted file mode 100644 index 7a88b19169bab72f6c16f37d65c25525aec6c1cb..0000000000000000000000000000000000000000 Binary files a/20221017/hp-uebung-20221017.pdf and /dev/null differ diff --git a/20221017/hp-uebung-20221017.tex b/20221017/hp-uebung-20221017.tex deleted file mode 100644 index 7eec41a20a3bd8a0e56e27003d3c7bef3f8c825c..0000000000000000000000000000000000000000 --- a/20221017/hp-uebung-20221017.tex +++ /dev/null @@ -1,170 +0,0 @@ -% hp-uebung-20221017.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Seltsame Programme, Kalender-Berechnung, Strings, Programm analysieren - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \thispagestyle{empty} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 17.\ Oktober 2022} - - \exercise{Seltsame Programme} - - Unter \url{https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20211017} - finden Sie (unter anderem)\\ - die Programme \gitfile{hp}{2022ws/20221017}{test-1.c}, - \gitfile{hp}{2022ws/20221017}{test-2.c} und \gitfile{hp}{2022ws/20221017}{test-3.c}. - - Was bewirken diese Programme, und warum verhalten sie sich so? - - \exercise{Kalender-Berechnung} - - Am 3.\,1.\,2009 meldete \emph{heise online\/}: - \begin{quote} - Kunden des ersten mobilen Media-Players von Microsoft - erlebten zum Jahresende eine böse Überraschung: - Am 31.\ Dezember 2008 fielen weltweit alle Zune-Geräte der ersten Generation aus. - Ursache war ein interner Fehler bei der Handhabung von Schaltjahren. - - \strut\hfill\url{http://heise.de/-193332}, - \end{quote} - Der Artikel verweist auf ein Quelltextfragment (Datei: \gitfile{hp}{2022ws/20221017}{aufgabe-2.c}), - das für einen gegebenen Wert \lstinline{days} - das Jahr und den Tag innerhalb des Jahres - für den \lstinline{days}-ten Tag nach dem 1.\,1.\,1980 berechnen soll: - \begin{lstlisting} - year = ORIGINYEAR; /* = 1980 */ - - while (days > 365) - { - if (IsLeapYear (year)) - { - if (days > 366) - { - days -= 366; - year += 1; - } - } - else - { - days -= 365; - year += 1; - } - } - \end{lstlisting} - Dieses Quelltextfragment enthält schlechten Programmierstil, - nämlich mehrere Code-Verdopplungen: - \begin{itemize} - \item - Die Anweisung \lstinline{year += 1} taucht an zwei Stellen auf. - \item - Es gibt zwei unabhängige Abfragen \lstinline{days > 365} und \lstinline{days > 366}:\\ - eine in einer \lstinline{while}- und die andere in einer \lstinline{if}-Bedingung. - \item - Die Länge eines Jahres wird nicht durch eine Funktion berechnet oder in einer Variablen gespeichert; - stattdessen werden an mehreren Stellen die expliziten numerischen Konstanten 365 und 366 verwendet. - \end{itemize} - Diese Probleme führten am 31.\ Dezember 2008 zu einer Endlosschleife. - - Gut hingegen ist die Verwendung einer Konstanten \lstinline{ORIGINYEAR} - anstelle der Zahl 1980 - sowie die Kapselung der Berechnung der Schaltjahr-Bedingung - in einer Funktion \lstinline{IsLeapYear()}. - - \begin{itemize} - \item[(a)] - Erklären Sie das Zustandekommen der Endlosschleife. - \item[(b)] - Schreiben Sie das Quelltextfragment so um, daß es die beschriebenen Probleme - nicht mehr enthält. - \end{itemize} - - \textbf{Hinweis 1:} Verwenden Sie für \lstinline{IsLeapYear()} - Ihre eigene Funktion aus Aufgabe 1 der letzten Übung. - - \textbf{Hinweis 2}: Schreiben Sie zusätzlich eine Funktion \lstinline{DaysInYear()}. - - \exercise{Strings} - - Strings werden in der Programmiersprache C - durch Zeiger auf \lstinline{char}-Variable realisiert. - - Wir betrachten die folgende Funktion (Datei: \gitfile{hp}{2022ws/20221017}{aufgabe-3.c}): - \begin{center} - \begin{minipage}{8cm} - \begin{lstlisting}[gobble=8] - int fun_1 (char *s1, char *s2) - { - int result = 1; - for (int i = 0; s1[i] && s2[i]; i++) - if (s1[i] != s2[i]) - result = 0; - return result; - } - \end{lstlisting} - \end{minipage}% - \end{center} - \begin{itemize} - \item[(a)] - Was bewirkt die Funktion? % \points{3} - \item[(b)] - Welchen Sinn hat die Bedingung "`\lstinline{s1[i] && s2[i]}"' - in der \lstinline{for}-Schleife? % \points{2} - \item[(c)] - Was würde sich ändern, wenn die Bedingung "`\lstinline{s1[i] && s2[i]}"' - in der \lstinline{for}-Schleife\\ - zu "`\lstinline{s1[i]}"' verkürzt würde? % \points{3} -% \item[(d)] -% Von welcher Ordnung (Landau-Symbol) ist die Funktion \lstinline{fun_1()} -% hinsichtlich der Anzahl ihrer Zugriffe auf die Zeichen in den Strings -% -- und warum? % \points{2} - \item[(d)] - Schreiben Sie eine eigene Funktion, - die dieselbe Aufgabe erledigt wie \lstinline{fun_1()}, nur effizienter. -% und geben Sie die Ordnung (Landau-Symbol) der von Ihnen geschriebenen Funktion an. % \points{5} - \end{itemize} - - \exercise{Programm analysieren} - - Wir betrachten das folgende C-Programm (Datei: \gitfile{hp}{2022ws/20221017}{aufgabe-4.c}): - \begin{lstlisting} - char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c";main(){printf(f,34,f,34,10);} - \end{lstlisting} - \vspace{-\medskipamount} - \begin{itemize} - \item[(a)] - Was bewirkt dieses Programm? - \item[(b)] - Wofür stehen die Zahlen? - \item[(c)] - Ergänzen Sie das Programm derart, daß seine \lstinline{main()}-Funktion - \lstinline{int main (void)} lautet und eine \lstinline{return}-Anweisung hat, - wobei die in Aufgabenteil (a) festgestellte Eigenschaft erhalten bleiben soll. - \end{itemize} - -\end{document} diff --git a/20221017/loesung-2-4.c b/20221017/loesung-2-4.c deleted file mode 100644 index d141e32582374a3b3e6955f5634191d15edb3709..0000000000000000000000000000000000000000 --- a/20221017/loesung-2-4.c +++ /dev/null @@ -1,41 +0,0 @@ -#include <stdio.h> - -int IsLeapYear (int year) -{ - if (year % 4) - return 0; - else if (year % 100) - return 1; - else if (year % 400) - return 0; - else - return 1; -} - -int main (void) -{ - int ORIGINYEAR = 1980; - int days = 366; - int year; - - year = ORIGINYEAR; /* = 1980 */ - - int DaysInYear; - if (IsLeapYear (year)) - DaysInYear = 366; - else - DaysInYear = 365; - - while (days > DaysInYear) - { - days -= DaysInYear; - year += 1; - if (IsLeapYear (year)) - DaysInYear = 366; - else - DaysInYear = 365; - } - - printf ("year = %d\ndays = %d\n", year, days); - return 0; -} diff --git a/20221017/loesung-2-5.c b/20221017/loesung-2-5.c deleted file mode 100644 index 8a71934b7df24a28d11a6696e212aaccc430277f..0000000000000000000000000000000000000000 --- a/20221017/loesung-2-5.c +++ /dev/null @@ -1,33 +0,0 @@ -#include <stdio.h> - -int IsLeapYear (int year) -{ - if (year % 4) - return 0; - else if (year % 100) - return 1; - else if (year % 400) - return 0; - else - return 1; -} - -int main (void) -{ - int ORIGINYEAR = 1980; - int days = 366; - int year; - - year = ORIGINYEAR; /* = 1980 */ - - int DaysInYear; - - while (days > (DaysInYear = IsLeapYear (year) ? 366 : 365)) - { - days -= DaysInYear; - year += 1; - } - - printf ("year = %d\ndays = %d\n", year, days); - return 0; -} diff --git a/20221017/loesung-2-6.c b/20221017/loesung-2-6.c deleted file mode 100644 index 0605571480991d1ec73a8cec50395ddf68ae3135..0000000000000000000000000000000000000000 --- a/20221017/loesung-2-6.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <stdio.h> - -int IsLeapYear (int year) -{ - if (year % 4) - return 0; - else if (year % 100) - return 1; - else if (year % 400) - return 0; - else - return 1; -} - -int DaysInYear (int year) -{ - if (IsLeapYear (year)) - return 366; - else - return 365; -} - -int main (void) -{ - int ORIGINYEAR = 1980; - int days = 366; - int year; - - year = ORIGINYEAR; /* = 1980 */ - - while (days > DaysInYear (year)) - { - days -= DaysInYear (year); - year += 1; - } - - printf ("year = %d\ndays = %d\n", year, days); - return 0; -} diff --git a/20221017/loesung-2-7.c b/20221017/loesung-2-7.c deleted file mode 100644 index 5c98286730aae146cf587b5f3401eb6eadd17aa7..0000000000000000000000000000000000000000 --- a/20221017/loesung-2-7.c +++ /dev/null @@ -1,41 +0,0 @@ -#include <stdio.h> - -int IsLeapYear (int year) -{ - if (year % 4) - return 0; - else if (year % 100) - return 1; - else if (year % 400) - return 0; - else - return 1; -} - -int DaysInYear (int year) -{ - if (IsLeapYear (year)) - return 366; - else - return 365; -} - -int main (void) -{ - int ORIGINYEAR = 1980; - int days = 366; - int year; - - year = ORIGINYEAR; /* = 1980 */ - - int d; - - while (days > (d = DaysInYear (year))) - { - days -= d; - year += 1; - } - - printf ("year = %d\ndays = %d\n", year, days); - return 0; -} diff --git a/20221017/loesung-2-8.c b/20221017/loesung-2-8.c deleted file mode 100644 index e94dc80375b88fd5ff3245e8a99f76a5955b6bb8..0000000000000000000000000000000000000000 --- a/20221017/loesung-2-8.c +++ /dev/null @@ -1,42 +0,0 @@ -#include <stdio.h> - -int IsLeapYear (int year) -{ - if (year % 4) - return 0; - else if (year % 100) - return 1; - else if (year % 400) - return 0; - else - return 1; -} - -int DaysInYear (int year) -{ - if (IsLeapYear (year)) - return 366; - else - return 365; -} - -int main (void) -{ - int ORIGINYEAR = 1980; - int days = 366; - int year; - - year = ORIGINYEAR; /* = 1980 */ - - int d = DaysInYear (year); - - while (days > d) - { - days -= d; - year += 1; - d = DaysInYear (year); - } - - printf ("year = %d\ndays = %d\n", year, days); - return 0; -} diff --git a/20221017/loesung-2-f1.c b/20221017/loesung-2-f1.c deleted file mode 100644 index 4d511c4fa7ee6a9dfb0bc2f69412eeb48745af56..0000000000000000000000000000000000000000 --- a/20221017/loesung-2-f1.c +++ /dev/null @@ -1,42 +0,0 @@ -#include <stdio.h> - -int IsLeapYear (int year) -{ - if (year % 4) - return 0; - else if (year % 100) - return 1; - else if (year % 400) - return 0; - else - return 1; -} - -int main (void) -{ - int ORIGINYEAR = 1980; - int days = 366; - int year; - - year = ORIGINYEAR; /* = 1980 */ - - while (days > 365) - { - if (IsLeapYear (year)) - { - if (days > 366) - { - days -= 366; - year += 1; - } - } - else - { - days -= 365; - year += 1; - } - } - - printf ("year = %d\ndays = %d\n", year, days); - return 0; -} diff --git a/20221017/loesung-2-f2.c b/20221017/loesung-2-f2.c deleted file mode 100644 index a44edb09ffde3d3c77cfe673da862260368c33e3..0000000000000000000000000000000000000000 --- a/20221017/loesung-2-f2.c +++ /dev/null @@ -1,43 +0,0 @@ -#include <stdio.h> - -int IsLeapYear (int year) -{ - if (year % 4) - return 0; - else if (year % 100) - return 1; - else if (year % 400) - return 0; - else - return 1; -} - -int main (void) -{ - int ORIGINYEAR = 1980; - int days = 366; - int year; - - year = ORIGINYEAR; /* = 1980 */ - - while ((IsLeapYear (year) && days > 366) - || (!IsLeapYear (year) && days > 365)) - { - if (IsLeapYear (year)) - { - if (days > 366) - { - days -= 366; - year += 1; - } - } - else - { - days -= 365; - year += 1; - } - } - - printf ("year = %d\ndays = %d\n", year, days); - return 0; -} diff --git a/20221017/loesung-2-f3.c b/20221017/loesung-2-f3.c deleted file mode 100644 index dbfe5040274953c3b90d6b2da194c0c8ae64f04f..0000000000000000000000000000000000000000 --- a/20221017/loesung-2-f3.c +++ /dev/null @@ -1,42 +0,0 @@ -#include <stdio.h> - -int IsLeapYear (int year) -{ - if (year % 4) - return 0; - else if (year % 100) - return 1; - else if (year % 400) - return 0; - else - return 1; -} - -int main (void) -{ - int ORIGINYEAR = 1980; - int days = 366; - int year; - - year = ORIGINYEAR; /* = 1980 */ - - while (days > (IsLeapYear (year) ? 366 : 365)) - { - if (IsLeapYear (year)) - { - if (days > 366) - { - days -= 366; - year += 1; - } - } - else - { - days -= 365; - year += 1; - } - } - - printf ("year = %d\ndays = %d\n", year, days); - return 0; -} diff --git a/20221017/loesung-3.c b/20221017/loesung-3.c deleted file mode 100644 index 29a2b7f234ea5c31b06780e9dd461dff95dd33a3..0000000000000000000000000000000000000000 --- a/20221017/loesung-3.c +++ /dev/null @@ -1,67 +0,0 @@ -#include <stdio.h> - -int fun_1 (char *s1, char *s2) -{ - int result = 1; - for (int i = 0; s1[i] && s2[i]; i++) - if (s1[i] != s2[i]) - result = 0; - return result; -} - -int fun_2 (char *s1, char *s2) -{ - int result = 1; - for (int i = 0; s1[i] && s2[i] && result; i++) - if (s1[i] != s2[i]) - result = 0; - return result; -} - -int fun_3 (char *s1, char *s2) -{ - for (int i = 0; s1[i] && s2[i]; i++) - if (s1[i] != s2[i]) - return 0; - return 1; -} - -int fun_4 (char *s1, char *s2) -{ - int result = 1; - for (int i = 0; s1[i] && s2[i]; i++) - if (s1[i] != s2[i]) - { - result = 0; - break; - } - return result; -} - -int main (void) -{ - char *s1 = "Apfel"; - char *s2 = "Apfelkuchen"; - if (fun_1 (s1, s2) && fun_2 (s1, s2) && fun_3 (s1, s2) && fun_4 (s1, s2)) - printf ("OK\n"); - else - printf ("failed\n"); - s1 = "Apfelkuchen"; - s2 = "Apfel"; - if (fun_1 (s1, s2) && fun_2 (s1, s2) && fun_3 (s1, s2) && fun_4 (s1, s2)) - printf ("OK\n"); - else - printf ("failed\n"); - s2 = "Birnenmarmelade"; - if (fun_1 (s1, s2) || fun_2 (s1, s2) || fun_3 (s1, s2) || fun_4 (s1, s2)) - printf ("failed\n"); - else - printf ("OK\n"); - s1 = s2; - s2 = "Apfelkuchen"; - if (fun_1 (s1, s2) || fun_2 (s1, s2) || fun_3 (s1, s2) || fun_4 (s1, s2)) - printf ("failed\n"); - else - printf ("OK\n"); - return 0; -} diff --git a/20221017/loesung-4.c b/20221017/loesung-4.c deleted file mode 100644 index 6346384a81d62e7e687f4db99be3ba8fe4020744..0000000000000000000000000000000000000000 --- a/20221017/loesung-4.c +++ /dev/null @@ -1 +0,0 @@ -char*f="char*f=%c%s%c;int main(void){printf(f,34,f,34,10);return 0;}%c";int main(void){printf(f,34,f,34,10);return 0;} diff --git a/20221017/loesung-4x.c b/20221017/loesung-4x.c deleted file mode 100644 index fcc65e153ddf009f55af118278774cd202f7c316..0000000000000000000000000000000000000000 --- a/20221017/loesung-4x.c +++ /dev/null @@ -1,2 +0,0 @@ -#include<stdio.h> -char*f="#include<stdio.h>%cchar*f=%c%s%c;int main(void){printf(f,10,34,f,34,10);return 0;}%c";int main(void){printf(f,10,34,f,34,10);return 0;} diff --git a/20221017/logo-hochschule-bochum-cvh-text-v2.pdf b/20221017/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221017/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221017/logo-hochschule-bochum.pdf b/20221017/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221017/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221017/main-params-01.c b/20221017/main-params-01.c deleted file mode 100644 index e6e64ba029e1042aff60960fc8b7c3d4d5d8e2e2..0000000000000000000000000000000000000000 --- a/20221017/main-params-01.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - for (int i = 0; i < argc; i++) - printf ("argv[%d] = \"%s\"\n", i, argv[i]); - return 0; -} diff --git a/20221017/main-params-01.txt b/20221017/main-params-01.txt deleted file mode 100644 index b4ff132e66b6baea75e4c41f4f506aac876fa4bf..0000000000000000000000000000000000000000 --- a/20221017/main-params-01.txt +++ /dev/null @@ -1,21 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - for (int i = 0; i < argc; i++) - printf ("argv[%d] = \"%s\"\n", i, argv[i]); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221017> gcc -Wall -O main-params-01.c -o main-params-01 -cassini/home/peter/bo/2022ws/hp/20221017> ./main-params-01 bla blubb -argc = 3 -argv[0] = "./main-params-01" -argv[1] = "bla" -argv[2] = "blubb" -cassini/home/peter/bo/2022ws/hp/20221017> /home/peter/bo/2022ws/hp/20221017/main-params-01 bla blubb -argc = 3 -argv[0] = "/home/peter/bo/2022ws/hp/20221017/main-params-01" -argv[1] = "bla" -argv[2] = "blubb" -cassini/home/peter/bo/2022ws/hp/20221017> diff --git a/20221017/main-params-02.c b/20221017/main-params-02.c deleted file mode 100644 index dc228bb2bed3ca98892f26c753668e6fb7d167e6..0000000000000000000000000000000000000000 --- a/20221017/main-params-02.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - for (int i = 0; *argv; argv++) - printf ("argv[%d] = \"%s\"\n", i, argv[i]); - return 0; -} diff --git a/20221017/main-params-02.txt b/20221017/main-params-02.txt deleted file mode 100644 index c90c054481d3feebd65dcd19b3993645473e6286..0000000000000000000000000000000000000000 --- a/20221017/main-params-02.txt +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - for (int i = 0; *argv; argv++) - printf ("argv[%d] = \"%s\"\n", i, argv[i]); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221017> gcc -Wall -O main-params-02.c -o main-params-02 -cassini/home/peter/bo/2022ws/hp/20221017> ./main-params-02 bla blubb pruzzel proe -argc = 5 -argv[0] = "./main-params-02" -argv[0] = "bla" -argv[0] = "blubb" -argv[0] = "pruzzel" -argv[0] = "proe" -cassini/home/peter/bo/2022ws/hp/20221017> diff --git a/20221017/main-params-03.c b/20221017/main-params-03.c deleted file mode 100644 index 49e93fd84e36b54d429eee78af8906856b68ff35..0000000000000000000000000000000000000000 --- a/20221017/main-params-03.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - for (int i = 0; *argv; argv++) - printf ("argv[%d] = \"%s\"\n", i, *argv); - return 0; -} diff --git a/20221017/main-params-04.c b/20221017/main-params-04.c deleted file mode 100644 index 0e932b379ce3c7381241c8d8d58d2a8cad4a2f76..0000000000000000000000000000000000000000 --- a/20221017/main-params-04.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - for (int i = 0; *argv; i++, argv++) - printf ("argv[%d] = \"%s\"\n", i, *argv); - return 0; -} diff --git a/20221017/main-params-05.c b/20221017/main-params-05.c deleted file mode 100644 index 1edea2347d90713756b31e06b0f5dcef59adcbc9..0000000000000000000000000000000000000000 --- a/20221017/main-params-05.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - for (int i = 0; *argv; argv++) - printf ("argv[%d] = \"%s\"\n", i++, *argv); - return 0; -} diff --git a/20221017/main-params-06.c b/20221017/main-params-06.c deleted file mode 100644 index f4c1bb7bd17edc00d98586f73a91ab68e8a126f8..0000000000000000000000000000000000000000 --- a/20221017/main-params-06.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - for (int i = 0; *argv; argv++) - { - printf ("argv[%d] = \"%s\"\n", i, *argv); - i++; - } - return 0; -} diff --git a/20221017/main-params-07.c b/20221017/main-params-07.c deleted file mode 100644 index c9e41612a9001cd12a2ceb94b0b19015cf13de60..0000000000000000000000000000000000000000 --- a/20221017/main-params-07.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - int i = 0; - for (; *argv; argv++) - { - printf ("argv[%d] = \"%s\"\n", i, *argv); - i++; - } - return 0; -} diff --git a/20221017/main-params-08.c b/20221017/main-params-08.c deleted file mode 100644 index 4182397a45152e780baf611a6031c37f9dcea5ac..0000000000000000000000000000000000000000 --- a/20221017/main-params-08.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - int i = 0; - while (*argv) - { - printf ("argv[%d] = \"%s\"\n", i, *argv); - i++; - argv++; - } - return 0; -} diff --git a/20221017/main-params-09.c b/20221017/main-params-09.c deleted file mode 100644 index 8fa64e701d9257dae4040a694ec651a054657cf4..0000000000000000000000000000000000000000 --- a/20221017/main-params-09.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (int argc, char **argv) -{ - printf ("argc = %d\n", argc); - int i = 0; - while (*argv) - printf ("argv[%d] = \"%s\"\n", i++, *argv++); - return 0; -} diff --git a/20221017/pgscript.sty b/20221017/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221017/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221017/pgslides.sty b/20221017/pgslides.sty deleted file mode 120000 index 5be1416f4216f076aa268901f52a15d775e43f64..0000000000000000000000000000000000000000 --- a/20221017/pgslides.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgslides.sty \ No newline at end of file diff --git a/20221017/pointers-07.c b/20221017/pointers-07.c deleted file mode 100644 index 169a038c369979cf1de7015ccb4a6f5e2e2e8df6..0000000000000000000000000000000000000000 --- a/20221017/pointers-07.c +++ /dev/null @@ -1,14 +0,0 @@ -#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; -} diff --git a/20221017/pointers-08.c b/20221017/pointers-08.c deleted file mode 100644 index c83794a4cb515e9a033529340e979c8ec4dd0308..0000000000000000000000000000000000000000 --- a/20221017/pointers-08.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int answer; - int *b = &answer; - *b = 42; - printf ("The answer is %d.\n", answer); - return 0; -} diff --git a/20221017/pointers-09.c b/20221017/pointers-09.c deleted file mode 100644 index 856e938ed0ce5a0c48ac64477859cf86ab6a3768..0000000000000000000000000000000000000000 --- a/20221017/pointers-09.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int answer; - int *b, c; - b = &answer; - c = &answer; - *b = 42; - printf ("The answer is %d.\n", answer); - printf ("c = %d\n", c); - return 0; -} diff --git a/20221017/pointers-10.c b/20221017/pointers-10.c deleted file mode 100644 index 615080b1e9ff5a1d13b8cb76fddf3f3fcd4c56a2..0000000000000000000000000000000000000000 --- a/20221017/pointers-10.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int answer; - int* b, c; - b = &answer; - c = &answer; - *b = 42; - printf ("The answer is %d.\n", answer); - printf ("c = %d\n", c); - return 0; -} diff --git a/20221017/string-constants.png b/20221017/string-constants.png deleted file mode 100644 index 3dba40f2857abbd1454eab9d85a96f70d6b509d4..0000000000000000000000000000000000000000 Binary files a/20221017/string-constants.png and /dev/null differ diff --git a/20221017/string-constants.xcf.gz b/20221017/string-constants.xcf.gz deleted file mode 100644 index a8fc3f2c62506054b51891b51888b55680ab7883..0000000000000000000000000000000000000000 Binary files a/20221017/string-constants.xcf.gz and /dev/null differ diff --git a/20221017/string-ops-01.c b/20221017/string-ops-01.c deleted file mode 100644 index 1c0d36087e291cfa3b200955724b7de6f4460995..0000000000000000000000000000000000000000 --- a/20221017/string-ops-01.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char hello[] = "Hello, world!\n"; - - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); - - return 0; - - printf ("%s\n", hello + 7); - printf ("%zd\n", strlen (hello + 7)); - - hello[5] = 0; - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); -} diff --git a/20221017/string-ops-02.c b/20221017/string-ops-02.c deleted file mode 100644 index 0bf558ba459b2fe31b744b2703f26d1a3201a457..0000000000000000000000000000000000000000 --- a/20221017/string-ops-02.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char hello[] = "Hello, world!\n"; - - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); - - printf ("%s\n", hello + 7); - printf ("%zd\n", strlen (hello + 7)); - - return 0; - - hello[5] = 0; - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); -} diff --git a/20221017/string-ops-03.c b/20221017/string-ops-03.c deleted file mode 100644 index dd05111f79e0573d616522593362f6f93beb89e7..0000000000000000000000000000000000000000 --- a/20221017/string-ops-03.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char hello[] = "Hello, world!\n"; - - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); - - printf ("%s\n", hello + 7); - printf ("%zd\n", strlen (hello + 7)); - - hello[5] = 0; - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); - - return 0; -} diff --git a/20221017/string-ops-04.c b/20221017/string-ops-04.c deleted file mode 100644 index 99538d235b7958a12d169ae378bcc5c311c7830f..0000000000000000000000000000000000000000 --- a/20221017/string-ops-04.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *hello = "Hello, world!\n"; - - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); - - printf ("%s\n", hello + 7); - printf ("%zd\n", strlen (hello + 7)); - - hello[5] = 0; - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); - - return 0; -} diff --git a/20221017/string-ops-05.c b/20221017/string-ops-05.c deleted file mode 100644 index 74e2143811efbe6c4d428a688f2a2e05aefe6b34..0000000000000000000000000000000000000000 --- a/20221017/string-ops-05.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *anton = "Anton"; - char *zacharias = "Zacharias"; - - printf ("%d\n", strcmp (anton, zacharias)); - printf ("%d\n", strcmp (zacharias, anton)); - printf ("%d\n", strcmp (anton, anton)); - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-06.c b/20221017/string-ops-06.c deleted file mode 100644 index 45a05920ade15e321a1f9942cd3aecafa6dab452..0000000000000000000000000000000000000000 --- a/20221017/string-ops-06.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *anton = "anton"; - char *zacharias = "Zacharias"; - - printf ("%d\n", strcmp (anton, zacharias)); - printf ("%d\n", strcmp (zacharias, anton)); - printf ("%d\n", strcmp (anton, anton)); - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-07.c b/20221017/string-ops-07.c deleted file mode 100644 index c164eba2a9a4871ae1c6ed5a2b9b365df58511ad..0000000000000000000000000000000000000000 --- a/20221017/string-ops-07.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *anton = "anton"; - char *Anton = "Anton"; - char *zacharias = "Zacharias"; - - printf ("%d\n", strcasecmp (anton, zacharias)); - printf ("%d\n", strcasecmp (zacharias, anton)); - printf ("%d\n", strcasecmp (anton, Anton)); - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-08.c b/20221017/string-ops-08.c deleted file mode 100644 index 87e2cf826d340393a5ce37a7eb3676a24a8040c3..0000000000000000000000000000000000000000 --- a/20221017/string-ops-08.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *anton = "anton"; - char *Bnton = "Bnton"; - char *zacharias = "Zacharias"; - - printf ("%d\n", strcasecmp (Bnton, zacharias)); - printf ("%d\n", strcasecmp (zacharias, anton)); - printf ("%d\n", strcasecmp (anton, Bnton)); - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-09.c b/20221017/string-ops-09.c deleted file mode 100644 index 6a803adb92c01db1a80b73321fa6646779b877e6..0000000000000000000000000000000000000000 --- a/20221017/string-ops-09.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *anton = "anton"; - char *aenton = "änton"; - char *zacharias = "Zacharias"; - - printf ("%d\n", strcasecmp (aenton, zacharias)); - printf ("%d\n", strcasecmp (zacharias, anton)); - printf ("%d\n", strcasecmp (anton, aenton)); - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-10.c b/20221017/string-ops-10.c deleted file mode 100644 index 0009a89d769500bc6c04abc09610baa31ff39cc2..0000000000000000000000000000000000000000 --- a/20221017/string-ops-10.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *anton = "Anton"; - char *zacharias = "Zacharias"; - - if (anton < zacharias) - printf ("Anton liegt weiter vorne im Alphabet.\n"); - else - printf ("Zacharias liegt weiter vorne im Alphabet.\n"); - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-11.c b/20221017/string-ops-11.c deleted file mode 100644 index fb4915dc48a83bcd8fab2997d4a8f73e3465cccb..0000000000000000000000000000000000000000 --- a/20221017/string-ops-11.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *anton = "Zbnton"; - char *zacharias = "Zacharias"; - - if (anton < zacharias) - printf ("Zbnton liegt weiter vorne im Alphabet.\n"); - else - printf ("Zacharias liegt weiter vorne im Alphabet.\n"); - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-12.c b/20221017/string-ops-12.c deleted file mode 100644 index 93f47f4729cca2f0d1801dfc583ad26648e115f6..0000000000000000000000000000000000000000 --- a/20221017/string-ops-12.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -char *anton = "Anton"; -char *zacharias = "Zacharias"; - -int main (void) -{ - if (anton < zacharias) - printf ("Anton liegt weiter vorne im Alphabet.\n"); - else - printf ("Zacharias liegt weiter vorne im Alphabet.\n"); - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-13.c b/20221017/string-ops-13.c deleted file mode 100644 index 297c5bbb3638b6ce5ff8c3913970eab65c03fc08..0000000000000000000000000000000000000000 --- a/20221017/string-ops-13.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <stdio.h> -#include <string.h> - -char *anton = "Anton"; -char *zacharias = "Zacharias"; - -int main (void) -{ - if (anton < zacharias) - printf ("Anton (%016zx) liegt weiter vorne im Alphabet ... äh ... Speicher als Zacharias (%016zx).\n", - anton, zacharias); - else - printf ("Zacharias (%016zx) liegt weiter vorne im Alphabet ... äh ... Speicher als Anton (%016zx).\n", - zacharias, anton); - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-14.c b/20221017/string-ops-14.c deleted file mode 100644 index 2f2271d3b6c73b7f0bec3cae078662184754a20a..0000000000000000000000000000000000000000 --- a/20221017/string-ops-14.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *anton = "Anton"; - char *zacharias = "Zacharias"; - if (anton < zacharias) - printf ("Anton (%016zx) liegt weiter vorne im Alphabet ... äh ... Speicher als Zacharias (%016zx).\n", - anton, zacharias); - else - printf ("Zacharias (%016zx) liegt weiter vorne im Alphabet ... äh ... Speicher als Anton (%016zx).\n", - zacharias, anton); - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-15.c b/20221017/string-ops-15.c deleted file mode 100644 index 6534185f01b2c478bb7fbe9da91155226ed4b944..0000000000000000000000000000000000000000 --- a/20221017/string-ops-15.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *anton = "Anton"; - char *zacharias = "Zacharias"; - if (anton < zacharias) - { - printf ("Anton (%016zx) liegt weiter vorne im Speicher als Zacharias (%016zx).\n", - anton, zacharias); - for (int i = 0; i < 6 + 10; i++) - printf ("%c", anton[i]); - printf ("\n"); - } - else - { - printf ("Zacharias (%016zx) liegt weiter vorne im Speicher als Anton (%016zx).\n", - zacharias, anton); - for (int i = 0; i < 6 + 10; i++) - printf ("%c", zacharias[i]); - printf ("\n"); - } - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-15.txt b/20221017/string-ops-15.txt deleted file mode 100644 index ed71965d6b30782d2a39eb29577e667b34435c6b..0000000000000000000000000000000000000000 --- a/20221017/string-ops-15.txt +++ /dev/null @@ -1,35 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221017> cat string-ops-15.c -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *anton = "Anton"; - char *zacharias = "Zacharias"; - if (anton < zacharias) - { - printf ("Anton (%016zx) liegt weiter vorne im Speicher als Zacharias (%016zx).\n", - anton, zacharias); - for (int i = 0; i < 6 + 10; i++) - printf ("%c", anton[i]); - printf ("\n"); - } - else - { - printf ("Zacharias (%016zx) liegt weiter vorne im Speicher als Anton (%016zx).\n", - zacharias, anton); - for (int i = 0; i < 6 + 10; i++) - printf ("%c", zacharias[i]); - printf ("\n"); - } - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} -cassini/home/peter/bo/2022ws/hp/20221017> ./string-ops-15 -Anton (000055954d678004) liegt weiter vorne im Speicher als Zacharias (000055954d67800a). -AntonZacharias -cassini/home/peter/bo/2022ws/hp/20221017> diff --git a/20221017/string-ops-16.c b/20221017/string-ops-16.c deleted file mode 100644 index ab1d9bbafd170d9a104482a6f26d6c21bc2f0b4b..0000000000000000000000000000000000000000 --- a/20221017/string-ops-16.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdio.h> -#include <string.h> - -char *anton = "Anton"; -char *zacharias = "Zacharias"; - -int main (void) -{ - if (anton < zacharias) - { - printf ("Anton (%016zx) liegt weiter vorne im Speicher als Zacharias (%016zx).\n", - anton, zacharias); - for (int i = 0; i < 6 + 10; i++) - printf ("%c", anton[i]); - printf ("\n"); - } - else - { - printf ("Zacharias (%016zx) liegt weiter vorne im Speicher als Anton (%016zx).\n", - zacharias, anton); - for (int i = 0; i < 6 + 10; i++) - printf ("%c", zacharias[i]); - printf ("\n"); - } - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-17.c b/20221017/string-ops-17.c deleted file mode 100644 index cd3a6272d0ddfe0c6f3d6f0144df40095a361549..0000000000000000000000000000000000000000 --- a/20221017/string-ops-17.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdio.h> -#include <string.h> - -char *anton = "Zanton"; -char *zacharias = "Acharias"; - -int main (void) -{ - if (anton < zacharias) - { - printf ("Anton (%016zx) liegt weiter vorne im Speicher als Zacharias (%016zx).\n", - anton, zacharias); - for (int i = 0; i < 6 + 10; i++) - printf ("%c", anton[i]); - printf ("\n"); - } - else - { - printf ("Zacharias (%016zx) liegt weiter vorne im Speicher als Anton (%016zx).\n", - zacharias, anton); - for (int i = 0; i < 6 + 10; i++) - printf ("%c", zacharias[i]); - printf ("\n"); - } - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-18.c b/20221017/string-ops-18.c deleted file mode 100644 index baf37b3e79e3057f17521efc31311189a830afbb..0000000000000000000000000000000000000000 --- a/20221017/string-ops-18.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdio.h> -#include <string.h> - -char *anton = "Zanton"; -char *zacharias = "Acharias"; - -int main (void) -{ - if (anton < zacharias) - { - printf ("Anton (%016zx) liegt weiter vorne im Speicher als Zacharias (%016zx).\n", - anton, zacharias); - for (int i = 0; i < 6 + 10; i++) - printf ("%c", zacharias[i]); - printf ("\n"); - } - else - { - printf ("Zacharias (%016zx) liegt weiter vorne im Speicher als Anton (%016zx).\n", - zacharias, anton); - for (int i = 0; i < 6 + 10; i++) - printf ("%c", anton[i]); - printf ("\n"); - } - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-19.c b/20221017/string-ops-19.c deleted file mode 100644 index 62a9f0df37321b5eec49a9de5d7661f9aa8d0021..0000000000000000000000000000000000000000 --- a/20221017/string-ops-19.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdio.h> -#include <string.h> - -char *anton = "Zanton"; -char *zacharias = "Acharias"; - -int main (void) -{ - if (anton < zacharias) - { - printf ("Anton (%016zx) liegt weiter vorne im Speicher als Zacharias (%016zx).\n", - anton, zacharias); - for (int i = 0; i < 6 * 10; i++) - printf ("%c", zacharias[i]); - printf ("\n"); - } - else - { - printf ("Zacharias (%016zx) liegt weiter vorne im Speicher als Anton (%016zx).\n", - zacharias, anton); - for (int i = 0; i < 6 * 10; i++) - printf ("%c", anton[i]); - printf ("\n"); - } - - return 0; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); -} diff --git a/20221017/string-ops-20.c b/20221017/string-ops-20.c deleted file mode 100644 index 03e024d01e5bf877fddeeb504e598fcdb41bc694..0000000000000000000000000000000000000000 --- a/20221017/string-ops-20.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <string.h> - - -int main (void) -{ - char *anton = "Anton"; - char *zacharias = "Zacharias"; - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); - - return 0; -} diff --git a/20221017/string-ops-21.c b/20221017/string-ops-21.c deleted file mode 100644 index 594601909cd8f0e260e3208cf5811d22b9d4122a..0000000000000000000000000000000000000000 --- a/20221017/string-ops-21.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> -#include <string.h> - - -int main (void) -{ - char *anton = "Anton"; - - char buffer[100] = "Huber "; - printf ("%s\n", buffer + anton); - - return 0; -} diff --git a/20221017/string-ops-22.c b/20221017/string-ops-22.c deleted file mode 100644 index 7c0aacf68e3921750491f0465f6e29a1af05dadd..0000000000000000000000000000000000000000 --- a/20221017/string-ops-22.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> -#include <string.h> - - -int main (void) -{ - char *anton = "Anton"; - - char buffer[100] = "Huber "; - printf ("%s\n", buffer + (size_t) anton); - - return 0; -} diff --git a/20221017/string-ops-23.c b/20221017/string-ops-23.c deleted file mode 100644 index fcc025bd59846119aef2c3d5b7ec83ea4c507e1b..0000000000000000000000000000000000000000 --- a/20221017/string-ops-23.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> -#include <string.h> - - -int main (void) -{ - char *anton = "Anton"; - - char buffer[100] = "Huber "; - printf ("%s\n", (char *) ((((size_t) buffer) + ((size_t) anton)) / 2)); - - return 0; -} diff --git a/20221017/string-ops-24.c b/20221017/string-ops-24.c deleted file mode 100644 index 9c3065113aece788f0461db4bd4707bcf8166ed4..0000000000000000000000000000000000000000 --- a/20221017/string-ops-24.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char anton[] = "Anton"; - - char buffer[100] = "Huber "; - printf ("%s\n", (char *) ((((size_t) buffer) + ((size_t) anton)) / 2)); - - return 0; -} diff --git a/20221017/string-ops-25.c b/20221017/string-ops-25.c deleted file mode 100644 index 45fdeeed2df23439397757af1817f12a743d5072..0000000000000000000000000000000000000000 --- a/20221017/string-ops-25.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char anton[] = "Anton"; - - char buffer[] = "Huber "; - printf ("%s\n", (char *) ((((size_t) buffer) + ((size_t) anton)) / 2)); - - return 0; -} diff --git a/20221017/string-ops-26.c b/20221017/string-ops-26.c deleted file mode 100644 index e0d2b837ea7e2f45395a76e4274e40917c0294b3..0000000000000000000000000000000000000000 --- a/20221017/string-ops-26.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char anton[] = "Anton"; - char buffer[] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); - - return 0; -} diff --git a/20221017/string-ops-27.c b/20221017/string-ops-27.c deleted file mode 100644 index 26499716b01376b82f282494ff553a7f69674706..0000000000000000000000000000000000000000 --- a/20221017/string-ops-27.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char buffer[] = "Huber "; - char anton[] = "Anton"; - strcat (buffer, anton); - printf ("%s\n", buffer); - - return 0; -} diff --git a/20221017/string-ops-28.c b/20221017/string-ops-28.c deleted file mode 100644 index 0b29dc578e3152bcee2524b1e0437dc1b9cb4fdd..0000000000000000000000000000000000000000 --- a/20221017/string-ops-28.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char buffer[] = "Huber "; - char anton[] = "Anton"; - strncat (buffer, anton, sizeof (buffer)); - printf ("%s\n", buffer); - - return 0; -} diff --git a/20221017/strings-20.c b/20221017/strings-20.c deleted file mode 100644 index 68227c25325d9699430cacc3d071c5dad629fb40..0000000000000000000000000000000000000000 --- a/20221017/strings-20.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "Hello, world!\n"; - printf ("%s", hello); - return 0; -} diff --git a/20221017/strings-21.c b/20221017/strings-21.c deleted file mode 100644 index c75e8485434dd0f3578ad93e7c574f466424e544..0000000000000000000000000000000000000000 --- a/20221017/strings-21.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char *hello = "Hello, world!\n"; - printf ("%s", hello); - return 0; -} diff --git a/20221017/strings-22.c b/20221017/strings-22.c deleted file mode 100644 index 73e417a3abe90db0bb6ce622d79eab3def11bcde..0000000000000000000000000000000000000000 --- a/20221017/strings-22.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "Hello!\n"; - hello[1] = 'a'; - printf ("%s", hello); - return 0; -} diff --git a/20221017/strings-23.c b/20221017/strings-23.c deleted file mode 100644 index 98bddafb3dea6ccefc966d7a6537a3df761d0953..0000000000000000000000000000000000000000 --- a/20221017/strings-23.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char *hello = "Hello!\n"; - hello[1] = 'a'; - printf ("%s", hello); - return 0; -} diff --git a/20221017/strings-24.c b/20221017/strings-24.c deleted file mode 100644 index 23d6aac897415e9f4f2e29eb6ab2c386acb2d911..0000000000000000000000000000000000000000 --- a/20221017/strings-24.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char *hello = "Hello!\n"; - hello = "Hallo!\n"; - printf ("%s", hello); - return 0; -} diff --git a/20221017/strings-25.c b/20221017/strings-25.c deleted file mode 100644 index 1c63f136d23cef03382cbde14b5e4144b009124b..0000000000000000000000000000000000000000 --- a/20221017/strings-25.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char hello[] = "Hello!\n"; - hello = "Hallo!\n"; - printf ("%s", hello); - return 0; -} diff --git a/20221017/strings-26.c b/20221017/strings-26.c deleted file mode 100644 index 281ee0463cf4c4172d942fcd02c3e9eba190c7b8..0000000000000000000000000000000000000000 --- a/20221017/strings-26.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char hello[] = "Hello!\n"; - strcpy (hello, "Hallo!\n"); - printf ("%s", hello); - return 0; -} diff --git a/20221017/structs-01.c b/20221017/structs-01.c deleted file mode 100644 index b0d790ead7b2e2dfb1e51d87547bc991e0919779..0000000000000000000000000000000000000000 --- a/20221017/structs-01.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - char day, month; - int year; -} -date; - -int main (void) -{ - date today = { 17, 10, 2022 }; - printf ("%d.%d.%d\n", today.day, today.month, today.year); - return 0; -} diff --git a/20221017/structs-02.c b/20221017/structs-02.c deleted file mode 100644 index 00e0bfecfc64464c668ba88e8a741481b919b574..0000000000000000000000000000000000000000 --- a/20221017/structs-02.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - char day, month; - int year; -} -date; - -void set_date (date *d) -{ - (*d).day = 17; - (*d).month = 10; - (*d).year = 2022; -} - -int main (void) -{ - date today; - set_date (&today); - printf ("%d.%d.%d\n", today.day, today.month, today.year); - return 0; -} diff --git a/20221017/structs-03.c b/20221017/structs-03.c deleted file mode 100644 index 7decf4b72015984f5c733873dfb6eb0c856f9f3b..0000000000000000000000000000000000000000 --- a/20221017/structs-03.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - char day, month; - int year; -} -date; - -void set_date (date *d) -{ - d->day = 17; - d->month = 10; - d->year = 2022; -} - -int main (void) -{ - date today; - set_date (&today); - printf ("%d.%d.%d\n", today.day, today.month, today.year); - return 0; -} diff --git a/20221017/test-1.c b/20221017/test-1.c deleted file mode 100644 index 9dcb8ff47664fe804b3c9973166afe0d28b53ade..0000000000000000000000000000000000000000 --- a/20221017/test-1.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - return - printf ("Hello, world!\n"), - 0; -} diff --git a/20221017/test-2.c b/20221017/test-2.c deleted file mode 100644 index 216c924cde653228187b133b1a899765eb865584..0000000000000000000000000000000000000000 --- a/20221017/test-2.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 137; - int b = 13 * a; - if (b = 42) - printf ("Die Antwort lautet: %d\n", b); - else - printf ("Die Antwort lautet: keine Ahnung\n"); - return 0; -} diff --git a/20221017/test-3.c b/20221017/test-3.c deleted file mode 100644 index b8964c8308aec57ed4de30acae8c3e3d31b9fa38..0000000000000000000000000000000000000000 --- a/20221017/test-3.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 42; - printf ("Die Antwort lautet: "); - printf (a); - return 0; -} diff --git a/20221017/uebung-20221010-aufgabe-4-01.c b/20221017/uebung-20221010-aufgabe-4-01.c deleted file mode 100644 index b8b3de796fbef94bd4a86f944e1269b97e97982b..0000000000000000000000000000000000000000 --- a/20221017/uebung-20221010-aufgabe-4-01.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - for (int i = 10; i = 0; i - 1) - printf ("%d\n", i); - return 0; -} diff --git a/20221017/uebung-20221010-aufgabe-4-02.c b/20221017/uebung-20221010-aufgabe-4-02.c deleted file mode 100644 index b62b1cbc67ca4edcee870b3643dbcff3780e0a6e..0000000000000000000000000000000000000000 --- a/20221017/uebung-20221010-aufgabe-4-02.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - for (int i = 10; i == 0; i - 1) - printf ("%d\n", i); - return 0; -} diff --git a/20221017/uebung-20221010-aufgabe-4-03.c b/20221017/uebung-20221010-aufgabe-4-03.c deleted file mode 100644 index c5235c8dcbc8aac56b13aa0305b7cf49d84ed82f..0000000000000000000000000000000000000000 --- a/20221017/uebung-20221010-aufgabe-4-03.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - for (int i = 10; i >= 0; i - 1) - printf ("%d\n", i); - return 0; -} diff --git a/20221017/uebung-20221010-aufgabe-4-04.c b/20221017/uebung-20221010-aufgabe-4-04.c deleted file mode 100644 index f27992d11dfbfb45702d23a8e7b21e1bbeef9518..0000000000000000000000000000000000000000 --- a/20221017/uebung-20221010-aufgabe-4-04.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - for (int i = 10; i >= 0; i = i - 1) - printf ("%d\n", i); - return 0; -} diff --git a/20221017/variables-01.c b/20221017/variables-01.c deleted file mode 100644 index 141f046a673a4dbb0b09e0ee362eb98728d7d372..0000000000000000000000000000000000000000 --- a/20221017/variables-01.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -void foo (int a) -{ - printf ("a = %d\n", a); -} - -int main (void) -{ - foo (137); - foo (); - return 0; -} diff --git a/20221017/variables-02.c b/20221017/variables-02.c deleted file mode 100644 index 10b7d1e9bf4c08da4fff49614977f58135264506..0000000000000000000000000000000000000000 --- a/20221017/variables-02.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -void foo (a) - int a; -{ - printf ("a = %d\n", a); -} - -int main (void) -{ - foo (137); - foo (); - return 0; -} diff --git a/20221017/variables-03.c b/20221017/variables-03.c deleted file mode 100644 index 99865a7759c4f30a6ca0a5f8e510529a9e303ffe..0000000000000000000000000000000000000000 --- a/20221017/variables-03.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -void foo (a) - int a; -{ - printf ("a = %d\n", a); -} - -int main (void) -{ - foo (137); - printf ("Hallo?\n"); - foo (); - return 0; -} diff --git a/20221017/void-01.c b/20221017/void-01.c deleted file mode 100644 index 2daa2e6ad050466b49c9424736fabc415a2537ad..0000000000000000000000000000000000000000 --- a/20221017/void-01.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -int add_verbose (int a, int b) -{ - printf ("%d + %d = %d\n", a, b, a + b); - return a + b; -} - -int main (void) -{ - add_verbose (3, 7); - return 0; -} diff --git a/20221017/void-02.c b/20221017/void-02.c deleted file mode 100644 index 035859c89e3e3051d78deaf29178c72790d850dd..0000000000000000000000000000000000000000 --- a/20221017/void-02.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -void add_verbose (int a, int b) -{ - printf ("%d + %d = %d\n", a, b, a + b); -} - -int main (void) -{ - int c = add_verbose (3, 7); - printf ("c = %d \n", c); - return 0; -} diff --git a/20221024/answer.c b/20221024/answer.c deleted file mode 100644 index 65a1dc248becb3157f2a226fc7b30df2ffb82e00..0000000000000000000000000000000000000000 --- a/20221024/answer.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "answer.h" - -int answer (void) -{ - return 23; -} diff --git a/20221024/answer.h b/20221024/answer.h deleted file mode 100644 index b6777e8210983d315b3ac3424a61bd9c9f0437b1..0000000000000000000000000000000000000000 --- a/20221024/answer.h +++ /dev/null @@ -1 +0,0 @@ -extern int answer (void); diff --git a/20221024/aufgabe-1.c b/20221024/aufgabe-1.c deleted file mode 100644 index 632b4b796ae2f4060878a8870b9e7e55e5f064b9..0000000000000000000000000000000000000000 --- a/20221024/aufgabe-1.c +++ /dev/null @@ -1,22 +0,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, -1 }; - int b[] = { 7, 14, 0, 8, 9, 22, 10, -1 }; - f (a, b); - return 0; -} diff --git a/20221024/aufgabe-1c.c b/20221024/aufgabe-1c.c deleted file mode 100644 index 9b6e7ab2ecfbddc16121acd229a13745182190c2..0000000000000000000000000000000000000000 --- a/20221024/aufgabe-1c.c +++ /dev/null @@ -1,22 +0,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; -} diff --git a/20221024/aufgabe-3.c b/20221024/aufgabe-3.c deleted file mode 100644 index cd80c21b95b5a4c91a43a8b3e849f5e12db183c7..0000000000000000000000000000000000000000 --- a/20221024/aufgabe-3.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int n, i, divisors; - for (n = 0; n < 100; n++) - divisors = 0; - for (i = 0; i < n; i++) - if (n % i == 0) - divisors++; - if (divisors = 2) - printf ("%d ist eine Primzahl.\n", n); - return 0; -} diff --git a/20221024/constants-01.c b/20221024/constants-01.c deleted file mode 100644 index 77c13753cad6cc9440b1e6fa76f2b0a4062e087a..0000000000000000000000000000000000000000 --- a/20221024/constants-01.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -#define N 5 - -int main (void) -{ - int prime[N] = { 2, 3, 5, 7, 11 }; - for (int i = 0; i < N; i++) - printf ("%d\n", prime[i]); - return 0; -} diff --git a/20221024/constants-02.c b/20221024/constants-02.c deleted file mode 100644 index 19d92aed504318956e4b2a53cc85a525ba555257..0000000000000000000000000000000000000000 --- a/20221024/constants-02.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -const int N = 5; - -int main (void) -{ - int prime[N] = { 2, 3, 5, 7, 11 }; - for (int i = 0; i < N; i++) - printf ("%d\n", prime[i]); - return 0; -} diff --git a/20221024/constants-02.txt b/20221024/constants-02.txt deleted file mode 100644 index bf36ca587d37fe813d8d3cb0c8794b2401764e6a..0000000000000000000000000000000000000000 --- a/20221024/constants-02.txt +++ /dev/null @@ -1,44 +0,0 @@ -#include <stdio.h> - -const int N = 5; - -int main (void) -{ - int prime[N] = { 2, 3, 5, 7, 11 }; - for (int i = 0; i < N; i++) - printf ("%d\n", prime[i]); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O constants-02.c -o constants-02 -constants-02.c: In function ‘main’: -constants-02.c:7:3: error: variable-sized object may not be initialized - int prime[N] = { 2, 3, 5, 7, 11 }; - ^~~ -constants-02.c:7:20: warning: excess elements in array initializer - int prime[N] = { 2, 3, 5, 7, 11 }; - ^ -constants-02.c:7:20: note: (near initialization for ‘prime’) -constants-02.c:7:23: warning: excess elements in array initializer - int prime[N] = { 2, 3, 5, 7, 11 }; - ^ -constants-02.c:7:23: note: (near initialization for ‘prime’) -constants-02.c:7:26: warning: excess elements in array initializer - int prime[N] = { 2, 3, 5, 7, 11 }; - ^ -constants-02.c:7:26: note: (near initialization for ‘prime’) -constants-02.c:7:29: warning: excess elements in array initializer - int prime[N] = { 2, 3, 5, 7, 11 }; - ^ -constants-02.c:7:29: note: (near initialization for ‘prime’) -constants-02.c:7:32: warning: excess elements in array initializer - int prime[N] = { 2, 3, 5, 7, 11 }; - ^~ -constants-02.c:7:32: note: (near initialization for ‘prime’) -cassini/home/peter/bo/2022ws/hp/20221024> g++ -Wall -O constants-02.c -o constants-02 -cassini/home/peter/bo/2022ws/hp/20221024> ./constants-02 -2 -3 -5 -7 -11 -cassini/home/peter/bo/2022ws/hp/20221024> diff --git a/20221024/gtk-01.c b/20221024/gtk-01.c deleted file mode 100644 index 884a14ea528431e54f8391c801958a6e494dfe43..0000000000000000000000000000000000000000 --- a/20221024/gtk-01.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <gtk/gtk.h> - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221024/gtk-01.txt b/20221024/gtk-01.txt deleted file mode 100644 index 330b209772656a51091cb317945ee7a8754b4439..0000000000000000000000000000000000000000 --- a/20221024/gtk-01.txt +++ /dev/null @@ -1,28 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O $(pkg-config --cflags gtk+-3.0) gtk-01.c -o gtk-01 -/usr/bin/ld: /tmp/ccgTelwD.o: in function `main': -gtk-01.c:(.text+0x16): undefined reference to `gtk_init' -/usr/bin/ld: gtk-01.c:(.text+0x20): undefined reference to `gtk_window_new' -/usr/bin/ld: gtk-01.c:(.text+0x28): undefined reference to `gtk_window_get_type' -/usr/bin/ld: gtk-01.c:(.text+0x33): undefined reference to `g_type_check_instance_cast' -/usr/bin/ld: gtk-01.c:(.text+0x42): undefined reference to `gtk_window_set_title' -/usr/bin/ld: gtk-01.c:(.text+0x4a): undefined reference to `gtk_widget_show' -/usr/bin/ld: gtk-01.c:(.text+0x4f): undefined reference to `gtk_main' -collect2: error: ld returned 1 exit status -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O $(pkg-config --cflags gtk+-3.0) gtk-01.c -c -cassini/home/peter/bo/2022ws/hp/20221024> ./gtk-01 -bash: ./gtk-01: Datei oder Verzeichnis nicht gefunden -cassini/home/peter/bo/2022ws/hp/20221024> ls -l gtk-01* --rw-r--r-- 1 peter peter 256 Jan 4 2021 gtk-01.c --rw-r--r-- 1 peter peter 2024 Okt 31 11:43 gtk-01.o -cassini/home/peter/bo/2022ws/hp/20221024> gcc gtk-01.o -o gtek-01 -/usr/bin/ld: gtk-01.o: in function `main': -gtk-01.c:(.text+0x16): undefined reference to `gtk_init' -/usr/bin/ld: gtk-01.c:(.text+0x20): undefined reference to `gtk_window_new' -/usr/bin/ld: gtk-01.c:(.text+0x28): undefined reference to `gtk_window_get_type' -/usr/bin/ld: gtk-01.c:(.text+0x33): undefined reference to `g_type_check_instance_cast' -/usr/bin/ld: gtk-01.c:(.text+0x42): undefined reference to `gtk_window_set_title' -/usr/bin/ld: gtk-01.c:(.text+0x4a): undefined reference to `gtk_widget_show' -/usr/bin/ld: gtk-01.c:(.text+0x4f): undefined reference to `gtk_main' -collect2: error: ld returned 1 exit status -cassini/home/peter/bo/2022ws/hp/20221024> gcc gtk-01.o $(pkg-config --libs gtk+-3.0) -o gtk-01 -cassini/home/peter/bo/2022ws/hp/20221024> ./gtk-01 \ No newline at end of file diff --git a/20221024/gtk-02.c b/20221024/gtk-02.c deleted file mode 100644 index c5db19f8d7e859ff12b08ffd6425b84deab35d07..0000000000000000000000000000000000000000 --- a/20221024/gtk-02.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <gtk/gtk.h> - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221024/gtk-03.c b/20221024/gtk-03.c deleted file mode 100644 index 26fcdd9bf83023b4f3e704a93218134149829f83..0000000000000000000000000000000000000000 --- a/20221024/gtk-03.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <gtk/gtk.h> - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (window), button); - gtk_widget_show (button); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221024/hello-01.E b/20221024/hello-01.E deleted file mode 100644 index edf9f9fc1f6cf4f61af8edc584f3ea270ddc27b6..0000000000000000000000000000000000000000 --- a/20221024/hello-01.E +++ /dev/null @@ -1,815 +0,0 @@ -# 1 "hello-01.c" -# 1 "<built-in>" -# 1 "<command-line>" -# 31 "<command-line>" -# 1 "/usr/include/stdc-predef.h" 1 3 4 -# 32 "<command-line>" 2 -# 1 "hello-01.c" -# 1 "/usr/include/stdio.h" 1 3 4 -# 27 "/usr/include/stdio.h" 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 1 3 4 -# 33 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 3 4 -# 1 "/usr/include/features.h" 1 3 4 -# 424 "/usr/include/features.h" 3 4 -# 1 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 1 3 4 -# 442 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 -# 443 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/long-double.h" 1 3 4 -# 444 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4 -# 425 "/usr/include/features.h" 2 3 4 -# 448 "/usr/include/features.h" 3 4 -# 1 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 1 3 4 -# 10 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 3 4 -# 1 "/usr/include/x86_64-linux-gnu/gnu/stubs-64.h" 1 3 4 -# 11 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 2 3 4 -# 449 "/usr/include/features.h" 2 3 4 -# 34 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 2 3 4 -# 28 "/usr/include/stdio.h" 2 3 4 - - - - - -# 1 "/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h" 1 3 4 -# 216 "/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h" 3 4 - -# 216 "/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h" 3 4 -typedef long unsigned int size_t; -# 34 "/usr/include/stdio.h" 2 3 4 - - -# 1 "/usr/lib/gcc/x86_64-linux-gnu/8/include/stdarg.h" 1 3 4 -# 40 "/usr/lib/gcc/x86_64-linux-gnu/8/include/stdarg.h" 3 4 -typedef __builtin_va_list __gnuc_va_list; -# 37 "/usr/include/stdio.h" 2 3 4 - -# 1 "/usr/include/x86_64-linux-gnu/bits/types.h" 1 3 4 -# 27 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 -# 28 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 - - -typedef unsigned char __u_char; -typedef unsigned short int __u_short; -typedef unsigned int __u_int; -typedef unsigned long int __u_long; - - -typedef signed char __int8_t; -typedef unsigned char __uint8_t; -typedef signed short int __int16_t; -typedef unsigned short int __uint16_t; -typedef signed int __int32_t; -typedef unsigned int __uint32_t; - -typedef signed long int __int64_t; -typedef unsigned long int __uint64_t; - - - - - - -typedef __int8_t __int_least8_t; -typedef __uint8_t __uint_least8_t; -typedef __int16_t __int_least16_t; -typedef __uint16_t __uint_least16_t; -typedef __int32_t __int_least32_t; -typedef __uint32_t __uint_least32_t; -typedef __int64_t __int_least64_t; -typedef __uint64_t __uint_least64_t; - - - -typedef long int __quad_t; -typedef unsigned long int __u_quad_t; - - - - - - - -typedef long int __intmax_t; -typedef unsigned long int __uintmax_t; -# 140 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/typesizes.h" 1 3 4 -# 141 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 - - -typedef unsigned long int __dev_t; -typedef unsigned int __uid_t; -typedef unsigned int __gid_t; -typedef unsigned long int __ino_t; -typedef unsigned long int __ino64_t; -typedef unsigned int __mode_t; -typedef unsigned long int __nlink_t; -typedef long int __off_t; -typedef long int __off64_t; -typedef int __pid_t; -typedef struct { int __val[2]; } __fsid_t; -typedef long int __clock_t; -typedef unsigned long int __rlim_t; -typedef unsigned long int __rlim64_t; -typedef unsigned int __id_t; -typedef long int __time_t; -typedef unsigned int __useconds_t; -typedef long int __suseconds_t; - -typedef int __daddr_t; -typedef int __key_t; - - -typedef int __clockid_t; - - -typedef void * __timer_t; - - -typedef long int __blksize_t; - - - - -typedef long int __blkcnt_t; -typedef long int __blkcnt64_t; - - -typedef unsigned long int __fsblkcnt_t; -typedef unsigned long int __fsblkcnt64_t; - - -typedef unsigned long int __fsfilcnt_t; -typedef unsigned long int __fsfilcnt64_t; - - -typedef long int __fsword_t; - -typedef long int __ssize_t; - - -typedef long int __syscall_slong_t; - -typedef unsigned long int __syscall_ulong_t; - - - -typedef __off64_t __loff_t; -typedef char *__caddr_t; - - -typedef long int __intptr_t; - - -typedef unsigned int __socklen_t; - - - - -typedef int __sig_atomic_t; -# 39 "/usr/include/stdio.h" 2 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/types/__fpos_t.h" 1 3 4 - - - - -# 1 "/usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h" 1 3 4 -# 13 "/usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h" 3 4 -typedef struct -{ - int __count; - union - { - unsigned int __wch; - char __wchb[4]; - } __value; -} __mbstate_t; -# 6 "/usr/include/x86_64-linux-gnu/bits/types/__fpos_t.h" 2 3 4 - - - - -typedef struct _G_fpos_t -{ - __off_t __pos; - __mbstate_t __state; -} __fpos_t; -# 40 "/usr/include/stdio.h" 2 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/types/__fpos64_t.h" 1 3 4 -# 10 "/usr/include/x86_64-linux-gnu/bits/types/__fpos64_t.h" 3 4 -typedef struct _G_fpos64_t -{ - __off64_t __pos; - __mbstate_t __state; -} __fpos64_t; -# 41 "/usr/include/stdio.h" 2 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/types/__FILE.h" 1 3 4 - - - -struct _IO_FILE; -typedef struct _IO_FILE __FILE; -# 42 "/usr/include/stdio.h" 2 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/types/FILE.h" 1 3 4 - - - -struct _IO_FILE; - - -typedef struct _IO_FILE FILE; -# 43 "/usr/include/stdio.h" 2 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h" 1 3 4 -# 35 "/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h" 3 4 -struct _IO_FILE; -struct _IO_marker; -struct _IO_codecvt; -struct _IO_wide_data; - - - - -typedef void _IO_lock_t; - - - - - -struct _IO_FILE -{ - int _flags; - - - char *_IO_read_ptr; - char *_IO_read_end; - char *_IO_read_base; - char *_IO_write_base; - char *_IO_write_ptr; - char *_IO_write_end; - char *_IO_buf_base; - char *_IO_buf_end; - - - char *_IO_save_base; - char *_IO_backup_base; - char *_IO_save_end; - - struct _IO_marker *_markers; - - struct _IO_FILE *_chain; - - int _fileno; - int _flags2; - __off_t _old_offset; - - - unsigned short _cur_column; - signed char _vtable_offset; - char _shortbuf[1]; - - _IO_lock_t *_lock; - - - - - - - - __off64_t _offset; - - struct _IO_codecvt *_codecvt; - struct _IO_wide_data *_wide_data; - struct _IO_FILE *_freeres_list; - void *_freeres_buf; - size_t __pad5; - int _mode; - - char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; -}; -# 44 "/usr/include/stdio.h" 2 3 4 -# 52 "/usr/include/stdio.h" 3 4 -typedef __gnuc_va_list va_list; -# 63 "/usr/include/stdio.h" 3 4 -typedef __off_t off_t; -# 77 "/usr/include/stdio.h" 3 4 -typedef __ssize_t ssize_t; - - - - - - -typedef __fpos_t fpos_t; -# 133 "/usr/include/stdio.h" 3 4 -# 1 "/usr/include/x86_64-linux-gnu/bits/stdio_lim.h" 1 3 4 -# 134 "/usr/include/stdio.h" 2 3 4 - - - -extern FILE *stdin; -extern FILE *stdout; -extern FILE *stderr; - - - - - - -extern int remove (const char *__filename) __attribute__ ((__nothrow__ , __leaf__)); - -extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ , __leaf__)); - - - -extern int renameat (int __oldfd, const char *__old, int __newfd, - const char *__new) __attribute__ ((__nothrow__ , __leaf__)); -# 173 "/usr/include/stdio.h" 3 4 -extern FILE *tmpfile (void) ; -# 187 "/usr/include/stdio.h" 3 4 -extern char *tmpnam (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; - - - - -extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; -# 204 "/usr/include/stdio.h" 3 4 -extern char *tempnam (const char *__dir, const char *__pfx) - __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ; - - - - - - - -extern int fclose (FILE *__stream); - - - - -extern int fflush (FILE *__stream); -# 227 "/usr/include/stdio.h" 3 4 -extern int fflush_unlocked (FILE *__stream); -# 246 "/usr/include/stdio.h" 3 4 -extern FILE *fopen (const char *__restrict __filename, - const char *__restrict __modes) ; - - - - -extern FILE *freopen (const char *__restrict __filename, - const char *__restrict __modes, - FILE *__restrict __stream) ; -# 279 "/usr/include/stdio.h" 3 4 -extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ , __leaf__)) ; -# 292 "/usr/include/stdio.h" 3 4 -extern FILE *fmemopen (void *__s, size_t __len, const char *__modes) - __attribute__ ((__nothrow__ , __leaf__)) ; - - - - -extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ , __leaf__)) ; - - - - - -extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)); - - - -extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, - int __modes, size_t __n) __attribute__ ((__nothrow__ , __leaf__)); - - - - -extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf, - size_t __size) __attribute__ ((__nothrow__ , __leaf__)); - - -extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); - - - - - - - -extern int fprintf (FILE *__restrict __stream, - const char *__restrict __format, ...); - - - - -extern int printf (const char *__restrict __format, ...); - -extern int sprintf (char *__restrict __s, - const char *__restrict __format, ...) __attribute__ ((__nothrow__)); - - - - - -extern int vfprintf (FILE *__restrict __s, const char *__restrict __format, - __gnuc_va_list __arg); - - - - -extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg); - -extern int vsprintf (char *__restrict __s, const char *__restrict __format, - __gnuc_va_list __arg) __attribute__ ((__nothrow__)); - - - -extern int snprintf (char *__restrict __s, size_t __maxlen, - const char *__restrict __format, ...) - __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4))); - -extern int vsnprintf (char *__restrict __s, size_t __maxlen, - const char *__restrict __format, __gnuc_va_list __arg) - __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0))); -# 379 "/usr/include/stdio.h" 3 4 -extern int vdprintf (int __fd, const char *__restrict __fmt, - __gnuc_va_list __arg) - __attribute__ ((__format__ (__printf__, 2, 0))); -extern int dprintf (int __fd, const char *__restrict __fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); - - - - - - - -extern int fscanf (FILE *__restrict __stream, - const char *__restrict __format, ...) ; - - - - -extern int scanf (const char *__restrict __format, ...) ; - -extern int sscanf (const char *__restrict __s, - const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__)); -# 409 "/usr/include/stdio.h" 3 4 -extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf") - - ; -extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf") - ; -extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__)) - - ; -# 434 "/usr/include/stdio.h" 3 4 -extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, - __gnuc_va_list __arg) - __attribute__ ((__format__ (__scanf__, 2, 0))) ; - - - - - -extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) - __attribute__ ((__format__ (__scanf__, 1, 0))) ; - - -extern int vsscanf (const char *__restrict __s, - const char *__restrict __format, __gnuc_va_list __arg) - __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0))); -# 457 "/usr/include/stdio.h" 3 4 -extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf") - - - - __attribute__ ((__format__ (__scanf__, 2, 0))) ; -extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf") - - __attribute__ ((__format__ (__scanf__, 1, 0))) ; -extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ , __leaf__)) - - - - __attribute__ ((__format__ (__scanf__, 2, 0))); -# 491 "/usr/include/stdio.h" 3 4 -extern int fgetc (FILE *__stream); -extern int getc (FILE *__stream); - - - - - -extern int getchar (void); - - - - - - -extern int getc_unlocked (FILE *__stream); -extern int getchar_unlocked (void); -# 516 "/usr/include/stdio.h" 3 4 -extern int fgetc_unlocked (FILE *__stream); -# 527 "/usr/include/stdio.h" 3 4 -extern int fputc (int __c, FILE *__stream); -extern int putc (int __c, FILE *__stream); - - - - - -extern int putchar (int __c); -# 543 "/usr/include/stdio.h" 3 4 -extern int fputc_unlocked (int __c, FILE *__stream); - - - - - - - -extern int putc_unlocked (int __c, FILE *__stream); -extern int putchar_unlocked (int __c); - - - - - - -extern int getw (FILE *__stream); - - -extern int putw (int __w, FILE *__stream); - - - - - - - -extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) - ; -# 609 "/usr/include/stdio.h" 3 4 -extern __ssize_t __getdelim (char **__restrict __lineptr, - size_t *__restrict __n, int __delimiter, - FILE *__restrict __stream) ; -extern __ssize_t getdelim (char **__restrict __lineptr, - size_t *__restrict __n, int __delimiter, - FILE *__restrict __stream) ; - - - - - - - -extern __ssize_t getline (char **__restrict __lineptr, - size_t *__restrict __n, - FILE *__restrict __stream) ; - - - - - - - -extern int fputs (const char *__restrict __s, FILE *__restrict __stream); - - - - - -extern int puts (const char *__s); - - - - - - -extern int ungetc (int __c, FILE *__stream); - - - - - - -extern size_t fread (void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream) ; - - - - -extern size_t fwrite (const void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __s); -# 679 "/usr/include/stdio.h" 3 4 -extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream) ; -extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream); - - - - - - - -extern int fseek (FILE *__stream, long int __off, int __whence); - - - - -extern long int ftell (FILE *__stream) ; - - - - -extern void rewind (FILE *__stream); -# 713 "/usr/include/stdio.h" 3 4 -extern int fseeko (FILE *__stream, __off_t __off, int __whence); - - - - -extern __off_t ftello (FILE *__stream) ; -# 737 "/usr/include/stdio.h" 3 4 -extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos); - - - - -extern int fsetpos (FILE *__stream, const fpos_t *__pos); -# 763 "/usr/include/stdio.h" 3 4 -extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); - -extern int feof (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; - -extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; - - - -extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); -extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; -extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; - - - - - - - -extern void perror (const char *__s); - - - - - -# 1 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 1 3 4 -# 26 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 3 4 -extern int sys_nerr; -extern const char *const sys_errlist[]; -# 788 "/usr/include/stdio.h" 2 3 4 - - - - -extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; - - - - -extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; -# 806 "/usr/include/stdio.h" 3 4 -extern FILE *popen (const char *__command, const char *__modes) ; - - - - - -extern int pclose (FILE *__stream); - - - - - -extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__)); -# 846 "/usr/include/stdio.h" 3 4 -extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); - - - -extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; - - -extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); -# 864 "/usr/include/stdio.h" 3 4 -extern int __uflow (FILE *); -extern int __overflow (FILE *, int); - - - - -# 1 "/usr/include/x86_64-linux-gnu/bits/stdio.h" 1 3 4 -# 38 "/usr/include/x86_64-linux-gnu/bits/stdio.h" 3 4 -extern __inline __attribute__ ((__gnu_inline__)) int -vprintf (const char *__restrict __fmt, __gnuc_va_list __arg) -{ - return vfprintf (stdout, __fmt, __arg); -} - - - -extern __inline __attribute__ ((__gnu_inline__)) int -getchar (void) -{ - return getc (stdin); -} - - - - -extern __inline __attribute__ ((__gnu_inline__)) int -fgetc_unlocked (FILE *__fp) -{ - return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++); -} - - - - - -extern __inline __attribute__ ((__gnu_inline__)) int -getc_unlocked (FILE *__fp) -{ - return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++); -} - - -extern __inline __attribute__ ((__gnu_inline__)) int -getchar_unlocked (void) -{ - return (__builtin_expect (((stdin)->_IO_read_ptr >= (stdin)->_IO_read_end), 0) ? __uflow (stdin) : *(unsigned char *) (stdin)->_IO_read_ptr++); -} - - - - -extern __inline __attribute__ ((__gnu_inline__)) int -putchar (int __c) -{ - return putc (__c, stdout); -} - - - - -extern __inline __attribute__ ((__gnu_inline__)) int -fputc_unlocked (int __c, FILE *__stream) -{ - return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c))); -} - - - - - -extern __inline __attribute__ ((__gnu_inline__)) int -putc_unlocked (int __c, FILE *__stream) -{ - return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c))); -} - - -extern __inline __attribute__ ((__gnu_inline__)) int -putchar_unlocked (int __c) -{ - return (__builtin_expect (((stdout)->_IO_write_ptr >= (stdout)->_IO_write_end), 0) ? __overflow (stdout, (unsigned char) (__c)) : (unsigned char) (*(stdout)->_IO_write_ptr++ = (__c))); -} -# 127 "/usr/include/x86_64-linux-gnu/bits/stdio.h" 3 4 -extern __inline __attribute__ ((__gnu_inline__)) int -__attribute__ ((__nothrow__ , __leaf__)) feof_unlocked (FILE *__stream) -{ - return (((__stream)->_flags & 0x0010) != 0); -} - - -extern __inline __attribute__ ((__gnu_inline__)) int -__attribute__ ((__nothrow__ , __leaf__)) ferror_unlocked (FILE *__stream) -{ - return (((__stream)->_flags & 0x0020) != 0); -} -# 871 "/usr/include/stdio.h" 2 3 4 -# 879 "/usr/include/stdio.h" 3 4 - -# 2 "hello-01.c" 2 - - -# 3 "hello-01.c" -int main (void) -{ - printf ("Hello, world!\n"); - return 0; -} diff --git a/20221024/hello-01.EP b/20221024/hello-01.EP deleted file mode 100644 index af4f56a1620eea8ac018f34a7e4a8021b467ed10..0000000000000000000000000000000000000000 --- a/20221024/hello-01.EP +++ /dev/null @@ -1,325 +0,0 @@ - -typedef long unsigned int size_t; -typedef __builtin_va_list __gnuc_va_list; -typedef unsigned char __u_char; -typedef unsigned short int __u_short; -typedef unsigned int __u_int; -typedef unsigned long int __u_long; -typedef signed char __int8_t; -typedef unsigned char __uint8_t; -typedef signed short int __int16_t; -typedef unsigned short int __uint16_t; -typedef signed int __int32_t; -typedef unsigned int __uint32_t; -typedef signed long int __int64_t; -typedef unsigned long int __uint64_t; -typedef __int8_t __int_least8_t; -typedef __uint8_t __uint_least8_t; -typedef __int16_t __int_least16_t; -typedef __uint16_t __uint_least16_t; -typedef __int32_t __int_least32_t; -typedef __uint32_t __uint_least32_t; -typedef __int64_t __int_least64_t; -typedef __uint64_t __uint_least64_t; -typedef long int __quad_t; -typedef unsigned long int __u_quad_t; -typedef long int __intmax_t; -typedef unsigned long int __uintmax_t; -typedef unsigned long int __dev_t; -typedef unsigned int __uid_t; -typedef unsigned int __gid_t; -typedef unsigned long int __ino_t; -typedef unsigned long int __ino64_t; -typedef unsigned int __mode_t; -typedef unsigned long int __nlink_t; -typedef long int __off_t; -typedef long int __off64_t; -typedef int __pid_t; -typedef struct { int __val[2]; } __fsid_t; -typedef long int __clock_t; -typedef unsigned long int __rlim_t; -typedef unsigned long int __rlim64_t; -typedef unsigned int __id_t; -typedef long int __time_t; -typedef unsigned int __useconds_t; -typedef long int __suseconds_t; -typedef int __daddr_t; -typedef int __key_t; -typedef int __clockid_t; -typedef void * __timer_t; -typedef long int __blksize_t; -typedef long int __blkcnt_t; -typedef long int __blkcnt64_t; -typedef unsigned long int __fsblkcnt_t; -typedef unsigned long int __fsblkcnt64_t; -typedef unsigned long int __fsfilcnt_t; -typedef unsigned long int __fsfilcnt64_t; -typedef long int __fsword_t; -typedef long int __ssize_t; -typedef long int __syscall_slong_t; -typedef unsigned long int __syscall_ulong_t; -typedef __off64_t __loff_t; -typedef char *__caddr_t; -typedef long int __intptr_t; -typedef unsigned int __socklen_t; -typedef int __sig_atomic_t; -typedef struct -{ - int __count; - union - { - unsigned int __wch; - char __wchb[4]; - } __value; -} __mbstate_t; -typedef struct _G_fpos_t -{ - __off_t __pos; - __mbstate_t __state; -} __fpos_t; -typedef struct _G_fpos64_t -{ - __off64_t __pos; - __mbstate_t __state; -} __fpos64_t; -struct _IO_FILE; -typedef struct _IO_FILE __FILE; -struct _IO_FILE; -typedef struct _IO_FILE FILE; -struct _IO_FILE; -struct _IO_marker; -struct _IO_codecvt; -struct _IO_wide_data; -typedef void _IO_lock_t; -struct _IO_FILE -{ - int _flags; - char *_IO_read_ptr; - char *_IO_read_end; - char *_IO_read_base; - char *_IO_write_base; - char *_IO_write_ptr; - char *_IO_write_end; - char *_IO_buf_base; - char *_IO_buf_end; - char *_IO_save_base; - char *_IO_backup_base; - char *_IO_save_end; - struct _IO_marker *_markers; - struct _IO_FILE *_chain; - int _fileno; - int _flags2; - __off_t _old_offset; - unsigned short _cur_column; - signed char _vtable_offset; - char _shortbuf[1]; - _IO_lock_t *_lock; - __off64_t _offset; - struct _IO_codecvt *_codecvt; - struct _IO_wide_data *_wide_data; - struct _IO_FILE *_freeres_list; - void *_freeres_buf; - size_t __pad5; - int _mode; - char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; -}; -typedef __gnuc_va_list va_list; -typedef __off_t off_t; -typedef __ssize_t ssize_t; -typedef __fpos_t fpos_t; -extern FILE *stdin; -extern FILE *stdout; -extern FILE *stderr; -extern int remove (const char *__filename) __attribute__ ((__nothrow__ , __leaf__)); -extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ , __leaf__)); -extern int renameat (int __oldfd, const char *__old, int __newfd, - const char *__new) __attribute__ ((__nothrow__ , __leaf__)); -extern FILE *tmpfile (void) ; -extern char *tmpnam (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; -extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; -extern char *tempnam (const char *__dir, const char *__pfx) - __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ; -extern int fclose (FILE *__stream); -extern int fflush (FILE *__stream); -extern int fflush_unlocked (FILE *__stream); -extern FILE *fopen (const char *__restrict __filename, - const char *__restrict __modes) ; -extern FILE *freopen (const char *__restrict __filename, - const char *__restrict __modes, - FILE *__restrict __stream) ; -extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ , __leaf__)) ; -extern FILE *fmemopen (void *__s, size_t __len, const char *__modes) - __attribute__ ((__nothrow__ , __leaf__)) ; -extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ , __leaf__)) ; -extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)); -extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, - int __modes, size_t __n) __attribute__ ((__nothrow__ , __leaf__)); -extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf, - size_t __size) __attribute__ ((__nothrow__ , __leaf__)); -extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); -extern int fprintf (FILE *__restrict __stream, - const char *__restrict __format, ...); -extern int printf (const char *__restrict __format, ...); -extern int sprintf (char *__restrict __s, - const char *__restrict __format, ...) __attribute__ ((__nothrow__)); -extern int vfprintf (FILE *__restrict __s, const char *__restrict __format, - __gnuc_va_list __arg); -extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg); -extern int vsprintf (char *__restrict __s, const char *__restrict __format, - __gnuc_va_list __arg) __attribute__ ((__nothrow__)); -extern int snprintf (char *__restrict __s, size_t __maxlen, - const char *__restrict __format, ...) - __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4))); -extern int vsnprintf (char *__restrict __s, size_t __maxlen, - const char *__restrict __format, __gnuc_va_list __arg) - __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0))); -extern int vdprintf (int __fd, const char *__restrict __fmt, - __gnuc_va_list __arg) - __attribute__ ((__format__ (__printf__, 2, 0))); -extern int dprintf (int __fd, const char *__restrict __fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); -extern int fscanf (FILE *__restrict __stream, - const char *__restrict __format, ...) ; -extern int scanf (const char *__restrict __format, ...) ; -extern int sscanf (const char *__restrict __s, - const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__)); -extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf") ; -extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf") ; -extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__)); -extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, - __gnuc_va_list __arg) - __attribute__ ((__format__ (__scanf__, 2, 0))) ; -extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) - __attribute__ ((__format__ (__scanf__, 1, 0))) ; -extern int vsscanf (const char *__restrict __s, - const char *__restrict __format, __gnuc_va_list __arg) - __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0))); -extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf") - __attribute__ ((__format__ (__scanf__, 2, 0))) ; -extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf") - __attribute__ ((__format__ (__scanf__, 1, 0))) ; -extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ , __leaf__)) - __attribute__ ((__format__ (__scanf__, 2, 0))); -extern int fgetc (FILE *__stream); -extern int getc (FILE *__stream); -extern int getchar (void); -extern int getc_unlocked (FILE *__stream); -extern int getchar_unlocked (void); -extern int fgetc_unlocked (FILE *__stream); -extern int fputc (int __c, FILE *__stream); -extern int putc (int __c, FILE *__stream); -extern int putchar (int __c); -extern int fputc_unlocked (int __c, FILE *__stream); -extern int putc_unlocked (int __c, FILE *__stream); -extern int putchar_unlocked (int __c); -extern int getw (FILE *__stream); -extern int putw (int __w, FILE *__stream); -extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) - ; -extern __ssize_t __getdelim (char **__restrict __lineptr, - size_t *__restrict __n, int __delimiter, - FILE *__restrict __stream) ; -extern __ssize_t getdelim (char **__restrict __lineptr, - size_t *__restrict __n, int __delimiter, - FILE *__restrict __stream) ; -extern __ssize_t getline (char **__restrict __lineptr, - size_t *__restrict __n, - FILE *__restrict __stream) ; -extern int fputs (const char *__restrict __s, FILE *__restrict __stream); -extern int puts (const char *__s); -extern int ungetc (int __c, FILE *__stream); -extern size_t fread (void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream) ; -extern size_t fwrite (const void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __s); -extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream) ; -extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream); -extern int fseek (FILE *__stream, long int __off, int __whence); -extern long int ftell (FILE *__stream) ; -extern void rewind (FILE *__stream); -extern int fseeko (FILE *__stream, __off_t __off, int __whence); -extern __off_t ftello (FILE *__stream) ; -extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos); -extern int fsetpos (FILE *__stream, const fpos_t *__pos); -extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); -extern int feof (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; -extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; -extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); -extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; -extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; -extern void perror (const char *__s); -extern int sys_nerr; -extern const char *const sys_errlist[]; -extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; -extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; -extern FILE *popen (const char *__command, const char *__modes) ; -extern int pclose (FILE *__stream); -extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__)); -extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); -extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; -extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); -extern int __uflow (FILE *); -extern int __overflow (FILE *, int); -extern __inline __attribute__ ((__gnu_inline__)) int -vprintf (const char *__restrict __fmt, __gnuc_va_list __arg) -{ - return vfprintf (stdout, __fmt, __arg); -} -extern __inline __attribute__ ((__gnu_inline__)) int -getchar (void) -{ - return getc (stdin); -} -extern __inline __attribute__ ((__gnu_inline__)) int -fgetc_unlocked (FILE *__fp) -{ - return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++); -} -extern __inline __attribute__ ((__gnu_inline__)) int -getc_unlocked (FILE *__fp) -{ - return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++); -} -extern __inline __attribute__ ((__gnu_inline__)) int -getchar_unlocked (void) -{ - return (__builtin_expect (((stdin)->_IO_read_ptr >= (stdin)->_IO_read_end), 0) ? __uflow (stdin) : *(unsigned char *) (stdin)->_IO_read_ptr++); -} -extern __inline __attribute__ ((__gnu_inline__)) int -putchar (int __c) -{ - return putc (__c, stdout); -} -extern __inline __attribute__ ((__gnu_inline__)) int -fputc_unlocked (int __c, FILE *__stream) -{ - return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c))); -} -extern __inline __attribute__ ((__gnu_inline__)) int -putc_unlocked (int __c, FILE *__stream) -{ - return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c))); -} -extern __inline __attribute__ ((__gnu_inline__)) int -putchar_unlocked (int __c) -{ - return (__builtin_expect (((stdout)->_IO_write_ptr >= (stdout)->_IO_write_end), 0) ? __overflow (stdout, (unsigned char) (__c)) : (unsigned char) (*(stdout)->_IO_write_ptr++ = (__c))); -} -extern __inline __attribute__ ((__gnu_inline__)) int -__attribute__ ((__nothrow__ , __leaf__)) feof_unlocked (FILE *__stream) -{ - return (((__stream)->_flags & 0x0010) != 0); -} -extern __inline __attribute__ ((__gnu_inline__)) int -__attribute__ ((__nothrow__ , __leaf__)) ferror_unlocked (FILE *__stream) -{ - return (((__stream)->_flags & 0x0020) != 0); -} - -int main (void) -{ - printf ("Hello, world!\n"); - return 0; -} diff --git a/20221024/hello-01.c b/20221024/hello-01.c deleted file mode 100644 index b19d80e9bd0bd7c5ed8f54b20c6a50d9166f03ac..0000000000000000000000000000000000000000 --- a/20221024/hello-01.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Hello, world!\n"); - return 0; -} diff --git a/20221024/hello-01.s b/20221024/hello-01.s deleted file mode 100644 index cb01acba7d1f0e09cf72a12a32af03fc5c685059..0000000000000000000000000000000000000000 --- a/20221024/hello-01.s +++ /dev/null @@ -1,24 +0,0 @@ - .file "hello-01.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "Hello, world!" - .text - .globl main - .type main, @function -main: -.LFB11: - .cfi_startproc - subq $8, %rsp - .cfi_def_cfa_offset 16 - leaq .LC0(%rip), %rdi - call puts@PLT - movl $0, %eax - addq $8, %rsp - .cfi_def_cfa_offset 8 - ret - .cfi_endproc -.LFE11: - .size main, .-main - .ident "GCC: (Debian 8.3.0-6) 8.3.0" - .section .note.GNU-stack,"",@progbits diff --git a/20221024/hello-01.txt b/20221024/hello-01.txt deleted file mode 100644 index 31f96669f3ea83924355a1c5f97b63bceaaf7c43..0000000000000000000000000000000000000000 --- a/20221024/hello-01.txt +++ /dev/null @@ -1,41 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O hello-01.c -o hello-01 -cassini/home/peter/bo/2022ws/hp/20221024> gcc -v -Wall -O hello-01.c -o hello-01 -Using built-in specs. -COLLECT_GCC=gcc -COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper -OFFLOAD_TARGET_NAMES=nvptx-none -OFFLOAD_TARGET_DEFAULT=1 -Target: x86_64-linux-gnu -Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu -Thread model: posix -gcc version 8.3.0 (Debian 8.3.0-6) -COLLECT_GCC_OPTIONS='-v' '-Wall' '-O' '-o' 'hello-01' '-mtune=generic' '-march=x86-64' - /usr/lib/gcc/x86_64-linux-gnu/8/cc1 -quiet -v -imultiarch x86_64-linux-gnu hello-01.c -quiet -dumpbase hello-01.c -mtune=generic -march=x86-64 -auxbase hello-01 -O -Wall -version -o /tmp/ccgLD8oO.s -GNU C17 (Debian 8.3.0-6) version 8.3.0 (x86_64-linux-gnu) - compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.20-GMP - -GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 -ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" -ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/8/../../../../x86_64-linux-gnu/include" -#include "..." search starts here: -#include <...> search starts here: - /usr/lib/gcc/x86_64-linux-gnu/8/include - /usr/local/include - /usr/lib/gcc/x86_64-linux-gnu/8/include-fixed - /usr/include/x86_64-linux-gnu - /usr/include -End of search list. -GNU C17 (Debian 8.3.0-6) version 8.3.0 (x86_64-linux-gnu) - compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.20-GMP - -GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 -Compiler executable checksum: 694977f912fd7ca2c14d66a7306be21c -COLLECT_GCC_OPTIONS='-v' '-Wall' '-O' '-o' 'hello-01' '-mtune=generic' '-march=x86-64' - as -v --64 -o /tmp/cc0fYgdQ.o /tmp/ccgLD8oO.s -GNU assembler version 2.31.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.31.1 -COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/ -LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/8/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/8/../../../:/lib/:/usr/lib/ -COLLECT_GCC_OPTIONS='-v' '-Wall' '-O' '-o' 'hello-01' '-mtune=generic' '-march=x86-64' - /usr/lib/gcc/x86_64-linux-gnu/8/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/8/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper -plugin-opt=-fresolution=/tmp/cc2nIv2R.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -o hello-01 /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/8/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/8 -L/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/8/../../.. /tmp/cc0fYgdQ.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/8/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crtn.o -COLLECT_GCC_OPTIONS='-v' '-Wall' '-O' '-o' 'hello-01' '-mtune=generic' '-march=x86-64' -cassini/home/peter/bo/2022ws/hp/20221024> diff --git a/20221024/hello-02.c b/20221024/hello-02.c deleted file mode 100644 index 304452b8c501faf03fbd0afaa267e6ef0172807e..0000000000000000000000000000000000000000 --- a/20221024/hello-02.c +++ /dev/null @@ -1,7 +0,0 @@ -extern int printf (const char *__restrict __format, ...); - -int main (void) -{ - printf ("Hello, world!\n"); - return 0; -} diff --git a/20221024/hello-02.s b/20221024/hello-02.s deleted file mode 100644 index d1d17acda44e10d9d3f6902227b9d82b970b35c0..0000000000000000000000000000000000000000 --- a/20221024/hello-02.s +++ /dev/null @@ -1,24 +0,0 @@ - .file "hello-02.c" - .text - .section .rodata.str1.1,"aMS",@progbits,1 -.LC0: - .string "Hello, world!" - .text - .globl main - .type main, @function -main: -.LFB0: - .cfi_startproc - subq $8, %rsp - .cfi_def_cfa_offset 16 - leaq .LC0(%rip), %rdi - call puts@PLT - movl $0, %eax - addq $8, %rsp - .cfi_def_cfa_offset 8 - ret - .cfi_endproc -.LFE0: - .size main, .-main - .ident "GCC: (Debian 8.3.0-6) 8.3.0" - .section .note.GNU-stack,"",@progbits diff --git a/20221024/hello-gtk.c b/20221024/hello-gtk.c deleted file mode 100644 index 016867d41e42de57390a21653de467c061e5ded0..0000000000000000000000000000000000000000 --- a/20221024/hello-gtk.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <gtk/gtk.h> - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); - GtkWidget *label = gtk_label_new ("Hello, world!"); - gtk_container_add (GTK_CONTAINER (vbox), label); - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - gtk_widget_show (button); - gtk_widget_show (label); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221024/hello-gtk.txt b/20221024/hello-gtk.txt deleted file mode 100644 index 26f616a6eda80c7ef47fa961d9f1110bdc0ae227..0000000000000000000000000000000000000000 --- a/20221024/hello-gtk.txt +++ /dev/null @@ -1,92 +0,0 @@ -#include <gtk/gtk.h> - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); - GtkWidget *label = gtk_label_new ("Hello, world!"); - gtk_container_add (GTK_CONTAINER (vbox), label); - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - gtk_widget_show (button); - gtk_widget_show (label); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O hello-gtk.c -o hello-gtk -hello-gtk.c:1:10: fatal error: gtk/gtk.h: Datei oder Verzeichnis nicht gefunden - #include <gtk/gtk.h> - ^~~~~~~~~~~ -compilation terminated. -cassini/home/peter/bo/2022ws/hp/20221024> locate gtk.h -/usr/include/gtk-2.0/gtk/gtk.h -/usr/include/gtk-3.0/gtk/gtk.h -cassini/home/peter/bo/2022ws/hp/20221024> gcc -I /usr/include/gtk-3.0 -Wall -O hello-gtk.c -o hello-gtk -In file included from /usr/include/gtk-3.0/gdk/gdk.h:30, - from /usr/include/gtk-3.0/gtk/gtk.h:30, - from hello-gtk.c:1: -/usr/include/gtk-3.0/gdk/gdkconfig.h:13:10: fatal error: glib.h: Datei oder Verzeichnis nicht gefunden - #include <glib.h> - ^~~~~~~~ -compilation terminated. -cassini/home/peter/bo/2022ws/hp/20221024> locate glib.h -/home/peter/bo/2012ws/rtech/material/usbstick/fdos/source/command/command/suppl/msglib.h -/usr/include/jpeglib.h -/usr/include/dbus-1.0/dbus/dbus-glib.h -/usr/include/glib-2.0/glib.h -/usr/include/harfbuzz/hb-glib.h -/usr/include/reglib/reglib.h -/usr/src/linux-headers-4.19.0-21-amd64/include/config/blk/dev/bsglib.h -/usr/src/linux-headers-4.19.0-22-amd64/include/config/blk/dev/bsglib.h -/usr/src/linux-headers-4.19.0-8-amd64/include/config/blk/dev/bsglib.h -cassini/home/peter/bo/2022ws/hp/20221024> gcc -I /usr/include/glib-2.0 -I /usr/include/gtk-3.0 -Wall -O hello-gtk.c -o hello-gtk -In file included from /usr/include/glib-2.0/glib/galloca.h:32, - from /usr/include/glib-2.0/glib.h:30, - from /usr/include/gtk-3.0/gdk/gdkconfig.h:13, - from /usr/include/gtk-3.0/gdk/gdk.h:30, - from /usr/include/gtk-3.0/gtk/gtk.h:30, - from hello-gtk.c:1: -/usr/include/glib-2.0/glib/gtypes.h:32:10: fatal error: glibconfig.h: Datei oder Verzeichnis nicht gefunden - #include <glibconfig.h> - ^~~~~~~~~~~~~~ -compilation terminated. -cassini/home/peter/bo/2022ws/hp/20221024> -cassini/home/peter/bo/2022ws/hp/20221024> pkg-config -Must specify package names on the command line -cassini/home/peter/bo/2022ws/hp/20221024> pkg-config gtk+-3.0 -cassini/home/peter/bo/2022ws/hp/20221024> pkg-config --cflags 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/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -cassini/home/peter/bo/2022ws/hp/20221024> pkg-config --libs gtk+-3.0 --lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -cassini/home/peter/bo/2022ws/hp/20221024> 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/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -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 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O -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/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -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 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 hello- -hello-01 hello-01.E hello-01.s hello-02 hello-02.s hello-gtk.txt -hello-01.c hello-01.EP hello-01.txt hello-02.c hello-gtk.c -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O -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/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -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 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 hello- -hello-01 hello-01.E hello-01.s hello-02 hello-02.s hello-gtk.txt -hello-01.c hello-01.EP hello-01.txt hello-02.c hello-gtk.c -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O -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/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -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 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 hello- -hello-01 hello-01.E hello-01.s hello-02 hello-02.s hello-gtk.txt -hello-01.c hello-01.EP hello-01.txt hello-02.c hello-gtk.c -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O -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/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -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 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 hello-gtk.c -o hello-gtk -cassini/home/peter/bo/2022ws/hp/20221024> ./hello-gtk -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O $(pkg-config --cflags --libs gtk+-2.0) -o hello-gtk /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x20): undefined reference to `main' collect2: error: ld returned 1 exit status cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O $(pkg-config --cflags --libs gtk+-2.0) hello-gtk.c -o hello-gtk hello-gtk.c: In function ‘main’: hello-gtk.c:9:21: warning: implicit declaration of function ‘gtk_box_new’; did you mean ‘gtk_hbox_new’? [-Wimplicit-function-declaration] - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - ^~~~~~~~~~~ - gtk_hbox_new -hello-gtk.c:9:21: warning: initialization of ‘GtkWidget *’ {aka ‘struct _GtkWidget *’} from int’ makes pointer from integer without a cast [-Wint-conversion] -/usr/bin/ld: /tmp/ccxhf5CJ.o: in function `main': -hello-gtk.c:(.text+0x89): undefined reference to `gtk_box_new' -collect2: error: ld returned 1 exit status -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O $(pkg-config --cflags --libs gtk+-3.0) hello-gtk.c -o hello-gtk -cassini/home/peter/bo/2022ws/hp/20221024> ./hello-gtk -cassini/home/peter/bo/2022ws/hp/20221024> diff --git a/20221024/hexe.h b/20221024/hexe.h deleted file mode 100644 index 2b98e2bb0231a5114084d64430290fea93281edc..0000000000000000000000000000000000000000 --- a/20221024/hexe.h +++ /dev/null @@ -1 +0,0 @@ -eine kleine Hexe. diff --git a/20221024/higher-math-01.c b/20221024/higher-math-01.c deleted file mode 100644 index 0d1a61a7f3f115e878707bf9ab97d8536e46e9bb..0000000000000000000000000000000000000000 --- a/20221024/higher-math-01.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -#define VIER 4 - -int main (void) -{ - printf ("2 + 2 = %d\n", VIER); - return 0; -} diff --git a/20221024/higher-math-02.c b/20221024/higher-math-02.c deleted file mode 100644 index 4f8bfec89f2f1d3a82ee0911dadee9d3955bed50..0000000000000000000000000000000000000000 --- a/20221024/higher-math-02.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -#define wuppdich printf -#define holla main -#define pruzzel return -#define VIER 4 - -int holla (void) -{ - wuppdich ("2 + 2 = %d\n", VIER); - pruzzel 0; -} diff --git a/20221024/higher-math-03.c b/20221024/higher-math-03.c deleted file mode 100644 index 0774461371a771e36ef4682648194a3161f4e1b6..0000000000000000000000000000000000000000 --- a/20221024/higher-math-03.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -#define VIER 2 + 2 - -int main (void) -{ - printf ("2 + 3 * 4 = %d\n", 2 + 3 * VIER); - return 0; -} diff --git a/20221024/higher-math-04.c b/20221024/higher-math-04.c deleted file mode 100644 index 66907e2c7865f7e345f31376748ebfd62134fa43..0000000000000000000000000000000000000000 --- a/20221024/higher-math-04.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -#define VIER (2 + 2) - -int main (void) -{ - printf ("2 + 3 * 4 = %d\n", 2 + 3 * VIER); - return 0; -} diff --git a/20221024/higher-math-05.c b/20221024/higher-math-05.c deleted file mode 100644 index 77a4e4ccc520044f3be85c473f440f313ac9f0fa..0000000000000000000000000000000000000000 --- a/20221024/higher-math-05.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> - -#define VIER (2 + 2)); - -int main (void) -{ - printf ("2 + 3 * 4 = %d\n", 2 + 3 * VIER - return 0; -} diff --git a/20221024/hp-20221024.pdf b/20221024/hp-20221024.pdf deleted file mode 100644 index c3030d4513a8e4e1273c0ac21740553139c5ff65..0000000000000000000000000000000000000000 Binary files a/20221024/hp-20221024.pdf and /dev/null differ diff --git a/20221024/hp-20221024.tex b/20221024/hp-20221024.tex deleted file mode 100644 index 78a5ebadb425e463c5e0f9a94ca4288bef1b686c..0000000000000000000000000000000000000000 --- a/20221024/hp-20221024.tex +++ /dev/null @@ -1,889 +0,0 @@ -% hp-20221024.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Bibliotheken - -\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} - -\newcommand{\redurl}[1]{\href{#1}{\color{red}\nolinkurl{#1}}} - -\title{Hardwarenahe Programmierung} -\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{24.\ Oktober 2022} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \begin{itemize} - \vspace*{-\smallskipamount} - \item[\dots] - \item[2.10] Zeiger - \item[2.11] Arrays und Strings - \color{medgreen} - \item[2.12] Strukturen - \item[2.13] Dateien und Fehlerbehandlung - \item[2.14] Parameter des Hauptprogramms - \color{orange} - \item[2.15] String-Operationen - \end{itemize} - \item[\textbf{3}] \textbf{Bibliotheken} - \begin{itemize} - \color{red} - \item[3.1] Der Präprozessor - \item[3.2] Bibliotheken einbinden - \item[3.3] Bibliotheken verwenden - \color{black} - \item[3.4] Projekt organisieren: make - \end{itemize} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \vspace*{-\smallskipamount} - \item[\textbf{\dots}] - \end{itemize} - -\end{frame} - -\setcounter{section}{1} -\section{Einführung in C} -\setcounter{subsection}{11} -\subsection{Strukturen} - -\begin{frame}[fragile] - \showsubsection - - \begin{lstlisting} - #include <stdio.h> - - typedef struct - { - char day, month; - int year; - } - date; - - int main (void) - { - date today = { 24, 10, 2022 }; - printf ("%d.%d.%d\n", today.day, today.month, today.year); - return 0; - } - \end{lstlisting} -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - \vspace*{0.9mm} - \begin{minipage}[b]{6cm} - \begin{lstlisting}[gobble=6] - ¡#include <stdio.h> - - typedef struct - { - char day, month; - int year; - } - date; - - void set_date (date *d) - { - (*d).day = 24; - (*d).month = 10; - (*d).year = 2022; - }¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[b]{6cm} - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - date today; - set_date (&today); - printf ("%d.%d.%d\n", today.day, - today.month, today.year); - return 0; - }¿ - \end{lstlisting} - \end{minipage} -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - \vspace*{0.9mm} - \begin{minipage}[b]{6cm} - \begin{lstlisting}[gobble=6] - ¡#include <stdio.h> - - typedef struct - { - char day, month; - int year; - } - date; - - void set_date (date *d) - { - d->day = 24; - d->month = 10; - d->year = 2022; - }¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[b]{6cm} - \hspace*{-1cm}% - \lstinline{foo->bar} - ist Abkürzung für - \lstinline{(*foo).bar} - - \bigskip - - \visible<2->{% - \hspace*{-1cm}% - Eine Funktion, die mit einem \lstinline{struct} arbeitet,\\ - \hspace*{-1cm}% - kann man eine \newterm{Methode\/} des \lstinline{struct} nennen.} - - \bigskip - \bigskip - - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - date today; - set_date (&today); - printf ("%d.%d.%d\n", today.day, - today.month, today.year); - return 0; - }¿ - \end{lstlisting} - \end{minipage} - -\end{frame} - -\subsection{Dateien und Fehlerbehandlung} - -\begin{frame}[fragile] - \showsubsection - \vspace*{-0.2925cm} - \begin{minipage}[t]{6cm} - \begin{onlyenv}<1> - \begin{lstlisting}[gobble=8] - ¡#include <stdio.h> - - int main (void) - { - FILE *f = fopen ("fhello.txt", "w"); - fprintf (f, "Hello, world!\n"); - fclose (f); - return 0; - }¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<2> - \begin{lstlisting}[gobble=8] - ¡#include <stdio.h> - - int main (void) - { - FILE *f = fopen ("fhello.txt", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - return 0; - }¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<3> - \begin{lstlisting}[gobble=8] - ¡#include <stdio.h> - #include <errno.h> - - int main (void) - { - FILE *f = fopen ("fhello.txt", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - fprintf (stderr, "error #%d\n", errno); - return 0; - }¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<4> - \begin{lstlisting}[gobble=8] - ¡#include <stdio.h> - #include <errno.h> - #include <string.h> - - int main (void) - { - FILE *f = fopen ("fhello.txt", "w"); - if (f) - { - fprintf (f, "Hello, world!\n"); - fclose (f); - } - else - { - char *msg = strerror (errno); - fprintf (stderr, "%s\n", msg); - } - return 0; - }¿ - \end{lstlisting} - \vspace*{-1cm} - \end{onlyenv} - \begin{onlyenv}<5-> - \begin{lstlisting}[gobble=8] - ¡#include <stdio.h> - #include <errno.h> - #include <er¡ror.h> - - int main (void) - { - FILE *f = fopen ("fhello.txt", "w"); - if (!f) - error (errno, errno, "cannot open file"); - fprintf (f, "Hello, world!\n"); - fclose (f); - return 0; - } - \end{lstlisting} - \end{onlyenv} - \end{minipage}\pause\hspace*{-1.5cm}% - \begin{minipage}[t]{8.5cm} - \bigskip - \only<3->{\bigskip} - \begin{itemize} - \item - Wenn die Datei nicht geöffnet werden kann,\\ - gibt \lstinline{fopen()} den Wert \lstinline{NULL} zurück. - \pause - \medskip - \item - \addtolength{\leftskip}{1cm} - Die globale Variable \lstinline{int errno}\\ - enthält dann die Nummer des Fehlers.\\ - Benötigt: \lstinline{#include <errno.h>} - \pause - \medskip - \only<5->{\bigskip} - \item - Die Funktion \lstinline{strerror()} wandelt \lstinline{errno}\\ - in einen Fehlermeldungstext um.\\ - Benötigt: \lstinline{#include <string.h>} - \pause - \medskip - \item - \addtolength{\leftskip}{-1.5cm} - Die Funktion \lstinline{error()} gibt eine Fehlermeldung aus\\ - und beendet das Programm.\\ - Benötigt: \lstinline{#include <er¡¿ror.h>} - \pause - \medskip - \item - \textbf{Niemals Fehler einfach ignorieren!} - \end{itemize} - \addtolength{\leftskip}{0.5cm} - \end{minipage} -\end{frame} - -\subsection{Parameter des Hauptprogramms} - -\begin{frame}[fragile] - - \showsubsection - - \begin{lstlisting} - #include <stdio.h> - - int main (int argc, char **argv) - { - printf ("argc = %d\n", argc); - for (int i = 0; i < argc; i++) - printf ("argv[%d] = \"%s\"\n", i, argv[i]); - return 0; - } - \end{lstlisting} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \begin{lstlisting} - #include <stdio.h> - - int main (int argc, char **argv) - { - printf ("argc = %d\n", argc); - for (int i = 0; *argv; i++, argv++) - printf ("argv[%d] = \"%s\"\n", i, *argv); - return 0; - } - \end{lstlisting} - -\end{frame} - -\subsection{String-Operationen} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char hello[] = "Hello, world!\n"; - - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); - - printf ("%s\n", hello + 7); - printf ("%zd\n", strlen (hello + 7)); - - hello[5] = 0; - printf ("%s\n", hello); - printf ("%zd\n", strlen (hello)); - - return 0; - } - \end{lstlisting} - \vspace*{-1cm} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char *anton = "Anton"; - char *zacharias = "Zacharias"; - - printf ("%d\n", strcmp (anton, zacharias)); - printf ("%d\n", strcmp (zacharias, anton)); - printf ("%d\n", strcmp (anton, anton)); - - char buffer[100] = "Huber "; - strcat (buffer, anton); - printf ("%s\n", buffer); - - return 0; - } - \end{lstlisting} - \vspace*{-1cm} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char *anton = "Anton"; - char *huber ="Huber"; - - int size = strlen (huber) + strlen (" ") + strlen (anton) + 1; - char buffer[size]; - buffer[0] = 0; - strcat (buffer, huber); - strcat (buffer, " "); - strcat (buffer, anton); - printf ("%s\n", buffer); - - return 0; - } - \end{lstlisting} - \vspace*{-1cm} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char buffer[100] = ""; - sprintf (buffer, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - return 0; - } - \end{lstlisting} - \vspace*{-1cm} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char buffer[100] = ""; - snprintf (buffer, 100, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - return 0; - } - \end{lstlisting} - -\end{frame} - -\begin{frame} - - \showsection - - Sprachelemente weitgehend komplett - - \bigskip - Es fehlen: - \begin{itemize} - \item - Ergänzungen (z.\,B.\ ternärer Operator, \lstinline{union}, \lstinline{unsigned}, \lstinline{volatile}) - \item - Bibliotheksfunktionen (z.\,B.\ \lstinline{malloc()}) - \arrowitem - werden eingeführt, wenn wir sie brauchen - \bigskip - \item - Konzepte (z.\,B.\ rekursive Datenstrukturen, Klassen selbst bauen) - \arrowitem - werden eingeführt, wenn wir sie brauchen, oder: - \arrowitem - Literatur\\[\smallskipamount] - (z.\,B.\ Wikibooks: C-Programmierung,\\ - Dokumentation zu Compiler und Bibliotheken) - \bigskip - \item - Praxiserfahrung - \arrowitem - Übung und Praktikum: nur Einstieg - \arrowitem - selbständig arbeiten - \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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \begin{itemize} - \vspace*{-\smallskipamount} - \item[\dots] - \item[2.10] Zeiger - \item[2.11] Arrays und Strings - \item[2.12] Strukturen - \item[2.13] Dateien und Fehlerbehandlung - \item[2.14] Parameter des Hauptprogramms - \color{medgreen} - \item[2.15] String-Operationen - \end{itemize} - \item[\textbf{3}] \textbf{Bibliotheken} - \begin{itemize} - \color{red} - \item[3.1] Der Präprozessor - \item[3.2] Bibliotheken einbinden - \item[3.3] Bibliotheken verwenden - \color{black} - \item[3.4] Projekt organisieren: make - \end{itemize} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \vspace*{-\smallskipamount} - \item[\textbf{\dots}] - \end{itemize} - -\end{frame} - -\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 SIX 6}: Text ersetzen lassen -- Konstante definieren - \begin{itemize} - \pause - \item - Kein Semikolon! - \pause - \item - Berechnungen in Klammern setzen:\\ - \lstinline{#define SIX (1 + 5)} - \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*{-3cm} - \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-sp - i-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-g - nu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/inclu - de/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pa - ngo-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1. - 0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/in - clude/pixman-1 -I/usr/include/freetype2 -I/usr/include/ - libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/l - ibpng16 -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 -lcairo-gobject -lcairo -lgdk_pix - buf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -o hello-gtk¿ - \end{lstlisting} - \vspace*{-2cm} - \end{onlyenv} - \begin{onlyenv}<5-> - \begin{lstlisting}[style=terminal,gobble=10] - $ ¡gcc -Wall -O hello-gtk.c $(pkg-config --cflags --libs - gtk+-3.0) -o hello-gtk¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<5> - \begin{picture}(0,0)(0.3,0.3) - \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}~~~\strut}}} - \end{picture} - \end{onlyenv} - \pause - \pause - \item - Auf manchen Plattformen kommt es auf die Reihenfolge an: - \begin{lstlisting}[style=terminal,gobble=8] - $ ¡gcc -Wall -O $(pkg-config --cflags gtk+-3.0) \ - hello-gtk.c $(pkg-config --libs gtk+-3.0) \ - -o hello-gtk¿ - \end{lstlisting} - (Backslash = "`Es geht in der nächsten Zeile weiter."') - \end{itemize} - -\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)(-0.07,0.2) - \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)(-0.07,0.2) - \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} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \begin{itemize} - \vspace*{-\smallskipamount} - \item[\dots] - \item[2.10] Zeiger - \item[2.11] Arrays und Strings - \item[2.12] Strukturen - \item[2.13] Dateien und Fehlerbehandlung - \item[2.14] Parameter des Hauptprogramms - \color{medgreen} - \item[2.15] String-Operationen - \end{itemize} - \item[\textbf{3}] \textbf{Bibliotheken} - \begin{itemize} - \color{medgreen} - \item[3.1] Der Präprozessor - \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} - \vspace*{-\smallskipamount} - \item[\textbf{\dots}] - \end{itemize} - -\end{frame} - -\end{document} diff --git a/20221024/hp-musterloesung-20221024.pdf b/20221024/hp-musterloesung-20221024.pdf deleted file mode 100644 index 480cde67b2698b1b57bd60ffc5042be2c1bf9fa2..0000000000000000000000000000000000000000 Binary files a/20221024/hp-musterloesung-20221024.pdf and /dev/null differ diff --git a/20221024/hp-musterloesung-20221024.tex b/20221024/hp-musterloesung-20221024.tex deleted file mode 100644 index 2865fb9a300ff3b66a71acfdf1ffd38963f64195..0000000000000000000000000000000000000000 --- a/20221024/hp-musterloesung-20221024.tex +++ /dev/null @@ -1,347 +0,0 @@ -% hp-musterloesung-20221024.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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, Datum-Bibliothek, fehlerhaftes Primzahl-Programm - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 24.\ Oktober 2022} - - \exercise{Arrays mit Zahlen} - - \begin{minipage}[t]{0.4\textwidth} - Wir betrachten das folgende Programm\\ - (Datei: \gitfile{hp}{2022ws/20221024}{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.55\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? -% Begründen Sie Ihre Antwort. -% -% 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? - Begründen Sie Ihre Antwort. - \points{2} - \item - Was kann passieren, wenn Sie das Hauptprogramm wie folgt abändern - (\gitfile{hp}{2022ws/20221024}{aufgabe-1c.c})? - Begründen Sie Ihre Antwort. - \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} - - \solution - - \begin{enumerate}[\quad(a)] - \item - \textbf{Was bewirkt die Funktion \lstinline{f}, und wie funktioniert sie?} - - Die Funktion gibt alle Zahlen aus, die sowohl im Array \lstinline{s0} - als auch im Array \lstinline{s1} vorkommen (Schnittmenge). - - Dies geschieht, indem der Zeiger \lstinline{s0} das gesamte Array durchläuft - (äußere Schleife). - Für jedes Element des ersten Arrays durchläuft der Zeiger \lstinline{s} - das gesamte zweite Array (innere Schleife). - Auf diese Weise wird jedes Element von \lstinline{s0} - mit jedem von \lstinline{s1} verglichen und bei Gleichheit ausgegeben. - - Um die Schleifen abbrechen zu können, enthalten beide Arrays - als Ende-Markierung eine negative Zahl (\lstinline{-1}). - - \item - \textbf{Was passiert, wenn Sie beim Aufruf der Funktion für einen der - Parameter den Wert \lstinline{NULL} übergeben? - Begründen Sie Ihre Antwort.} - - In dem Moment, wo auf den jeweiligen Parameter-Zeiger zugegriffen wird - (\lstinline{while (*s0 >= 0)} für \lstinline{s0} bzw.\ - \lstinline{int *s = s1; while (*s >= 0)} für \lstinline{s1}), - kommt es zu einem Absturz (Speicherzugriffsfehler). - Die Dereferenzierung eines Zeigers mit dem Wert \lstinline{NULL} - ist nicht zulässig. - - \item - \textbf{Was kann passieren, wenn Sie das Hauptprogramm wie folgt abändern - (\gitfile{hp}{2022ws/20221024}{aufgabe-1c.c})? - Begründen Sie Ihre Antwort.} - - \begin{minipage}{0.35\textwidth} - \begin{lstlisting}[gobble=10] - 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} - \end{minipage}\hfill - \begin{minipage}{0.575\textwidth} - Durch die fehlenden Ende-Markierungen der Arrays - laufen die Schleifen immer weiter, - bis sie irgendwann zufällig auf Speicherzellen stoßen, - die sich als Ende-Markierungen interpretieren lassen (negative Zahlen). - Dadurch kann es zu einem Lesezugriff auf Speicher kommen, - für den das Programm kein Lesezugriffsrecht hat, - also zu einem Absturz (Speicherzugriffsfehler). - \end{minipage} - \end{enumerate} - - \exercise{Datum-Bibliothek} - - Schreiben Sie eine Bibliothek (\file{.c}-Datei und \file{.h}-Datei) - zur Behandlung von Datumsangaben. - - Diese soll enthalten: - \begin{itemize} - \item - einen \lstinline{struct}-Datentyp \lstinline{date}, - der eine Datumsangabe speichert, - \item - eine Funktion \lstinline{void date_print (date *d)}, die ein Datum ausgibt, - \item - eine Funktion \lstinline{int date_set (date *d, int day, int month, int year)}, - die ein Datum auf einen gegebenen Tag setzt - und zurückgibt, ob es sich um ein gültiges Datum handelt (0 = nein, 1 = ja), - \item - eine Funktion \lstinline{void date_next (date *d)}, - die ein Datum auf den nächsten Tag vorrückt. - \end{itemize} - - Schreiben Sie auch ein Programm, das die o.\,a.\ Funktionen testet. - - \solution - - Die Dateien \gitfile{hp}{2022ws/20221024}{loesung-2.c}, - \gitfile{hp}{2022ws/20221024}{loesung-2.h} - und \gitfile{hp}{2022ws/20221024}{loesung-2-test.c} - enthalten die Bibliothek und das Test-Programm. - - Eine detaillierte Anleitung, - wie man auf die Funktion \lstinline{date_next()} kommt, - finden Sie im Skript zur Lehrveranstaltung, - Datei \gitfile{hp}{2022ws/script/hp-2022ws.pdf}{hp-2022ws.pdf}, - ab Seite 29. - - \exercise{Fehlerhaftes Primzahl-Programm} - - \begin{minipage}[t]{5.5cm} - Das nebenstehende Primzahlsuchprogramm (Datei: \gitfile{hp}{2022ws/20221024}{aufgabe-3.c}) - soll Zahlen ausgeben, die genau zwei Teiler haben, ist aber fehlerhaft. - - \smallskip - - Korrigieren Sie das Programm derart, daß ein Programm entsteht, - welches alle Primzahlen kleiner 100 ausgibt.% \points 5 - \end{minipage}\hfill - \begin{minipage}[t]{9cm} - \vspace*{-0.5cm} - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int n, i, divisors; - for (n = 0; n < 100; n++) - divisors = 0; - for (i = 0; i < n; i++) - if (n % i == 0) - divisors++; - if (divisors = 2) - printf ("%d ist eine Primzahl.\n", n); - return 0; - } - \end{lstlisting} - \end{minipage} - - \solution - - Beim Compilieren des Beispiel-Programms mit - \lstinline[style=cmd]{gcc -Wall} erhalten wir die folgende Warnung: - \begin{lstlisting}[style=terminal] - aufgabe-2.c:11:5: warning: suggest parentheses around assignment - used as truth value [-Wparentheses] - \end{lstlisting} - Beim Ausführen gibt das Programm die folgende (falsche) Behauptung aus: - \begin{lstlisting}[style=terminal] - 100 ist eine Primzahl. - \end{lstlisting} - - Einen ersten Hinweis auf den Fehler im Programm liefert die Warnung. - Die Bedingung \lstinline{if (divisors = 2)} in Zeile 11 - steht \emph{nicht\/} für einen Vergleich - der Variablen \lstinline{divisors} mit der Zahl 2, - sondern für eine Zuweisung der Zahl 2 an die Variable \lstinline{divisors}. - Neben dem \emph{Seiteneffekt\/} der Zuweisung gibt \lstinline{divisors = 2} - den Wert \lstinline{2} zurück. - Als Bedingung interpretiert, hat \lstinline{2} den Wahrheitswert "`wahr"' ("`true"'); - die \lstinline{printf()}-Anweisung wird daher in jedem Fall ausgeführt. - - Korrektur dieses Fehlers: \lstinline{if (divisors == 2)} - -- siehe die Datei \gitfile{hp}{2022ws/20221024}{loesung-2-1.c}. - - \bigskip - - Nach der Korrektur dieses Fehlers compiliert das Programm ohne Warnung, - gibt aber beim Ausführen die folgende Fehlermeldung aus: - \begin{lstlisting}[style=terminal] - Gleitkomma-Ausnahme - \end{lstlisting} - (Bemerkung: Bei ausgeschalteter Optimierung - -- \lstinline[style=cmd]{gcc} ohne \lstinline[style=cmd]{-O} -- - kommt diese Fehlermeldung bereits beim ersten Versuch, das Programm auszuführen. - Der Grund für dieses Verhalten ist, daß bei eingeschalteter Optimierung - irrelevante Teile des Programms entfernt und gar nicht ausgeführt werden, - so daß der Fehler nicht zum Tragen kommt. - In diesem Fall wurde die Berechnung von \lstinline{divisors} komplett wegoptimiert, - da der Wert dieser Variablen nirgendwo abgefragt, - sondern durch die Zuweisung \lstinline{if (divisors = 2)} - sofort wieder überschrieben wurde.) - - Die Fehlermeldung "`\lstinline[style=terminal]{Gleitkomma-Ausnahme}"' - ist insofern irreführend, als daß hier gar keine Gleitkommazahlen im Spiel sind; - andererseits deutet sie auf einen Rechenfehler hin, was auch tatsächlich zutrifft. - Durch Untersuchen aller Rechenoperationen - -- z.\,B.\ durch das Einfügen zusätzlicher \lstinline{printf()} -- - finden wir den Fehler in Zeile 9: - Die Modulo-Operation \lstinline{n % i} ist eine Division, - die dann fehlschlägt, wenn der Divisor \lstinline{i} den Wert 0 hat. - Die Fehlerursache ist die bei 0 beginnende \lstinline{for}-Schleife in Zeile 8: - \lstinline{for (i = 0; i < n; i++)}. - - Korrektur dieses Fehlers: Beginn der Schleife mit \lstinline{i = 1} - statt \lstinline{i = 0} -- siehe die Datei \gitfile{hp}{2022ws/20221024}{loesung-2-2.c}. - - \bigskip - - Nach der Korrektur dieses Fehlers gibt das Programm überhaupt nichts mehr aus. - - Durch Untersuchen des Verhaltens des Programms - -- z.\,B.\ durch das Einfügen zusätzlicher \lstinline{printf()} -- - stellen wir fest, daß die Zeilen 8 bis 12 des Programms nur einmal ausgeführt werden - und nicht, wie die \lstinline{for}-Schleife in Zeile 6 vermuten ließe, 100mal. - Der Grund dafür ist, daß sich die \lstinline{for}-Schleife - nur auf die unmittelbar folgende Anweisung \lstinline{divisors = 0} bezieht. - Nur diese Zuweisung wird 100mal ausgeführt; - alles andere befindet sich außerhalb der \lstinline{for}-Schleife. - (Die Einrückung hat in C keine inhaltliche Bedeutung, - sondern dient nur zur Verdeutlichung der Struktur des Programms. - In diesem Fall entsprach die tatsächliche Struktur nicht der beabsichtigten.) - - Korrektur dieses Fehlers: - geschweifte Klammern um den Inhalt der äußeren \lstinline{for}-Schleife - -- siehe die Datei \gitfile{hp}{2022ws/20221024}{loesung-2-3.c}. - - \bigskip - - Nach der Korrektur dieses Fehlers gibt das Programm folgendes aus: - \begin{lstlisting}[style=terminal] - 4 ist eine Primzahl. - 9 ist eine Primzahl. - 25 ist eine Primzahl. - 49 ist eine Primzahl. - \end{lstlisting} - Diese Zahlen sind keine Primzahlen (mit zwei Teilern), - sondern sie haben drei Teiler. - Demnach findet das Programm einen Teiler zu wenig. - (Um diesen Fehler zu finden, kann man sich zu jeder Zahl - die gefundene Anzahl der Teiler \lstinline{divisors} ausgeben lassen.) - - Der nicht gefundene Teiler ist jeweils die Zahl selbst. - Dies kommt daher, daß die Schleife - \lstinline{for (i = 1; i < n; i++)} nur bis \lstinline{n - 1} geht, - also keine Division durch \lstinline{n} stattfindet. - - Korrektur dieses Fehlers: Schleifenbedingung \lstinline{i <= n} - statt \lstinline{i < n} - -- siehe die Datei \gitfile{hp}{2022ws/20221024}{loesung-2-4.c}. - - \bigskip - - Nach der Korrektur dieses Fehlers verhält sich das Programm korrekt. - - Die Datei \gitfile{hp}{2022ws/20221024}{loesung-2-4.c} enthält somit das korrigierte Programm. - -\end{document} diff --git a/20221024/hp-uebung-20221024.pdf b/20221024/hp-uebung-20221024.pdf deleted file mode 100644 index 76b61cf781c6008d26dc8e85bf8e2b75dad23d1a..0000000000000000000000000000000000000000 Binary files a/20221024/hp-uebung-20221024.pdf and /dev/null differ diff --git a/20221024/hp-uebung-20221024.tex b/20221024/hp-uebung-20221024.tex deleted file mode 100644 index e05ad70d1580a93fc873231ea33c9474d0ed5012..0000000000000000000000000000000000000000 --- a/20221024/hp-uebung-20221024.tex +++ /dev/null @@ -1,181 +0,0 @@ -% hp-uebung-20221024.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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, Datum-Bibliothek, fehlerhaftes Primzahl-Programm - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \thispagestyle{empty} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 24.\ Oktober 2022} - - 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.4\textwidth} - Wir betrachten das folgende Programm\\ - (Datei: \gitfile{hp}{2022ws/20221024}{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.55\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? -% Begründen Sie Ihre Antwort. -% -% 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? - Begründen Sie Ihre Antwort. - \points{2} - \item - Was kann passieren, wenn Sie das Hauptprogramm wie folgt abändern - (\gitfile{hp}{2022ws/20221024}{aufgabe-1c.c})? - Begründen Sie Ihre Antwort. - \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{Datum-Bibliothek} - - Schreiben Sie eine Bibliothek (\file{.c}-Datei und \file{.h}-Datei) - zur Behandlung von Datumsangaben. - - Diese soll enthalten: - \begin{itemize} - \item - einen \lstinline{struct}-Datentyp \lstinline{date}, - der eine Datumsangabe speichert, - \item - eine Funktion \lstinline{void date_print (date *d)}, die ein Datum ausgibt, - \item - eine Funktion \lstinline{int date_set (date *d, int day, int month, int year)}, - die ein Datum auf einen gegebenen Tag setzt - und zurückgibt, ob es sich um ein gültiges Datum handelt (0 = nein, 1 = ja), - \item - eine Funktion \lstinline{void date_next (date *d)}, - die ein Datum auf den nächsten Tag vorrückt. - \end{itemize} - - Schreiben Sie auch ein Programm, das die o.\,a.\ Funktionen testet. - - \points{8} - - \exercise{Fehlerhaftes Primzahl-Programm} - - \begin{minipage}[t]{5.5cm} - Das nebenstehende Primzahlsuchprogramm (Datei: \gitfile{hp}{2022ws/20221024}{aufgabe-3.c}) - soll Zahlen ausgeben, die genau zwei Teiler haben, ist aber fehlerhaft. - - \smallskip - - Korrigieren Sie das Programm derart, daß ein Programm entsteht, - welches alle Primzahlen kleiner 100 ausgibt. \points 5 - \end{minipage}\hfill - \begin{minipage}[t]{9cm} - \vspace*{-0.5cm} - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - int main (void) - { - int n, i, divisors; - for (n = 0; n < 100; n++) - divisors = 0; - for (i = 0; i < n; i++) - if (n % i == 0) - divisors++; - if (divisors = 2) - printf ("%d ist eine Primzahl.\n", n); - return 0; - } - \end{lstlisting} - \end{minipage} - - \makeatletter - \immediate\write\@mainaux{\string\gdef\string\totalpoints{\arabic{points}}} - \makeatother - -\end{document} diff --git a/20221024/loesung-2-test.c b/20221024/loesung-2-test.c deleted file mode 100644 index 7947ae0afe7221e20f66fed108c900c3964ccfc0..0000000000000000000000000000000000000000 --- a/20221024/loesung-2-test.c +++ /dev/null @@ -1,42 +0,0 @@ -#include <stdio.h> -#include "loesung-2.h" - -void check (char day, char month, int year) -{ - date d; - if (date_set (&d, day, month, year)) - { - date_print (&d); - printf (" --> "); - date_next (&d); - date_print (&d); - printf ("\n"); - } - else - printf ("%02d.%02d.%04d: invalid date\n", day, month, year); -} - -int main (void) -{ - check (6, 11, 2018); - check (29, 11, 2018); - check (30, 11, 2018); - check (31, 11, 2018); - check (29, 12, 2018); - check (30, 12, 2018); - check (31, 12, 2018); - check (28, 2, 2016); - check (29, 2, 2016); - check (30, 2, 2016); - check (28, 2, 2015); - check (29, 2, 2015); - check (30, 2, 2015); - check (31, 12, 2008); - check (28, 2, 2000); - check (29, 2, 2000); - check (30, 2, 2000); - check (28, 2, 1900); - check (29, 2, 1900); - check (30, 2, 1900); - return 0; -} diff --git a/20221024/loesung-2.c b/20221024/loesung-2.c deleted file mode 100644 index 9ce7f9da4be532c884be6a463dfcaeec32c4e134..0000000000000000000000000000000000000000 --- a/20221024/loesung-2.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "loesung-2.h" - -int is_leap_year (int year) -{ - if (year % 4 == 0) - if (year % 100 == 0) - if (year % 400 == 0) - return 1; - else - return 0; - else - return 1; - else - return 0; -} - -int days_in_month (int month, int year) -{ - if (month == 2) - if (is_leap_year (year)) - return 29; - else - return 28; - else if (month == 4 || month == 6 || month == 9 || month == 11) - return 30; - else - return 31; -} - -void date_print (date *d) -{ - printf ("%02d.%02d.%04d", d->day, d->month, d->year); -} - -int date_set (date *d, char day, char month, int year) -{ - d->year = year; - if (month > 0 && month <= 12) - d->month = month; - else - return 0; - if (day > 0 && day <= days_in_month (month, year)) - d->day = day; - else - return 0; - return 1; -} - -void date_next (date *d) -{ - d->day++; - if (d->day > days_in_month (d->month, d->year)) - { - d->month++; - d->day = 1; - if (d->month > 12) - { - d->year++; - d->month = 1; - } - } -} diff --git a/20221024/loesung-2.h b/20221024/loesung-2.h deleted file mode 100644 index f0d8f5991518d851931ffe06a13387f57cef1905..0000000000000000000000000000000000000000 --- a/20221024/loesung-2.h +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - char day, month; - int year; -} -date; - -extern int is_leap_year (int year); -extern int days_in_month (int month, int year); -extern void date_print (date *d); -extern int date_set (date *d, char day, char month, int year); -extern void date_next (date *d); diff --git a/20221024/loesung-3-1.c b/20221024/loesung-3-1.c deleted file mode 100644 index 248883b772ca68d498ae4dc080e83899eb715570..0000000000000000000000000000000000000000 --- a/20221024/loesung-3-1.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int n, i, divisors; - for (n = 0; n < 100; n++) - divisors = 0; - for (i = 0; i < n; i++) - if (n % i == 0) - divisors++; - if (divisors == 2) - printf ("%d ist eine Primzahl.\n", n); - return 0; -} diff --git a/20221024/loesung-3-2.c b/20221024/loesung-3-2.c deleted file mode 100644 index 0cc3db639099eab0040c568acbd46987eb599645..0000000000000000000000000000000000000000 --- a/20221024/loesung-3-2.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int n, i, divisors; - for (n = 0; n < 100; n++) - divisors = 0; - for (i = 1; i < n; i++) - if (n % i == 0) - divisors++; - if (divisors == 2) - printf ("%d ist eine Primzahl.\n", n); - return 0; -} diff --git a/20221024/loesung-3-3.c b/20221024/loesung-3-3.c deleted file mode 100644 index af2694c1ad2f710d79d7913b9dcfc7348be96115..0000000000000000000000000000000000000000 --- a/20221024/loesung-3-3.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int n, i, divisors; - for (n = 0; n < 100; n++) - { - divisors = 0; - for (i = 1; i < n; i++) - if (n % i == 0) - divisors++; - if (divisors == 2) - printf ("%d ist eine Primzahl.\n", n); - } - return 0; -} diff --git a/20221024/loesung-3-4.c b/20221024/loesung-3-4.c deleted file mode 100644 index 770d92706cc68f64147e5efd443880ac3d875495..0000000000000000000000000000000000000000 --- a/20221024/loesung-3-4.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int n, i, divisors; - for (n = 0; n < 100; n++) - { - divisors = 0; - for (i = 1; i <= n; i++) - if (n % i == 0) - divisors++; - if (divisors == 2) - printf ("%d ist eine Primzahl.\n", n); - } - return 0; -} diff --git a/20221024/logo-hochschule-bochum-cvh-text-v2.pdf b/20221024/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221024/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221024/logo-hochschule-bochum.pdf b/20221024/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221024/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221024/maerchen.c b/20221024/maerchen.c deleted file mode 100644 index 5c2716e85205136d406ad2e20285c18ddc967c07..0000000000000000000000000000000000000000 --- a/20221024/maerchen.c +++ /dev/null @@ -1,4 +0,0 @@ -Vor langer, langer Zeit -gab es einmal -#include "hexe.h" -Die lebte in einem Wald. diff --git a/20221024/maerchen.txt b/20221024/maerchen.txt deleted file mode 100644 index 1ed8f3fc48aaf0ca6cfe59e6ad4e80b19d758339..0000000000000000000000000000000000000000 --- a/20221024/maerchen.txt +++ /dev/null @@ -1,34 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221024> cat maerchen.c -Vor langer, langer Zeit -gab es einmal -#include "hexe.h" -Die lebte in einem Wald. -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O maerchen.c -o maerchen -maerchen.c:1:1: error: unknown type name ‘Vor’ - Vor langer, langer Zeit - ^~~ -maerchen.c:1:20: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Zeit’ - Vor langer, langer Zeit - ^~~~ -cassini/home/peter/bo/2022ws/hp/20221024> cat hexe.h -eine kleine Hexe. -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O maerchen.c -E -# 1 "maerchen.c" -# 1 "<built-in>" -# 1 "<command-line>" -# 31 "<command-line>" -# 1 "/usr/include/stdc-predef.h" 1 3 4 -# 32 "<command-line>" 2 -# 1 "maerchen.c" -Vor langer, langer Zeit -gab es einmal -# 1 "hexe.h" 1 -eine kleine Hexe. -# 4 "maerchen.c" 2 -Die lebte in einem Wald. -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O maerchen.c -E -P -Vor langer, langer Zeit -gab es einmal -eine kleine Hexe. -Die lebte in einem Wald. -cassini/home/peter/bo/2022ws/hp/20221024> diff --git a/20221024/pgscript.sty b/20221024/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221024/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221024/pgslides.sty b/20221024/pgslides.sty deleted file mode 120000 index 5be1416f4216f076aa268901f52a15d775e43f64..0000000000000000000000000000000000000000 --- a/20221024/pgslides.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgslides.sty \ No newline at end of file diff --git a/20221024/philosophy-01.txt b/20221024/philosophy-01.txt deleted file mode 100644 index a232d84cae0080e821abb7972c50b677c183d20b..0000000000000000000000000000000000000000 --- a/20221024/philosophy-01.txt +++ /dev/null @@ -1,26 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221024> cat philosophy.c -#include <stdio.h> -#include "answer.h" - -int main (void) -{ - printf ("The answer is %d.\n", answer ()); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221024> cat answer.h -extern int answer (void); -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O philosophy.c -o philosophy -/usr/bin/ld: /tmp/cc2KFjiS.o: in function `main': -philosophy.c:(.text+0x5): undefined reference to `answer' -collect2: error: ld returned 1 exit status -cassini/home/peter/bo/2022ws/hp/20221024> cat answer.c -#include "answer.h" - -int answer (void) -{ - return 23; -} -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O philosophy.c answer.c -o philosophy -cassini/home/peter/bo/2022ws/hp/20221024> ./philosophy -The answer is 23. -cassini/home/peter/bo/2022ws/hp/20221024> diff --git a/20221024/philosophy-02.txt b/20221024/philosophy-02.txt deleted file mode 100644 index aeb445c994e232e3ec5b6556cccfaefa567e4b6e..0000000000000000000000000000000000000000 --- a/20221024/philosophy-02.txt +++ /dev/null @@ -1,27 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221024> cat philosophy.c -#include <stdio.h> -#include "answer.h" - -int main (void) -{ - printf ("The answer is %d.\n", answer ()); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221024> cat answer.h -extern int answer (void); -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O philosophy.c -c -cassini/home/peter/bo/2022ws/hp/20221024> cat answer.c -#include "answer.h" - -int answer (void) -{ - return 23; -} -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O answer.c -c -cassini/home/peter/bo/2022ws/hp/20221024> ls -l *.o --rw-r--r-- 1 peter peter 1208 Okt 24 14:19 answer.o --rw-r--r-- 1 peter peter 1632 Okt 24 14:19 philosophy.o -cassini/home/peter/bo/2022ws/hp/20221024> gcc philosophy.o answer.o -o philosophy -cassini/home/peter/bo/2022ws/hp/20221024> ./philosophy -The answer is 23. -cassini/home/peter/bo/2022ws/hp/20221024> diff --git a/20221024/philosophy-03.txt b/20221024/philosophy-03.txt deleted file mode 100644 index 0478bee33106bc904058cd2ec11ec23154f0c90d..0000000000000000000000000000000000000000 --- a/20221024/philosophy-03.txt +++ /dev/null @@ -1,12 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O philosophy.c -lanswer -o philosophy -/usr/bin/ld: -lanswer kann nicht gefunden werden -collect2: error: ld returned 1 exit status -cassini/home/peter/bo/2022ws/hp/20221024> gcc -Wall -O philosophy.c -L . -lanswer -o philosophy -cassini/home/peter/bo/2022ws/hp/20221024> ./philosophy -The answer is 23. -cassini/home/peter/bo/2022ws/hp/20221024> ls -l *answer* --rw-r--r-- 1 peter peter 56 Nov 21 2013 answer.c --rw-r--r-- 1 peter peter 26 Nov 22 2012 answer.h --rw-r--r-- 1 peter peter 1208 Okt 24 14:19 answer.o --rw-r--r-- 1 peter peter 1352 Okt 24 14:24 libanswer.a -cassini/home/peter/bo/2022ws/hp/20221024> diff --git a/20221024/philosophy.c b/20221024/philosophy.c deleted file mode 100644 index e9f508a501d9ec66d02e0636a9f6c71f2c7a8594..0000000000000000000000000000000000000000 --- a/20221024/philosophy.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> -#include "answer.h" - -int main (void) -{ - printf ("The answer is %d.\n", answer ()); - return 0; -} diff --git a/20221024/string-ops-29.c b/20221024/string-ops-29.c deleted file mode 100644 index 52bad3372f3fe29acd4cff1513d97011e6d65bd3..0000000000000000000000000000000000000000 --- a/20221024/string-ops-29.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char buffer[100] = ""; - sprintf (buffer, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - return 0; - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); -} diff --git a/20221024/string-ops-30.c b/20221024/string-ops-30.c deleted file mode 100644 index 7598955bfd6adddaddb9fea4adb91883a4107bad..0000000000000000000000000000000000000000 --- a/20221024/string-ops-30.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char buffer[100] = ""; - snprintf (buffer, 100, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - return 0; - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); -} diff --git a/20221024/string-ops-31.c b/20221024/string-ops-31.c deleted file mode 100644 index ba6cba525ef34bd29c7b9ca1c42c983261eabf48..0000000000000000000000000000000000000000 --- a/20221024/string-ops-31.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char buffer[20] = ""; - snprintf (buffer, 20, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - return 0; - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); -} diff --git a/20221024/string-ops-32.c b/20221024/string-ops-32.c deleted file mode 100644 index 1e019e9380d0e5905d7ba0df4e7fc99ae52ed689..0000000000000000000000000000000000000000 --- a/20221024/string-ops-32.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char buffer[20] = ""; - snprintf (buffer, 20, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - for (int i = 0; i < 20; i++) - printf ("%d ", buffer[i]); - printf ("\n"); - - return 0; - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); -} diff --git a/20221024/string-ops-33.c b/20221024/string-ops-33.c deleted file mode 100644 index e1c1e84fba7eade92c2a0c818104de31b24c5f61..0000000000000000000000000000000000000000 --- a/20221024/string-ops-33.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char buffer[100] = ""; - snprintf (buffer, 100, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - return 0; -} diff --git a/20221024/string-ops-34.c b/20221024/string-ops-34.c deleted file mode 100644 index 6ebc6462291daa9e03981a89cf769e14610e781b..0000000000000000000000000000000000000000 --- a/20221024/string-ops-34.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - return 0; -} diff --git a/20221024/string-ops-35.c b/20221024/string-ops-35.c deleted file mode 100644 index f4fe37ff52dcd147ec15e491ad1fd61e0e2636ca..0000000000000000000000000000000000000000 --- a/20221024/string-ops-35.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer = strstr (buffer, "Antwort"); - while (answer) - { - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - buffer = answer; - } - - return 0; -} diff --git a/20221024/string-ops-36.c b/20221024/string-ops-36.c deleted file mode 100644 index 5ffbb840d2fa41e69380f70836eb23979abd4e83..0000000000000000000000000000000000000000 --- a/20221024/string-ops-36.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer = strstr (buffer, "Antwort"); - while (answer) - { - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - buffer = answer + strlen ("Antwort"); - } - - return 0; -} diff --git a/20221024/string-ops-37.c b/20221024/string-ops-37.c deleted file mode 100644 index 42272e0cf7323af7042fc3bc6b2cae2cd462e2bb..0000000000000000000000000000000000000000 --- a/20221024/string-ops-37.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer; - do - { - answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - buffer = answer + strlen ("Antwort"); - } - while (answer); - - return 0; -} diff --git a/20221024/string-ops-38.c b/20221024/string-ops-38.c deleted file mode 100644 index 4716dc12e45cc141001359283ae8015b48fcf729..0000000000000000000000000000000000000000 --- a/20221024/string-ops-38.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer; - do - { - answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - } - while (answer); - - return 0; -} diff --git a/20221024/string-ops-39.c b/20221024/string-ops-39.c deleted file mode 100644 index 63599c10f8067200a09623add6bc65698979d2c0..0000000000000000000000000000000000000000 --- a/20221024/string-ops-39.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer; - do - { - printf ("am Anfang der Schleife\n"); - answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - - printf ("am Ende der Schleife\n"); - } - while (answer); - - return 0; -} diff --git a/20221024/string-ops-40.c b/20221024/string-ops-40.c deleted file mode 100644 index 4b9382ea1db7cb190411df65b274b0a5e3b5743f..0000000000000000000000000000000000000000 --- a/20221024/string-ops-40.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer; - do - { - printf ("am Anfang der Schleife\n"); - answer = strstr (buffer, "Antwort"); - printf ("answer = %s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - - printf ("am Ende der Schleife\n"); - } - while (answer); - - return 0; -} diff --git a/20221024/string-ops-41.c b/20221024/string-ops-41.c deleted file mode 100644 index b0ab057b396413ce38b2909efb59dad9887ca562..0000000000000000000000000000000000000000 --- a/20221024/string-ops-41.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer; - do - { - printf ("am Anfang der Schleife\n"); - answer = strstr (buffer, "Antwort"); - if (answer) - { - printf ("answer = %s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - } - printf ("am Ende der Schleife\n"); - } - while (answer); - - return 0; -} diff --git a/20221024/string-ops-42.c b/20221024/string-ops-42.c deleted file mode 100644 index 5611152af6d81f0e43e7852ef1515f0ff202b50b..0000000000000000000000000000000000000000 --- a/20221024/string-ops-42.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer; - do - { - answer = strstr (buffer, "Antwort"); - if (answer) - { - printf ("answer = %s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - } - } - while (answer); - - return 0; -} diff --git a/20221024/string-ops-43.c b/20221024/string-ops-43.c deleted file mode 100644 index 3393165d283fc91a147d7bd68414fa3638b7fec5..0000000000000000000000000000000000000000 --- a/20221024/string-ops-43.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer; - do - { - answer = strstr (buffer, "Antwort"); - if (!answer) - break; - - printf ("answer = %s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - } - while (answer); - - return 0; -} diff --git a/20221024/string-ops-44.c b/20221024/string-ops-44.c deleted file mode 100644 index 9090e72f4db4d932fe3189652a9e7376c2495ffd..0000000000000000000000000000000000000000 --- a/20221024/string-ops-44.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer = strstr (buffer, "Antwort"); - while (answer) - { - printf ("answer = %s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - - answer = strstr (buffer, "Antwort"); - } - - return 0; -} diff --git a/20221024/string-ops-45.c b/20221024/string-ops-45.c deleted file mode 100644 index e9241d19b9b813d0a4ca249994218306551e27e4..0000000000000000000000000000000000000000 --- a/20221024/string-ops-45.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - while (char *answer = strstr (buffer, "Antwort")) - { - printf ("answer = %s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - } - - return 0; -} diff --git a/20221024/string-ops-46.c b/20221024/string-ops-46.c deleted file mode 100644 index c5a455ed55ed22c8c4f204117cff04aa66f1cca2..0000000000000000000000000000000000000000 --- a/20221024/string-ops-46.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer; - while (answer = strstr (buffer, "Antwort")) - { - printf ("answer = %s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - } - - return 0; -} diff --git a/20221024/string-ops-47.c b/20221024/string-ops-47.c deleted file mode 100644 index ecfdf79dcded01dd158df7c5291c0574e26da47f..0000000000000000000000000000000000000000 --- a/20221024/string-ops-47.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer; - while ((answer = strstr (buffer, "Antwort")) != NULL) - { - printf ("answer = %s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - } - - return 0; -} diff --git a/20221024/string-ops-48.c b/20221024/string-ops-48.c deleted file mode 100644 index 2e06ed6d679f5fb42f844accde21a370531972fc..0000000000000000000000000000000000000000 --- a/20221024/string-ops-48.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void search (char *buffer, char **answer) -{ - *answer = strstr (buffer, "Antwort"); -} - -int main (void) -{ - char *buffer = "Wie lautet die Antwort aller Antworten?"; - - char *answer; - search (buffer, &answer); - while (answer) - { - printf ("answer = %s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - if (strlen (answer) > strlen ("Antwort")) - buffer = answer + strlen ("Antwort"); - - search (buffer, &answer); - } - - return 0; -} diff --git a/20221024/test-01.c b/20221024/test-01.c deleted file mode 100644 index 111d08bdce2ab333aeadf8b07071df27d38f8ef8..0000000000000000000000000000000000000000 --- a/20221024/test-01.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Test 1\n"); - return 0; -} diff --git a/20221024/test-02.c b/20221024/test-02.c deleted file mode 100644 index ce558a8f73682af3aac928e0557f2554c3482704..0000000000000000000000000000000000000000 --- a/20221024/test-02.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Test 2\n"); - return 0; -} diff --git a/20221024/test-03.c b/20221024/test-03.c deleted file mode 100644 index e7af02664293d81a715f1faf6d368cbb695a0d4e..0000000000000000000000000000000000000000 --- a/20221024/test-03.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Test 3\n"); - return 0; -} diff --git a/20221024/test-04.c b/20221024/test-04.c deleted file mode 100644 index 21cb955281ea2d5027b797447668e599ca600668..0000000000000000000000000000000000000000 --- a/20221024/test-04.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Test 4\n"); - return 0; -} diff --git a/20221024/test-05.c b/20221024/test-05.c deleted file mode 100644 index 8e0ca62231d8fddd26225fdf9f7a0b61d91608fc..0000000000000000000000000000000000000000 --- a/20221024/test-05.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Test 5\n"); - return 0; -} diff --git a/20221024/test-06.c b/20221024/test-06.c deleted file mode 100644 index 35c63e10ed5dbed1f9160292ee112dc8e77ad0f4..0000000000000000000000000000000000000000 --- a/20221024/test-06.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Test 6\n"); - return 0; -} diff --git a/20221024/test-07.c b/20221024/test-07.c deleted file mode 100644 index fbf6b08327d7f8a14b3cfe08a3fe7d4f63aac617..0000000000000000000000000000000000000000 --- a/20221024/test-07.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Test 7\n"); - return 0; -} diff --git a/20221024/test-08.c b/20221024/test-08.c deleted file mode 100644 index f429e361f7a51a1ff568e1503fee0512b2c30440..0000000000000000000000000000000000000000 --- a/20221024/test-08.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Test 8\n"); - return 0; -} diff --git a/20221024/test-09.c b/20221024/test-09.c deleted file mode 100644 index 9ff9c2a4d01d4264d908cd084a08a6bebc8d1b7c..0000000000000000000000000000000000000000 --- a/20221024/test-09.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Test 9\n"); - return 0; -} diff --git a/20221024/test-10.c b/20221024/test-10.c deleted file mode 100644 index c9c0edb469c65011fad2da980df2141df25512b8..0000000000000000000000000000000000000000 --- a/20221024/test-10.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Test 10\n"); - return 0; -} diff --git a/20221031/400_points_breadboard.jpg b/20221031/400_points_breadboard.jpg deleted file mode 100644 index 8ba048255851581a84db16c4d5a50802f7521486..0000000000000000000000000000000000000000 Binary files a/20221031/400_points_breadboard.jpg and /dev/null differ diff --git a/20221031/Makefile b/20221031/Makefile deleted file mode 100644 index 7ae33df99f68fcf460324cfbb008f3f7a3863638..0000000000000000000000000000000000000000 --- a/20221031/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -%.elf: %.c - avr-gcc -Wall -Os -mmcu=atmega328p $< -o $@ - -%.hex: %.elf - avr-objcopy -O ihex $< $@ - -download: - ./download.sh diff --git a/20221031/Makefile-1 b/20221031/Makefile-1 deleted file mode 100644 index bfc1b10a929f22a8c2f4f0cf0368c78db14ad0b0..0000000000000000000000000000000000000000 --- a/20221031/Makefile-1 +++ /dev/null @@ -1,8 +0,0 @@ -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 diff --git a/20221031/Makefile-2 b/20221031/Makefile-2 deleted file mode 100644 index 60aab7c7d51b28879c41e8590ab422e9edfadee5..0000000000000000000000000000000000000000 --- a/20221031/Makefile-2 +++ /dev/null @@ -1,16 +0,0 @@ -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) diff --git a/20221031/Makefile-3 b/20221031/Makefile-3 deleted file mode 100644 index 0ac355bfddfd237fe0f1b5062c5a242ab0d3e97e..0000000000000000000000000000000000000000 --- a/20221031/Makefile-3 +++ /dev/null @@ -1,13 +0,0 @@ -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) diff --git a/20221031/answer.c b/20221031/answer.c deleted file mode 100644 index 65a1dc248becb3157f2a226fc7b30df2ffb82e00..0000000000000000000000000000000000000000 --- a/20221031/answer.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "answer.h" - -int answer (void) -{ - return 23; -} diff --git a/20221031/answer.h b/20221031/answer.h deleted file mode 100644 index b6777e8210983d315b3ac3424a61bd9c9f0437b1..0000000000000000000000000000000000000000 --- a/20221031/answer.h +++ /dev/null @@ -1 +0,0 @@ -extern int answer (void); diff --git a/20221031/aufgabe-2.c b/20221031/aufgabe-2.c deleted file mode 100644 index 1afa7b1260506cb307aff5f929c6357c7bdcb708..0000000000000000000000000000000000000000 --- a/20221031/aufgabe-2.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <avr/io.h> - -int main (void) -{ - DDRA = 0xff; - DDRB = 0xff; - DDRC = 0xff; - DDRD = 0xff; - PORTA = 0x1f; - PORTB = 0x10; - PORTD = 0x10; - PORTC = 0xfc; - while (1); - return 0; -} diff --git a/20221031/aufgabe-3.c b/20221031/aufgabe-3.c deleted file mode 100644 index 9ae72941b931c04f3c380cb3bbcd64bec7f08c20..0000000000000000000000000000000000000000 --- a/20221031/aufgabe-3.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void insert_into_string (char src, char *target, int pos) -{ - int len = strlen (target); - for (int i = pos; i < len; i++) - target[i+1] = target[i]; - target[pos] = src; -} - -int main (void) -{ - char test[100] = "Hochshule Bochum"; - insert_into_string ('c', test, 5); - printf ("%s\n", test); - return 0; -} diff --git a/20221031/bit-operations-01.txt b/20221031/bit-operations-01.txt deleted file mode 100644 index 755e818c94957694eef920f7b158f2c1d18803ae..0000000000000000000000000000000000000000 --- a/20221031/bit-operations-01.txt +++ /dev/null @@ -1,46 +0,0 @@ - - A = 0011 1010 ein Bit auf 1 setzen - | 0000 0100 bitweise Oder-Verknüpfung mit "Maske" (oder "Bitmaske") - --------- - 0011 1110 - - A = 0011 1010 ein Bit auf 1 setzen - | 0000 1000 bitweise Oder-Verknüpfung mit "Maske" (oder "Bitmaske") - --------- - 0011 1010 - - A = 0011 1010 ein Bit auf 0 setzen - & 1111 0111 bitweise Und-Verknüpfung mit "Maske" (oder "Bitmaske") - --------- - 0011 0010 - -Maske für Und = Einerkomplement der Maske für Oder (und umgekehrt) - -In C: - - Oder-Verknüpfung: C = A | B A |= B - Und-Verknüpfung: C = A & B A &= B - Einerkomplement: C = ~A - -Erzeugen einer Oder-Maske: Bit-Verschiebung einer 1 nach links - - 0000 0001 << 2 = 0000 0100 Sprechweise: "Bit 2" - 0000 0001 << 0 = 0000 0001 Sprechweise: "Bit 0" - - Durchnumerierung der Bits: von rechts, beginnend mit 0 - -Erzeugen einer Und-Maske: Einerkomplement einer Oder-Maske - - ~(0000 0001 << 2) = 1111 1011 Sprechweise: "Bit 2" - ~(0000 0001 << 0) = 1111 1110 Sprechweise: "Bit 0" - - - A = 0011 1010 ein Bit umklappen - ^ 0000 1000 bitweise Exklusiv-Oder-Verknüpfung mit "Maske" (oder "Bitmaske") - --------- - 0011 0010 - - A = 0011 1010 ein Bit abfragen - & 0000 1000 bitweise Und-Verknüpfung mit Oder-Maske - --------- - 0000 1000 != 0 Ergebnis ungleich 0 bedeutet: Bit ist gesetzt diff --git a/20221031/blink-0.c b/20221031/blink-0.c deleted file mode 100644 index b0022c681fd1482ed0a6d9fded7bb0a54699de32..0000000000000000000000000000000000000000 --- a/20221031/blink-0.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <avr/io.h> - -int main (void) -{ - DDRD = 0x40; /* binär: 0100 0000 */ - PORTD = 0x40; /* binär: 0100 0000 */ - while (1); - return 0; -} diff --git a/20221031/blink-0.hex b/20221031/blink-0.hex deleted file mode 100644 index 6a05b7db67b71fe56b83474cab2ab278834e3777..0000000000000000000000000000000000000000 --- a/20221031/blink-0.hex +++ /dev/null @@ -1,10 +0,0 @@ -:100000000C9434000C943E000C943E000C943E0082 -:100010000C943E000C943E000C943E000C943E0068 -:100020000C943E000C943E000C943E000C943E0058 -:100030000C943E000C943E000C943E000C943E0048 -:100040000C943E000C943E000C943E000C943E0038 -:100050000C943E000C943E000C943E000C943E0028 -:100060000C943E000C943E0011241FBECFEFD8E04C -:10007000DEBFCDBF0E9440000C9444000C940000F1 -:0C00800080E48AB98BB9FFCFF894FFCF61 -:00000001FF diff --git a/20221031/blink-0.txt b/20221031/blink-0.txt deleted file mode 100644 index e6c0b93daa66a274edeb47e355ca87175f609715..0000000000000000000000000000000000000000 --- a/20221031/blink-0.txt +++ /dev/null @@ -1,79 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221031> cat blink-0.c -#include <avr/io.h> - -int main (void) -{ - DDRD = 0x40; /* binär: 0100 0000 */ - PORTD = 0x40; /* binär: 0100 0000 */ - while (1); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221031> gcc -Wall -O blink-0.c -o blink-0 -blink-0.c:1:10: fatal error: avr/io.h: Datei oder Verzeichnis nicht gefunden - #include <avr/io.h> - ^~~~~~~~~~ -compilation terminated. -cassini/home/peter/bo/2022ws/hp/20221031> cat Makefile -%.elf: %.c - avr-gcc -Wall -Os -mmcu=atmega328p $< -o $@ - -%.hex: %.elf - avr-objcopy -O ihex $< $@ - -download: - ./download.sh -cassini/home/peter/bo/2022ws/hp/20221031> avr-gcc -Wall -Os -mmcu=atmega328p blink-0.c -o blink-0.elf -cassini/home/peter/bo/2022ws/hp/20221031> ls -l blink-0.* --rw-r--r-- 1 peter peter 148 Jan 4 2021 blink-0.c --rwxr-xr-x 1 peter peter 6360 Okt 31 15:01 blink-0.elf -cassini/home/peter/bo/2022ws/hp/20221031> ./blink-0.elf -bash: ./blink-0.elf: Kann die Binärdatei nicht ausführen: Fehler im Format der Programmdatei -cassini/home/peter/bo/2022ws/hp/20221031> avr-objcopy -O ihex blink-0.elf blink-0.hex -cassini/home/peter/bo/2022ws/hp/20221031> cat blink-0.hex -:100000000C9434000C943E000C943E000C943E0082 -:100010000C943E000C943E000C943E000C943E0068 -:100020000C943E000C943E000C943E000C943E0058 -:100030000C943E000C943E000C943E000C943E0048 -:100040000C943E000C943E000C943E000C943E0038 -:100050000C943E000C943E000C943E000C943E0028 -:100060000C943E000C943E0011241FBECFEFD8E04C -:10007000DEBFCDBF0E9440000C9444000C940000F1 -:0C00800080E48AB98BB9FFCFF894FFCF61 -:00000001FF -cassini/home/peter/bo/2022ws/hp/20221031> cat download.sh -port=$(ls -rt /dev/ttyACM* | tail -1) -echo avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) -avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) 2>/dev/null -cassini/home/peter/bo/2022ws/hp/20221031> avrdude -P /dev/ttyACM0 -c arduino -p m328p -U flash:w:blink-0.hex - -avrdude: AVR device initialized and ready to accept instructions - -Reading | ################################################## | 100% 0.00s - -avrdude: Device signature = 0x1e950f (probably m328p) -avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed - To disable this feature, specify the -D option. -avrdude: erasing chip -avrdude: reading input file "blink-0.hex" -avrdude: input file blink-0.hex auto detected as Intel Hex -avrdude: writing flash (140 bytes): - -Writing | ################################################## | 100% 0.04s - -avrdude: 140 bytes of flash written -avrdude: verifying flash memory against blink-0.hex: -avrdude: load data flash data from input file blink-0.hex: -avrdude: input file blink-0.hex auto detected as Intel Hex -avrdude: input file blink-0.hex contains 140 bytes -avrdude: reading on-chip flash data: - -Reading | ################################################## | 100% 0.03s - -avrdude: verifying ... -avrdude: 140 bytes of flash verified - -avrdude: safemode: Fuses OK (E:00, H:00, L:00) - -avrdude done. Thank you. - -cassini/home/peter/bo/2022ws/hp/20221031> diff --git a/20221031/blink-0a.c b/20221031/blink-0a.c deleted file mode 100644 index 7093fa4cbf094be60a9ae35117c84be13258235c..0000000000000000000000000000000000000000 --- a/20221031/blink-0a.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <avr/io.h> - -int main (void) -{ - DDRD = 0x40; /* binär: 0100 0000 */ - PORTD = 0x00; /* binär: 0000 0000 */ - while (1); - return 0; -} diff --git a/20221031/blink-1.c b/20221031/blink-1.c deleted file mode 100644 index 6d28dce84f94375094c98479c30a54ace1b2a9d9..0000000000000000000000000000000000000000 --- a/20221031/blink-1.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <avr/io.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -int main (void) -{ - DDRD = 0x01; - PORTD |= 0x01; - while (1) - { - _delay_ms (500); - PORTD &= ~0x01; - _delay_ms (500); - PORTD |= 0x01; - } - return 0; -} diff --git a/20221031/blink-1a.c b/20221031/blink-1a.c deleted file mode 100644 index f594cc175fa238d3ba3f930bc8bcbfeb1ddaa43b..0000000000000000000000000000000000000000 --- a/20221031/blink-1a.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <avr/io.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -int main (void) -{ - DDRD = 0xff; /* 1111 1111 --> alle Ports als Output-Ports nutzen */ - PORTD = 0x1a; /* 0001 1010 */ - while (1) - { - _delay_ms (500); - PORTD &= ~0x01; - _delay_ms (500); - PORTD |= 0x01; - } - return 0; -} diff --git a/20221031/blink-1b.c b/20221031/blink-1b.c deleted file mode 100644 index f435112888a5ba118a33c689de63462776d1d072..0000000000000000000000000000000000000000 --- a/20221031/blink-1b.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <avr/io.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -int main (void) -{ - DDRD = 0x7f; /* 0111 1111 --> alle Ports als Output-Ports nutzen */ - PORTD = 0x01; /* 0000 0001 */ - while (1) - { - while (PIND & 0x80) /* 1000 0000 */ - { - _delay_ms (500); - PORTD &= ~0x01; - _delay_ms (500); - PORTD |= 0x01; - } - } - return 0; -} diff --git a/20221031/download.sh b/20221031/download.sh deleted file mode 100755 index 770c3b5dca74ac09778be055c9d6f5adb0df293b..0000000000000000000000000000000000000000 --- a/20221031/download.sh +++ /dev/null @@ -1,3 +0,0 @@ -port=$(ls -rt /dev/ttyACM* | tail -1) -echo avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) -avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) 2>/dev/null diff --git a/20221031/gtk-04.c b/20221031/gtk-04.c deleted file mode 100644 index 132dbcb61fb979372da88225e8cb881d2b81a2d4..0000000000000000000000000000000000000000 --- a/20221031/gtk-04.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <gtk/gtk.h> - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - GtkWidget *drawing_area = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (vbox), drawing_area); - - gtk_widget_show (drawing_area); - gtk_widget_show (button); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221031/gtk-05.c b/20221031/gtk-05.c deleted file mode 100644 index c77feaac44766ae3e7b157d3a72e03f62c9c687b..0000000000000000000000000000000000000000 --- a/20221031/gtk-05.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <gtk/gtk.h> - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - GtkWidget *drawing_area = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (vbox), drawing_area); - gtk_widget_set_size_request (drawing_area, 100, 100); - - gtk_widget_show (drawing_area); - gtk_widget_show (button); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221031/gtk-06.c b/20221031/gtk-06.c deleted file mode 100644 index 81e12e6958d3c0adbed8d315927104482bc4c681..0000000000000000000000000000000000000000 --- a/20221031/gtk-06.c +++ /dev/null @@ -1,53 +0,0 @@ -#include <gtk/gtk.h> - -gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data) -{ - GdkRGBA red = { 1.0, 0.0, 0.0, 0.8 }; - GdkRGBA yellow = { 1.0, 1.0, 0.0, 0.6 }; - GdkRGBA blue = { 0.0, 0.5, 1.0, 0.4 }; - - gdk_cairo_set_source_rgba (c, &red); - cairo_rectangle (c, 10, 10, 60, 40); - cairo_fill (c); - - gdk_cairo_set_source_rgba (c, &yellow); - cairo_arc (c, 65, 50, 30, 0, 2 * G_PI); - cairo_fill (c); - - gdk_cairo_set_source_rgba (c, &blue); - cairo_move_to (c, 10, 70); - cairo_line_to (c, 70, 70); - cairo_line_to (c, 40, 18); - cairo_close_path (c); - cairo_fill (c); - - return FALSE; /* TRUE to stop other handlers from being invoked for the event. - FALSE to propagate the event further. */ -} - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - GtkWidget *drawing_area = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (vbox), drawing_area); - g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - gtk_widget_set_size_request (drawing_area, 100, 100); - - gtk_widget_show (drawing_area); - gtk_widget_show (button); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221031/gtk-07.c b/20221031/gtk-07.c deleted file mode 100644 index 11041fbe1d27585ca4edb951f195f114ddad126e..0000000000000000000000000000000000000000 --- a/20221031/gtk-07.c +++ /dev/null @@ -1,71 +0,0 @@ -#include <stdio.h> -#include <gtk/gtk.h> - -gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data) -{ - GdkRGBA red = { 1.0, 0.0, 0.0, 0.8 }; - GdkRGBA yellow = { 1.0, 1.0, 0.0, 0.6 }; - GdkRGBA blue = { 0.0, 0.5, 1.0, 0.4 }; - - gdk_cairo_set_source_rgba (c, &red); - cairo_rectangle (c, 10, 10, 60, 40); - cairo_fill (c); - - gdk_cairo_set_source_rgba (c, &yellow); - cairo_arc (c, 65, 50, 30, 0, 2 * G_PI); - cairo_fill (c); - - gdk_cairo_set_source_rgba (c, &blue); - cairo_move_to (c, 10, 70); - cairo_line_to (c, 70, 70); - cairo_line_to (c, 40, 18); - cairo_close_path (c); - cairo_fill (c); - - return FALSE; /* TRUE to stop other handlers from being invoked for the event. - FALSE to propagate the event further. */ -} - -gboolean button_press (GtkWidget *widget, GdkEventButton *e, gpointer data) -{ - printf ("button %d pressed at (%lf, %lf)\n", e->button, e->x, e->y); - return FALSE; -} - -gboolean key_press (GtkWidget *widget, GdkEventKey *e, gpointer data) -{ - printf ("key '%c' (%d) pressed\n", e->keyval, e->keyval); - return FALSE; -} - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - GtkWidget *drawing_area = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (vbox), drawing_area); - g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - gtk_widget_set_size_request (drawing_area, 100, 100); - gtk_widget_add_events (drawing_area, GDK_BUTTON_PRESS_MASK); - g_signal_connect (drawing_area, "button_press_event", G_CALLBACK (button_press), NULL); - - gtk_widget_add_events (window, GDK_KEY_PRESS_MASK); - g_signal_connect (window, "key_press_event", G_CALLBACK (key_press), NULL); - - gtk_widget_show (drawing_area); - gtk_widget_show (button); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221031/gtk-08.c b/20221031/gtk-08.c deleted file mode 100644 index d3092d009f1b20909a96ed89be3cfe971c11263f..0000000000000000000000000000000000000000 --- a/20221031/gtk-08.c +++ /dev/null @@ -1,54 +0,0 @@ -#include <gtk/gtk.h> - -#define WIDTH 320 -#define HEIGHT 240 - -double x = 5; -double y = 95; - -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, 5, 0, 2 * G_PI); - cairo_fill (c); - return FALSE; -} - -gboolean timer (GtkWidget *widget) -{ - x += 0.5; - y -= 0.7; - 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_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - GtkWidget *drawing_area = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (vbox), drawing_area); - g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_widget_show (drawing_area); - gtk_widget_show (button); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221031/gtk-09.c b/20221031/gtk-09.c deleted file mode 100644 index 91af21857c6bb810659fbb4c11afbcab293fa188..0000000000000000000000000000000000000000 --- a/20221031/gtk-09.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <gtk/gtk.h> - -#define WIDTH 320 -#define HEIGHT 240 - -double x = 5; -double y = 95; -double vx = 0.5; -double vy = 0.7; -double dt = 0.05; -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, 5, 0, 2 * G_PI); - cairo_fill (c); - return FALSE; -} - -gboolean timer (GtkWidget *widget) -{ - x += vx * dt; - y += vy * dt; - vx += 0.0 * dt; - vy += (-g) * dt; - 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_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - GtkWidget *drawing_area = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (vbox), drawing_area); - g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_widget_show (drawing_area); - gtk_widget_show (button); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221031/gtk-10.c b/20221031/gtk-10.c deleted file mode 100644 index f7fb2d5b1c4d3f1082a15b8f3a23fb5480fdd4f1..0000000000000000000000000000000000000000 --- a/20221031/gtk-10.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <gtk/gtk.h> - -#define WIDTH 320 -#define HEIGHT 240 - -double x = 5; -double y = 95; -double vx = 0.5; -double vy = 0.7; -double dt = 0.05; -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, HEIGHT - y, 5, 0, 2 * G_PI); - cairo_fill (c); - return FALSE; -} - -gboolean timer (GtkWidget *widget) -{ - x += vx * dt; - y += vy * dt; - vx += 0.0 * dt; - vy += (-g) * dt; - 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_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - GtkWidget *drawing_area = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (vbox), drawing_area); - g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_widget_show (drawing_area); - gtk_widget_show (button); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221031/gtk-11.c b/20221031/gtk-11.c deleted file mode 100644 index 1fa3d7169dc09ed0a5e89abffdce3cb297509842..0000000000000000000000000000000000000000 --- a/20221031/gtk-11.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <gtk/gtk.h> - -#define WIDTH 640 -#define HEIGHT 480 - -double x = 5; -double y = 95; -double vx = 0.5; -double vy = 0.7; -double dt = 0.05; -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, HEIGHT - y, 5, 0, 2 * G_PI); - cairo_fill (c); - return FALSE; -} - -gboolean timer (GtkWidget *widget) -{ - x += vx * dt; - y += vy * dt; - vx += 0.0 * dt; - vy += (-g) * dt; - 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_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - GtkWidget *drawing_area = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (vbox), drawing_area); - g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_widget_show (drawing_area); - gtk_widget_show (button); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221031/gtk-12.c b/20221031/gtk-12.c deleted file mode 100644 index e0c274336e1ea7a21983daaa95a563796b532e25..0000000000000000000000000000000000000000 --- a/20221031/gtk-12.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <gtk/gtk.h> - -#define WIDTH 640 -#define HEIGHT 480 - -double x = 5; -double y = 95; -double vx = 5.0; -double vy = 0.7; -double dt = 0.05; -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, HEIGHT - y, 5, 0, 2 * G_PI); - cairo_fill (c); - return FALSE; -} - -gboolean timer (GtkWidget *widget) -{ - x += vx * dt; - y += vy * dt; - vx += 0.0 * dt; - vy += (-g) * dt; - 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_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - GtkWidget *drawing_area = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (vbox), drawing_area); - g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_widget_show (drawing_area); - gtk_widget_show (button); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221031/higher-math-06.c b/20221031/higher-math-06.c deleted file mode 100644 index 973ebb7a5cdd6a72036e5896b21724fd83e96eee..0000000000000000000000000000000000000000 --- a/20221031/higher-math-06.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -#define SIX 1 + 5 -#define NINE 8 + 1 - -int main (void) -{ - printf ("Six times nine = %d.\n", SIX * NINE); - return 0; -} diff --git a/20221031/higher-math-06.txt b/20221031/higher-math-06.txt deleted file mode 100644 index 39cf04fd7e451b1585739a0a6cf1e3a688ebe0c9..0000000000000000000000000000000000000000 --- a/20221031/higher-math-06.txt +++ /dev/null @@ -1,12 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221031> gcc -Wall -O higher-math-06.c -E -P | tail -__attribute__ ((__nothrow__ , __leaf__)) ferror_unlocked (FILE *__stream) -{ - return (((__stream)->_flags & 0x0020) != 0); -} - -int main (void) -{ - printf ("Six times nine = %d.\n", 1 + 5 * 8 + 1); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221031> diff --git a/20221031/higher-math-07.c b/20221031/higher-math-07.c deleted file mode 100644 index a422dcca1512afa4e3daf48f242f5fd1264d5494..0000000000000000000000000000000000000000 --- a/20221031/higher-math-07.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -#define SIX 1 + 5 -#define NINE 8 + 1 - -int main (void) -{ - printf ("Six = %d.\n", SIX); - printf ("Nine = %d.\n", NINE); - printf ("Six times nine = %d.\n", SIX * NINE); - return 0; -} diff --git a/20221031/hp-20221031.pdf b/20221031/hp-20221031.pdf deleted file mode 100644 index 7e293396b330de1685fd4d03ccc9becee7c4a797..0000000000000000000000000000000000000000 Binary files a/20221031/hp-20221031.pdf and /dev/null differ diff --git a/20221031/hp-20221031.tex b/20221031/hp-20221031.tex deleted file mode 100644 index 42b011c21588311a5ff7d48eb1ff7db39ef7118f..0000000000000000000000000000000000000000 --- a/20221031/hp-20221031.tex +++ /dev/null @@ -1,812 +0,0 @@ -% hp-20221031.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Callback-Funktionen, make, Bit-Operationen, I/O-Ports - -\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} - -\newcommand{\redurl}[1]{\href{#1}{\color{red}\nolinkurl{#1}}} - -\title{Hardwarenahe Programmierung} -\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{31.\ Oktober 2022} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \begin{itemize} - \vspace*{-\smallskipamount} - \item[\dots] - \item[2.13] Dateien und Fehlerbehandlung - \item[2.14] Parameter des Hauptprogramms - \color{medgreen} - \item[2.15] String-Operationen - \end{itemize} - \item[\textbf{3}] \textbf{Bibliotheken} - \begin{itemize} - \color{medgreen} - \item[3.1] Der Präprozessor - \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} - \vspace*{-\smallskipamount} - \item[\textbf{\dots}] - \end{itemize} - -\end{frame} - -\setcounter{section}{1} -\section{Einführung in C} -\setcounter{subsection}{13} -\subsection{String-Operationen} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char buffer[100] = ""; - sprintf (buffer, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - return 0; - } - \end{lstlisting} - \vspace*{-1cm} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - \vspace*{-0.4cm} - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - int main (void) - { - char buffer[100] = ""; - snprintf (buffer, 100, "Die Antwort lautet: %d", 42); - printf ("%s\n", buffer); - - char *answer = strstr (buffer, "Antwort"); - printf ("%s\n", answer); - printf ("found at: %zd\n", answer - buffer); - - return 0; - } - \end{lstlisting} - -\end{frame} - -\begin{frame} - - \showsection - - Sprachelemente weitgehend komplett - - \bigskip - Es fehlen: - \begin{itemize} - \item - Ergänzungen (z.\,B.\ ternärer Operator, \lstinline{union}, \lstinline{unsigned}, \lstinline{volatile}) - \item - Bibliotheksfunktionen (z.\,B.\ \lstinline{malloc()}) - \arrowitem - werden eingeführt, wenn wir sie brauchen - \bigskip - \item - Konzepte (z.\,B.\ rekursive Datenstrukturen, Klassen selbst bauen) - \arrowitem - werden eingeführt, wenn wir sie brauchen, oder: - \arrowitem - Literatur\\[\smallskipamount] - (z.\,B.\ Wikibooks: C-Programmierung,\\ - Dokumentation zu Compiler und Bibliotheken) - \bigskip - \item - Praxiserfahrung - \arrowitem - Übung und Praktikum: nur Einstieg - \arrowitem - selbständig arbeiten - \end{itemize} -\end{frame} - -\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 SIX 6}: Text ersetzen lassen -- Konstante definieren - \begin{itemize} -% \pause - \item - Kein Semikolon! -% \pause - \item - Berechnungen in Klammern setzen:\\ - \lstinline{#define SIX (1 + 5)} -% \pause - \item - Konvention: Großbuchstaben - \end{itemize} - - Zum Debuggen: \lstinline[style=cmd]{gcc -E -P} - -\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*{-3cm} - \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-sp - i-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-g - nu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/inclu - de/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pa - ngo-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1. - 0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/in - clude/pixman-1 -I/usr/include/freetype2 -I/usr/include/ - libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/l - ibpng16 -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 -lcairo-gobject -lcairo -lgdk_pix - buf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -o hello-gtk¿ - \end{lstlisting} - \vspace*{-2cm} - \end{onlyenv} - \begin{onlyenv}<5-> - \begin{lstlisting}[style=terminal,gobble=10] - $ ¡gcc -Wall -O hello-gtk.c $(pkg-config --cflags --libs - gtk+-3.0) -o hello-gtk¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<5> - \begin{picture}(0,0)(0.3,0.3) - \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}~~~\strut}}} - \end{picture} - \end{onlyenv} - \pause - \pause - \item - Auf manchen Plattformen kommt es auf die Reihenfolge an: - \begin{lstlisting}[style=terminal,gobble=8] - $ ¡gcc -Wall -O $(pkg-config --cflags gtk+-3.0) \ - hello-gtk.c $(pkg-config --libs gtk+-3.0) \ - -o hello-gtk¿ - \end{lstlisting} - (Backslash = "`Es geht in der nächsten Zeile weiter."') - \end{itemize} - -\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)(-0.07,0.2) - \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)(-0.07,0.2) - \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} - -\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} - -\section{Hardwarenahe Programmierung} -\subsection{Bit-Operationen} -\subsubsection{Zahlensysteme} - -\begin{frame}[fragile] - - \showsection - \vspace*{-\smallskipamount} - \showsubsection - \vspace*{-\medskipamount} - \showsubsubsection - - \begin{tabular}{rlrl} - Basis & Name & Beispiel & Anwendung \\[\smallskipamount] - 2 & Binärsystem & 1\,0000\,0011 & Bit-Operationen \\ - 8 & Oktalsystem & \lstinline,0403, & Dateizugriffsrechte (Unix) \\ - 10 & Dezimalsystem & \lstinline,259, & Alltag \\ - 16 & Hexadezimalsystem & \lstinline,0x103, & Bit-Operationen \\ - 256 & (keiner gebräuchlich) & 0.0.1.3 & IP-Adressen (IPv4) - \end{tabular} - - \bigskip - - \begin{itemize} - \item - Computer rechnen im Binärsystem. - \item - Für viele Anwendungen (z.\,B.\ I/O-Ports, Grafik, \dots) ist es notwendig,\\ - Bits in Zahlen einzeln ansprechen zu können. - \end{itemize} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsubsection - - \begin{tabular}{rlrlrc} - \qquad 000 & \bf 0 \hspace*{1.5cm} & 0000 & \bf 0 & \quad 1000 & \bf 8\\ - 001 & \bf 1 & 0001 & \bf 1 & 1001 & \bf 9\\ - 010 & \bf 2 & 0010 & \bf 2 & 1010 & \bf A\\ - 011 & \bf 3 & 0011 & \bf 3 & 1011 & \bf B\\[\smallskipamount] - 100 & \bf 4 & 0100 & \bf 4 & 1100 & \bf C\\ - 101 & \bf 5 & 0101 & \bf 5 & 1101 & \bf D\\ - 110 & \bf 6 & 0110 & \bf 6 & 1110 & \bf E\\ - 111 & \bf 7 & 0111 & \bf 7 & 1111 & \bf F\\ - \end{tabular} - - \medskip - - \begin{itemize} - \item - Oktal- und Hexadezimalzahlen lassen sich ziffernweise\\ - in Binär-Zahlen umrechnen. - \item - Hexadezimalzahlen sind eine Kurzschreibweise für Binärzahlen,\\ - gruppiert zu jeweils 4 Bits. - \item - Oktalzahlen sind eine Kurzschreibweise für Binärzahlen,\\ - gruppiert zu jeweils 3 Bits. - \item - Trotz Taschenrechner u.\,ä.\ lohnt es sich,\\ - die o.\,a.\ Umrechnungstabelle \textbf{auswendig} zu kennen. - \end{itemize} - -\end{frame} - -\subsubsection{Bit-Operationen in C} - -\begin{frame}[fragile] - - \showsubsubsection - - \begin{tabular}{lll} - C-Operator & Verknüpfung & Anwendung \\[\smallskipamount] - \lstinline,&, & Und & Bits gezielt löschen \\ - \lstinline,|, & Oder & Bits gezielt setzen \\ - \lstinline,^, & Exklusiv-Oder & Bits gezielt invertieren \\ - \lstinline,~, & Nicht & Alle Bits invertieren \\[\smallskipamount] - \lstinline,<<, & Verschiebung nach links & Maske generieren \\ - \lstinline,>>, & Verschiebung nach rechts & Bits isolieren - \end{tabular} - - \bigskip - - Numerierung der Bits: von rechts ab 0 - - \medskip - - \begin{tabular}{ll} - Bit Nr.\ 3 auf 1 setzen: & - \lstinline,a |= 1 << 3;, \\ - Bit Nr.\ 4 auf 0 setzen: & - \lstinline,a &= ~(1 << 4);, \\ - Bit Nr.\ 0 invertieren: & - \lstinline,a ^= 1 << 0;, - \end{tabular} - - \smallskip - - ~~Abfrage, ob Bit Nr.\ 1 gesetzt ist:\quad - \lstinline{if (a & (1 << 1))} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsubsection - - C-Datentypen für Bit-Operationen: - \smallskip\par - \lstinline{#include <stdint.h>} - \medskip\par - \begin{tabular}{lllll} - & 8 Bit & 16 Bit & 32 Bit & 64 Bit \\ - mit Vorzeichen & \lstinline,int8_t, - & \lstinline,int16_t, - & \lstinline,int32_t, - & \lstinline,int64_t, \\ - ohne Vorzeichen & \lstinline,uint8_t, - & \lstinline,uint16_t, - & \lstinline,uint32_t, - & \lstinline,uint64_t, - \end{tabular} - - \bigskip - \bigskip - - Ausgabe: - \smallskip\par - \begin{lstlisting} - #include <stdio.h> - #include <stdint.h> - #include <inttypes.h> - ... - uint64_t x = 42; - printf ("Die Antwort lautet: %" PRIu64 "\n", x); - \end{lstlisting} - -\iffalse - - \bigskip - - Aufgabe: Schreiben Sie C-Funktionen, die ein "`Array von Bits"' realisieren, z.\,B. - - \smallskip - - \begin{tabular}[t]{ll} - \lstinline|void set_bit (int i);| & Bei Index $i$ auf 1 setzen \\ - \lstinline|void clear_bit (int i);| & Bei Index $i$ auf 0 setzen \\ - \lstinline|int get_bit (int i);| & Bei Index $i$ lesen - \end{tabular} - - \medskip - - Hinweise: - \begin{itemize} - \item - Die Größe des Bit-"`Arrays"' (z.\,B.\ 1000) dürfen Sie als \emph{vorher bekannt\/} voraussetzen. - \item - Sie benötigen ein Array, z.\,B.\ von \lstinline|char|- oder \lstinline|int|-Variablen. - \item - Sie benötigen eine Division (\lstinline|/|) sowie den Divisionsrest (Modulo: \lstinline|%|). - \end{itemize} - -\fi - -\end{frame} - -\subsection{I/O-Ports} - -\begin{frame}[fragile] - -% \showsection - \showsubsection - \vspace*{-1.5\medskipamount} - {\large\textbf{\color{structure}4.3\quad Interrupts}} - - \bigskip - - Kommunikation mit externen Geräten - - \bigskip - - \begin{center} - \includegraphics{io-ports-and-interrupts.pdf} - \end{center} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - In Output-Port schreiben = Aktoren ansteuern - - Beispiel: LED - - \medskip - - \begin{lstlisting} - #include <avr/io.h> - ... - DDRC = 0x70; - PORTC = 0x40; - \end{lstlisting} - \begin{picture}(0,0) - \put(3,0.67){\begin{minipage}{3cm} - \color{red}% - binär: 0111\,0000\\ - binär: 0100\,0000 - \end{minipage}} - \put(10,0.67){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}} - \end{picture} - - \bigskip - - \lstinline{DDR} = Data Direction Register\\ - Bit = 1 für Output-Port\\ - Bit = 0 für Input-Port - - \bigskip - - \emph{Details: siehe Datenblatt und Schaltplan} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Aus Input-Port lesen = Sensoren abfragen - - Beispiel: Taster - - \medskip - - \begin{lstlisting} - #include <avr/io.h> - ... - DDRC = 0xfd; - while ((PINC & 0x02) == 0) - ; /* just wait */ - \end{lstlisting} - \begin{picture}(0,0)(-1.5,-0.42) - \put(3,0.67){\begin{minipage}{3cm} - \color{red}% - binär: 1111\,1101\\ - binär: 0000\,0010 - \end{minipage}} - \put(10,0.67){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}} - \end{picture} - - \bigskip - - \lstinline{DDR} = Data Direction Register\\ - Bit = 1 für Output-Port\\ - Bit = 0 für Input-Port - - \bigskip - - \emph{Details: siehe Datenblatt und Schaltplan} - - \bigskip - - Praktikumsaufgabe: Druckknopfampel - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \begin{itemize} - \item[3.1] Der Präprozessor - \item[3.2] Bibliotheken einbinden - \color{medgreen} - \item[3.3] Bibliotheken verwenden - \item[3.4] Projekt organisieren: make - \end{itemize} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \begin{itemize} - \color{medgreen} - \item[4.1] Bit-Operationen - \item[4.2] I/O-Ports - \color{red} - \item[4.3] Interrupts - \vspace*{-0.1cm} - \item[\dots] - \end{itemize} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{\dots}] - \end{itemize} - -\end{frame} - -\end{document} diff --git a/20221031/hp-2022ws-p2.pdf b/20221031/hp-2022ws-p2.pdf deleted file mode 100644 index 8cc34b0e76299d099b6a7be2669935f56fba17c7..0000000000000000000000000000000000000000 Binary files a/20221031/hp-2022ws-p2.pdf and /dev/null differ diff --git a/20221031/hp-2022ws-p2.tex b/20221031/hp-2022ws-p2.tex deleted file mode 100644 index dd2e4f0d238f0e796a3c992eb5e06703b36780de..0000000000000000000000000000000000000000 --- a/20221031/hp-2022ws-p2.tex +++ /dev/null @@ -1,180 +0,0 @@ -% hp-2022ws-p2.pdf - Labor Notes on Low-Level Programming -% Copyright (C) 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Versuch 2: Druckknopfampel - -\documentclass[a4paper]{article} - -\usepackage{pgscript} -\usepackage{multicol} -\usepackage{amsmath} -\usepackage{sfmath} - -\sloppy -\raggedcolumns -\pagestyle{empty} -\addtolength{\textheight}{1cm} -\newcommand{\sep}{~$\cdot$~} -\newcommand{\mylicense}{CC-by-sa (Version 3.0) oder GNU GPL (Version 3 oder höher)} - -\begin{document} - - \makebox(0,0.005)[tl]{\includegraphics[scale=0.72]{logo-hochschule-bochum-cvh-text-v2.pdf}}\hfill - \makebox(0,0)[tr]{\includegraphics[scale=0.5]{logo-hochschule-bochum.pdf}} - \par\bigskip\bigskip - \begin{center} - \Large\textbf{Praktikumsversuch 2: Druckknopfampel} - \par\medskip - \normalsize Hardwarenahe Programmierung\sep - Wintersemester 2022/23\sep - Prof.~Dr.~Peter Gerwinski - \end{center} - - Aufgabe: Programmieren Sie einen Mikrocontroller so, - daß er eine Druckknopfampel steuern kann. - - \begin{multicols}{2} - - \begin{itemize} - \item - Normalerweise zeigt eine Druckknopfampel rotes Licht für die - Fußgänger und grünes Licht für die Straße. - \item - Nach Knopfdruck wechselt die Straße über Gelb nach Rot. - Danach bekommen die Fußgänger Grün. - Nach einer gewissen Zeit bekommen die Fußgänger wieder Rot, - und die Straße wechselt über Rot-Gelb wieder zu Grün. - - \medskip - \item - Als Mikrocontroller-Entwicklungsplattform stellen wir Ihnen - einen \emph{Arduino Uno\/} zur Verfügung. - \item - Software-Entwiklung für den Arduino geschieht üblicherweise - mit Hilfe der Entwicklungswerkzeuge \emph{GCC, binutils und - glibc für AVR} sowie \emph{avrdude\/} für das Herunterladen - des geschriebenen Programms vom PC auf den Mikrocontroller. - - Die Arduino-Entwicklungsumgebung (siehe z.\,B.\ - \url{https://www.arduino.cc/en/Main/Software}) integriert - alle diese Komponenten. - \item - Wir schreiben unser Programm in C und nicht in der INO-Sprache. - Wenn die Quelltext-Dateien in der Arduino-Entwicklungsumgebung - die Endung \file{.ino} haben, ist das kein Problem, - sofern der Inhalt der Datei in C geschrieben ist. - \item - Den Schaltplan des Arduino Uno sowie das Datenblatt des - ATmega328p finden Sie per Web-Recherche. - - \columnbreak - - \item - Sie können Ihr Programm direkt aus der Arduino-Entwicklungsumgebung heraus - compilieren und auf den Mikrocontroller herunterladen. - Wenn Sie dies von der Kommandozeile aus machen möchten, - geht dies folgendermaßen: - - \lstinline[style=cmd]{avr-gcc -Wall -Os -mmcu=atmega328p \}\\ - \lstinline[style=cmd]{dateiname.c -o dateiname.elf} - - \lstinline[style=cmd]{avr-objcopy -O ihex \}\\ - \lstinline[style=cmd]{dateiname-4.elf dateiname-4.hex} - - \lstinline[style=cmd]{avrdude -P /dev/ttyACM0 -c arduino \}\\ - \lstinline[style=cmd]{-p m328p -U flash:w:dateiname.hex} - - Notfalls: \lstinline[style=cmd]{sudo chmod 666 /dev/ttyACM0} - - \medskip - \item - Die Verdrahtung erfolgt auf Steckplatinen -- siehe - Abb.~\ref{Steckplatine}. - Die mit roten und blauen Streifen markierten Lochreihen sind - in Längsrichtung elektrisch verbunden, alle anderen in - Querrichtung mit einer Trennung in der Mitte. Üblicherweise - verwendet man die Längsrichtung für die Stromversorgung: Rot - = Versorgungsspannung, Blau = 0\,V. - \item - LEDs sind keine Glühlampen! Sie haben einen Pluspol (länger) - und einen Minuspol (kürzer, Gehäuse abgeflacht), und sie dürfen - \textbf{nur mit Vorwiderstand} betrieben werden, - andernfalls besteht die Gefahr einer Zerstörung der LED - und/oder des Arduino. - \item - Anstelle eines Drucktasters verwenden wir ein Stück Draht. - \item - Bevor Sie Ihre Schaltung unter Strom setzen, lassen Sie - diese \textbf{durch einen Betreuer prüfen}. - \end{itemize} - - \vspace*{-\medskipamount} - - \strut\hfill\emph{Viel Erfolg!}\\[-3.5cm] - - \end{multicols} - - \vspace*{-1.5\bigskipamount} - - \begin{figure}[h] - \begin{minipage}{7.3cm} - \includegraphics[width=8cm]{400_points_breadboard.jpg} - \vspace*{-1cm} - \caption{Steckplatine\label{Steckplatine}} - \vspace*{1cm} - \end{minipage}% - \begin{minipage}{9cm} - \small\raggedright - \vspace*{1cm} - Bildquelle: - \href{https://commons.wikimedia.org/wiki/File:400_points_breadboard.jpg}% - {\nolinkurl{https://commons.wikimedia.org/}\\ - \nolinkurl{wiki/File:400_points_breadboard.jpg}}\\ - Autor: \url{https://www.flickr.com/people/33504192@N00}\\ - Lizenz: CC-BY-SA 2.0 Generic - \end{minipage} - \end{figure} - - \vspace*{-1.5\bigskipamount} - - \vfill - - \begingroup - - \small - - \setlength{\leftskip}{3cm} - - Stand: 31.\ Oktober 2022 - -% Soweit nicht anders angegeben:\\ - Copyright \copyright\ 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022\quad Peter Gerwinski\\ - Lizenz: \mylicense - - Sie können diese Praktikumsunterlagen einschließlich \LaTeX-Quelltext -% und Beispielprogramme\\ - herunterladen unter:\\ - \url{https://gitlab.cvh-server.de/pgerwinski/hp} - - \endgroup - -\end{document} diff --git a/20221031/hp-musterloesung-20221031.pdf b/20221031/hp-musterloesung-20221031.pdf deleted file mode 100644 index a10e2c9e2717e7e4f4799aadff5c4517c2b442a7..0000000000000000000000000000000000000000 Binary files a/20221031/hp-musterloesung-20221031.pdf and /dev/null differ diff --git a/20221031/hp-musterloesung-20221031.tex b/20221031/hp-musterloesung-20221031.tex deleted file mode 100644 index 124e067b33be400f158d0293e3b8255d0c291532..0000000000000000000000000000000000000000 --- a/20221031/hp-musterloesung-20221031.tex +++ /dev/null @@ -1,554 +0,0 @@ -% hp-musterloesung-20221031.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Zahlensysteme, Mikrocontroller, Einfügen in Strings - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 31.\ Oktober 2022} - - \exercise{Zahlensysteme} - - Wandeln Sie ohne Hilfsmittel - - \begin{minipage}[t]{0.3\textwidth} - \begin{itemize} - \item - nach Dezimal: - \begin{itemize} - \item[(a)] - 0010\,0000$_2$ - \item[(b)] - 42$_{16}$ - \item[(c)] - 17$_8$ - \end{itemize} - \end{itemize} - \end{minipage}\hfill - \begin{minipage}[t]{0.3\textwidth} - \begin{itemize} - \item - nach Hexadezimal: - \begin{itemize} - \item[(d)] - 0010\,0000$_2$ - \item[(e)] - 42$_{10}$ - \item[(f)] - 192.168.20.254$_{256}$ - \end{itemize} - \end{itemize} - \end{minipage}\hfill - \begin{minipage}[t]{0.3\textwidth} - \begin{itemize} - \item - nach Binär: - \begin{itemize} - \item[(g)] - 750$_8$ - \item[(h)] - 42$_{10}$ - \item[(i)] - AFFE$_{16}$ - \end{itemize} - \end{itemize} - \end{minipage} - - \medskip - - Berechnen Sie ohne Hilfsmittel: - \begin{itemize} - \item[(j)] - 750$_8$ \& 666$_8$ - \item[(k)] - A380$_{16}$ + B747$_{16}$ - \item[(l)] - AFFE$_{16} >> 1$ - \end{itemize} - - Die tiefgestellte Zahl steht für die Basis des Zahlensystems. - Jede Teilaufgabe zählt 1 Punkt. \addtocounter{points}{12} - - (In der Klausur sind Hilfsmittel zugelassen, - daher ist dies \emph{keine\/} typische Klausuraufgabe.) - - \solution - - Wandeln Sie ohne Hilfsmittel - - \begin{itemize} - \item - nach Dezimal: - \begin{itemize} - \item[(a)] - $0010\,0000_2 = 32_{10}$ - - Eine Eins mit fünf Nullen dahinter steht binär für $2^5 = 32$:\\ - mit $1$ anfangen und fünfmal verdoppeln. - \item[(b)] - $42_{16} = 4 \cdot 16 + 2 \cdot 1 = 64 + 2 = 66$ - \item[(c)] - $17_8 = 1 \cdot 8 + 7 \cdot 1 = 8 + 7 = 15$ - \end{itemize} - Umwandlung von und nach Dezimal ist immer rechenaufwendig. - Umwandlungen zwischen Binär, Oktal und Hexadezimal gehen ziffernweise - und sind daher wesentlich einfacher. - \item - nach Hexadezimal: - \begin{itemize} - \item[(d)] - $0010\,0000_2 = 20_{16}$ - - Umwandlung von Binär nach Hexadezimal geht ziffernweise:\\ - Vier Binärziffern werden zu einer Hex-Ziffer. - \item[(e)] - $\rm 42_{10} = 32_{10} + 10_{10} = 20_{16} + A_{16} = 2A_{16}$ - \item[(f)] - $\rm 192.168.20.254_{256} = C0\,A8\,14\,FE_{16}$ - - Umwandlung von der Basis 256 nach Hexadezimal geht ziffernweise:\\ - Eine 256er-Ziffer wird zu zwei Hex-Ziffern. - - Da die 256er-Ziffern dezimal angegeben sind, - müssen wir viermal Dezimal nach Hexadezimal umwandeln. - Hierfür bieten sich unterschiedliche Wege an. - - $\rm 192_{10} = 128_{10} + 64_{10} = 1100\,0000_{2} = C0_{16}$ - - $\rm 168_{10} = 10_{10} \cdot 16_{10} + 8_{10} = A_{16} \cdot 10_{16} + 8_{16} = A8_{16}$ - - $20_{10} = 16_{10} + 4_{10} = 10_{16} + 4_{16} = 14$ - - $\rm 254_{10} = 255_{10} - 1_{10} = FF_{16} - 1_{16} = FE_{16}$ - \end{itemize} - \item - nach Binär: - \begin{itemize} - \item[(g)] - $750_8 = 111\,101\,000_2$ - - Umwandlung von Oktal nach Binär geht ziffernweise:\\ - Eine Oktalziffer wird zu drei Binärziffern. - \item[(h)] - $\rm 42_{10} = 2A_{16}$ (siehe oben) $= 0010\,1010_{16}$ - - Umwandlung von Hexadezimal nach Binär geht ziffernweise:\\ - Eine Hex-Ziffer wird zu vier Binärziffern. - \item[(i)] - $\rm AFFE_{16} = 1010\,1111\,1111\,1110_2$ - - Umwandlung von Hexadezimal nach Binär geht ziffernweise:\\ - Eine Hex-Ziffer wird zu vier Binärziffern. - \end{itemize} - \end{itemize} - - \medskip - - Berechnen Sie ohne Hilfsmittel: - \begin{itemize} - \item[(j)] - $750_8\,\&\,666_8 - = 111\,101\,000_2\,\&\,110\,110\,110_2 - = 110\,100\,000_2 - = 640_8$ - - Binäre Und-Operationen lassen sich am leichtesten - in binärer Schreibweise durchführen. - Umwandlung zwischen Oktal und Binär geht ziffernweise: - Eine Oktalziffer wird zu drei Binärziffern und umgekehrt. - - Mit etwas Übung funktionieren diese Operationen - auch direkt mit Oktalzahlen im Kopf. - - \item[(k)] - $\rm\phantom{+}A380_{16}$\\ - $\rm+\kern2ptB747_{16}$\\[-\medskipamount] - \rule{1.4cm}{0.5pt}\\ - $\rm 15AC7_{16}$ - \begin{picture}(0,0) - \put(-1.4,0.35){\mbox{\scriptsize\bf 1}} - \end{picture} - - Mit Hexadezimalzahlen (und Binär- und Oktal- und sonstigen Zahlen) - kann man genau wie mit Dezimalzahlen schriftlich rechnen. - Man muß nur daran denken, daß der "`Zehner"'-Überlauf nicht bei - $10_{10}$ stattfindet, sondern erst bei $10_{16} = 16_{10}$ - (hier: $\rm 8_{16} + 4_{16} = C_{16}$ und - $\rm 3_{16} + 7_{16} = A_{16}$, aber - $\rm A_{16} + B_{16} = 10_{10} + 11_{10} - = 21_{10} = 16_{10} + 5_{10} = 10_{16} + 5_{16} = 15_{16}$). - - \item[(l)] - $\rm AFFE_{16} >> 1 - = 1010\,1111\,1111\,1110_2 >> 1 - = 0101\,0111\,1111\,1111_2 - = 57FF_{16}$ - - Bit-Verschiebungen lassen sich am leichtesten - in binärer Schreibweise durchführen. - Umwandlung zwischen Hexadezimal und Binär geht ziffernweise: - Eine Hex-Ziffer wird zu vier Binärziffern und umgekehrt. - - Mit etwas Übung funktionieren diese Operationen - auch direkt mit Hexadezimalzahlen im Kopf. - - \end{itemize} - - \exercise{Mikrocontroller} - - \begin{minipage}[t]{10cm} - An die vier Ports eines ATmega16-Mikrocontrollers sind Leuchtdioden angeschlossen: - \begin{itemize} - \item - von links nach rechts an die Ports A, B, C und D, - \item - von oben nach unten an die Bits Nr.\ 0 bis 7. - \end{itemize} - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221031}{aufgabe-2.c}): - - \begin{lstlisting}[gobble=6] - #include <avr/io.h> - - int main (void) - { - DDRA = 0xff; - DDRB = 0xff; - DDRC = 0xff; - DDRD = 0xff; - PORTA = 0x1f; - PORTB = 0x10; - PORTD = 0x10; - PORTC = 0xfc; - while (1); - return 0; - } - \end{lstlisting} - \end{minipage}\hfill - \begin{minipage}[t]{3cm} - \strut\\[-\baselineskip] - \includegraphics[width=3cm]{leds.jpg} - \end{minipage} - - \vspace*{-3cm} - - \strut\hfill - \begin{minipage}{11.8cm} - \begin{itemize} - \item[(a)] - Was bewirkt dieses Programm? \points{4} - \item[(b)] - Wozu dienen die ersten vier Zeilen des Hauptprogramms? \points{2} - \item[(c)] - Was würde stattdessen die Zeile \lstinline{DDRA, DDRB, DDRC, DDRD = 0xff;} bewirken? - \points{2} - \item[(d)] - Schreiben Sie das Programm so um, - daß die durch das Programm dargestellte Figur spiegelverkehrt erscheint. \points{3} - \item[(e)] - Wozu dient das \lstinline{while (1)}? \points{2} - \item - Alle Antworten bitte mit Begründung. - \end{itemize} - \end{minipage} - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Was bewirkt dieses Programm?} - - \newcommand{\x}{$\bullet$} - \renewcommand{\o}{$\circ$} - - \begin{minipage}[t]{0.75\textwidth}\parskip\smallskipamount - Es läßt die LEDs in dem rechts abgebildeten Muster aufleuchten,\\ - das z.\,B.\ als die Ziffer 4 gelesen werden kann. - - (Das Zeichen \x\ steht für eine leuchtende, \o\ für eine nicht leuchtende LED.) - - Die erste Spalte (Port A) von unten nach oben gelesen (Bit 7 bis 0)\\ - entspricht der Binärdarstellung von \lstinline{0x1f}: 0001\,1111. - - Die dritte Spalte (Port C) von unten nach oben gelesen (Bit 7 bis 0)\\ - entspricht der Binärdarstellung von \lstinline{0xfc}: 1111\,1100. - - Die zweite und vierte Spalte (Port B und D) von unten nach oben gelesen\\ - (Bit 7 bis 0) entsprechen der Binärdarstellung von \lstinline{0x10}: 0001\,0000. - - Achtung: Die Zuweisung der Werte an die Ports erfolgt im Programm\\ - \emph{nicht\/} in der Reihenfolge A B C D, sondern in der Reihenfolge A B D C. - \end{minipage}\hfill - \begin{minipage}[t]{0.15\textwidth} - \vspace*{-0.5cm}% - \begin{tabular}{cccc} - \x & \o & \o & \o \\ - \x & \o & \o & \o \\ - \x & \o & \x & \o \\ - \x & \o & \x & \o \\ - \x & \x & \x & \x \\ - \o & \o & \x & \o \\ - \o & \o & \x & \o \\ - \o & \o & \x & \o \\ - \end{tabular} - \end{minipage} - - \item[(b)] - \textbf{Wozu dienen die ersten vier Zeilen des Hauptprogramms?} - - Mit diesen Zeilen werden alle jeweils 8 Bits aller 4 Ports - als Output-Ports konfiguriert. - - \item[(c)] - \textbf{Was würde stattdessen die Zeile \lstinline{DDRA, DDRB, DDRC, DDRD = 0xff;} bewirken?} - - Der Komma-Operator in C bewirkt, daß der erste Wert berechnet - und wieder verworfen wird und stattdessen der zweite Wert weiterverarbeitet wird. - Konkret hier hätte das zur Folge, - daß \lstinline{DDRA}, \lstinline{DDRB} und \lstinline{DDRC} - gelesen und die gelesenen Werte ignoriert werden; - anschließend wird \lstinline{DDRD} der Wert \lstinline{0xff} zugewiesen. - Damit würde also nur einer von vier Ports überhaupt konfiguriert. - - Da es sich bei den \lstinline{DDR}-Variablen - um \lstinline{volatile}-Variable handelt, - nimmt der Compiler an, daß der Lesezugriff schon irgendeinen Sinn hätte. - Der Fehler bliebe also unbemerkt. - - \item[(d)] - \textbf{Schreiben Sie das Programm so um, - daß die durch das Programm dargestellte Figur spiegelverkehrt erscheint.} - - Hierzu vertauschen wir die Zuweisungen - an \lstinline{PORTA} und \lstinline{PORTD} - sowie die Zuweisungen - an \lstinline{PORTB} und \lstinline{PORTC}: - - \begin{lstlisting}[gobble=8] - PORTD = 0x1f; - PORTC = 0x10; - PORTA = 0x10; - PORTB = 0xfc; - \end{lstlisting} - - Damit ergibt sich eine Spiegelung an der vertikalen Achse. - - Alternativ kann man auch an der horizontalen Achse spiegeln. - Dafür muß man die Bits in den Hexadezimalzahlen umdrehen: - - \begin{lstlisting}[gobble=8] - PORTA = 0xf8; - PORTB = 0x08; - PORTD = 0x08; - PORTC = 0x3f; - \end{lstlisting} - - Die Frage, welche der beiden Spiegelungen gewünscht ist, - wäre übrigens \emph{auch in der Klausur zulässig}. - - \item[(e)] - \textbf{Wozu dient das \lstinline{while (1)}?} - - Mit dem \lstinline{return}-Befehl am Ende des Hauptprogramms - gibt das Programm die Kontrolle an das Betriebssystem zurück. - - Dieses Programm jedoch läuft auf einem Mikrocontroller, - auf dem es kein Betriebssystem gibt. - Wenn das \lstinline{return} ausgeführt würde, - hätte es ein undefiniertes Verhalten zur Folge. - - Um dies zu verhindern, endet das Programm in einer Endlosschleife, - mit der wir den Mikrocontroller anweisen, - nach der Ausführung des Programms \emph{nichts mehr\/} zu tun - (im Gegensatz zu: \emph{irgendetwas Undefiniertes\/} zu tun). - - \end{itemize} - - \exercise{Einfügen in Strings} - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221031}{aufgabe-2.c}): -% \begin{lstlisting}[style=numbered] - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - void insert_into_string (char src, char *target, int pos) - { - int len = strlen (target); - for (int i = pos; i < len; i++) - target[i+1] = target[i]; - target[pos] = src; - } - - int main (void) - { - char test[100] = "Hochshule Bochum"; - insert_into_string ('c', test, 5); - printf ("%s\n", test); - return 0; - } - \end{lstlisting} - Die Ausgabe des Programms lautet: - \lstinline[style=terminal]{Hochschhhhhhhhhhh} - - \begin{enumerate}[\quad(a)] - \item - Erklären Sie, wie die Ausgabe zustandekommt. - \points{3} -% \workspace{12} - \item - Schreiben Sie die Funktion \lstinline|insert_into_string()| so um, - daß sie den Buchstaben \lstinline{src} an der Stelle \lstinline{pos} - in den String \lstinline{target} einfügt.\par - Die Ausgabe des Programms müßte dann - \lstinline[style=terminal]{Hochschule Bochum} lauten. - \points{2} -% \workspace{13} - \item - Was kann passieren, wenn Sie die Zeile - \lstinline{char test[100] = "Hochshule Bochum";}\\ - durch - \lstinline{char test[] = "Hochshule Bochum";} ersetzen? - Begründen Sie Ihre Antwort. - \points{2} -% \workspace{10} - \item - Was kann passieren, wenn Sie die Zeile - \lstinline{char test[100] = "Hochshule Bochum";}\\ - durch - \lstinline{char *test = "Hochshule Bochum";} ersetzen? - Begründen Sie Ihre Antwort. - \points{2} -% \workspace{10} -% \item -% Schreiben Sie eine Funktion -% \lstinline{void insert_into_string_sorted (char src, char *target)}, -% die voraussetzt, daß der String \lstinline{target} alphabetisch sortiert ist -% und den Buchstaben \lstinline{src} an der alphabetisch richtigen Stelle -% einfügt. Diese Funktion darf die bereits vorhandene Funktion -% \lstinline|insert_into_string()| aufrufen.\\ -% \points{4}\par -% Zum Testen eignen sich die folgenden Zeilen im Hauptprogramm: -% \begin{lstlisting}[gobble=8] -% char test[100] = ""; -% insert_into_string_sorted ('c', test); -% insert_into_string_sorted ('a', test); -% insert_into_string_sorted ('d', test); -% insert_into_string_sorted ('b', test); -% \end{lstlisting} -% Danach sollte \lstinline{test[]} die Zeichenfolge \lstinline{"abcd"} enthalten. -% \workspace{14} -% \item -% Wie schnell (Landau-Symbol in Abhängigkeit von der Länge $n$ des Strings) -% arbeitet Ihre Funktion -% \lstinline{void insert_into_string_sorted (char src, char *target)} -% und warum? -% \points{1} -% \workspace{10} -% \item -% Beschreiben Sie -- in Worten oder als C-Quelltext --, wie man die Funktion\\ -% \lstinline{void insert_into_string_sorted (char src, char *target)} -% so gestalten kann,\\ -% daß sie in $\mathcal{O}(\log n)$ arbeitet. -% \points{3} -% \workspace{35} - \end{enumerate} - - \solution - - \begin{enumerate}[\quad(a)] - \item - \textbf{Erklären Sie, wie die Ausgabe zustandekommt.} - - In der Schleife wird \emph{zuerst\/} der nächste Buchstabe \lstinline{target[i + 1]} - gleich dem aktuellen gesetzt - und \emph{danach\/} der Zähler \lstinline{i} erhöht. - Dadurch wird im nächsten Schleifendurchlauf der bereits verschobene Buchstabe - noch weiter geschoben und letztlich alle Buchstaben in \lstinline{target[]} - durch den an der Stelle \lstinline{pos} ersetzt. - - \item - \textbf{Schreiben Sie die Funktion \lstinline|insert_into_string()| so um, - daß sie den Buchstben \lstinline{src} an der Stelle \lstinline{pos} - in den String \lstinline{target} einfügt.}\par - \textbf{Die Ausgabe des Programms müßte dann - \lstinline[style=terminal]{Hochschule Bochum} lauten.} - - Um im String "`Platz zu schaffen"', muß man von hinten beginnen, - also die Schleife umdrehen\\ - (siehe: \gitfile{hp}{2022ws/20221031}{loesung-3.c}): - \begin{lstlisting}{gobble=8} - for (int i = len; i >= pos; i--) - target[i + 1] = target[i]; - \end{lstlisting} - - \item - \textbf{Was kann passieren, wenn Sie die Zeile - \lstinline{char test[100] = "Hochshule Bochum";}\\ - durch - \lstinline{char test[] = "Hochshule Bochum";} - ersetzen und warum?} - - Die Schreibweise \lstinline{test[]} bedeutet, - daß der Compiler selbst zählt, wieviel Speicherplatz der String benötigt, - un dann genau die richtige Menge Speicher reserviert - (anstatt, wie wir es manuell getan haben, pauschal Platz für 100 Zeichen). - - Wenn wir nun in den String ein zusätzliches Zeichen einfügen, - ist dafür kein Speicherplatz reserviert worden, - und wir \textbf{überschreiben} dann Speicher, an dem sich andere Variable befinden, - was zu einem \textbf{Absturz} führen kann. - - Da wir hier nur ein einziges Zeichen schreiben, - wird dieser Fehler nicht sofort auffallen. - Dies ist schlimmer, als wenn das Programm direkt beim ersten Test abstürzt, - denn dadurch entsteht bei uns der Eindruck, es sei in Ordnung. - Wenn danach der Fehler in einer Produktivumgebung auftritt, - kann dadurch Schaden entstehen -- je nach Einsatzgebiet der Software - u.\,U.\ erheblicher Vermögens-, Sach- und/oder Personenschaden - (z.\,B.\ Absturz eines Raumflugkörpers). - - \item - \textbf{Was kann passieren, wenn Sie - \lstinline{char test[100] = "Hochshule Bochum";}\\ - durch - \lstinline{char *test = "Hochshule Bochum";} - ersetzen und warum?} - - In diesem Fall wird der Speicher für den eigentlichen String - in einem unbenannten, \textbf{nicht schreibbaren} Teil des Speichers reserviert. - Unser Versuch, dorthin ein zusätzliches Zeichen zu schreiben, - fürt dann normalerweise zu einem \textbf{Absturz}. - - In manchen Systemen (Betriebssystem, Compiler, \dots) - ist der Speicherbereich tatsächlich sehr wohl schreibbar. - In diesem Fall tritt der Absturz nicht immer und nicht immer sofort auf -- - genau wie in Aufgabenteil (c). - - \end{enumerate} - -\end{document} diff --git a/20221031/hp-uebung-20221031.pdf b/20221031/hp-uebung-20221031.pdf deleted file mode 100644 index 07b200cd72ae7406dcb15eb2b94b0aec6e2675ff..0000000000000000000000000000000000000000 Binary files a/20221031/hp-uebung-20221031.pdf and /dev/null differ diff --git a/20221031/hp-uebung-20221031.tex b/20221031/hp-uebung-20221031.tex deleted file mode 100644 index c8039a92a5de856a8ba95ca5380f2cd7e2babd45..0000000000000000000000000000000000000000 --- a/20221031/hp-uebung-20221031.tex +++ /dev/null @@ -1,262 +0,0 @@ -% hp-uebung-20221031.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Zahlensysteme, Mikrocontroller, Einfügen in Strings - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \thispagestyle{empty} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 31.\ Oktober 2022} - - Diese Übung enthält Punkteangaben wie in einer Klausur. - Um zu "`bestehen"', müssen Sie innerhalb von 85 Minuten - unter Verwendung ausschließlich zugelassener Hilfsmittel - 17 Punkte (von insgesamt \totalpoints) erreichen. - - \exercise{Zahlensysteme} - - Wandeln Sie ohne Hilfsmittel - - \begin{minipage}[t]{0.3\textwidth} - \begin{itemize} - \item - nach Dezimal: - \begin{itemize} - \item[(a)] - 0010\,0000$_2$ - \item[(b)] - 42$_{16}$ - \item[(c)] - 17$_8$ - \end{itemize} - \end{itemize} - \end{minipage}\hfill - \begin{minipage}[t]{0.3\textwidth} - \begin{itemize} - \item - nach Hexadezimal: - \begin{itemize} - \item[(d)] - 0010\,0000$_2$ - \item[(e)] - 42$_{10}$ - \item[(f)] - 192.168.20.254$_{256}$ - \end{itemize} - \end{itemize} - \end{minipage}\hfill - \begin{minipage}[t]{0.3\textwidth} - \begin{itemize} - \item - nach Binär: - \begin{itemize} - \item[(g)] - 750$_8$ - \item[(h)] - 42$_{10}$ - \item[(i)] - AFFE$_{16}$ - \end{itemize} - \end{itemize} - \end{minipage} - - \medskip - - Berechnen Sie ohne Hilfsmittel: - \begin{itemize} - \item[(j)] - 750$_8$ \& 666$_8$ - \item[(k)] - A380$_{16}$ + B747$_{16}$ - \item[(l)] - AFFE$_{16} >> 1$ - \end{itemize} - - Die tiefgestellte Zahl steht für die Basis des Zahlensystems. - Jede Teilaufgabe zählt 1 Punkt. \addtocounter{points}{12} - - (In der Klausur sind Hilfsmittel zugelassen, - daher ist dies \emph{keine\/} typische Klausuraufgabe.) - - \exercise{Mikrocontroller} - - \begin{minipage}[t]{10cm} - An die vier Ports eines ATmega16-Mikrocontrollers sind Leuchtdioden angeschlossen: - \begin{itemize} - \item - von links nach rechts an die Ports A, B, C und D, - \item - von oben nach unten an die Bits Nr.\ 0 bis 7. - \end{itemize} - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221031}{aufgabe-2.c}): - - \begin{lstlisting}[gobble=6] - #include <avr/io.h> - - int main (void) - { - DDRA = 0xff; - DDRB = 0xff; - DDRC = 0xff; - DDRD = 0xff; - PORTA = 0x1f; - PORTB = 0x10; - PORTD = 0x10; - PORTC = 0xfc; - while (1); - return 0; - } - \end{lstlisting} - \end{minipage}\hfill - \begin{minipage}[t]{3cm} - \strut\\[-\baselineskip] - \includegraphics[width=3cm]{leds.jpg} - \end{minipage} - - \vspace*{-3cm} - - \strut\hfill - \begin{minipage}{11.8cm} - \begin{itemize} - \item[(a)] - Was bewirkt dieses Programm? \points{4} - \item[(b)] - Wozu dienen die ersten vier Zeilen des Hauptprogramms? \points{2} - \item[(c)] - Was würde stattdessen die Zeile \lstinline{DDRA, DDRB, DDRC, DDRD = 0xff;} bewirken? - \points{2} - \item[(d)] - Schreiben Sie das Programm so um, - daß die durch das Programm dargestellte Figur spiegelverkehrt erscheint. \points{3} - \item[(e)] - Wozu dient das \lstinline{while (1)}? \points{2} - \item - Alle Antworten bitte mit Begründung. - \end{itemize} - \end{minipage} - - \exercise{Einfügen in Strings} - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221031}{aufgabe-3.c}): -% \begin{lstlisting}[style=numbered] - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - void insert_into_string (char src, char *target, int pos) - { - int len = strlen (target); - for (int i = pos; i < len; i++) - target[i+1] = target[i]; - target[pos] = src; - } - - int main (void) - { - char test[100] = "Hochshule Bochum"; - insert_into_string ('c', test, 5); - printf ("%s\n", test); - return 0; - } - \end{lstlisting} - Die Ausgabe des Programms lautet: - \lstinline[style=terminal]{Hochschhhhhhhhhhh} - - \begin{enumerate}[\quad(a)] - \item - Erklären Sie, wie die Ausgabe zustandekommt. - \points{3} -% \workspace{12} - \item - Schreiben Sie die Funktion \lstinline|insert_into_string()| so um, - daß sie den Buchstaben \lstinline{src} an der Stelle \lstinline{pos} - in den String \lstinline{target} einfügt.\par - Die Ausgabe des Programms müßte dann - \lstinline[style=terminal]{Hochschule Bochum} lauten. - \points{2} -% \workspace{13} - \item - Was kann passieren, wenn Sie die Zeile - \lstinline{char test[100] = "Hochshule Bochum";}\\ - durch - \lstinline{char test[] = "Hochshule Bochum";} ersetzen? - Begründen Sie Ihre Antwort. - \points{2} -% \workspace{10} - \item - Was kann passieren, wenn Sie die Zeile - \lstinline{char test[100] = "Hochshule Bochum";}\\ - durch - \lstinline{char *test = "Hochshule Bochum";} ersetzen? - Begründen Sie Ihre Antwort. - \points{2} -% \workspace{10} -% \item -% Schreiben Sie eine Funktion -% \lstinline{void insert_into_string_sorted (char src, char *target)}, -% die voraussetzt, daß der String \lstinline{target} alphabetisch sortiert ist -% und den Buchstaben \lstinline{src} an der alphabetisch richtigen Stelle -% einfügt. Diese Funktion darf die bereits vorhandene Funktion -% \lstinline|insert_into_string()| aufrufen.\\ -% \points{4}\par -% Zum Testen eignen sich die folgenden Zeilen im Hauptprogramm: -% \begin{lstlisting}[gobble=8] -% char test[100] = ""; -% insert_into_string_sorted ('c', test); -% insert_into_string_sorted ('a', test); -% insert_into_string_sorted ('d', test); -% insert_into_string_sorted ('b', test); -% \end{lstlisting} -% Danach sollte \lstinline{test[]} die Zeichenfolge \lstinline{"abcd"} enthalten. -% \workspace{14} -% \item -% Wie schnell (Landau-Symbol in Abhängigkeit von der Länge $n$ des Strings) -% arbeitet Ihre Funktion -% \lstinline{void insert_into_string_sorted (char src, char *target)} -% und warum? -% \points{1} -% \workspace{10} -% \item -% Beschreiben Sie -- in Worten oder als C-Quelltext --, wie man die Funktion\\ -% \lstinline{void insert_into_string_sorted (char src, char *target)} -% so gestalten kann,\\ -% daß sie in $\mathcal{O}(\log n)$ arbeitet. -% \points{3} -% \workspace{35} - \end{enumerate} - - \begin{flushright} - \textit{Viel Erfolg!} - \end{flushright} - - \makeatletter - \immediate\write\@mainaux{\string\gdef\string\totalpoints{\arabic{points}}} - \makeatother - -\end{document} diff --git a/20221031/int-types-01.c b/20221031/int-types-01.c deleted file mode 100644 index f25506073bdc0111222ff93f88d586b35383e0e8..0000000000000000000000000000000000000000 --- a/20221031/int-types-01.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> -#include <stdint.h> -#include <inttypes.h> - -int main (void) -{ - uint64_t x = 42; - printf ("Die Antwort lautet: %" PRIu64 "\n", x); - return 0; -} diff --git a/20221031/int-types-01.txt b/20221031/int-types-01.txt deleted file mode 100644 index 58fdfb4d785ccbeffe1f9498d3e11df72fce0e68..0000000000000000000000000000000000000000 --- a/20221031/int-types-01.txt +++ /dev/null @@ -1,34 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221031> cat int-types-01.c -#include <stdio.h> -#include <stdint.h> -#include <inttypes.h> - -int main (void) -{ - uint64_t x = 42; - printf ("Die Antwort lautet: %" PRIu64 "\n", x); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221031> gcc -Wall -O int-types-01.c -E -P | tail -{ - return __wcstoul_internal (nptr, endptr, base, 0); -} - -int main (void) -{ - uint64_t x = 42; - printf ("Die Antwort lautet: %" "l" "u" "\n", x); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221031> gcc -m32 -Wall -O int-types-01.c -E -P | tail -{ - return __wcstoull_internal (nptr, endptr, base, 0); -} - -int main (void) -{ - uint64_t x = 42; - printf ("Die Antwort lautet: %" "ll" "u" "\n", x); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221031> diff --git a/20221031/io-ports-and-interrupts.pdf b/20221031/io-ports-and-interrupts.pdf deleted file mode 120000 index bcd46f7afb35605b20bdb05637e6de0a039893ec..0000000000000000000000000000000000000000 --- a/20221031/io-ports-and-interrupts.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/io-ports-and-interrupts.pdf \ No newline at end of file diff --git a/20221031/leds.jpg b/20221031/leds.jpg deleted file mode 120000 index 5e66b77c5c428129f6f4abcc80ae48f0c9a53c35..0000000000000000000000000000000000000000 --- a/20221031/leds.jpg +++ /dev/null @@ -1 +0,0 @@ -../common/leds.jpg \ No newline at end of file diff --git a/20221031/loesung-3.c b/20221031/loesung-3.c deleted file mode 100644 index 85abfcf3e1e4bacf454acd10f6832b757a64ac35..0000000000000000000000000000000000000000 --- a/20221031/loesung-3.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void insert_into_string (char src, char *target, int pos) -{ - int len = strlen (target); - for (int i = len; i >= pos; i--) - target[i + 1] = target[i]; - target[pos] = src; -} - -int main (void) -{ - char test[100] = "Hochshule Bochum"; - insert_into_string ('c', test, 5); - printf ("%s\n", test); - return 0; -} diff --git a/20221031/logo-hochschule-bochum-cvh-text-v2.pdf b/20221031/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221031/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221031/logo-hochschule-bochum.pdf b/20221031/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221031/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221031/pgscript.sty b/20221031/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221031/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221031/pgslides.sty b/20221031/pgslides.sty deleted file mode 120000 index 5be1416f4216f076aa268901f52a15d775e43f64..0000000000000000000000000000000000000000 --- a/20221031/pgslides.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgslides.sty \ No newline at end of file diff --git a/20221031/philosophy-03.txt b/20221031/philosophy-03.txt deleted file mode 100644 index b201e09fe01bbcda4b0582c14639e79335688876..0000000000000000000000000000000000000000 --- a/20221031/philosophy-03.txt +++ /dev/null @@ -1,24 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221031> cat philosophy.c -#include <stdio.h> -#include "answer.h" - -int main (void) -{ - printf ("The answer is %d.\n", answer ()); - return 0; -} -cassini/home/peter/bo/2022ws/hp/20221031> cat answer.h -extern int answer (void); -cassini/home/peter/bo/2022ws/hp/20221031> cat answer.c -#include "answer.h" - -int answer (void) -{ - return 23; -} -cassini/home/peter/bo/2022ws/hp/20221031> gcc -Wall -O philosophy.c -c -cassini/home/peter/bo/2022ws/hp/20221031> gcc -Wall -O answer.c -c -cassini/home/peter/bo/2022ws/hp/20221031> gcc philosophy.o answer.o -o philosophy -cassini/home/peter/bo/2022ws/hp/20221031> ./philosophy -The answer is 23. -cassini/home/peter/bo/2022ws/hp/20221031> \ No newline at end of file diff --git a/20221031/philosophy-04.txt b/20221031/philosophy-04.txt deleted file mode 100644 index cf8db4e6dd5aea1e9424d2bd3bc9150bc21076a9..0000000000000000000000000000000000000000 --- a/20221031/philosophy-04.txt +++ /dev/null @@ -1,17 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221031> ls -lrt philosophy* answer.* --rw-r--r-- 1 peter peter 26 Nov 22 2012 answer.h --rw-r--r-- 1 peter peter 117 Nov 22 2012 philosophy.c --rw-r--r-- 1 peter peter 56 Nov 21 2013 answer.c --rw-r--r-- 1 peter peter 1632 Okt 31 12:28 philosophy.o --rw-r--r-- 1 peter peter 1208 Okt 31 12:29 answer.o --rwxr-xr-x 1 peter peter 16680 Okt 31 12:29 philosophy --rw-r--r-- 1 peter peter 705 Okt 31 12:29 philosophy-03.txt -cassini/home/peter/bo/2022ws/hp/20221031> rm philosophy -cassini/home/peter/bo/2022ws/hp/20221031> make -f Makefile-1 -gcc philosophy.o answer.o -o philosophy -cassini/home/peter/bo/2022ws/hp/20221031> rm philosophy.o answer.o -cassini/home/peter/bo/2022ws/hp/20221031> make -f Makefile-1 -gcc -Wall -O philosophy.c -c -gcc -Wall -O answer.c -c -gcc philosophy.o answer.o -o philosophy -cassini/home/peter/bo/2022ws/hp/20221031> diff --git a/20221031/philosophy.c b/20221031/philosophy.c deleted file mode 100644 index e9f508a501d9ec66d02e0636a9f6c71f2c7a8594..0000000000000000000000000000000000000000 --- a/20221031/philosophy.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> -#include "answer.h" - -int main (void) -{ - printf ("The answer is %d.\n", answer ()); - return 0; -} diff --git a/20221107/Makefile b/20221107/Makefile deleted file mode 100644 index 7ae33df99f68fcf460324cfbb008f3f7a3863638..0000000000000000000000000000000000000000 --- a/20221107/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -%.elf: %.c - avr-gcc -Wall -Os -mmcu=atmega328p $< -o $@ - -%.hex: %.elf - avr-objcopy -O ihex $< $@ - -download: - ./download.sh diff --git a/20221107/aufgabe-2.c b/20221107/aufgabe-2.c deleted file mode 100644 index d0b065941fbc0082bf867d872527299dca97b98f..0000000000000000000000000000000000000000 --- a/20221107/aufgabe-2.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <string.h> - -int fun_1 (char *s) -{ - int x = 0; - for (int i = 0; i < strlen (s); i++) - x += s[i]; - return x; -} - -int fun_2 (char *s) -{ - int i = 0, x = 0; - int len = strlen (s); - while (i < len) - x += s[i++]; - return x; -} diff --git a/20221107/aufgabe-3.c b/20221107/aufgabe-3.c deleted file mode 100644 index 4c95eb6ad4881c904448309c6b7c46fa101cc109..0000000000000000000000000000000000000000 --- a/20221107/aufgabe-3.c +++ /dev/null @@ -1,33 +0,0 @@ -#include <stdint.h> -#include <avr/io.h> -#include <avr/interrupt.h> - -uint8_t counter = 1; -uint8_t leds = 0; - -ISR (TIMER0_COMP_vect) -{ - if (counter == 0) - { - leds = (leds + 1) % 8; - PORTC = leds << 4; - } - counter++; -} - -void init (void) -{ - cli (); - TCCR0 = (1 << CS01) | (1 << CS00); - TIMSK = 1 << OCIE0; - sei (); - DDRC = 0x70; -} - -int main (void) -{ - init (); - while (1) - ; /* do nothing */ - return 0; -} diff --git a/20221107/blink-0.c b/20221107/blink-0.c deleted file mode 100644 index b0022c681fd1482ed0a6d9fded7bb0a54699de32..0000000000000000000000000000000000000000 --- a/20221107/blink-0.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <avr/io.h> - -int main (void) -{ - DDRD = 0x40; /* binär: 0100 0000 */ - PORTD = 0x40; /* binär: 0100 0000 */ - while (1); - return 0; -} diff --git a/20221107/blink-0a.c b/20221107/blink-0a.c deleted file mode 100644 index 7093fa4cbf094be60a9ae35117c84be13258235c..0000000000000000000000000000000000000000 --- a/20221107/blink-0a.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <avr/io.h> - -int main (void) -{ - DDRD = 0x40; /* binär: 0100 0000 */ - PORTD = 0x00; /* binär: 0000 0000 */ - while (1); - return 0; -} diff --git a/20221107/blink-1.c b/20221107/blink-1.c deleted file mode 100644 index 6d28dce84f94375094c98479c30a54ace1b2a9d9..0000000000000000000000000000000000000000 --- a/20221107/blink-1.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <avr/io.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -int main (void) -{ - DDRD = 0x01; - PORTD |= 0x01; - while (1) - { - _delay_ms (500); - PORTD &= ~0x01; - _delay_ms (500); - PORTD |= 0x01; - } - return 0; -} diff --git a/20221107/blink-10.c b/20221107/blink-10.c deleted file mode 100644 index 6c36fbe183bb4c68bb0ae757145dd96897106dd9..0000000000000000000000000000000000000000 --- a/20221107/blink-10.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> -#include <stdint.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -volatile uint8_t key_pressed = 0; - -ISR (INT0_vect) /* PD2 */ -{ - key_pressed = 1; -} - -int main (void) -{ - cli (); - EICRA = 1 << ISC00 | 1 << ISC01; /* INT0: steigende Flanke */ - EIMSK = 1 << INT0; /* INT0 einschalten */ - sei (); - DDRD = 0xfb; /* binär: 1111 1011 */ - PORTD = 0x44; /* binär: 0100 0100 */ - while (1) - { - while (!key_pressed) - ; /* just wait */ - PORTD ^= 0x40; - key_pressed = 0; - } - return 0; -} diff --git a/20221107/blink-10.s b/20221107/blink-10.s deleted file mode 100644 index b77f3989646f63d842f03582b278c2b2b8937ca4..0000000000000000000000000000000000000000 --- a/20221107/blink-10.s +++ /dev/null @@ -1,75 +0,0 @@ - .file "blink-10.c" -__SP_H__ = 0x3e -__SP_L__ = 0x3d -__SREG__ = 0x3f -__tmp_reg__ = 0 -__zero_reg__ = 1 - .text -.global __vector_1 - .type __vector_1, @function -__vector_1: - push r1 - push r0 - in r0,__SREG__ - push r0 - clr __zero_reg__ - push r24 -/* prologue: Signal */ -/* frame size = 0 */ -/* stack size = 4 */ -.L__stack_usage = 4 - ldi r24,lo8(1) - sts key_pressed,r24 -/* epilogue start */ - pop r24 - pop r0 - out __SREG__,r0 - pop r0 - pop r1 - reti - .size __vector_1, .-__vector_1 - .section .text.startup,"ax",@progbits -.global main - .type main, @function -main: -/* prologue: function */ -/* frame size = 0 */ -/* stack size = 0 */ -.L__stack_usage = 0 -/* #APP */ - ; 17 "blink-10.c" 1 - cli - ; 0 "" 2 -/* #NOAPP */ - ldi r24,lo8(3) - sts 105,r24 - ldi r24,lo8(1) - out 0x1d,r24 -/* #APP */ - ; 20 "blink-10.c" 1 - sei - ; 0 "" 2 -/* #NOAPP */ - ldi r24,lo8(-5) - out 0xa,r24 - ldi r24,lo8(68) - out 0xb,r24 - ldi r25,lo8(64) -.L3: - lds r24,key_pressed - tst r24 - breq .L3 - in r24,0xb - eor r24,r25 - out 0xb,r24 - sts key_pressed,__zero_reg__ - rjmp .L3 - .size main, .-main -.global key_pressed - .section .bss - .type key_pressed, @object - .size key_pressed, 1 -key_pressed: - .zero 1 - .ident "GCC: (GNU) 5.4.0" -.global __do_clear_bss diff --git a/20221107/blink-11.c b/20221107/blink-11.c deleted file mode 100644 index 72020dc5c582d1ce19e4efd8a079818760e89f27..0000000000000000000000000000000000000000 --- a/20221107/blink-11.c +++ /dev/null @@ -1,32 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> -#include <stdint.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -volatile uint8_t key_pressed = 0; - -ISR (INT0_vect) /* PD2 */ -{ - key_pressed = 1; -} - -int main (void) -{ - cli (); - EICRA = 1 << ISC00 | 1 << ISC01; /* INT0: steigende Flanke */ - EIMSK = 1 << INT0; /* INT0 einschalten */ - sei (); - DDRD = 0xfb; /* binär: 1111 1011 */ - PORTD = 0x44; /* binär: 0100 0100 */ - while (1) - { - while (!key_pressed) - ; /* just wait */ - _delay_ms (1); - PORTD ^= 0x40; - key_pressed = 0; - } - return 0; -} diff --git a/20221107/blink-1a.c b/20221107/blink-1a.c deleted file mode 100644 index f594cc175fa238d3ba3f930bc8bcbfeb1ddaa43b..0000000000000000000000000000000000000000 --- a/20221107/blink-1a.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <avr/io.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -int main (void) -{ - DDRD = 0xff; /* 1111 1111 --> alle Ports als Output-Ports nutzen */ - PORTD = 0x1a; /* 0001 1010 */ - while (1) - { - _delay_ms (500); - PORTD &= ~0x01; - _delay_ms (500); - PORTD |= 0x01; - } - return 0; -} diff --git a/20221107/blink-1b.c b/20221107/blink-1b.c deleted file mode 100644 index f435112888a5ba118a33c689de63462776d1d072..0000000000000000000000000000000000000000 --- a/20221107/blink-1b.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <avr/io.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -int main (void) -{ - DDRD = 0x7f; /* 0111 1111 --> alle Ports als Output-Ports nutzen */ - PORTD = 0x01; /* 0000 0001 */ - while (1) - { - while (PIND & 0x80) /* 1000 0000 */ - { - _delay_ms (500); - PORTD &= ~0x01; - _delay_ms (500); - PORTD |= 0x01; - } - } - return 0; -} diff --git a/20221107/blink-2.c b/20221107/blink-2.c deleted file mode 100644 index 9389b19b1bf46d5ca90bac823e3f94269fe02878..0000000000000000000000000000000000000000 --- a/20221107/blink-2.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <avr/io.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -int main (void) -{ - DDRD = 0x02; /* binär: 0000 0010 */ - PORTD = 0x02; - while (1) - { - _delay_ms (250); - PORTD ^= 0x02; - } - return 0; -} diff --git a/20221107/blink-2a.c b/20221107/blink-2a.c deleted file mode 100644 index a2e246a00bb109a865f246dabc20a0e1f0bbc792..0000000000000000000000000000000000000000 --- a/20221107/blink-2a.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <avr/io.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -int main (void) -{ - DDRD = 0x04; /* binär: 0000 0100 */ - PORTD = 0x04; - while (1) - { - _delay_ms (250); - PORTD ^= 0x04; - } - return 0; -} diff --git a/20221107/blink-3.c b/20221107/blink-3.c deleted file mode 100644 index 5268e7977f0f2a99b2005a81a2fa7560dfea481f..0000000000000000000000000000000000000000 --- a/20221107/blink-3.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <avr/io.h> - -#define F_CPU 16000000 -#include <util/delay.h> - -int main (void) -{ - DDRD = 0x01; - PORTD = 0x01; - while (1) - { - while ((PIND & 0x02) == 0) - ; /* just wait */ - PORTD ^= 0x01; - } - return 0; -} diff --git a/20221107/blink-4.c b/20221107/blink-4.c deleted file mode 100644 index ceafab6b1e7462497fde98b7a12e72cc34132bbe..0000000000000000000000000000000000000000 --- a/20221107/blink-4.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <avr/io.h> - -#define F_CPU 16000000 -#include <util/delay.h> - -int main (void) -{ - DDRD = 0x01; /* binär: 0000 0001 */ - PORTD = 0x01; /* ^ Ouptut */ - while (1) /* ^ Input */ - { - while ((PIND & 0x02) == 0) /* binär: 0000 0010 */ - ; /* just wait */ - PORTD ^= 0x01; - _delay_ms (200); - } - return 0; -} diff --git a/20221107/blink-5.c b/20221107/blink-5.c deleted file mode 100644 index bb755f0de02d3e224909f1d2a37789f3c14a0f03..0000000000000000000000000000000000000000 --- a/20221107/blink-5.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> - -ISR (TIMER0_COMPB_vect) -{ - PORTD ^= 0x40; -} - -int main (void) -{ - cli (); - TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */ - TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */ - sei (); - DDRD = 0xfd; /* binär: 1111 1101 */ - PORTD = 0x40; /* binär: 0100 0000 */ - while (1); - return 0; -} diff --git a/20221107/blink-6.c b/20221107/blink-6.c deleted file mode 100644 index 651ab6e4ac926242337a0520c11f2bbd935bdd22..0000000000000000000000000000000000000000 --- a/20221107/blink-6.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> -#include <stdint.h> - -ISR (TIMER0_COMPB_vect) -{ - static uint8_t counter = 0; - if (counter++ == 0) - PORTD ^= 0x40; -} - -int main (void) -{ - cli (); - TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */ - TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */ - sei (); - DDRD = 0xfd; /* binär: 1111 1101 */ - PORTD = 0x40; /* binär: 0100 0000 */ - while (1); - return 0; -} diff --git a/20221107/blink-7.c b/20221107/blink-7.c deleted file mode 100644 index 7ed39822752f61b636f001b77eb3742a57e953a9..0000000000000000000000000000000000000000 --- a/20221107/blink-7.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> -#include <stdint.h> - -ISR (INT0_vect) /* PD2 */ -{ - PORTD ^= 0x40; -} - -int main (void) -{ - cli (); - EICRA = 1 << ISC00 | 1 << ISC01; /* INT0: steigende Flanke */ - EIMSK = 1 << INT0; /* INT0 einschalten */ - sei (); - DDRD = 0xfb; /* binär: 1111 1011 */ - PORTD = 0x40; /* binär: 0100 0000 */ - while (1); - return 0; -} diff --git a/20221107/blink-8.c b/20221107/blink-8.c deleted file mode 100644 index aba94f07176a75656619d1ba09e83093cbc66c89..0000000000000000000000000000000000000000 --- a/20221107/blink-8.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> -#include <stdint.h> - -ISR (INT0_vect) /* PD2 */ -{ - PORTD ^= 0x40; -} - -int main (void) -{ - cli (); - EICRA = 1 << ISC00 | 1 << ISC01; /* INT0: steigende Flanke */ - EIMSK = 1 << INT0; /* INT0 einschalten */ - sei (); - DDRD = 0xff; /* binär: 1111 1111 */ - PORTD = 0x40; /* binär: 0100 0000 */ - while (1); - return 0; -} diff --git a/20221107/blink-9.c b/20221107/blink-9.c deleted file mode 100644 index 486b7a2d07ea524e709560a627b4121ead7ed332..0000000000000000000000000000000000000000 --- a/20221107/blink-9.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> -#include <stdint.h> - -#define F_CPU 16000000l -#include <util/delay.h> - -uint8_t key_pressed = 0; - -ISR (INT0_vect) /* PD2 */ -{ - key_pressed = 1; -} - -int main (void) -{ - cli (); - EICRA = 1 << ISC00 | 1 << ISC01; /* INT0: steigende Flanke */ - EIMSK = 1 << INT0; /* INT0 einschalten */ - sei (); - DDRD = 0xfb; /* binär: 1111 1011 */ - PORTD = 0x44; /* binär: 0100 0100 */ - while (1) - { - while (!key_pressed) - ; /* just wait */ - PORTD ^= 0x40; - key_pressed = 0; - } - return 0; -} diff --git a/20221107/blink-9.s b/20221107/blink-9.s deleted file mode 100644 index 82e900d919212d857c79b51e071b1a13babbfc75..0000000000000000000000000000000000000000 --- a/20221107/blink-9.s +++ /dev/null @@ -1,78 +0,0 @@ - .file "blink-9.c" -__SP_H__ = 0x3e -__SP_L__ = 0x3d -__SREG__ = 0x3f -__tmp_reg__ = 0 -__zero_reg__ = 1 - .text -.global __vector_1 - .type __vector_1, @function -__vector_1: - push r1 - push r0 - in r0,__SREG__ - push r0 - clr __zero_reg__ - push r24 -/* prologue: Signal */ -/* frame size = 0 */ -/* stack size = 4 */ -.L__stack_usage = 4 - ldi r24,lo8(1) - sts key_pressed,r24 -/* epilogue start */ - pop r24 - pop r0 - out __SREG__,r0 - pop r0 - pop r1 - reti - .size __vector_1, .-__vector_1 - .section .text.startup,"ax",@progbits -.global main - .type main, @function -main: -/* prologue: function */ -/* frame size = 0 */ -/* stack size = 0 */ -.L__stack_usage = 0 -/* #APP */ - ; 17 "blink-9.c" 1 - cli - ; 0 "" 2 -/* #NOAPP */ - ldi r24,lo8(3) - sts 105,r24 - ldi r24,lo8(1) - out 0x1d,r24 -/* #APP */ - ; 20 "blink-9.c" 1 - sei - ; 0 "" 2 -/* #NOAPP */ - ldi r24,lo8(-5) - out 0xa,r24 - ldi r24,lo8(68) - out 0xb,r24 - ldi r25,lo8(64) -.L4: - lds r24,key_pressed - cpse r24,__zero_reg__ - rjmp .L7 -.L6: - rjmp .L6 -.L7: - in r24,0xb - eor r24,r25 - out 0xb,r24 - sts key_pressed,__zero_reg__ - rjmp .L4 - .size main, .-main -.global key_pressed - .section .bss - .type key_pressed, @object - .size key_pressed, 1 -key_pressed: - .zero 1 - .ident "GCC: (GNU) 5.4.0" -.global __do_clear_bss diff --git a/20221107/download.sh b/20221107/download.sh deleted file mode 100755 index 770c3b5dca74ac09778be055c9d6f5adb0df293b..0000000000000000000000000000000000000000 --- a/20221107/download.sh +++ /dev/null @@ -1,3 +0,0 @@ -port=$(ls -rt /dev/ttyACM* | tail -1) -echo avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) -avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) 2>/dev/null diff --git a/20221107/hp-20221107.pdf b/20221107/hp-20221107.pdf deleted file mode 100644 index ebeb94f73fb232d1b3ce27c703301b6a3b3e1e89..0000000000000000000000000000000000000000 Binary files a/20221107/hp-20221107.pdf and /dev/null differ diff --git a/20221107/hp-20221107.tex b/20221107/hp-20221107.tex deleted file mode 100644 index 159a1850f21fe03f04efee08f9ab126438794a63..0000000000000000000000000000000000000000 --- a/20221107/hp-20221107.tex +++ /dev/null @@ -1,1148 +0,0 @@ -% hp-20221107.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Interrupts, volatile-Variable, Endianness - -\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} - -\newcommand{\redurl}[1]{\href{#1}{\color{red}\nolinkurl{#1}}} - -\title{Hardwarenahe Programmierung} -\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{7.\ November 2022} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \begin{itemize} - \item[3.1] Der Präprozessor - \item[3.2] Bibliotheken einbinden - \color{medgreen} - \item[3.3] Bibliotheken verwenden - \item[3.4] Projekt organisieren: make - \end{itemize} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \begin{itemize} - \color{medgreen} - \item[4.1] Bit-Operationen - \item[4.2] I/O-Ports - \color{red} - \item[4.3] Interrupts - \vspace*{-0.1cm} - \item[\dots] - \end{itemize} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \item[\textbf{7}] \textbf{Datenstrukturen} - \end{itemize} - -\end{frame} - -\setcounter{section}{2} -\section{Bibliotheken} -\setcounter{subsection}{2} -\subsection{Bibliotheken 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*{-3cm} - \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-sp - i-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-g - nu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/inclu - de/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pa - ngo-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1. - 0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/in - clude/pixman-1 -I/usr/include/freetype2 -I/usr/include/ - libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/l - ibpng16 -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 -lcairo-gobject -lcairo -lgdk_pix - buf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -o hello-gtk¿ - \end{lstlisting} - \vspace*{-2cm} - \end{onlyenv} - \begin{onlyenv}<5-> - \begin{lstlisting}[style=terminal,gobble=10] - $ ¡gcc -Wall -O hello-gtk.c $(pkg-config --cflags --libs - gtk+-3.0) -o hello-gtk¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<5> - \begin{picture}(0,0)(0.3,0.3) - \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}~~~\strut}}} - \end{picture} - \end{onlyenv} - \pause - \pause - \item - Auf manchen Plattformen kommt es auf die Reihenfolge an: - \begin{lstlisting}[style=terminal,gobble=8] - $ ¡gcc -Wall -O $(pkg-config --cflags gtk+-3.0) \ - hello-gtk.c $(pkg-config --libs gtk+-3.0) \ - -o hello-gtk¿ - \end{lstlisting} - (Backslash = "`Es geht in der nächsten Zeile weiter."') - \end{itemize} - -\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)(-0.07,0.2) - \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)(-0.07,0.2) - \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} - -\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} - -\section{Hardwarenahe Programmierung} -\subsection{Bit-Operationen} -\subsubsection{Zahlensysteme} - -\begin{frame}[fragile] - - \showsection - \vspace*{-\smallskipamount} - \showsubsection - \vspace*{-\medskipamount} - \showsubsubsection - - \begin{tabular}{rlrl} - Basis & Name & Beispiel & Anwendung \\[\smallskipamount] - 2 & Binärsystem & 1\,0000\,0011 & Bit-Operationen \\ - 8 & Oktalsystem & \lstinline,0403, & Dateizugriffsrechte (Unix) \\ - 10 & Dezimalsystem & \lstinline,259, & Alltag \\ - 16 & Hexadezimalsystem & \lstinline,0x103, & Bit-Operationen \\ - 256 & (keiner gebräuchlich) & 0.0.1.3 & IP-Adressen (IPv4) - \end{tabular} - - \bigskip - - \begin{itemize} - \item - Computer rechnen im Binärsystem. - \item - Für viele Anwendungen (z.\,B.\ I/O-Ports, Grafik, \dots) ist es notwendig,\\ - Bits in Zahlen einzeln ansprechen zu können. - \end{itemize} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsubsection - - \begin{tabular}{rlrlrc} - \qquad 000 & \bf 0 \hspace*{1.5cm} & 0000 & \bf 0 & \quad 1000 & \bf 8\\ - 001 & \bf 1 & 0001 & \bf 1 & 1001 & \bf 9\\ - 010 & \bf 2 & 0010 & \bf 2 & 1010 & \bf A\\ - 011 & \bf 3 & 0011 & \bf 3 & 1011 & \bf B\\[\smallskipamount] - 100 & \bf 4 & 0100 & \bf 4 & 1100 & \bf C\\ - 101 & \bf 5 & 0101 & \bf 5 & 1101 & \bf D\\ - 110 & \bf 6 & 0110 & \bf 6 & 1110 & \bf E\\ - 111 & \bf 7 & 0111 & \bf 7 & 1111 & \bf F\\ - \end{tabular} - - \medskip - - \begin{itemize} - \item - Oktal- und Hexadezimalzahlen lassen sich ziffernweise\\ - in Binär-Zahlen umrechnen. - \item - Hexadezimalzahlen sind eine Kurzschreibweise für Binärzahlen,\\ - gruppiert zu jeweils 4 Bits. - \item - Oktalzahlen sind eine Kurzschreibweise für Binärzahlen,\\ - gruppiert zu jeweils 3 Bits. - \item - Trotz Taschenrechner u.\,ä.\ lohnt es sich,\\ - die o.\,a.\ Umrechnungstabelle \textbf{auswendig} zu kennen. - \end{itemize} - -\end{frame} - -\subsubsection{Bit-Operationen in C} - -\begin{frame}[fragile] - - \showsubsubsection - - \begin{tabular}{lll} - C-Operator & Verknüpfung & Anwendung \\[\smallskipamount] - \lstinline,&, & Und & Bits gezielt löschen \\ - \lstinline,|, & Oder & Bits gezielt setzen \\ - \lstinline,^, & Exklusiv-Oder & Bits gezielt invertieren \\ - \lstinline,~, & Nicht & Alle Bits invertieren \\[\smallskipamount] - \lstinline,<<, & Verschiebung nach links & Maske generieren \\ - \lstinline,>>, & Verschiebung nach rechts & Bits isolieren - \end{tabular} - - \bigskip - - Numerierung der Bits: von rechts ab 0 - - \medskip - - \begin{tabular}{ll} - Bit Nr.\ 3 auf 1 setzen: & - \lstinline,a |= 1 << 3;, \\ - Bit Nr.\ 4 auf 0 setzen: & - \lstinline,a &= ~(1 << 4);, \\ - Bit Nr.\ 0 invertieren: & - \lstinline,a ^= 1 << 0;, - \end{tabular} - - \smallskip - - ~~Abfrage, ob Bit Nr.\ 1 gesetzt ist:\quad - \lstinline{if (a & (1 << 1))} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsubsection - - C-Datentypen für Bit-Operationen: - \smallskip\par - \lstinline{#include <stdint.h>} - \medskip\par - \begin{tabular}{lllll} - & 8 Bit & 16 Bit & 32 Bit & 64 Bit \\ - mit Vorzeichen & \lstinline,int8_t, - & \lstinline,int16_t, - & \lstinline,int32_t, - & \lstinline,int64_t, \\ - ohne Vorzeichen & \lstinline,uint8_t, - & \lstinline,uint16_t, - & \lstinline,uint32_t, - & \lstinline,uint64_t, - \end{tabular} - - \bigskip - \bigskip - - Ausgabe: - \smallskip\par - \begin{lstlisting} - #include <stdio.h> - #include <stdint.h> - #include <inttypes.h> - ... - uint64_t x = 42; - printf ("Die Antwort lautet: %" PRIu64 "\n", x); - \end{lstlisting} - -\end{frame} - -\subsection{I/O-Ports} - -\begin{frame}[fragile] - -% \showsection - \showsubsection - \vspace*{-1.5\medskipamount} - {\large\textbf{\color{structure}4.3\quad Interrupts}} - - \bigskip - - Kommunikation mit externen Geräten - - \bigskip - - \begin{center} - \includegraphics{io-ports-and-interrupts.pdf} - \end{center} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - In Output-Port schreiben = Aktoren ansteuern - - Beispiel: LED - - \medskip - - \begin{lstlisting} - #include <avr/io.h> - ... - DDRC = 0x70; - PORTC = 0x40; - \end{lstlisting} - \begin{picture}(0,0) - \put(3,0.67){\begin{minipage}{3cm} - \color{red}% - binär: 0111\,0000\\ - binär: 0100\,0000 - \end{minipage}} - \put(10,0.67){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}} - \end{picture} - - \bigskip - - \lstinline{DDR} = Data Direction Register\\ - Bit = 1 für Output-Port\\ - Bit = 0 für Input-Port - - \bigskip - - \emph{Details: siehe Datenblatt und Schaltplan} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Aus Input-Port lesen = Sensoren abfragen - - Beispiel: Taster - - \medskip - - \begin{lstlisting} - #include <avr/io.h> - ... - DDRC = 0xfd; - while ((PINC & 0x02) == 0) - ; /* just wait */ - \end{lstlisting} - \begin{picture}(0,0)(-1.5,-0.42) - \put(3,0.67){\begin{minipage}{3cm} - \color{red}% - binär: 1111\,1101\\ - binär: 0000\,0010 - \end{minipage}} - \put(10,0.67){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}} - \end{picture} - - \bigskip - - \lstinline{DDR} = Data Direction Register\\ - Bit = 1 für Output-Port\\ - Bit = 0 für Input-Port - - \bigskip - - \emph{Details: siehe Datenblatt und Schaltplan} - - \bigskip - - Praktikumsaufgabe: Druckknopfampel - -\end{frame} - -\subsection{Interrupts} - -\begin{frame}[fragile] - - \showsubsection - - Externes Gerät ruft (per Stromsignal) Unterprogramm auf - - Zeiger hinterlegen: "`Interrupt-Vektor"' - - Beispiel: eingebaute Uhr\hfill - \makebox(0,0)[tr]{% - \only<1->{\begin{minipage}[t]{4.7cm} - \vspace*{-0.3cm}% - statt Zählschleife (\lstinline{_delay_ms}):\\ - Hauptprogramm kann\\ - andere Dinge tun - \end{minipage}}% - } - - \medskip - - \begin{lstlisting} - #include <avr/interrupt.h> - - ... - - - ISR (TIMER0B_COMP_vect) - { - PORTD ^= 0x40; - } - \end{lstlisting} - \begin{picture}(0,0) - \color{red} - \put(1.9,3.1){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-1.4,-1.0);}}} - \put(2.0,3.2){\makebox(0,0)[l]{"`Dies ist ein Interrupt-Handler."'}} - \put(2.3,2.6){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-0.6,-0.55);}}} - \put(2.4,2.6){\makebox(0,0)[l]{Interrupt-Vektor darauf zeigen lassen}} - \end{picture} - - Initialisierung über spezielle Ports: - \lstinline{TCCR0B}, \lstinline{TIMSK0} - - \bigskip - - \emph{Details: siehe Datenblatt und Schaltplan} - - \vspace*{-2.5cm}\hfill - {\color{red}Herstellerspezifisch!}% - \hspace*{1cm} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Externes Gerät ruft (per Stromsignal) Unterprogramm auf - - Zeiger hinterlegen: "`Interrupt-Vektor"' - - Beispiel: Taster\hfill - \makebox(0,0)[tr]{% - \begin{minipage}[t]{4.7cm} - \vspace*{-0.3cm}% - statt \newterm{Busy Waiting\/}:\\ - Hauptprogramm kann\\ - andere Dinge tun - \end{minipage}} - - \medskip - - \begin{lstlisting} - #include <avr/interrupt.h> - ... - - ISR (INT0_vect) - { - PORTD ^= 0x40; - } - \end{lstlisting} - - \medskip - - Initialisierung über spezielle Ports: - \lstinline{EICRA}, \lstinline{EIMSK} - - \bigskip - - \emph{Details: siehe Datenblatt und Schaltplan} - - \vspace*{-2.5cm}\hfill - {\color{red}Herstellerspezifisch!}% - \hspace*{1cm} - -\end{frame} - -\subsection{volatile-Variable} - -\begin{frame}[fragile] - - \showsubsection - - Externes Gerät ruft (per Stromsignal) Unterprogramm auf - - Zeiger hinterlegen: "`Interrupt-Vektor"' - - Beispiel: Taster - - \vspace*{-2.5pt} - - \begin{minipage}[t]{5cm} - \begin{onlyenv}<1> - \begin{lstlisting}[gobble=8] - ¡#include <avr/interrupt.h> - ... - - uint8_t key_pressed = 0; - - ISR (INT0_vect) - { - key_pressed = 1; - }¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<2> - \begin{lstlisting}[gobble=8] - ¡#include <avr/interrupt.h> - ... - - volatile uint8_t key_pressed = 0; - - ISR (INT0_vect) - { - key_pressed = 1; - }¿ - \end{lstlisting} - \end{onlyenv} - \end{minipage}\hfill - \begin{minipage}[t]{6cm} - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - ... - - while (1) - { - while (!key_pressed) - ; /* just wait */ - PORTD ^= 0x40; - key_pressed = 0; - } - return 0; - }¿ - \end{lstlisting} - \end{minipage} - - \pause - \begin{picture}(0,0) - \color{red} - \put(10.3,4.0){\makebox(0,0)[b]{\begin{minipage}{6cm} - \begin{center} - \textbf{volatile}:\\ - Speicherzugriff\\ - nicht wegoptimieren - \end{center} - \end{minipage}}} - \put(10.3,3.95){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-0.5,-0.9);}}} - \end{picture} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Was ist eigentlich \lstinline{PORTD}? - - \bigskip - \pause - - \lstinline[style=cmd]{avr-gcc -Wall -Os -mmcu=atmega328p blink-3.c -E} - - \bigskip - \pause - \lstinline{PORTD = 0x01;}\\ - \textarrow\quad - \lstinline[style=terminal]{(*(volatile uint8_t *)((0x0B) + 0x20)) = 0x01;}\\ - \pause - \begin{picture}(0,2)(0,-1.7) - \color{red} - \put(5.75,0.3){$\underbrace{\rule{2.95cm}{0pt}}_{\mbox{Zahl: \lstinline|0x2B|}}$} - \pause - \put(1.55,0.3){$\underbrace{\rule{4.0cm}{0pt}}_{\mbox{\shortstack[t]{Umwandlung in Zeiger\\ - auf \lstinline|volatile uint8_t|}}}$} - \pause - \put(1.32,-1){\makebox(0,0)[b]{\tikz{\draw[-latex](0,0)--(0,1.3)}}} - \put(1.12,-1.1){\makebox(0,0)[tl]{Dereferenzierung des Zeigers}} - \end{picture} - - \pause - \textarrow\quad - \lstinline|volatile uint8_t|-Variable an Speicheradresse \lstinline|0x2B| - - \pause - \bigskip - \bigskip - - \textarrow\quad - \lstinline|PORTA = PORTB = PORTC = PORTD = 0| ist eine schlechte Idee. - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \begin{itemize} - \item[4.1] Bit-Operationen - \item[4.2] I/O-Ports - \color{medgreen} - \item[4.3] Interrupts - \item[4.4] volatile-Variable - \color{red} - \item[4.5] Byte-Reihenfolge -- Endianness - \color{black} - \item[4.6] Binärdarstellung negativer Zahlen - \item[4.7] Speicherausrichtung -- Alignment - \end{itemize} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \item[\textbf{7}] \textbf{Datenstrukturen} - \end{itemize} - -\end{frame} - -\subsection{Byte-Reihenfolge -- Endianness} -\subsubsection{Konzept} - -\begin{frame}[fragile] - - \showsubsection - \showsubsubsection - - Eine Zahl geht über mehrere Speicherzellen.\\ - Beispiel: 16-Bit-Zahl in 2 8-Bit-Speicherzellen - - \smallskip - - Welche Bits liegen wo? - - \pause - \bigskip - - $1027 = 1024 + 2 + 1 = 0000\,0100\,0000\,0011_2 = 0403_{16}$ - - \pause - \bigskip - Speicherzellen: - - \medskip - \begin{tabular}{|c|c|l}\cline{1-2} - \raisebox{-0.25ex}{04} & \raisebox{-0.25ex}{03} & \strut Big-Endian "`großes Ende zuerst"' \\\cline{1-2} - \multicolumn{2}{c}{} & \pause für Menschen leichter lesbar \pause \\ - \multicolumn{3}{c}{} \\[-5pt]\cline{1-2} - \raisebox{-0.25ex}{03} & \raisebox{-0.25ex}{04} & \strut Little-Endian "`kleines Ende zuerst"' \\\cline{1-2} - \multicolumn{2}{c}{} & \pause bei Additionen effizienter - \end{tabular} - - \pause - \medskip - \textarrow\ Geschmackssache - \pause\\ - \quad\textbf{\dots\ außer bei Datenaustausch!} - -% \pause -% \bigskip -% -% Aber: nicht verwechseln! \qquad $0304_{16} = 772$ - -\end{frame} - -\begin{frame} - - \showsubsection - \showsubsubsection - - Eine Zahl geht über mehrere Speicherzellen.\\ - Beispiel: 16-Bit-Zahl in 2 8-Bit-Speicherzellen - - \smallskip - - Welche Bits liegen wo? - - \medskip - - \textarrow\ Geschmackssache\\ - \textbf{\dots\ außer bei Datenaustausch!} - - \begin{itemize} - \item - Dateiformate - \item - Datenübertragung - \end{itemize} - -\end{frame} - -\subsubsection{Dateiformate} - -\begin{frame} - - \showsubsection - \showsubsubsection - - Audio-Formate: Reihenfolge der Bytes in 16- und 32-Bit-Zahlen - \begin{itemize} - \item - RIFF-WAVE-Dateien (\file{.wav}): Little-Endian - \item - Au-Dateien (\file{.au}): Big-Endian - \pause - \item - ältere AIFF-Dateien (\file{.aiff}): Big-Endian - \item - neuere AIFF-Dateien (\file{.aiff}): Little-Endian - \end{itemize} - - \pause - \bigskip - - Grafik-Formate: Reihenfolge der Bits in den Bytes - \begin{itemize} - \item - PBM-Dateien: Big-Endian\only<4->{, MSB first} - \item - XBM-Dateien: Little-Endian\only<4->{, LSB first} - \end{itemize} - \only<4->{MSB/LSB = most/least significant bit} - -\end{frame} - -\iffalse - -\subsubsection{Datenübertragung} - -\begin{frame} - - \showsubsection - \showsubsubsection - - \begin{itemize} - \item - RS-232 (serielle Schnittstelle): LSB first - \item - I$^2$C: MSB first - \item - USB: beides - \pause - \medskip - \item - Ethernet: LSB first - \item - TCP/IP (Internet): Big-Endian - \end{itemize} - -\end{frame} - -\subsection{Binärdarstellung negativer Zahlen} - -\begin{frame}[fragile] - - \showsubsection - - Speicher ist begrenzt!\\ - \textarrow\ feste Anzahl von Bits - - \medskip - - 8-Bit-Zahlen ohne Vorzeichen: \lstinline{uint8_t}\\ - \textarrow\ Zahlenwerte von \lstinline{0x00} bis \lstinline{0xff} = 0 bis 255\\ - \pause - \textarrow\ 255 + 1 = 0 - - \pause - \medskip - - 8-Bit-Zahlen mit Vorzeichen: \lstinline{int8_t}\\ - \lstinline{0xff} = 255 ist die "`natürliche"' Schreibweise für $-1$.\\ - \pause - \textarrow\ Zweierkomplement - - \pause - \medskip - - Oberstes Bit = 1: negativ\\ - Oberstes Bit = 0: positiv\\ - \textarrow\ 127 + 1 = $-128$ - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Speicher ist begrenzt!\\ - \textarrow\ feste Anzahl von Bits - - \medskip - - 16-Bit-Zahlen ohne Vorzeichen: - \lstinline{uint16_t}\hfill\lstinline{uint8_t}\\ - \textarrow\ Zahlenwerte von \lstinline{0x0000} bis \lstinline{0xffff} - = 0 bis 65535\hfill 0 bis 255\\ - \textarrow\ 65535 + 1 = 0\hfill 255 + 1 = 0 - - \medskip - - 16-Bit-Zahlen mit Vorzeichen: - \lstinline{int16_t}\hfill\lstinline{int8_t}\\ - \lstinline{0xffff} = 66535 ist die "`natürliche"' Schreibweise für $-1$.\hfill - \lstinline{0xff} = 255 = $-1$\\ - \textarrow\ Zweierkomplement - - \medskip - - Oberstes Bit = 1: negativ\\ - Oberstes Bit = 0: positiv\\ - \textarrow\ 32767 + 1 = $-32768$ - - \bigskip - Literatur: \url{http://xkcd.com/571/} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Frage: \emph{Für welche Zahl steht der Speicherinhalt\, - \raisebox{2pt}{% - \tabcolsep0.25em - \begin{tabular}{|c|c|}\hline - \rule{0pt}{11pt}a3 & 90 \\\hline - \end{tabular}} - (hexadezimal)?} - - \pause - \smallskip - Antwort: \emph{Das kommt darauf an.} ;--) - - \pause - \medskip - Little-Endian: - - \smallskip - - \begin{tabular}{lrl} - als \lstinline,int8_t,: & $-93$ & (nur erstes Byte)\\ - als \lstinline,uint8_t,: & $163$ & (nur erstes Byte)\\ - als \lstinline,int16_t,: & $-28509$\\ - als \lstinline,uint16_t,: & $37027$\\ - \lstinline,int32_t, oder größer: & $37027$ - & (zusätzliche Bytes mit Nullen aufgefüllt) - \end{tabular} - - \pause - \medskip - Big-Endian: - - \smallskip - - \begin{tabular}{lrl} - als \lstinline,int8_t,: & $-93$ & (nur erstes Byte)\\ - als \lstinline,uint8_t,: & $163$ & (nur erstes Byte)\\ - als \lstinline,int16_t,: & $-23664$\\ - als \lstinline,uint16_t,: & $41872$\\ als \lstinline,int32_t,: & $-1550843904$ & (zusätzliche Bytes\\ - als \lstinline,uint32_t,: & $2744123392$ & mit Nullen aufgefüllt)\\ - als \lstinline,int64_t,: & $-6660823848880963584$\\ - als \lstinline,uint64_t,: & $11785920224828588032$\\ - \end{tabular} - - \vspace*{-1cm} - -\end{frame} - -\subsection{Speicherausrichtung -- Alignment} - -\begin{frame}[fragile] - - \showsubsection - - \begin{lstlisting} - #include <stdint.h> - - uint8_t a; - uint16_t b; - uint8_t c; - \end{lstlisting} - - \pause - \bigskip - - Speicheradresse durch 2 teilbar -- "`16-Bit-Alignment"' - \begin{itemize} - \item - 2-Byte-Operation: effizienter - \pause - \item - \dots\ oder sogar nur dann erlaubt - \pause - \arrowitem - Compiler optimiert Speicherausrichtung - \end{itemize} - - \medskip - - \pause - \begin{minipage}{3cm} - \begin{lstlisting}[gobble=6] - ¡uint8_t a; - uint8_t dummy; - uint16_t b; - uint8_t c;¿ - \end{lstlisting} - \end{minipage} - \pause - \begin{minipage}{3cm} - \begin{lstlisting}[gobble=6] - ¡uint8_t a; - uint8_t c; - uint16_t b;¿ - \end{lstlisting} - \end{minipage} - - \pause - \vspace{-1.75cm} - \strut\hfill - \begin{minipage}{6.5cm} - Fazit: - \begin{itemize} - \item - \textbf{Adressen von Variablen\\ - sind systemabhängig} - \item - Bei Definition von Datenformaten\\ - Alignment beachten \textarrow\ effizienter - \end{itemize} - \end{minipage} - -\end{frame} - -\fi - -\end{document} diff --git a/20221107/hp-musterloesung-20221107.pdf b/20221107/hp-musterloesung-20221107.pdf deleted file mode 100644 index 1800b1be645e13b5540dfa4917c13e99038f6a7d..0000000000000000000000000000000000000000 Binary files a/20221107/hp-musterloesung-20221107.pdf and /dev/null differ diff --git a/20221107/hp-musterloesung-20221107.tex b/20221107/hp-musterloesung-20221107.tex deleted file mode 100644 index 22e4b5e8bd3c2671c0fe3b09351dbe37339808b5..0000000000000000000000000000000000000000 --- a/20221107/hp-musterloesung-20221107.tex +++ /dev/null @@ -1,447 +0,0 @@ -% hp-musterloesung-20221031.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Ausgabe von Hexadezimalzahlen, Länge von Strings, LED-Blinkmuster - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 7.\ November 2022} - - \exercise{Ausgabe von Hexadezimalzahlen} - - Schreiben Sie eine Funktion \lstinline{void print_hex (uint32_t x)}, - die eine gegebene vorzeichenlose 32-Bit-Ganzzahl \lstinline{x} - als Hexadezimalzahl ausgibt. - (Der Datentyp \lstinline{uint32_t} ist mit \lstinline{#include <stdint.h>} verfügbar.) - - Verwenden Sie dafür \emph{nicht\/} \lstinline{printf()} mit - der Formatspezifikation \lstinline{%x} als fertige Lösung, - sondern programmieren Sie die nötige Ausgabe selbst. - (Für Tests ist \lstinline{%x} hingegen erlaubt und sicherlich nützlich.) - - Die Verwendung von \lstinline{printf()} - mit anderen Formatspezifikationen wie z.\,B.\ \lstinline{%d} - oder \lstinline{%c} oder \lstinline{%s} ist hingegen zulässig. - - \points{8} - - (Hinweis für die Klausur: Abgabe auf Datenträger ist erlaubt und erwünscht, - aber nicht zwingend.) - - \solution - - Um die Ziffern von \lstinline{x} zur Basis 16 zu isolieren, - berechnen wir \lstinline{x % 16} (modulo 16 = Rest bei Division durch 16) - und dividieren anschließend \lstinline{x} durch 16, - solange bis \lstinline{x} den Wert 0 erreicht. - - Wenn wir die auf diese Weise ermittelten Ziffern direkt ausgeben, - sind sie \emph{Little-Endian}, erscheinen also in umgekehrter Reihenfolge. - Die Datei \gitfile{hp}{2022ws/20221107}{loesung-1-1.c} setzt diesen Zwischenschritt um. - - Die Ausgabe der Ziffern erfolgt in \gitfile{hp}{2022ws/20221107}{loesung-1-1.c} - über \lstinline{printf ("%d")} - für die Ziffern 0 bis 9. Für die darüberliegenden Ziffern - wird der Buchstabe \lstinline{a} um die Ziffer abzüglich 10 inkrementiert - und der erhaltene Wert mit \lstinline{printf ("%c")} als Zeichen ausgegeben. - - Um die umgekehrte Reihenfolge zu beheben, - speichern wir die Ziffern von \lstinline{x} - in einem Array \lstinline{digits[]} zwischen - und geben sie anschließend in einer zweiten Schleife - in umgekehrter Reihenfolge aus (siehe \gitfile{hp}{2022ws/20221107}{loesung-1-2.c}). - Da wir wissen, daß \lstinline{x} eine 32-Bit-Zahl ist - und daher höchstens 8 Hexadezimalziffern haben kann, - ist 8 eine sinnvolle Länge für das Ziffern-Array \lstinline{digits[8]}. - - Nun sind die Ziffern in der richtigen Reihenfolge, - aber wir erhalten zusätzlich zu den eigentlichen Ziffern führende Nullen. - Da in der Aufgabenstellung nicht von führenden Nullen die Rede war, - sind diese nicht verboten; \gitfile{hp}{2022ws/20221107}{loesung-1-2.c} ist daher - eine richtige Lösung der Aufgabe. - - \breath - - Wenn wir die führenden Nullen vermeiden wollen, - können wir die \lstinline{for}-Schleifen durch \lstinline{while}-Schleifen ersetzen. - Die erste Schleife zählt hoch, solange \lstinline{x} ungleich 0 ist; - die zweite zählt von dem erreichten Wert aus wieder herunter - -- siehe \gitfile{hp}{2022ws/20221107}{loesung-1-3.c}. - Da wir wissen, daß die Zahl \lstinline{x} höchstens 32 Bit, - also höchstens 8 Hexadezimalziffern hat, - wissen wir, daß \lstinline{i} höchstens den Wert 8 erreichen kann, - das Array also nicht überlaufen wird. - - Man beachte, daß der Array-Index nach der ersten Schleife "`um einen zu hoch"' ist. - In der zweiten Schleife muß daher \emph{zuerst\/} der Index dekrementiert werden. - Erst danach darf ein Zugriff auf \lstinline{digit[i]} erfolgen. - - \breath - - Alternativ können wir auch mitschreiben, - ob bereits eine Ziffer ungleich Null ausgegeben wurde, - und andernfalls die Ausgabe von Null-Ziffern unterdrücken - -- siehe \gitfile{hp}{2022ws/20221107}{loesung-1-4.c}. - - \breath - - Weitere Möglichkeiten ergeben sich, wenn man bedenkt, - daß eine Hexadezimalziffer genau einer Gruppe von vier Binärziffern entspricht. - Eine Bitverschiebung um 4 nach rechts - ist daher dasselbe wie eine Division durch 16, - und eine Und-Verknüpfung mit 15$_{10}$ = f$_{16}$ = 1111$_2$ - ist dasselbe wie die Operation Modulo 16. - Die Datei \gitfile{hp}{2022ws/20221107}{loesung-1-5.c} ist eine in dieser Weise abgewandelte Variante - von \gitfile{hp}{2022ws/20221107}{loesung-1-3.c}. - - Mit dieser Methode kann man nicht nur auf die jeweils unterste Ziffer, - sondern auf alle Ziffern direkt zugreifen. - Damit ist kein Array als zusätzlicher Speicher mehr nötig. - Die Datei \gitfile{hp}{2022ws/20221107}{loesung-1-6.c} setzt dies auf einfache Weise um. - Sie gibt wieder führende Nullen mit aus, - ist aber trotzdem eine weitere richtige Lösung der Aufgabe. - - Die führenden Nullen ließen sich auf die gleiche Weise vermeiden - wie in \gitfile{hp}{2022ws/20221107}{loesung-1-4.c}. - - Die Bitverschiebungsmethode hat den Vorteil, - daß kein zusätzliches Array benötigt wird. - Auch wird die als Parameter übergebene Zahl \lstinline{x} nicht verändert, - was bei größeren Zahlen, die über Zeiger übergeben werden, von Vorteil sein kann. - Demgegenüber steht der Nachteil, - daß diese Methode nur für eine ganze Anzahl von Bits funktioniert, - also für Basen, die Zweierpotenzen sind (z.\,B.\ 2, 8, 16, 256). - Für alle anderen Basen (z.\,B.\ 10) eignet sich nur die Methode - mit Division und Modulo-Operation. - - \exercise{Länge von Strings} - - Strings werden in der Programmiersprache C durch Zeiger auf \lstinline{char}-Variable realisiert. - - Beispiel: \lstinline{char *hello_world = "Hello, world!\n"} - - Die Systembibliothek stellt eine Funktion \lstinline{strlen()} zur Ermittlung der Länge von Strings\\ - zur Verfügung (\lstinline{#include <string.h>}). - - \begin{itemize} - \item[(a)] - Auf welche Weise ist die Länge eines Strings gekennzeichnet? - \points{1} - \item[(b)] - Wie lang ist die Beispiel-String-Konstante \lstinline{"Hello, world!\n"}, - und wieviel Speicherplatz belegt sie?\\ - \points{2} - \item[(c)] - Schreiben Sie eine eigene Funktion \lstinline{int strlen (char *s)}, - die die Länge eines Strings zurückgibt.\\ - \points{3} - \end{itemize} - - Wir betrachten nun die folgenden Funktionen (Datei: \gitfile{hp}{2022ws/20221107}{aufgabe-2.c}): - \begin{center} - \begin{minipage}{8cm} - \begin{lstlisting}[gobble=8] - int fun_1 (char *s) - { - int x = 0; - for (int i = 0; i < strlen (s); i++) - x += s[i]; - return x; - } - \end{lstlisting} - \end{minipage}% - \begin{minipage}{6cm} - \vspace*{-1cm} - \begin{lstlisting}[gobble=8] - int fun_2 (char *s) - { - int i = 0, x = 0; - int len = strlen (s); - while (i < len) - x += s[i++]; - return x; - } - \end{lstlisting} - \vspace*{-1cm} - \end{minipage} - \end{center} - \begin{itemize} - \item[(d)] - Was bewirken die beiden Funktionen? - \points{2} - \item[(e)] -% Von welcher Ordnung (Landau-Symbol) sind die beiden Funktionen -% hinsichtlich der Anzahl ihrer Zugriffe auf die Zeichen im String -- und warum? -% Sie dürfen für \lstinline{strlen()} Ihre eigene Version der Funktion voraussetzen. -% \points 3 -% \item[(f)] - Schreiben Sie eine eigene Funktion, - die dieselbe Aufgabe erledigt wie \lstinline{fun_2()},\\ - nur effizienter. - \points{4} - \end{itemize} - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Auf welche Weise ist die Länge eines Strings gekennzeichnet?} - - Ein String ist ein Array von \lstinline{char}s. - Nach den eigentlichen Zeichen des Strings enthält das Array - \textbf{ein Null-Symbol} (Zeichen mit Zahlenwert 0, - nicht zu verwechseln mit der Ziffer \lstinline{'0'}) als Ende-Markierung. - Die Länge eines Strings ist die Anzahl der Zeichen - \emph{vor\/} diesem Symbol. - - \item[(b)] - {\bf Wie lang ist die Beispiel-String-Konstante \lstinline{"Hello, world!\n"}, - und wieviel Speicherplatz belegt sie?} - - Sie ist 14 Zeichen lang (\lstinline{'\n'} ist nur 1 Zeichen; - das Null-Symbol, das das Ende markiert, zählt hier nicht mit) - und belegt Speicherplatz für 15 Zeichen - (15 Bytes -- einschließlich Null-Symbol / Ende-Markierung). - - \item[(c)] - \textbf{Schreiben Sie eine eigene Funktion \lstinline{int strlen (char *s)}, - die die Länge eines Strings zurückgibt.} - - Siehe die Dateien \gitfile{hp}{2022ws/20221107}{loesung-2c-1.c} (mit Array-Index) - und \gitfile{hp}{2022ws/20221107}{loesung-2c-2.c} (mit Zeiger-Arithmetik). - Beide Lösungen sind korrekt und arbeiten gleich schnell. - - Die Warnung \lstinline[style=terminal]{conflicting types for built-in function "strlen"} - kann normalerweise ignoriert werden; - auf manchen Systemen (z.\,B.\ MinGW) hat jedoch die eingebaute Funktion \lstinline{strlen()} - beim Linken Vorrang vor der selbstgeschriebenen, - so daß die selbstgeschriebene Funktion nie aufgerufen wird. - In solchen Fällen ist es zulässig, die selbstgeschriebene Funktion - anders zu nennen (z.\,B.\ \lstinline{my_strlen()}). - - \item[(d)] - \textbf{Was bewirken die beiden Funktionen?} - - Beide addieren die Zahlenwerte der im String enthaltenen Zeichen - und geben die Summe als Funktionsergebnis zurück. - - Im Falle des Test-Strings \lstinline{"Hello, world!\n"} - lautet der Rückgabewert 1171 (siehe \gitfile{hp}{2022ws/20221107}{loesung-2d-1.c} und \gitfile{hp}{2022ws/20221107}{loesung-2d-2.c}). - - \item[(e)] -% \textbf{Von welcher Ordnung (Landau-Symbol) sind die beiden Funktionen -% hinsichtlich der Anzahl ihrer Zugriffe auf die Zeichen im String -- und warum? -% Sie dürfen für \lstinline{strlen()} Ihre eigene Version der Funktion voraussetzen.} -% -% Vorüberlegung: \lstinline{strlen()} greift in einer Schleife -% auf alle Zeichen des Strings der Länge $n$ zu, -% hat also $\mathcal{O}(n)$. -% -% \lstinline{fun_1()} ruft in jedem Schleifendurchlauf -% (zum Prüfen der \lstinline{while}-Bedingung) einmal \lstinline{strlen()} auf -% und greift anschließend auf ein Zeichen des Strings zu, -% hat also $\mathcal{O}\bigl(n\cdot(n+1)\bigr) = \mathcal{O}(n^2)$. -% -% \lstinline{fun_2()} ruft einmalig \lstinline{strlen()} auf -% und greift anschließend in einer Schleife auf alle Zeichen des Strings zu, -% hat also $\mathcal{O}(n+n) = \mathcal{O}(n)$. -% -% \item[(f)] - \textbf{Schreiben Sie eine eigene Funktion, - die dieselbe Aufgabe erledigt wie \lstinline{fun_2()}, - nur effizienter.} - - Die Funktion wird effizienter, - wenn man auf den Aufruf von \lstinline{strlen()} verzichtet - und stattdessen die Ende-Prüfung in derselben Schleife vornimmt, - in der man auch die Zahlenwerte der Zeichen des Strings aufsummiert. - - Die Funktion \lstinline{fun_3()} in der Datei \gitfile{hp}{2022ws/20221107}{loesung-2e-1.c} - realisiert dies mit einem Array-Index, - Die Funktion \lstinline{fun_4()} in der Datei \gitfile{hp}{2022ws/20221107}{loesung-2e-2.c} - mit Zeiger-Arithmetik. - Beide Lösungen sind korrekt und arbeiten gleich schnell. - -% \textbf{Bemerkung:} Die effizientere Version der Funktion -% arbeitet doppelt so schnell wie die ursprüngliche, -% hat aber ebenfalls die Ordnung $\mathcal{O}(n)$. - - \end{itemize} - - \exercise{LED-Blinkmuster} - - Wir betrachten das folgende Programm für einen ATmega32-Mikro-Controller - (Datei: \gitfile{hp}{2022ws/20221107}{aufgabe-3.c}). - - \begin{minipage}[t]{7cm} - \begin{lstlisting}[gobble=6] - #include <stdint.h> - #include <avr/io.h> - #include <avr/interrupt.h> - - uint8_t counter = 1; - uint8_t leds = 0; - - ISR (TIMER0_COMP_vect) - { - if (counter == 0) - { - leds = (leds + 1) % 8; - PORTC = leds << 4; - } - counter++; - } - \end{lstlisting} - \end{minipage}\hfill\begin{minipage}[t]{8.5cm} - \begin{lstlisting}[gobble=6] - void init (void) - { - cli (); - TCCR0 = (1 << CS01) | (1 << CS00); - TIMSK = 1 << OCIE0; - sei (); - DDRC = 0x70; - } - - int main (void) - { - init (); - while (1) - ; /* do nothing */ - return 0; - } - \end{lstlisting} - \end{minipage} - - An die Bits Nr.\ 4, 5 und 6 des Output-Ports C des Mikro-Controllers sind LEDs angeschlossen.\\ - Sobald das Programm läuft, blinken diese in charakteristischer Weise: - \begin{quote} - \newcommand{\tdn}[1]{\raisebox{-2pt}{#1}} - \begin{tabular}{|c|c|c|c|}\hline - \tdn{Phase} & \tdn{LED oben (rot)} & \tdn{LED Mitte (gelb)} & \tdn{LED unten (grün)} \\[2pt]\hline - 1 & aus & aus & an \\\hline - 2 & aus & an & aus \\\hline - 3 & aus & an & an \\\hline - 4 & an & aus & aus \\\hline - 5 & an & aus & an \\\hline - 6 & an & an & aus \\\hline - 7 & an & an & an \\\hline - 8 & aus & aus & aus \\\hline - \end{tabular} - \end{quote} - Jede Phase dauert etwas länger als eine halbe Sekunde. - Nach 8 Phasen wiederholt sich das Schema. - - Erklären Sie das Verhalten des Programms anhand des Quelltextes: - \vspace{-\medskipamount} - \begin{itemize}\itemsep0pt - \item[(a)] - Wieso macht das Programm überhaupt etwas, - wenn doch das Hauptprogramm nach dem Initialisieren lediglich eine Endlosschleife ausführt, - in der \emph{nichts} passiert? - \points{1} - \item[(b)] - Wieso wird die Zeile \lstinline|PORTC = leds << 4;| überhaupt aufgerufen, - wenn dies doch nur unter der Bedingung \lstinline|counter == 0| passiert, - wobei die Variable \lstinline|counter| auf 1 initialisiert, - fortwährend erhöht und nirgendwo zurückgesetzt wird? - \points{2} - \item[(c)] - Wie kommt das oben beschriebene Blinkmuster zustande? - \points{2} - \item[(d)] - Wieso dauert eine Phase ungefähr eine halbe Sekunde? - \points{2} - \item[(e)] - Was bedeutet "`\lstinline|ISR (TIMER0_COMP_vect)|"'? - \points{1} - \end{itemize} - - \goodbreak - Hinweis: - \vspace{-\medskipamount} - \begin{itemize}\itemsep0pt - \item - Die Funktion \lstinline|init()| sorgt dafür, daß der Timer-Interrupt Nr.\ 0 des Mikro-Controllers - etwa 488mal pro Sekunde aufgerufen wird. - Außerdem initialisiert sie die benötigten Bits an Port C als Output-Ports. - Sie selbst brauchen die Funktion \lstinline|init()| nicht weiter zu erklären. - \end{itemize} - - \solution - - \begin{itemize}\itemsep0pt - \item[(a)] - \textbf{Wieso macht das Programm überhaupt etwas, - wenn doch das Hauptprogramm nach dem Initialisieren lediglich eine Endlosschleife ausführt, - in der \emph{nichts} passiert?} - - Das Blinken wird durch einen Interrupt-Handler implementiert. - Dieser wird nicht durch das Hauptprogramm, - sondern durch ein Hardware-Ereignis (hier: Uhr) aufgerufen. - - \item[(b)] - \textbf{Wieso wird die Zeile \lstinline|PORTC = leds << 4;| überhaupt aufgerufen, - wenn dies doch nur unter der Bedingung \lstinline|counter == 0| passiert, - wobei die Variable \lstinline|counter| auf 1 initialisiert, - fortwährend erhöht und nirgendwo zurückgesetzt wird?} - - Die vorzeichenlose 8-Bit-Variable \lstinline{counter} kann nur - Werte von 0 bis 255 annehmen; bei einem weiteren - Inkrementieren springt sie wieder auf 0 (Überlauf), - und die \lstinline{if}-Bedingung ist erfüllt. - - \item[(c)] - \textbf{Wie kommt das oben beschriebene Blinkmuster zustande?} - - In jedem Aufruf des Interrupt-Handlers wird die Variable - \lstinline{leds} um 1 erhöht und anschließend modulo 8 genommen. - Sie durchläuft daher immer wieder die Zahlen von 0 bis 7. - - Durch die Schiebeoperation \lstinline{leds << 4} werden die 3 Bits - der Variablen \lstinline{leds} an diejenigen Stellen im Byte - geschoben, an denen die LEDs an den Mikro-Controller - angeschlossen sind (Bits 4, 5 und 6). - - Entsprechend durchläuft das Blinkmuster immer wieder - die Binärdarstellungen der Zahlen von 0 bis 7 - (genauer: von 1 bis 7 und danach 0). - - \item[(d)] - \textbf{Wieso dauert eine Phase ungefähr eine halbe Sekunde?} - - Der Interrupt-Handler wird gemäß Hinweis 488mal pro Sekunde aufgerufen. - Bei jedem 256sten Aufruf ändert sich das LED-Muster. - Eine Phase dauert somit $\frac{256}{488} \approx 0.52$ Sekunden. - - \item[(e)] - \textbf{Was bedeutet "`\lstinline|ISR (TIMER0_COMP_vect)|"'?} - - Deklaration eines Interrupt-Handlers für den Timer-Interrupt Nr.\ 0 - \end{itemize} - -\end{document} diff --git a/20221107/hp-uebung-20221107.pdf b/20221107/hp-uebung-20221107.pdf deleted file mode 100644 index da415d10ebc69833dcb69539d57554e3abf18933..0000000000000000000000000000000000000000 Binary files a/20221107/hp-uebung-20221107.pdf and /dev/null differ diff --git a/20221107/hp-uebung-20221107.tex b/20221107/hp-uebung-20221107.tex deleted file mode 100644 index a2d90f5ef64065e0e6f6744604ae5e13ecdadf13..0000000000000000000000000000000000000000 --- a/20221107/hp-uebung-20221107.tex +++ /dev/null @@ -1,236 +0,0 @@ -% hp-uebung-20221107.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Ausgabe von Hexadezimalzahlen, Länge von Strings, LED-Blinkmuster - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \thispagestyle{empty} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 7.\ November 2022} - - Diese Übung enthält Punkteangaben wie in einer Klausur. - Um zu "`bestehen"', müssen Sie innerhalb von 80 Minuten - unter Verwendung ausschließlich zugelassener Hilfsmittel - 14 Punkte (von insgesamt \totalpoints) erreichen. - - \exercise{Ausgabe von Hexadezimalzahlen} - - Schreiben Sie eine Funktion \lstinline{void print_hex (uint32_t x)}, - die eine gegebene vorzeichenlose 32-Bit-Ganzzahl \lstinline{x} - als Hexadezimalzahl ausgibt. - (Der Datentyp \lstinline{uint32_t} ist mit \lstinline{#include <stdint.h>} verfügbar.) - - Verwenden Sie dafür \emph{nicht\/} \lstinline{printf()} mit - der Formatspezifikation \lstinline{%x} als fertige Lösung, - sondern programmieren Sie die nötige Ausgabe selbst. - (Für Tests ist \lstinline{%x} hingegen erlaubt und sicherlich nützlich.) - - Die Verwendung von \lstinline{printf()} - mit anderen Formatspezifikationen wie z.\,B.\ \lstinline{%d} - oder \lstinline{%c} oder \lstinline{%s} ist hingegen zulässig. - - \points{8} - - (Hinweis für die Klausur: Abgabe auf Datenträger ist erlaubt und erwünscht, - aber nicht zwingend.) - - \exercise{Länge von Strings} - - Strings werden in der Programmiersprache C durch Zeiger auf \lstinline{char}-Variable realisiert. - - Beispiel: \lstinline{char *hello_world = "Hello, world!\n"} - - Die Systembibliothek stellt eine Funktion \lstinline{strlen()} zur Ermittlung der Länge von Strings\\ - zur Verfügung (\lstinline{#include <string.h>}). - - \begin{itemize} - \item[(a)] - Auf welche Weise ist die Länge eines Strings gekennzeichnet? - \points{1} - \item[(b)] - Wie lang ist die Beispiel-String-Konstante \lstinline{"Hello, world!\n"}, - und wieviel Speicherplatz belegt sie?\\ - \points{2} - \item[(c)] - Schreiben Sie eine eigene Funktion \lstinline{int strlen (char *s)}, - die die Länge eines Strings zurückgibt.\\ - \points{3} - \end{itemize} - - Wir betrachten nun die folgenden Funktionen (Datei: \gitfile{hp}{2022ws/20221107}{aufgabe-2.c}): - \begin{center} - \begin{minipage}{8cm} - \begin{lstlisting}[gobble=8] - int fun_1 (char *s) - { - int x = 0; - for (int i = 0; i < strlen (s); i++) - x += s[i]; - return x; - } - \end{lstlisting} - \end{minipage}% - \begin{minipage}{6cm} - \vspace*{-1cm} - \begin{lstlisting}[gobble=8] - int fun_2 (char *s) - { - int i = 0, x = 0; - int len = strlen (s); - while (i < len) - x += s[i++]; - return x; - } - \end{lstlisting} - \vspace*{-1cm} - \end{minipage} - \end{center} - \begin{itemize} - \item[(d)] - Was bewirken die beiden Funktionen? - \points{2} - \item[(e)] -% Von welcher Ordnung (Landau-Symbol) sind die beiden Funktionen -% hinsichtlich der Anzahl ihrer Zugriffe auf die Zeichen im String -- und warum? -% Sie dürfen für \lstinline{strlen()} Ihre eigene Version der Funktion voraussetzen. -% \points 3 -% \item[(f)] - Schreiben Sie eine eigene Funktion, - die dieselbe Aufgabe erledigt wie \lstinline{fun_2()},\\ - nur effizienter. - \points{4} - \end{itemize} - - \exercise{LED-Blinkmuster} - - Wir betrachten das folgende Programm für einen ATmega32-Mikro-Controller - (Datei: \gitfile{hp}{2022ws/20221107}{aufgabe-3.c}). - - \begin{minipage}[t]{7cm} - \begin{lstlisting}[gobble=6] - #include <stdint.h> - #include <avr/io.h> - #include <avr/interrupt.h> - - uint8_t counter = 1; - uint8_t leds = 0; - - ISR (TIMER0_COMP_vect) - { - if (counter == 0) - { - leds = (leds + 1) % 8; - PORTC = leds << 4; - } - counter++; - } - \end{lstlisting} - \end{minipage}\hfill\begin{minipage}[t]{8.5cm} - \begin{lstlisting}[gobble=6] - void init (void) - { - cli (); - TCCR0 = (1 << CS01) | (1 << CS00); - TIMSK = 1 << OCIE0; - sei (); - DDRC = 0x70; - } - - int main (void) - { - init (); - while (1) - ; /* do nothing */ - return 0; - } - \end{lstlisting} - \end{minipage} - - An die Bits Nr.\ 4, 5 und 6 des Output-Ports C des Mikro-Controllers sind LEDs angeschlossen.\\ - Sobald das Programm läuft, blinken diese in charakteristischer Weise: - \begin{quote} - \newcommand{\tdn}[1]{\raisebox{-2pt}{#1}} - \begin{tabular}{|c|c|c|c|}\hline - \tdn{Phase} & \tdn{LED oben (rot)} & \tdn{LED Mitte (gelb)} & \tdn{LED unten (grün)} \\[2pt]\hline - 1 & aus & aus & an \\\hline - 2 & aus & an & aus \\\hline - 3 & aus & an & an \\\hline - 4 & an & aus & aus \\\hline - 5 & an & aus & an \\\hline - 6 & an & an & aus \\\hline - 7 & an & an & an \\\hline - 8 & aus & aus & aus \\\hline - \end{tabular} - \end{quote} - Jede Phase dauert etwas länger als eine halbe Sekunde. - Nach 8 Phasen wiederholt sich das Schema. - - Erklären Sie das Verhalten des Programms anhand des Quelltextes: - \vspace{-\medskipamount} - \begin{enumerate}[\quad(a)] - \item - Wieso macht das Programm überhaupt etwas, - wenn doch das Hauptprogramm nach dem Initialisieren lediglich eine Endlosschleife ausführt, - in der \emph{nichts} passiert? - \points{1} - \item - Wieso wird die Zeile \lstinline|PORTC = leds << 4;| überhaupt aufgerufen, - wenn dies doch nur unter der Bedingung \lstinline|counter == 0| passiert, - wobei die Variable \lstinline|counter| auf 1 initialisiert, - fortwährend erhöht und nirgendwo zurückgesetzt wird? - \points{2} - \item - Wie kommt das oben beschriebene Blinkmuster zustande? - \points{2} - \item - Wieso dauert eine Phase ungefähr eine halbe Sekunde? - \points{2} - \item - Was bedeutet "`\lstinline|ISR (TIMER0_COMP_vect)|"'? - \points{1} - \end{enumerate} - - Hinweis: - \vspace{-\medskipamount} - \begin{itemize}\itemsep0pt - \item - Die Funktion \lstinline|init()| sorgt dafür, daß der Timer-Interrupt Nr.\ 0 des Mikro-Controllers - etwa 488mal pro Sekunde aufgerufen wird. - Außerdem initialisiert sie die benötigten Bits an Port C als Output-Ports. - Sie selbst brauchen die Funktion \lstinline|init()| nicht weiter zu erklären. - \end{itemize} - - \begin{flushright} - \textit{Viel Erfolg!} - \end{flushright} - - \makeatletter - \immediate\write\@mainaux{\string\gdef\string\totalpoints{\arabic{points}}} - \makeatother - -\end{document} diff --git a/20221107/io-ports-and-interrupts.pdf b/20221107/io-ports-and-interrupts.pdf deleted file mode 120000 index bcd46f7afb35605b20bdb05637e6de0a039893ec..0000000000000000000000000000000000000000 --- a/20221107/io-ports-and-interrupts.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/io-ports-and-interrupts.pdf \ No newline at end of file diff --git a/20221107/loesung-1-1.c b/20221107/loesung-1-1.c deleted file mode 100644 index 98b2f03f19d21aa2a794fef1f3f98feff95f5142..0000000000000000000000000000000000000000 --- a/20221107/loesung-1-1.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -void print_hex (uint32_t x) -{ - while (x) - { - int digit = x % 16; - if (digit < 10) - printf ("%d", digit); - else - printf ("%c", 'a' + digit - 10); - x /= 16; - } -} - -int main (void) -{ - print_hex (0xcafe42); - printf ("\n"); - return 0; -} diff --git a/20221107/loesung-1-2.c b/20221107/loesung-1-2.c deleted file mode 100644 index 35aa3b3aea6fc8faaa55c7d5382f0a8de9282aee..0000000000000000000000000000000000000000 --- a/20221107/loesung-1-2.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -void print_hex (uint32_t x) -{ - char digit[8]; - for (int i = 0; i < 8; i++) - { - digit[i] = x % 16; - x /= 16; - } - for (int i = 7; i >= 0; i--) - { - if (digit[i] < 10) - printf ("%d", digit[i]); - else - printf ("%c", 'a' + digit[i] - 10); - } -} - -int main (void) -{ - print_hex (0xcafe42); - printf ("\n"); - return 0; -} diff --git a/20221107/loesung-1-3.c b/20221107/loesung-1-3.c deleted file mode 100644 index 2462f2b537896722d8d1774a5d47f374ee5ef7fa..0000000000000000000000000000000000000000 --- a/20221107/loesung-1-3.c +++ /dev/null @@ -1,29 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -void print_hex (uint32_t x) -{ - char digit[8]; - int i = 0; - while (x) - { - digit[i] = x % 16; - x /= 16; - i++; - } - while (i > 0) - { - i--; - if (digit[i] < 10) - printf ("%d", digit[i]); - else - printf ("%c", 'a' + digit[i] - 10); - } -} - -int main (void) -{ - print_hex (0xcafe42); - printf ("\n"); - return 0; -} diff --git a/20221107/loesung-1-4.c b/20221107/loesung-1-4.c deleted file mode 100644 index 5083dcb865c86beafd43ce3e8837510b13cbe850..0000000000000000000000000000000000000000 --- a/20221107/loesung-1-4.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -void print_hex (uint32_t x) -{ - char digit[8]; - for (int i = 0; i < 8; i++) - { - digit[i] = x % 16; - x /= 16; - } - int printing = 0; - for (int i = 7; i >= 0; i--) - { - if (printing || digit[i] != 0) - { - printing = 1; - if (digit[i] < 10) - printf ("%d", digit[i]); - else - printf ("%c", 'a' + digit[i] - 10); - } - } -} - -int main (void) -{ - print_hex (0xcafe42); - printf ("\n"); - return 0; -} diff --git a/20221107/loesung-1-5.c b/20221107/loesung-1-5.c deleted file mode 100644 index e3446edb4a40348ac14da420f344c208f8916f7e..0000000000000000000000000000000000000000 --- a/20221107/loesung-1-5.c +++ /dev/null @@ -1,29 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -void print_hex (uint32_t x) -{ - char digit[8]; - int i = 0; - while (x) - { - digit[i] = x & 0x0000000f; - x >>= 4; - i++; - } - while (i > 0) - { - i--; - if (digit[i] < 10) - printf ("%d", digit[i]); - else - printf ("%c", 'a' + digit[i] - 10); - } -} - -int main (void) -{ - print_hex (0xcafe42); - printf ("\n"); - return 0; -} diff --git a/20221107/loesung-1-6.c b/20221107/loesung-1-6.c deleted file mode 100644 index 7b8e8e1a9d7285b8a1e02ff1a91310f1dc02ed5b..0000000000000000000000000000000000000000 --- a/20221107/loesung-1-6.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -void print_hex (uint32_t x) -{ - int i = 32; - while (i > 0) - { - i -= 4; - int digit = (x >> i) & 0x0000000f; - if (digit < 10) - printf ("%d", digit); - else - printf ("%c", 'a' + digit - 10); - } -} - -int main (void) -{ - print_hex (0xcafe42); - printf ("\n"); - return 0; -} diff --git a/20221107/loesung-2.c b/20221107/loesung-2.c deleted file mode 100644 index 85abfcf3e1e4bacf454acd10f6832b757a64ac35..0000000000000000000000000000000000000000 --- a/20221107/loesung-2.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void insert_into_string (char src, char *target, int pos) -{ - int len = strlen (target); - for (int i = len; i >= pos; i--) - target[i + 1] = target[i]; - target[pos] = src; -} - -int main (void) -{ - char test[100] = "Hochshule Bochum"; - insert_into_string ('c', test, 5); - printf ("%s\n", test); - return 0; -} diff --git a/20221107/loesung-2c-1.c b/20221107/loesung-2c-1.c deleted file mode 100644 index 69ddd0e4e749f6ca31bfa3d4f929c333648ef6ea..0000000000000000000000000000000000000000 --- a/20221107/loesung-2c-1.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int strlen (char *s) -{ - int l = 0; - while (s[l]) - l++; - return l; -} - -int main (void) -{ - printf ("%d\n", strlen ("Hello, world!\n")); - return 0; -} diff --git a/20221107/loesung-2c-2.c b/20221107/loesung-2c-2.c deleted file mode 100644 index e783c474e485e80d08a6e86f8ae6e179f5a294f4..0000000000000000000000000000000000000000 --- a/20221107/loesung-2c-2.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int strlen (char *s) -{ - char *s0 = s; - while (*s) - s++; - return s - s0; -} - -int main (void) -{ - printf ("%d\n", strlen ("Hello, world!\n")); - return 0; -} diff --git a/20221107/loesung-2d-1.c b/20221107/loesung-2d-1.c deleted file mode 100644 index 57521382c21fb743c6f5f5c65320bc4ac9360b1a..0000000000000000000000000000000000000000 --- a/20221107/loesung-2d-1.c +++ /dev/null @@ -1,34 +0,0 @@ - -#include <stdio.h> - -int strlen (char *s) -{ - int l = 0; - while (s[l]) - l++; - return l; -} - -int fun_1 (char *s) -{ - int x = 0; - for (int i = 0; i < strlen (s); i++) - x += s[i]; - return x; -} - -int fun_2 (char *s) -{ - int i = 0, x = 0; - int len = strlen (s); - while (i < len) - x += s[i++]; - return x; -} - -int main (void) -{ - printf ("%d\n", fun_1 ("Hello, world!\n")); - printf ("%d\n", fun_2 ("Hello, world!\n")); - return 0; -} diff --git a/20221107/loesung-2d-2.c b/20221107/loesung-2d-2.c deleted file mode 100644 index 5f3f0961129aa16fc9c4510ae21bb77b69913b12..0000000000000000000000000000000000000000 --- a/20221107/loesung-2d-2.c +++ /dev/null @@ -1,34 +0,0 @@ - -#include <stdio.h> - -int strlen (char *s) -{ - char *s0 = s; - while (*s) - s++; - return s - s0; -} - -int fun_1 (char *s) -{ - int x = 0; - for (int i = 0; i < strlen (s); i++) - x += s[i]; - return x; -} - -int fun_2 (char *s) -{ - int i = 0, x = 0; - int len = strlen (s); - while (i < len) - x += s[i++]; - return x; -} - -int main (void) -{ - printf ("%d\n", fun_1 ("Hello, world!\n")); - printf ("%d\n", fun_2 ("Hello, world!\n")); - return 0; -} diff --git a/20221107/loesung-2e-1.c b/20221107/loesung-2e-1.c deleted file mode 100644 index 74f5add0c5f62cccb8f817d40f860893f496db11..0000000000000000000000000000000000000000 --- a/20221107/loesung-2e-1.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int fun_3 (char *s) -{ - int i = 0, x = 0; - while (s[i]) - x += s[i++]; - return x; -} - -int main (void) -{ - printf ("%d\n", fun_3 ("Hello, world!\n")); - return 0; -} diff --git a/20221107/loesung-2e-2.c b/20221107/loesung-2e-2.c deleted file mode 100644 index b223d2d17c261d7cf1373a8379def8911a45ccb7..0000000000000000000000000000000000000000 --- a/20221107/loesung-2e-2.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int fun_4 (char *s) -{ - int x = 0; - while (*s) - x += *s++; - return x; -} - -int main (void) -{ - printf ("%d\n", fun_4 ("Hello, world!\n")); - return 0; -} diff --git a/20221107/logo-hochschule-bochum-cvh-text-v2.pdf b/20221107/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221107/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221107/logo-hochschule-bochum.pdf b/20221107/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221107/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221107/pgscript.sty b/20221107/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221107/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221107/pgslides.sty b/20221107/pgslides.sty deleted file mode 120000 index 5be1416f4216f076aa268901f52a15d775e43f64..0000000000000000000000000000000000000000 --- a/20221107/pgslides.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgslides.sty \ No newline at end of file diff --git a/20221107/test.pbm b/20221107/test.pbm deleted file mode 100644 index 2196f5cf811f0705aa4324f82088418694246002..0000000000000000000000000000000000000000 Binary files a/20221107/test.pbm and /dev/null differ diff --git a/20221107/test.png b/20221107/test.png deleted file mode 100644 index 92e23a26dd9bdd61085f4265346a958438970d57..0000000000000000000000000000000000000000 Binary files a/20221107/test.png and /dev/null differ diff --git a/20221107/test.xbm b/20221107/test.xbm deleted file mode 100644 index 9cf13a19dca3b0c195cf23e35456562948aca16d..0000000000000000000000000000000000000000 --- a/20221107/test.xbm +++ /dev/null @@ -1,5 +0,0 @@ -#define test_width 9 -#define test_height 8 -static char test_bits[] = { - 0x00, 0x00, 0x44, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x82, 0x00, - 0x7C, 0x00, 0x00, 0x00, }; diff --git a/20221107/widerstaende-interner-pull-up.png b/20221107/widerstaende-interner-pull-up.png deleted file mode 100644 index c96fea6fd4c5771ff9dc8df05f7c5006a766f962..0000000000000000000000000000000000000000 Binary files a/20221107/widerstaende-interner-pull-up.png and /dev/null differ diff --git a/20221107/widerstaende-keine.png b/20221107/widerstaende-keine.png deleted file mode 100644 index fd8214fdcf448851af922827b6fb5f7a78e8306e..0000000000000000000000000000000000000000 Binary files a/20221107/widerstaende-keine.png and /dev/null differ diff --git a/20221107/widerstaende-pull-down.png b/20221107/widerstaende-pull-down.png deleted file mode 100644 index 7bc85ac1e2d7567c50b1bc254567ed57692fab46..0000000000000000000000000000000000000000 Binary files a/20221107/widerstaende-pull-down.png and /dev/null differ diff --git a/20221107/widerstaende-pull-up.png b/20221107/widerstaende-pull-up.png deleted file mode 100644 index 95879fa0099f6139728d40498cd2826765cc03b5..0000000000000000000000000000000000000000 Binary files a/20221107/widerstaende-pull-up.png and /dev/null differ diff --git a/20221107/widerstaende.xcf.gz b/20221107/widerstaende.xcf.gz deleted file mode 100644 index 6f88deabf7bd885256eeab2abef8813259b67091..0000000000000000000000000000000000000000 Binary files a/20221107/widerstaende.xcf.gz and /dev/null differ diff --git a/20221114/Tower_of_Hanoi.jpeg b/20221114/Tower_of_Hanoi.jpeg deleted file mode 120000 index a1a794afda08596ffa2f46f278db53455de25b6c..0000000000000000000000000000000000000000 --- a/20221114/Tower_of_Hanoi.jpeg +++ /dev/null @@ -1 +0,0 @@ -../common/Tower_of_Hanoi.jpeg \ No newline at end of file diff --git a/20221114/aufgabe-1.c b/20221114/aufgabe-1.c deleted file mode 100644 index 2afae773ac2d564771ab6dfb473eed664070d3e2..0000000000000000000000000000000000000000 --- a/20221114/aufgabe-1.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -int main (void) -{ - uint64_t x = 4262939000843297096; - char *s = &x; - printf ("%s\n", s); - return 0; -} diff --git a/20221114/aufgabe-3.c b/20221114/aufgabe-3.c deleted file mode 100644 index cb09b0e10aade5c202ed88fddcb2e52d700d9915..0000000000000000000000000000000000000000 --- a/20221114/aufgabe-3.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -typedef struct -{ - uint32_t a; - uint64_t b; - uint8_t c; -} three_numbers; - -int main (void) -{ - three_numbers xyz = { 1819042120, 2410670883059281007, 0 }; - printf ("%s\n", &xyz); - return 0; -} diff --git a/20221114/gtk-13.c b/20221114/gtk-13.c deleted file mode 100644 index a91d9abf14066d773103a8fca1e2c41abad40be3..0000000000000000000000000000000000000000 --- a/20221114/gtk-13.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <gtk/gtk.h> - -#define WIDTH 640 -#define HEIGHT 480 - -double x = 5; -double y = 95; -double vx = 50.0; -double vy = 0.7; -double dt = 0.05; -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, HEIGHT - y, 5, 0, 2 * G_PI); - cairo_fill (c); - return FALSE; -} - -gboolean timer (GtkWidget *widget) -{ - x += vx * dt; - y += vy * dt; - vx += 0.0 * dt; - vy += (-g) * dt; - 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_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - - GtkWidget *drawing_area = gtk_drawing_area_new (); - gtk_container_add (GTK_CONTAINER (vbox), drawing_area); - g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_widget_show (drawing_area); - gtk_widget_show (button); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221114/hanoi-0.c b/20221114/hanoi-0.c deleted file mode 100644 index 83b5f081e33e699f2d5eaa1f858320530e1b2820..0000000000000000000000000000000000000000 --- a/20221114/hanoi-0.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> - -#define DISKS 4 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -int main (void) -{ - n[0] = 0; - n[1] = 0; - n[2] = 0; - display (); - return 0; -} diff --git a/20221114/hanoi-1.c b/20221114/hanoi-1.c deleted file mode 100644 index 6d005f0b12afa6086afb65e1794fb5c977b474e2..0000000000000000000000000000000000000000 --- a/20221114/hanoi-1.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <stdio.h> - -#define DISKS 4 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -int main (void) -{ - n[0] = 4; - tower[0][0] = 4; - tower[0][1] = 3; - tower[0][2] = 2; - tower[0][3] = 1; - n[1] = 0; - n[2] = 0; - display (); - return 0; -} diff --git a/20221114/hanoi-2.c b/20221114/hanoi-2.c deleted file mode 100644 index c928c1130539da08d0882249bdffc877d72289b2..0000000000000000000000000000000000000000 --- a/20221114/hanoi-2.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <stdio.h> - -#define DISKS 4 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -int main (void) -{ - n[0] = DISKS; - for (int i = 0; i < DISKS; i++) - tower[0][i] = DISKS - i; - n[1] = 0; - n[2] = 0; - display (); - return 0; -} diff --git a/20221114/hanoi-3.c b/20221114/hanoi-3.c deleted file mode 100644 index 4b59c046962c1f79eca315882d93faf6b6c298c1..0000000000000000000000000000000000000000 --- a/20221114/hanoi-3.c +++ /dev/null @@ -1,44 +0,0 @@ -#include <stdio.h> -#include <error.h> - -#define DISKS 4 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -void move (int from, int to, int disks) -{ - if (disks == 1) - { - if (n[from] <= 0) - error (1, 0, "trying to move disk from empty tower"); - if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1]) - error (1, 0, "trying to move larger disk on smaller one"); - tower[to][n[to]] = tower[from][n[from] - 1]; - n[to]++; - n[from]--; - } -} - -int main (void) -{ - n[0] = DISKS; - for (int i = 0; i < DISKS; i++) - tower[0][i] = DISKS - i; - n[1] = 0; - n[2] = 0; - move (2, 0, 1); - display (); - return 0; -} diff --git a/20221114/hanoi-4.c b/20221114/hanoi-4.c deleted file mode 100644 index 162a5ba7cccedf64bff8ae9a514aaf146088e3a4..0000000000000000000000000000000000000000 --- a/20221114/hanoi-4.c +++ /dev/null @@ -1,44 +0,0 @@ -#include <stdio.h> -#include <error.h> - -#define DISKS 4 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -void move (int from, int to, int disks) -{ - if (disks == 1) - { - if (n[from] <= 0) - error (1, 0, "trying to move disk from empty tower"); - if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1]) - error (1, 0, "trying to move larger disk on smaller one"); - tower[to][n[to]] = tower[from][n[from] - 1]; - n[to]++; - n[from]--; - } -} - -int main (void) -{ - n[0] = DISKS; - for (int i = 0; i < DISKS; i++) - tower[0][i] = DISKS - i; - n[1] = 0; - n[2] = 0; - move (0, 2, 1); - display (); - return 0; -} diff --git a/20221114/hanoi-5.c b/20221114/hanoi-5.c deleted file mode 100644 index e04ad85f63fe92e5c15d22646beb9e9107bf78d6..0000000000000000000000000000000000000000 --- a/20221114/hanoi-5.c +++ /dev/null @@ -1,45 +0,0 @@ -#include <stdio.h> -#include <error.h> - -#define DISKS 4 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -void move (int from, int to, int disks) -{ - if (disks == 1) - { - if (n[from] <= 0) - error (1, 0, "trying to move disk from empty tower"); - if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1]) - error (1, 0, "trying to move larger disk on smaller one"); - tower[to][n[to]] = tower[from][n[from] - 1]; - n[to]++; - n[from]--; - display (); - } -} - -int main (void) -{ - n[0] = DISKS; - for (int i = 0; i < DISKS; i++) - tower[0][i] = DISKS - i; - n[1] = 0; - n[2] = 0; - display (); - move (0, 2, 1); - return 0; -} diff --git a/20221114/hanoi-6.c b/20221114/hanoi-6.c deleted file mode 100644 index 1267605f802246e857c32d29cc0a132609cb24ce..0000000000000000000000000000000000000000 --- a/20221114/hanoi-6.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <stdio.h> -#include <error.h> - -#define DISKS 4 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -void move (int from, int to, int disks) -{ - if (disks == 1) - { - if (n[from] <= 0) - error (1, 0, "trying to move disk from empty tower"); - if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1]) - error (1, 0, "trying to move larger disk on smaller one"); - tower[to][n[to]] = tower[from][n[from] - 1]; - n[to]++; - n[from]--; - display (); - } - else - { - int help = 0 + 1 + 2 - from - to; - move (from, help, disks - 1); - move (from, to, 1); - move (help, to, disks - 1); - } -} - -int main (void) -{ - n[0] = DISKS; - for (int i = 0; i < DISKS; i++) - tower[0][i] = DISKS - i; - n[1] = 0; - n[2] = 0; - display (); - move (0, 2, DISKS); - return 0; -} diff --git a/20221114/hanoi-7.c b/20221114/hanoi-7.c deleted file mode 100644 index f71fcdc0c3f66047ee3ad870d019a06eb328050f..0000000000000000000000000000000000000000 --- a/20221114/hanoi-7.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <stdio.h> -#include <error.h> - -#define DISKS 5 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -void move (int from, int to, int disks) -{ - if (disks == 1) - { - if (n[from] <= 0) - error (1, 0, "trying to move disk from empty tower"); - if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1]) - error (1, 0, "trying to move larger disk on smaller one"); - tower[to][n[to]] = tower[from][n[from] - 1]; - n[to]++; - n[from]--; - display (); - } - else - { - int help = 0 + 1 + 2 - from - to; - move (from, help, disks - 1); - move (from, to, 1); - move (help, to, disks - 1); - } -} - -int main (void) -{ - n[0] = DISKS; - for (int i = 0; i < DISKS; i++) - tower[0][i] = DISKS - i; - n[1] = 0; - n[2] = 0; - display (); - move (0, 2, DISKS); - return 0; -} diff --git a/20221114/hanoi-8.c b/20221114/hanoi-8.c deleted file mode 100644 index 6d804063531d424a82924a89d85424c33994793b..0000000000000000000000000000000000000000 --- a/20221114/hanoi-8.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <stdio.h> -#include <error.h> - -#define DISKS 64 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -void move (int from, int to, int disks) -{ - if (disks == 1) - { - if (n[from] <= 0) - error (1, 0, "trying to move disk from empty tower"); - if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1]) - error (1, 0, "trying to move larger disk on smaller one"); - tower[to][n[to]] = tower[from][n[from] - 1]; - n[to]++; - n[from]--; - display (); - } - else - { - int help = 0 + 1 + 2 - from - to; - move (from, help, disks - 1); - move (from, to, 1); - move (help, to, disks - 1); - } -} - -int main (void) -{ - n[0] = DISKS; - for (int i = 0; i < DISKS; i++) - tower[0][i] = DISKS - i; - n[1] = 0; - n[2] = 0; - display (); - move (0, 2, DISKS); - return 0; -} diff --git a/20221114/hanoi-9.c b/20221114/hanoi-9.c deleted file mode 100644 index 7694b373b7011e96f6be0ad0f00ba54b67086158..0000000000000000000000000000000000000000 --- a/20221114/hanoi-9.c +++ /dev/null @@ -1,58 +0,0 @@ -#include <stdio.h> -#include <error.h> - -#define DISKS 64 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -void move (int from, int to, int disks) -{ - if (disks == 1) - { - if (n[from] <= 0) - error (1, 0, "trying to move disk from empty tower"); - if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1]) - error (1, 0, "trying to move larger disk on smaller one"); - tower[to][n[to]] = tower[from][n[from] - 1]; - n[to]++; - n[from]--; - static int counter = 1; - if (counter++ >= 100000000) - { - display (); - counter = 1; - } - } - else - { - int help = 0 + 1 + 2 - from - to; - move (from, help, disks - 1); - move (from, to, 1); - move (help, to, disks - 1); - } -} - -int main (void) -{ - n[0] = DISKS; - for (int i = 0; i < DISKS; i++) - tower[0][i] = DISKS - i; - n[1] = 0; - n[2] = 0; - display (); - move (0, 2, DISKS); - display (); - return 0; -} diff --git a/20221114/hp-20221114.pdf b/20221114/hp-20221114.pdf deleted file mode 100644 index 2ff7cc6338c108570a7e8b83acd64d317063c8d0..0000000000000000000000000000000000000000 Binary files a/20221114/hp-20221114.pdf and /dev/null differ diff --git a/20221114/hp-20221114.tex b/20221114/hp-20221114.tex deleted file mode 100644 index 585f6e28f5c6fd4c7c8697bc71cad34a580707ba..0000000000000000000000000000000000000000 --- a/20221114/hp-20221114.tex +++ /dev/null @@ -1,1308 +0,0 @@ -% hp-20221114.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Binärdarstellung negativer Zahlen, Alignment, Differentialgleichungen, Rekursion - -\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} - -\newcommand{\redurl}[1]{\href{#1}{\color{red}\nolinkurl{#1}}} - -\title{Hardwarenahe Programmierung} -\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{14.\ November 2022} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \begin{itemize} - \item[4.1] Bit-Operationen - \item[4.2] I/O-Ports - \color{medgreen} - \item[4.3] Interrupts - \item[4.4] volatile-Variable - \color{orange} - \item[4.5] Byte-Reihenfolge -- Endianness - \color{red} - \item[4.6] Binärdarstellung negativer Zahlen - \item[4.7] Speicherausrichtung -- Alignment - \end{itemize} - \item[\textbf{5}] \textbf{Algorithmen} - \begin{itemize} - \color{red} - \item[5.1] Differentialgleichungen - \color{black} - \item[5.2] Rekursion - \item[5.3] Aufwandsabschätzungen - \end{itemize} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \item[\textbf{7}] \textbf{Datenstrukturen} - \end{itemize} - -\end{frame} - -\setcounter{section}{3} -\section{Hardwarenahe Programmierung} -\subsection{Bit-Operationen} -\subsubsection{Zahlensysteme} - -\begin{frame}[fragile] - - \showsection - \vspace*{-\smallskipamount} - \showsubsection - \vspace*{-\medskipamount} - \showsubsubsection - - \begin{tabular}{rlrl} - Basis & Name & Beispiel & Anwendung \\[\smallskipamount] - 2 & Binärsystem & 1\,0000\,0011 & Bit-Operationen \\ - 8 & Oktalsystem & \lstinline,0403, & Dateizugriffsrechte (Unix) \\ - 10 & Dezimalsystem & \lstinline,259, & Alltag \\ - 16 & Hexadezimalsystem & \lstinline,0x103, & Bit-Operationen \\ - 256 & (keiner gebräuchlich) & 0.0.1.3 & IP-Adressen (IPv4) - \end{tabular} - - \bigskip - - \begin{itemize} - \item - Computer rechnen im Binärsystem. - \item - Für viele Anwendungen (z.\,B.\ I/O-Ports, Grafik, \dots) ist es notwendig,\\ - Bits in Zahlen einzeln ansprechen zu können. - \end{itemize} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsubsection - - \begin{tabular}{rlrlrc} - \qquad 000 & \bf 0 \hspace*{1.5cm} & 0000 & \bf 0 & \quad 1000 & \bf 8\\ - 001 & \bf 1 & 0001 & \bf 1 & 1001 & \bf 9\\ - 010 & \bf 2 & 0010 & \bf 2 & 1010 & \bf A\\ - 011 & \bf 3 & 0011 & \bf 3 & 1011 & \bf B\\[\smallskipamount] - 100 & \bf 4 & 0100 & \bf 4 & 1100 & \bf C\\ - 101 & \bf 5 & 0101 & \bf 5 & 1101 & \bf D\\ - 110 & \bf 6 & 0110 & \bf 6 & 1110 & \bf E\\ - 111 & \bf 7 & 0111 & \bf 7 & 1111 & \bf F\\ - \end{tabular} - - \medskip - - \begin{itemize} - \item - Oktal- und Hexadezimalzahlen lassen sich ziffernweise\\ - in Binär-Zahlen umrechnen. - \item - Hexadezimalzahlen sind eine Kurzschreibweise für Binärzahlen,\\ - gruppiert zu jeweils 4 Bits. - \item - Oktalzahlen sind eine Kurzschreibweise für Binärzahlen,\\ - gruppiert zu jeweils 3 Bits. - \item - Trotz Taschenrechner u.\,ä.\ lohnt es sich,\\ - die o.\,a.\ Umrechnungstabelle \textbf{auswendig} zu kennen. - \end{itemize} - -\end{frame} - -\subsubsection{Bit-Operationen in C} - -\begin{frame}[fragile] - - \showsubsubsection - - \begin{tabular}{lll} - C-Operator & Verknüpfung & Anwendung \\[\smallskipamount] - \lstinline,&, & Und & Bits gezielt löschen \\ - \lstinline,|, & Oder & Bits gezielt setzen \\ - \lstinline,^, & Exklusiv-Oder & Bits gezielt invertieren \\ - \lstinline,~, & Nicht & Alle Bits invertieren \\[\smallskipamount] - \lstinline,<<, & Verschiebung nach links & Maske generieren \\ - \lstinline,>>, & Verschiebung nach rechts & Bits isolieren - \end{tabular} - - \bigskip - - Numerierung der Bits: von rechts ab 0 - - \medskip - - \begin{tabular}{ll} - Bit Nr.\ 3 auf 1 setzen: & - \lstinline,a |= 1 << 3;, \\ - Bit Nr.\ 4 auf 0 setzen: & - \lstinline,a &= ~(1 << 4);, \\ - Bit Nr.\ 0 invertieren: & - \lstinline,a ^= 1 << 0;, - \end{tabular} - - \smallskip - - ~~Abfrage, ob Bit Nr.\ 1 gesetzt ist:\quad - \lstinline{if (a & (1 << 1))} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsubsection - - C-Datentypen für Bit-Operationen: - \smallskip\par - \lstinline{#include <stdint.h>} - \medskip\par - \begin{tabular}{lllll} - & 8 Bit & 16 Bit & 32 Bit & 64 Bit \\ - mit Vorzeichen & \lstinline,int8_t, - & \lstinline,int16_t, - & \lstinline,int32_t, - & \lstinline,int64_t, \\ - ohne Vorzeichen & \lstinline,uint8_t, - & \lstinline,uint16_t, - & \lstinline,uint32_t, - & \lstinline,uint64_t, - \end{tabular} - - \bigskip - \bigskip - - Ausgabe: - \smallskip\par - \begin{lstlisting} - #include <stdio.h> - #include <stdint.h> - #include <inttypes.h> - ... - uint64_t x = 42; - printf ("Die Antwort lautet: %" PRIu64 "\n", x); - \end{lstlisting} - -\end{frame} - -\subsection{I/O-Ports} - -\begin{frame}[fragile] - -% \showsection - \showsubsection - \vspace*{-1.5\medskipamount} - {\large\textbf{\color{structure}4.3\quad Interrupts}} - - \bigskip - - Kommunikation mit externen Geräten - - \bigskip - - \begin{center} - \includegraphics{io-ports-and-interrupts.pdf} - \end{center} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - In Output-Port schreiben = Aktoren ansteuern - - Beispiel: LED - - \medskip - - \begin{lstlisting} - #include <avr/io.h> - ... - DDRC = 0x70; - PORTC = 0x40; - \end{lstlisting} - \begin{picture}(0,0) - \put(3,0.67){\begin{minipage}{3cm} - \color{red}% - binär: 0111\,0000\\ - binär: 0100\,0000 - \end{minipage}} - \put(10,0.67){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}} - \end{picture} - - \bigskip - - \lstinline{DDR} = Data Direction Register\\ - Bit = 1 für Output-Port\\ - Bit = 0 für Input-Port - - \bigskip - - \emph{Details: siehe Datenblatt und Schaltplan} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Aus Input-Port lesen = Sensoren abfragen - - Beispiel: Taster - - \medskip - - \begin{lstlisting} - #include <avr/io.h> - ... - DDRC = 0xfd; - while ((PINC & 0x02) == 0) - ; /* just wait */ - \end{lstlisting} - \begin{picture}(0,0)(-1.5,-0.42) - \put(3,0.67){\begin{minipage}{3cm} - \color{red}% - binär: 1111\,1101\\ - binär: 0000\,0010 - \end{minipage}} - \put(10,0.67){\makebox(0,0)[r]{\color{red}Herstellerspezifisch!}} - \end{picture} - - \bigskip - - \lstinline{DDR} = Data Direction Register\\ - Bit = 1 für Output-Port\\ - Bit = 0 für Input-Port - - \bigskip - - \emph{Details: siehe Datenblatt und Schaltplan} - - \bigskip - - Praktikumsaufgabe: Druckknopfampel - -\end{frame} - -\subsection{Interrupts} - -\begin{frame}[fragile] - - \showsubsection - - Externes Gerät ruft (per Stromsignal) Unterprogramm auf - - Zeiger hinterlegen: "`Interrupt-Vektor"' - - Beispiel: eingebaute Uhr\hfill - \makebox(0,0)[tr]{% - \only<1->{\begin{minipage}[t]{4.7cm} - \vspace*{-0.3cm}% - statt Zählschleife (\lstinline{_delay_ms}):\\ - Hauptprogramm kann\\ - andere Dinge tun - \end{minipage}}% - } - - \medskip - - \begin{lstlisting} - #include <avr/interrupt.h> - - ... - - - ISR (TIMER0B_COMP_vect) - { - PORTD ^= 0x40; - } - \end{lstlisting} - \begin{picture}(0,0) - \color{red} - \put(1.9,3.1){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-1.4,-1.0);}}} - \put(2.0,3.2){\makebox(0,0)[l]{"`Dies ist ein Interrupt-Handler."'}} - \put(2.3,2.6){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-0.6,-0.55);}}} - \put(2.4,2.6){\makebox(0,0)[l]{Interrupt-Vektor darauf zeigen lassen}} - \end{picture} - - Initialisierung über spezielle Ports: - \lstinline{TCCR0B}, \lstinline{TIMSK0} - - \bigskip - - \emph{Details: siehe Datenblatt und Schaltplan} - - \vspace*{-2.5cm}\hfill - {\color{red}Herstellerspezifisch!}% - \hspace*{1cm} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Externes Gerät ruft (per Stromsignal) Unterprogramm auf - - Zeiger hinterlegen: "`Interrupt-Vektor"' - - Beispiel: Taster\hfill - \makebox(0,0)[tr]{% - \begin{minipage}[t]{4.7cm} - \vspace*{-0.3cm}% - statt \newterm{Busy Waiting\/}:\\ - Hauptprogramm kann\\ - andere Dinge tun - \end{minipage}} - - \medskip - - \begin{lstlisting} - #include <avr/interrupt.h> - ... - - ISR (INT0_vect) - { - PORTD ^= 0x40; - } - \end{lstlisting} - - \medskip - - Initialisierung über spezielle Ports: - \lstinline{EICRA}, \lstinline{EIMSK} - - \bigskip - - \emph{Details: siehe Datenblatt und Schaltplan} - - \vspace*{-2.5cm}\hfill - {\color{red}Herstellerspezifisch!}% - \hspace*{1cm} - -\end{frame} - -\subsection{volatile-Variable} - -\begin{frame}[fragile] - - \showsubsection - - Externes Gerät ruft (per Stromsignal) Unterprogramm auf - - Zeiger hinterlegen: "`Interrupt-Vektor"' - - Beispiel: Taster - - \vspace*{-2.5pt} - - \begin{minipage}[t]{5cm} - \begin{onlyenv}<1> - \begin{lstlisting}[gobble=8] - ¡#include <avr/interrupt.h> - ... - - uint8_t key_pressed = 0; - - ISR (INT0_vect) - { - key_pressed = 1; - }¿ - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<2> - \begin{lstlisting}[gobble=8] - ¡#include <avr/interrupt.h> - ... - - volatile uint8_t key_pressed = 0; - - ISR (INT0_vect) - { - key_pressed = 1; - }¿ - \end{lstlisting} - \end{onlyenv} - \end{minipage}\hfill - \begin{minipage}[t]{6cm} - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - ... - - while (1) - { - while (!key_pressed) - ; /* just wait */ - PORTD ^= 0x40; - key_pressed = 0; - } - return 0; - }¿ - \end{lstlisting} - \end{minipage} - - \pause - \begin{picture}(0,0) - \color{red} - \put(10.3,4.0){\makebox(0,0)[b]{\begin{minipage}{6cm} - \begin{center} - \textbf{volatile}:\\ - Speicherzugriff\\ - nicht wegoptimieren - \end{center} - \end{minipage}}} - \put(10.3,3.95){\makebox(0,0)[tr]{\tikz{\draw[-latex](0,0)--(-0.5,-0.9);}}} - \end{picture} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Was ist eigentlich \lstinline{PORTD}? - - \bigskip -% \pause - - \lstinline[style=cmd]{avr-gcc -Wall -Os -mmcu=atmega328p blink-3.c -E} - - \bigskip -% \pause - \lstinline{PORTD = 0x01;}\\ - \textarrow\quad - \lstinline[style=terminal]{(*(volatile uint8_t *)((0x0B) + 0x20)) = 0x01;}\\ -% \pause - \begin{picture}(0,2)(0,-1.7) - \color{red} - \put(5.75,0.3){$\underbrace{\rule{2.95cm}{0pt}}_{\mbox{Zahl: \lstinline|0x2B|}}$} -% \pause - \put(1.55,0.3){$\underbrace{\rule{4.0cm}{0pt}}_{\mbox{\shortstack[t]{Umwandlung in Zeiger\\ - auf \lstinline|volatile uint8_t|}}}$} -% \pause - \put(1.32,-1){\makebox(0,0)[b]{\tikz{\draw[-latex](0,0)--(0,1.3)}}} - \put(1.12,-1.1){\makebox(0,0)[tl]{Dereferenzierung des Zeigers}} - \end{picture} - -% \pause - \textarrow\quad - \lstinline|volatile uint8_t|-Variable an Speicheradresse \lstinline|0x2B| - -% \pause - \bigskip - \bigskip - - \textarrow\quad - \lstinline|PORTA = PORTB = PORTC = PORTD = 0| ist eine schlechte Idee. - -\end{frame} - -\subsection{Byte-Reihenfolge -- Endianness} -\subsubsection{Konzept} - -\begin{frame}[fragile] - - \showsubsection - \showsubsubsection - - Eine Zahl geht über mehrere Speicherzellen.\\ - Beispiel: 16-Bit-Zahl in 2 8-Bit-Speicherzellen - - \smallskip - - Welche Bits liegen wo? - -% \pause - \bigskip - - $1027 = 1024 + 2 + 1 = 0000\,0100\,0000\,0011_2 = 0403_{16}$ - -% \pause - \bigskip - Speicherzellen: - - \medskip - \begin{tabular}{|c|c|l}\cline{1-2} - \raisebox{-0.25ex}{04} & \raisebox{-0.25ex}{03} & \strut Big-Endian "`großes Ende zuerst"' \\\cline{1-2} - \multicolumn{2}{c}{} & % \pause - für Menschen leichter lesbar % \pause - \\ - \multicolumn{3}{c}{} \\[-5pt]\cline{1-2} - \raisebox{-0.25ex}{03} & \raisebox{-0.25ex}{04} & \strut Little-Endian "`kleines Ende zuerst"' \\\cline{1-2} - \multicolumn{2}{c}{} & % \pause - bei Additionen effizienter - \end{tabular} - -% \pause - \medskip - \textarrow\ Geschmackssache -% \pause\\ - \quad\textbf{\dots\ außer bei Datenaustausch!} - -% \pause -% \bigskip -% -% Aber: nicht verwechseln! \qquad $0304_{16} = 772$ - -\end{frame} - -\begin{frame} - - \showsubsection - \showsubsubsection - - Eine Zahl geht über mehrere Speicherzellen.\\ - Beispiel: 16-Bit-Zahl in 2 8-Bit-Speicherzellen - - \smallskip - - Welche Bits liegen wo? - - \medskip - - \textarrow\ Geschmackssache\\ - \textbf{\dots\ außer bei Datenaustausch!} - - \begin{itemize} - \item - Dateiformate - \item - Datenübertragung - \end{itemize} - -\end{frame} - -\subsubsection{Dateiformate} - -\begin{frame} - - \showsubsection - \showsubsubsection - - Audio-Formate: Reihenfolge der Bytes in 16- und 32-Bit-Zahlen - \begin{itemize} - \item - RIFF-WAVE-Dateien (\file{.wav}): Little-Endian - \item - Au-Dateien (\file{.au}): Big-Endian -% \pause - \item - ältere AIFF-Dateien (\file{.aiff}): Big-Endian - \item - neuere AIFF-Dateien (\file{.aiff}): Little-Endian - \end{itemize} - -% \pause - \bigskip - - Grafik-Formate: Reihenfolge der Bits in den Bytes - \begin{itemize} - \item - PBM-Dateien: Big-Endian\only<1->{, MSB first} - \item - XBM-Dateien: Little-Endian\only<1->{, LSB first} - \end{itemize} - \only<1->{MSB/LSB = most/least significant bit} - -\end{frame} - -\subsubsection{Datenübertragung} - -\begin{frame} - - \showsubsection - \showsubsubsection - - \begin{itemize} - \item - RS-232 (serielle Schnittstelle): LSB first - \item - I$^2$C: MSB first - \item - USB: beides - \pause - \medskip - \item - Ethernet: LSB first - \item - TCP/IP (Internet): Big-Endian - \end{itemize} - -\end{frame} - -\subsection{Binärdarstellung negativer Zahlen} - -\begin{frame}[fragile] - - \showsubsection - - Speicher ist begrenzt!\\ - \textarrow\ feste Anzahl von Bits - - \medskip - - 8-Bit-Zahlen ohne Vorzeichen: \lstinline{uint8_t}\\ - \textarrow\ Zahlenwerte von \lstinline{0x00} bis \lstinline{0xff} = 0 bis 255\\ - \pause - \textarrow\ 255 + 1 = 0 - - \pause - \medskip - - 8-Bit-Zahlen mit Vorzeichen: \lstinline{int8_t}\\ - \lstinline{0xff} = 255 ist die "`natürliche"' Schreibweise für $-1$.\\ - \pause - \textarrow\ Zweierkomplement - - \pause - \medskip - - Oberstes Bit = 1: negativ\\ - Oberstes Bit = 0: positiv\\ - \textarrow\ 127 + 1 = $-128$ - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Speicher ist begrenzt!\\ - \textarrow\ feste Anzahl von Bits - - \medskip - - 16-Bit-Zahlen ohne Vorzeichen: - \lstinline{uint16_t}\hfill\lstinline{uint8_t}\\ - \textarrow\ Zahlenwerte von \lstinline{0x0000} bis \lstinline{0xffff} - = 0 bis 65535\hfill 0 bis 255\\ - \textarrow\ 65535 + 1 = 0\hfill 255 + 1 = 0 - - \medskip - - 16-Bit-Zahlen mit Vorzeichen: - \lstinline{int16_t}\hfill\lstinline{int8_t}\\ - \lstinline{0xffff} = 66535 ist die "`natürliche"' Schreibweise für $-1$.\hfill - \lstinline{0xff} = 255 = $-1$\\ - \textarrow\ Zweierkomplement - - \medskip - - Oberstes Bit = 1: negativ\\ - Oberstes Bit = 0: positiv\\ - \textarrow\ 32767 + 1 = $-32768$ - - \bigskip - Literatur: \url{http://xkcd.com/571/} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Frage: \emph{Für welche Zahl steht der Speicherinhalt\, - \raisebox{2pt}{% - \tabcolsep0.25em - \begin{tabular}{|c|c|}\hline - \rule{0pt}{11pt}a3 & 90 \\\hline - \end{tabular}} - (hexadezimal)?} - - \pause - \smallskip - Antwort: \emph{Das kommt darauf an.} ;--) - - \pause - \medskip - Little-Endian: - - \smallskip - - \begin{tabular}{lrl} - als \lstinline,int8_t,: & $-93$ & (nur erstes Byte)\\ - als \lstinline,uint8_t,: & $163$ & (nur erstes Byte)\\ - als \lstinline,int16_t,: & $-28509$\\ - als \lstinline,uint16_t,: & $37027$\\ - \lstinline,int32_t, oder größer: & $37027$ - & (zusätzliche Bytes mit Nullen aufgefüllt) - \end{tabular} - - \pause - \medskip - Big-Endian: - - \smallskip - - \begin{tabular}{lrl} - als \lstinline,int8_t,: & $-93$ & (nur erstes Byte)\\ - als \lstinline,uint8_t,: & $163$ & (nur erstes Byte)\\ - als \lstinline,int16_t,: & $-23664$\\ - als \lstinline,uint16_t,: & $41872$\\ als \lstinline,int32_t,: & $-1550843904$ & (zusätzliche Bytes\\ - als \lstinline,uint32_t,: & $2744123392$ & mit Nullen aufgefüllt)\\ - als \lstinline,int64_t,: & $-6660823848880963584$\\ - als \lstinline,uint64_t,: & $11785920224828588032$\\ - \end{tabular} - - \vspace*{-1cm} - -\end{frame} - -\subsection{Speicherausrichtung -- Alignment} - -\begin{frame}[fragile] - - \showsubsection - - \begin{lstlisting} - #include <stdint.h> - - uint8_t a; - uint16_t b; - uint8_t c; - \end{lstlisting} - - \pause - \bigskip - - Speicheradresse durch 2 teilbar -- "`16-Bit-Alignment"' - \begin{itemize} - \item - 2-Byte-Operation: effizienter - \pause - \item - \dots\ oder sogar nur dann erlaubt - \pause - \arrowitem - Compiler optimiert Speicherausrichtung - \end{itemize} - - \medskip - - \pause - \begin{minipage}{3cm} - \begin{lstlisting}[gobble=6] - ¡uint8_t a; - uint8_t dummy; - uint16_t b; - uint8_t c;¿ - \end{lstlisting} - \end{minipage} - \pause - \begin{minipage}{3cm} - \begin{lstlisting}[gobble=6] - ¡uint8_t a; - uint8_t c; - uint16_t b;¿ - \end{lstlisting} - \end{minipage} - - \pause - \vspace{-1.75cm} - \strut\hfill - \begin{minipage}{6.5cm} - Fazit: - \begin{itemize} - \item - \textbf{Adressen von Variablen\\ - sind systemabhängig} - \item - Bei Definition von Datenformaten\\ - Alignment beachten \textarrow\ effizienter - \end{itemize} - \end{minipage} - -\end{frame} - -\section{Algorithmen} -\subsection{Differentialgleichungen} - -\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} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \begin{itemize} - \item[4.1] Bit-Operationen - \item[4.2] I/O-Ports - \item[4.3] Interrupts - \item[4.4] volatile-Variable - \color{medgreen} - \item[4.5] Byte-Reihenfolge -- Endianness - \item[4.6] Binärdarstellung negativer Zahlen - \item[4.7] Speicherausrichtung -- Alignment - \end{itemize} - \item[\textbf{5}] \textbf{Algorithmen} - \begin{itemize} - \color{medgreen} - \item[5.1] Differentialgleichungen - \color{red} - \item[5.2] Rekursion - \color{black} - \item[5.3] Aufwandsabschätzungen - \end{itemize} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \item[\textbf{7}] \textbf{Datenstrukturen} - \end{itemize} - -\end{frame} - -\setcounter{section}{4} -\section{Algorithmen} -\setcounter{subsection}{1} -\subsection{Rekursion} - -\begin{frame}[fragile] - - \showsubsection - - Vollständige Induktion: - \vspace*{-0.725cm} - \begin{displaymath} - \hspace*{4cm} - \left. - \begin{array}{r} - \mbox{Aussage gilt für $n = 1$}\\[2pt] - \mbox{Schluß von $n - 1$ auf $n$} - \end{array} - \right\} - \mbox{Aussage gilt für alle $n\in\mathbb{N}$} - \end{displaymath} - \vspace*{-0.5cm} - - \pause - - Türme von Hanoi - - \begin{onlyenv}<2> - \begin{center} - \includegraphics[width=12.2cm]{Tower_of_Hanoi.jpeg} - \end{center} - \end{onlyenv} - - \begin{onlyenv}<3-> - \begin{itemize} - \item - 64 Scheiben, 3 Plätze, - \only<3-4>{\hfill\makebox(0,0)[rt]{\includegraphics[width=6cm]{Tower_of_Hanoi.jpeg}}}\\ - immer 1 Scheibe verschieben - \item - Ziel: Turm verschieben - \item - Es dürfen nur kleinere Scheiben\\ - auf größeren liegen. - \bigskip - \pause - \pause - \item - $n = 1$ Scheibe: fertig - \item - Wenn $n - 1$ Scheiben verschiebbar:\\ - schiebe $n - 1$ Scheiben auf Hilfsplatz,\\ - verschiebe die darunterliegende,\\ - hole $n - 1$ Scheiben von Hilfsplatz - \end{itemize} - \begin{onlyenv}<5> - \vspace{-4.3cm} - \begin{lstlisting}[gobble=8,xleftmargin=6.4cm] - void move (int from, int to, int disks) - { - if (disks == 1) - move_one_disk (from, to); - else - { - int help = 0 + 1 + 2 - from - to; - move (from, help, disks - 1); - move (from, to, 1); - move (help, to, disks - 1); - } - } - \end{lstlisting} - \end{onlyenv} -% \begin{onlyenv}<6-> -% \vspace{-5.0cm} -% \hspace*{7.4cm}\begin{minipage}[t]{5cm} -% 32 Scheiben: -% \begin{lstlisting}[gobble=10,style=terminal] -% $ ¡time ./hanoi-9b¿ -% ... -% real 0m30,672s -% user 0m30,662s -% sys 0m0,008s -% \end{lstlisting} -% \pause[7] -% \begin{itemize} -% \arrowitem -% etwas über 1 Minute\\ -% für 64 Scheiben -% \end{itemize} -% \pause -% \vspace*{-0.5cm} -% \begin{picture}(0,0) -% \color{red} -% \put(0,0){\makebox(0,0)[bl]{\tikz[line width=1pt]{\draw(0,0)--(4,0.8);}}} -% \put(0,0.8){\makebox(0,0)[tl]{\tikz[line width=1pt]{\draw(0,0)--(4,-0.8);}}} -% \end{picture} -% -% Für jede zusätzliche Scheibe\\verdoppelt sich die Rechenzeit! -% % 30.672 * 2^32 / 3600 / 24 / 365.25 = 4174.43775518138261464750 -% \begin{itemize} -% \arrowitem -% $\frac{30,672\,\text{s}\,\cdot\,2^{32}}{3600\,\cdot\,24\,\cdot\,365,25} \approx 4174$ -% Jahre\\[\smallskipamount] -% für 64 Scheiben -% \end{itemize} -% \end{minipage} -% \end{onlyenv} - \end{onlyenv} - -\end{frame} - -\iffalse - -\subsection{Aufwandsabschätzungen \protect\color{gray}-- Komplexitätsanalyse} - -\begin{frame}[fragile] - -% \newcommand{\w}{\hspace*{0.75pt}} - - \showsubsection - - \begin{picture}(0,0) - \put(7.6,-0.5){% - \begin{minipage}[t]{5.3cm} -% \vspace*{-1.0cm}\includegraphics{landau-symbols.pdf} - \vspace*{-1.0cm}\alt<16->{\includegraphics{landau-symbols-3.pdf}}% - {\alt<15->{\includegraphics{landau-symbols-2.pdf}}% - {\includegraphics{landau-symbols.pdf}}} - \small - \begin{description}\itemsep0pt\leftskip-0.5cm - \item[$n$:] Eingabedaten - \item[$g(n)$:] Rechenzeit - \end{description} - \end{minipage}} - \end{picture} - - \vspace*{-\bigskipamount} - - Wann ist ein Programm "`schnell"'? - - \medskip - - \begin{onlyenv}<1-2> - Türme von Hanoi: $\mathcal{O}(2^n)$ - \par\medskip - Für jede zusätzliche Scheibe\\verdoppelt sich die Rechenzeit! - \begin{itemize} - \arrowitem - $\frac{30,672\,\text{s}\,\cdot\,2^{32}}{3600\,\cdot\,24\,\cdot\,365,25} \approx 4174$ - Jahre\\[\smallskipamount] - für 64 Scheiben - \end{itemize} - - \bigskip - \end{onlyenv} - - \begin{onlyenv}<2-> - Faustregel:\\Schachtelung der Schleifen zählen\\ - $k$ Schleifen ineinander \textarrow\ $\mathcal{O}(n^k)$ - - \bigskip - \end{onlyenv} - - \begin{onlyenv}<3-13> - \textbf{Beispiel: Sortieralgorithmen} - - \smallskip - - Anzahl der Vergleiche bei $n$ Strings - \begin{itemize} - \item - Maximum suchen \pause[4]mit Schummeln\pause: $\mathcal{O}(1)$ - \pause - \item - Maximum suchen\pause: $\mathcal{O}(n)$ - \pause - \item - Selection-Sort\pause: $\mathcal{O}(n^2)$ - \pause - \item - Bubble-Sort\pause: $\mathcal{O}(n)$ bis $\mathcal{O}(n^2)$ - \pause - \item - Quicksort\pause: $\mathcal{O}(n\log n)$ bis $\mathcal{O}(n^2)$ - \end{itemize} - - \end{onlyenv} - - \begin{onlyenv}<14> - \textbf{Wie schnell ist RSA-Verschlüsselung?} - - \smallskip - - \begin{math} - c = m^e\,\%\,N - \end{math} - \quad - ("`$\%$"' = "`modulo"') - - \medskip - - \begin{lstlisting}[gobble=6,xleftmargin=2em] - int c = 1; - for (int i = 0; i < e; i++) - c = (c * m) % N; - \end{lstlisting} - - \smallskip - - \begin{itemize} - \item - $\mathcal{O}(e)$ Iterationen -% \item -% wenn $n$ die Anzahl der Binärziffern (Bits) von $e$ ist: -% $\mathcal{O}(2^n)$ Iterationen - \item - mit Trick: - $\mathcal{O}(\log e)$ Iterationen ($\log e$ = Anzahl der Ziffern von $e$) - \end{itemize} - - \smallskip - - Jede Iteration enthält eine Multiplikation und eine Division.\\ - Aufwand dafür: $\mathcal{O}(\log e)$\\ - \textarrow\ Gesamtaufwand: $\mathcal{O}\bigl((\log e)^2\bigr)$ - - \end{onlyenv} - - \begin{onlyenv}<15-> - - \textbf{Wie schnell ist RSA?}\\ - - \smallskip - - ($n$ = typische beteiligte Zahl, z.\,B. $e,p,q$) - - \begin{itemize} - \item - Ver- und Entschlüsselung (Exponentiation):\\ - \strut\hbox to 3.5cm{\color{red}$\mathcal{O}\!\left((\log n)^2\right)$\hss} - \only<16->{{\color{magenta}$\mathcal{O}(n^2)$}} - \item - Schlüsselerzeugung (Berechnung von $d$):\\ - \strut\hbox to 3.5cm{\color{red}$\mathcal{O}\!\left((\log n)^2\right)$\hss} - \only<16->{{\color{magenta}$\mathcal{O}(n^2)$}} - \item - Verschlüsselung brechen (Primfaktorzerlegung):\\ - \strut\hbox to 3.5cm{\color{red}$\mathcal{O}\bigl(2^{\sqrt{\log n\,\cdot\,\log\log n}}\bigr)$\hss} - \only<16->{{\color{magenta}$\mathcal{O}\bigl(2^{\sqrt{n\log n}}\bigr)$}} - \end{itemize} - - \vspace{0cm plus 1filll} - - \textbf{Die Sicherheit von RSA beruht darauf, - daß das Brechen der Verschlüsselung aufwendiger ist als - \boldmath$\mathcal{O}\bigl((\log n)^k\bigr)$ (für beliebiges $k$).} - - \vspace*{0.65cm} - - \end{onlyenv} - -\end{frame} - -\fi - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \begin{itemize} - \item[4.1] Bit-Operationen - \item[4.2] I/O-Ports - \item[4.3] Interrupts - \item[4.4] volatile-Variable - \color{medgreen} - \item[4.5] Byte-Reihenfolge -- Endianness - \item[4.6] Binärdarstellung negativer Zahlen - \item[4.7] Speicherausrichtung -- Alignment - \end{itemize} - \item[\textbf{5}] \textbf{Algorithmen} - \begin{itemize} - \color{medgreen} - \item[5.1] Differentialgleichungen - \item[5.2] Rekursion - \color{red} - \item[5.3] Aufwandsabschätzungen - \end{itemize} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \item[\textbf{7}] \textbf{Datenstrukturen} - \end{itemize} - -\end{frame} - -\end{document} diff --git a/20221114/hp-2022ws-p3.pdf b/20221114/hp-2022ws-p3.pdf deleted file mode 100644 index 798b215947f498d64b4ce1a884ede98669735dcb..0000000000000000000000000000000000000000 Binary files a/20221114/hp-2022ws-p3.pdf and /dev/null differ diff --git a/20221114/hp-2022ws-p3.tex b/20221114/hp-2022ws-p3.tex deleted file mode 100644 index d366456f39591a64cc89aae08697e7cef769718b..0000000000000000000000000000000000000000 --- a/20221114/hp-2022ws-p3.tex +++ /dev/null @@ -1,288 +0,0 @@ -% hp-2022ws-p3.pdf - Labor Notes on Low-Level Programming -% Copyright (C) 2014, 2015, 2018, 2019, 2020, 2021, 2022 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: Versuch 3: Weltraum-Simulation - -\documentclass[a4paper]{article} - -\usepackage{pgscript} -\usepackage{multicol} -%\usepackage{sfmath} - -\sloppy -\raggedcolumns -\pagestyle{empty} -\addtolength{\textheight}{1cm} -\newcommand{\sep}{~$\cdot$~} -\newcommand{\mylicense}{CC BY-SA (Version 4.0) oder GNU GPL (Version 3 oder höher)} - -\begin{document} - - \makebox(0,0.005)[tl]{\includegraphics[scale=0.72]{logo-hochschule-bochum-cvh-text-v2.pdf}}\hfill - \makebox(0,0)[tr]{\includegraphics[scale=0.5]{logo-hochschule-bochum.pdf}} - \par\bigskip\bigskip - \begin{center} - \Large\textbf{Praktikumsversuch 3: Weltraum-Simulation} - \par\medskip - \normalsize Hardwarenahe Programmierung\sep - Wintersemester 2022/23\sep - Prof.~Dr.~Peter Gerwinski - \end{center} - - Aufgabe: Schreiben Sie ein C-Programm, - das die Bahnen von beliebig vielen Massenpunkten unter Einfluß der Gravitation - simuliert und in bewegter Grafik darstellt. - - \begin{multicols}{2} - - \begin{itemize} - \item - Zwei Massenpunkte ("`Himmelskörper"') mit den Massen $m_i$ und $m_j$ - an den Orten $\vec{r}_i$ und $\vec{r}_j$ ziehen einander an. - Diese Kraft heißt Gravitation. Sie hat den Betrag: - \begin{equation} - |\vec{F}_{ij}| = \frac{m_j\cdot m_i\cdot G}{|\vec{r}_j - \vec{r}_i|^2} - \end{equation} - Hierbei ist $G$ eine Konstante (Gravitationskonstante). - - \item - Die auf einen Himmelskörper wirkende Gesamtkraft $\vec{F}_i$ - ergibt sich als Summe der von allen anderen Himmelskörpern herrührenden - Gravitationskräfte: - \begin{equation} - \vec{F}_i = \sum_{j=0,\,j\ne i}^{N - 1} \vec{F}_{ij} - \end{equation} - - \item - Die Gravitationskraft beschleunigt jeden Himmelskörper gemäß: - \begin{equation} - \vec{F_i} = m_i\cdot \vec{a_i} - \end{equation} - - \item - Beispiel: Wir betrachten zwei Himmelskörper. Einer davon ("`Zentralgestirn"') - ruht im Zentrum ($\vec{r}_0 = 0$, $\vec{v}_0 = 0$) - und hat eine wesentlich größere Masse als der andere - ("`Satellit"', $m_1 \ll m_0$). Mit geeignetem Anfangsort $\vec{r}_1$ - und geeigneter Anfangsgeschwindigkeit $\vec{v}_1$ beschreibt dann - der Satellit eine elliptische Umlaufbahn um das Zentralgestirn. - - \item - Wir rechnen in zwei Dimensionen $x$ und $y$. - - \item - Für die Zerlegung einer Kraft $\vec{F}_{ij}$ in $x$- und $y$-Komponenten - benötigen Sie nur die Grundrechenarten und die Wurzelfunktion, - jedoch insbesondere \emph{keine} trigonometrischen Funktionen: - \begin{equation} - \vec{F}_{ij} = |\vec{F}_{ij}| \cdot \frac{\vec{r}_j - \vec{r}_i}{|\vec{r}_j - \vec{r}_i|} - \end{equation} - - \item - Die Wurzelfunktion \lstinline{sqrt()} finden Sie - in der Mathematik-Bibliothek. - Um diese zu nutzen, verwenden Sie \lstinline{#include <math.h>} im Quelltext, - und geben Sie beim \lstinline[style=cmd]{gcc}-Aufruf - \lstinline[style=cmd]{-lm} mit an. - - \item - Speichern Sie die verschiedenen Körper nicht als separate Variable, - sondern in einem Array. Ihr Programm wird dadurch nicht nur flexibler, - sondern auch übersichtlicher und weniger fehleranfällig. - -% \columnbreak - - \item - Für die Simulation betrachten wir das System in kurzen Zeitintervallen $dt$ - und berechnen die Änderungen des Ortes $\vec{r}_i = (x_i,y_i)$ - und der Geschwindigkeit $\vec{v}_i = (v_{xi},v_{yi})$ jedes Himmelskörpers - mit Hilfe des expliziten Eulerschen Polygonzugverfahrens. - \par - (Wer möchte, darf natürlich auch andere Verfahren anwenden, - beispielsweise das klassische Runge-Kutta-Verfahren 4.~Ordnung.) - - \item - Für eine derartige Simulation - einschließlich ihrer Darstellung als bewegte Grafik - können Sie sich von dem Beispiel-Programm \gitfile{hp}{2022ws/20221114}{pendulum-1.c} - inspirieren lassen. -% (Compilieren mit: -% \lstinline[style=cmd]{gcc} -% \lstinline[style=cmd]{-Wall} -% \lstinline[style=cmd]{-O} -% \lstinline[style=cmd]{gtk-16.c} -% \lstinline[style=cmd]{$(pkg-config} -% \lstinline[style=cmd]{--cflags} -% \lstinline[style=cmd]{--libs} -% \lstinline[style=cmd]{gtk+-3.0)} -% \lstinline[style=cmd]{-o} -% \lstinline[style=cmd]{gtk-16}) - - \item - In einer \file{GTK+}-\lstinline{drawing_area} - liegt der Nullpunkt der Zeichnung oben links, - eine Längeneinheit entspricht einem Pixel, - und die $y$-Koordinate wächst nach unten. - Es empfiehlt sich, die Koordinaten so umzurechnen, - daß der Nullpunkt in der Mitte der Zeichnung liegt, - die Längeneinheit Ihrem persönlichen Geschmack entspricht - und die $y$-Koordinate nach oben wächst. - - \item - Beispiel-Szenarien für 3 oder mehr Körper: - \vspace{-\smallskipamount} - \begin{itemize}\itemsep0pt - \item - Planet mit Mond umkreist Sonne - \item - Sonne mit mehreren Planeten, die sich gegenseitig beeinflussen - \item - zwei Sonnen umkreisen sich gegenseitig, Planet kreist drumherum - \item - Raumsonde besucht nacheinander mehrere Planeten - \end{itemize} - - \end{itemize} - - \end{multicols} - - \bigskip - \textbf{GTK unter GNU/Linux} - \begin{itemize} - \item - Installieren Sie das Entwickler-Paket für GTK-3,\\ - z.\,B.\ unter Debian GNU/Linux und darauf basierenden Systemen: - \begin{lstlisting}[style=cmd,gobble=8] - apt-get install libgtk-3-dev - \end{lstlisting} - \end{itemize} - - \bigskip - \goodbreak - \textbf{GTK unter MacOS X} - \begin{itemize} - \item - Zuerst den Paketmanager "`Homebrew"' installieren: - \begin{lstlisting}[style=cmd,gobble=8] - ruby -e "$(curl -fsSL https://raw.githubusercontent.com/ - Homebrew/install/2020ws/install)" - \end{lstlisting} - (Die URL nicht trennen, sondern in einer Zeile schreiben.) - \item - Danach mit Hilfe von \lstinline[style=cmd]{brew} GTK installieren: - \begin{lstlisting}[style=cmd,gobble=8] - brew install gtk+3 - \end{lstlisting} - \end{itemize} - - \bigskip - \goodbreak - \textbf{GTK unter Microsoft Windows: Cygwin} - \begin{itemize} - \item - Im Cygwin-Setup-Programm die Pakete \file{libgtk3-devel}, - \file{xorg-server} und \file{dbus-x11} installieren. - \item - Bevor Sie GTK-Programme starten können, - müssen Sie einmalig den X-Server starten: - \begin{lstlisting}[style=cmd,gobble=8] - XWin -multiwindow & - \end{lstlisting} - \item - Bevor Sie GTK-Programme starten können, - müssen Sie einmalig pro Shell-Sitzung\\ - die \lstinline[style=cmd]{DISPLAY}-Variable setzen: - \begin{lstlisting}[style=cmd,gobble=8] - export DISPLAY=:0.0 - \end{lstlisting} - \end{itemize} - - \bigskip - \goodbreak - \textbf{GTK unter Microsoft Windows: MinGW} - \begin{itemize} - \item - Installieren Sie \file{MSYS2} (Installer). - \item - Installieren Sie von der MinGW-Shell aus GTK - und weitere Entwicklungswerkzeuge: - \begin{lstlisting}[style=cmd,gobble=8] - pacman -S mingw-w64-x86_64-gcc - pacman -S mingw-w64-x86_64-gtk3 - pacman -S mingw-w64-x86_64-pkg-config - \end{lstlisting} - \item - Falls nötig, ergänzen Sie in der MinGW-Shell - den Pfad zu den neu installierten Programmen: - \begin{lstlisting}[style=cmd,gobble=8] - export PATH=$PATH:/mingw64/bin - \end{lstlisting} - \end{itemize} - - \bigskip - \goodbreak - \textbf{GTK unter Microsoft Windows: WSL} - \begin{itemize} - \item - Installieren Sie die GTK-Entwicklungswerkzeuge in ihrer Linux-Umgebung (siehe oben). - \item - Installieren Sie einen X-Server für Ihr MS-Windows-System, z.\,B.\ \file{Xming}. - \item - Starten Sie Ihren X-Server mit \file{XLaunch} - und wählen Sie \emph{no access control} aus. - \item - Bevor Sie GTK-Programme starten können, - müssen Sie einmalig pro Shell-Sitzung\\ - die \lstinline[style=cmd]{DISPLAY}-Variable setzen: - \begin{lstlisting}[style=cmd,gobble=8] - export DISPLAY=$(cat /etc/resolv.conf \ - | grep nameserver | awk '{print $2}'):0 - \end{lstlisting} - (Der Backslash ist ein Zeilen-Verlängerungszeichen. Wenn Sie den gesamten\\ - Befehl in einer Zeile eingeben, entfällt der Backslash.) - \end{itemize} - - \vspace*{-\bigskipamount} - - \strut\hfill\emph{Viel Erfolg!}\qquad\qquad - - \vfill - - \begingroup - - \small - - \setlength{\leftskip}{3cm} - - Stand: 17.\ November 2022 - -% Soweit nicht anders angegeben:\\ - Copyright \copyright\ 2014, 2015, 2018, 2019, 2020, 2021, 2022\quad Peter Gerwinski\\ - Lizenz: \mylicense - - Sie können diese Praktikumsunterlagen einschließlich \LaTeX-Quelltext - und Beispielprogramm herunterladen unter: - \url{https://gitlab.cvh-server.de/pgerwinski/hp} - - \endgroup - -\end{document} diff --git a/20221114/hp-musterloesung-20221114.pdf b/20221114/hp-musterloesung-20221114.pdf deleted file mode 100644 index 641f3edd6955f1e19955d2b1e9344178a903a268..0000000000000000000000000000000000000000 Binary files a/20221114/hp-musterloesung-20221114.pdf and /dev/null differ diff --git a/20221114/hp-musterloesung-20221114.tex b/20221114/hp-musterloesung-20221114.tex deleted file mode 100644 index 6a752bf49af2c27b551e498ef2cb485b127d628d..0000000000000000000000000000000000000000 --- a/20221114/hp-musterloesung-20221114.tex +++ /dev/null @@ -1,484 +0,0 @@ -% hp-musterloesung-20221031.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Trickprogrammierung, Thermometer-Baustein an I²C-Bus, Speicherformate von Zahlen - -\documentclass[a4paper]{article} - -\usepackage{pgscript} -\usepackage{gensymb} - -\newcommand{\ItwoC}{I\raisebox{0.5ex}{\footnotesize 2}C} -\newcommand{\ITWOC}{I\raisebox{0.5ex}{\normalsize 2}C} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 14.\ November 2022} - - \exercise{Trickprogrammierung} - - Wir betrachten das folgende Programm (Datei: \gitfile{hp}{2022ws/20221114}{aufgabe-1.c}): - \begin{lstlisting} - #include <stdio.h> - #include <stdint.h> - - int main (void) - { - uint64_t x = 4262939000843297096; - char *s = &x; - printf ("%s\n", s); - return 0; - } - \end{lstlisting} - Das Programm wird compiliert und auf einem 64-Bit-Little-Endian-Computer ausgeführt: - \begin{lstlisting}[style=terminal] - $ ¡gcc -Wall -O aufgabe-1.c -o aufgabe-1¿ - aufgabe-1.c: In function `main': - aufgabe-1.c:7:13: warning: initialization from incompatible pointer type [...] - $ ¡./aufgabe-1¿ - Hallo - \end{lstlisting} - - \begin{itemize} - \item[(a)] - Erklären Sie die Warnung beim Compilieren. \points{2} - \item[(b)] - Erklären Sie die Ausgabe des Programms. \points{5} - \item[(c)] - Wie würde die Ausgabe des Programms auf einem 64-Bit-Big-Endian-Computer lauten? \points{3} - \end{itemize} - Hinweis: Modifizieren Sie das Programm - und lassen Sie sich Speicherinhalte ausgeben. - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Erklären Sie die Warnung beim Compilieren.} - - Zeile 7 des Programms enthält eine Zuweisung von \lstinline{&x} - an die Variable \lstinline{s}. - Der Ausdruck \lstinline{&x} steht für die Speicheradresse der Variablen \lstinline{x}, - ist also ein Zeiger auf \lstinline{x}, - also ein Zeiger auf eine \lstinline{uint64_t}. - Die Variable \lstinline{s} hingegen ist ein Zeiger auf \lstinline{char}, - also ein Zeiger auf eine viel kleinere Zahl, - also ein anderer Zeigertyp. - - \item[(b)] - \textbf{Erklären Sie die Ausgabe des Programms.} - - Die 64-Bit-Zahl (\lstinline{uint64_t}) \lstinline{x} - belegt 8 Speicherzellen (Bytes) von jeweils 8 Bit. - Um herauszufinden, was diese enthalten, - lassen wir uns \lstinline{x} als Hexadezimalzahl ausgeben, - z.\,B.\ mittels \lstinline{printf ("%lx\n", x)} - (auf 32-Bit-Rechnern: \lstinline{"%llx\n"}) - oder mittels \lstinline{printf ("%" PRIx64 "\n", x)} - (erfordert \lstinline{#include <inttypes.h>} - -- siehe die Datei \gitfile{hp}{2022ws/20221114}{loesung-1-1.c}). - Das Ergebnis lautet: - \begin{lstlisting}[style=terminal,gobble=8] - 3b29006f6c6c6148 - \end{lstlisting} - Auf einzelne Bytes verteilt: - \begin{lstlisting}[style=terminal,gobble=8] - 3b 29 00 6f 6c 6c 61 48 - \end{lstlisting} - Auf einem Little-Endian-Rechner - ist die Reihenfolge der Bytes in den Speicherzellen genau umgekehrt: - \begin{lstlisting}[style=terminal,gobble=8] - 48 61 6c 6c 6f 00 29 3b - \end{lstlisting} - Wenn wir uns diese Bytes als Zeichen ausgeben lassen - (\lstinline{printf()} mit \lstinline{%c} -- siehe die Datei \gitfile{hp}{2022ws/20221114}{loesung-1-2.c}), - erhalten wir: - \begin{lstlisting}[style=terminal,gobble=8] - H a l l o ) ; - \end{lstlisting} - Das Zeichen hinter "`Hallo"' ist ein Null-Symbol (Zahlenwert 0) - und wird von \lstinline{printf ("%s")} als Ende des Strings erkannt. - Damit ist die Ausgabe \lstinline[style=terminal]{Hallo} - des Programms erklärt. - - \goodbreak - \item[(c)] - \textbf{Wie würde die Ausgabe des Programms auf einem 64-Bit-Big-Endian-Computer lauten?} - - Auf einem Big-Endian-Computer (egal, wieviele Bits die Prozessorregister haben) - ist die Reihenfolge der Bytes in den Speicherzellen genau umgekehrt - wie auf einem Little-Endian-Computer, hier also: - \begin{lstlisting}[style=terminal,gobble=8] - 3b 29 00 6f 6c 6c 61 48 - \end{lstlisting} - \lstinline{printf ("%s")} gibt in diesem Fall die Hexadezimalzahlen - \lstinline[style=terminal]{3b} und \lstinline[style=terminal]{29} - als Zeichen aus. Danach steht das String-Ende-Symbol mit Zahlenwert 0, - und die Ausgabe bricht ab. - Da, wie oben ermittelt, die Hexadezimalzahl \lstinline[style=terminal]{3b} - für das Zeichen \lstinline[style=terminal]{;} - und \lstinline[style=terminal]{29} - für das Zeichen \lstinline[style=terminal]{)} steht, - lautet somit die Ausgabe: - \begin{lstlisting}[style=terminal,gobble=8] - ;) - \end{lstlisting} - Um die Aufgabe zu lösen, können Sie übrigens auch - auf einem Little-Endian-Computer (Standard-Notebook) - einen Big-Endian-Computer simulieren, - indem Sie die Reihenfolge der Bytes in der Zahl \lstinline{x} umdrehen - -- siehe die Datei \gitfile{hp}{2022ws/20221114}{loesung-1-3.c}. - \end{itemize} - - \exercise{Thermometer-Baustein an \ITWOC-Bus} - - Eine Firma stellt einen elektronischen Thermometer-Baustein her, - den man über die serielle Schnittstelle (RS-232) an einen PC anschließen kann, - um die Temperatur auszulesen. - Nun wird eine Variante des Thermo"-meter-Bausteins entwickelt, - die die Temperatur zusätzlich über einen \ItwoC-Bus bereitstellt. - - Um das neue Thermometer zu testen, wird es in ein Gefäß mit heißem Wasser gelegt, - das langsam auf Zimmertemperatur abkühlt. - Alle 10 Minuten liest ein Programm, das auf dem PC läuft, - die gemessene Temperatur über beide Schnittstellen aus - und erzeugt daraus die folgende Tabelle: - - \begin{center} - \renewcommand{\arraystretch}{1.2} - \begin{tabular}{|c|c|c|}\hline - Zeit /\,min. & Temperatur per RS-232 /\,\degree C & Temperatur per \ItwoC\ /\,\degree C \\\hline\hline - \phantom{0}0 & 94 & 122 \\\hline - 10 & 47 & 244 \\\hline - 20 & 30 & 120 \\\hline - 30 & 24 & \phantom{0}24 \\\hline - 40 & 21 & 168 \\\hline - \end{tabular} - \end{center} - - \begin{itemize} - \item[(a)] - Aus dem Vergleich der Meßdaten läßt sich - auf einen Fehler bei der \ItwoC-Übertragung schließen.\\ - Um welchen Fehler handelt es sich, - und wie ergibt sich dies aus den Meßdaten? - \points{5} - \item[(b)] - Schreiben Sie eine C-Funktion \lstinline{uint8_t repair (uint8_t data)}, - die eine über den \ItwoC-Bus empfangene fehlerhafte Temperatur \lstinline{data} korrigiert. - \points{5} - \end{itemize} - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Aus dem Vergleich der Meßdaten läßt sich - auf einen Fehler bei der \ItwoC-Übertragung schließen. - Um welchen Fehler handelt es sich, - und wie ergibt sich dies aus den Meßdaten?} - - Sowohl RS-232 als auch \ItwoC\ übertragen die Daten Bit für Bit. - Für die Fehlersuche ist es daher sinnvoll, - die Meßwerte als Binärzahlen zu betrachten: - - \begin{center} - \renewcommand{\arraystretch}{1.2} - \begin{tabular}{|c|c|c|}\hline - Zeit /\,min. & Temperatur per RS-232 /\,\degree C & Temperatur per \ItwoC\ /\,\degree C \\\hline\hline - \phantom{0}0 & 94$_{10}$ = 01011110$_2$ & 122$_{10}$ = 01111010$_2$ \\\hline - 10 & 47$_{10}$ = 00101111$_2$ & 244$_{10}$ = 11110100$_2$ \\\hline - 20 & 30$_{10}$ = 00011110$_2$ & 120$_{10}$ = 01111000$_2$ \\\hline - 30 & 24$_{10}$ = 00011000$_2$ & \phantom{0}24$_{10}$ = 00011000$_2$ \\\hline - 40 & 21$_{10}$ = 00010101$_2$ & 168$_{10}$ = 10101000$_2$ \\\hline - \end{tabular} - \end{center} - - Man erkennt, daß die Reihenfolge der Bits in den (fehlerhaften) \ItwoC-Meßwerten - genau die umgekehrte Reihenfolge der Bits in den (korrekten) RS-232-Mewßwerten ist. - Der Übertragungsfehler besteht also darin, - daß die Bits in der falschen Reihenfolge übertragen wurden. - - Dies paßt gut damit zusammen, - daß die Bit-Reihenfolge von \ItwoC\ \emph{MSB First}, die von RS-232 hingegen \emph{LSB First\/} ist. - Offenbar haben die Entwickler der \ItwoC-Schnittstelle dies übersehen - und die \ItwoC-Daten ebenfalls \emph{LSB First\/} übertragen. - - \goodbreak - \item[(b)] - \textbf{Schreiben Sie eine C-Funktion \lstinline{uint8_t repair (uint8_t data)}, - die eine über den \ItwoC-Bus empfangene fehlerhafte Temperatur \lstinline{data} korrigiert.} - - Die Aufgabe der Funktion besteht darin, - eine 8-Bit-Zahl \lstinline{data} entgegenzunehmen, - die Reihenfolge der 8 Bits genau umzudrehen - und das Ergebnis mittels \lstinline{return} zurückzugeben. - - Zu diesem Zweck gehen wir die 8 Bits in einer Schleife durch - -- siehe die Datei \gitfile{hp}{2022ws/20221114}{loesung-2.c}. - Wir lassen eine Lese-Maske \lstinline{mask_data} von rechts nach links - und gleichzeitig eine Schreib-Maske \lstinline{mask_result} - von links nach rechts wandern. - Immer wenn die Lese-Maske in \lstinline{data} eine 1 findet, - schreibt die Schreib-Maske diese in die Ergebnisvariable \lstinline{result}. - - Da \lstinline{result} auf 0 initialisiert wurde, - brauchen wir Nullen nicht hineinzuschreiben. - Ansonsten wäre dies mit \lstinline{result &= ~mask_result} möglich. - - Um die Schleife bis 8 zählen zu lassen, - könnte man eine weitere Zähler-Variable von 0 bis 7 zählen lassen, - z.\,B.\ \lstinline{for (int i = 0; i < 8; i++)}. - Dies ist jedoch nicht nötig, wenn man beachtet, - daß die Masken den Wert 0 annehmen, - sobald das Bit aus der 8-Bit-Variablen herausgeschoben wurde. - In \gitfile{hp}{2022ws/20221114}{loesung-2.c} wird \lstinline{mask_data} auf 0 geprüft; - genausogut könnte man auch \lstinline{mask_result} prüfen. - - Das \lstinline{return result} ist notwendig. - Eine Ausgabe des Ergebnisses per \lstinline{printf()} o.\,ä.\ - erfüllt \emph{nicht\/} die Aufgabenstellung. - (In \gitfile{hp}{2022ws/20221114}{loesung-2.c} erfolgt entsprechend \lstinline{printf()} - nur im Testprogramm \lstinline{main()}.) - \end{itemize} - - \exercise{Speicherformate von Zahlen} - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221114}{aufgabe-3.c}): - \begin{lstlisting} - #include <stdio.h> - #include <stdint.h> - - typedef struct - { - uint32_t a; - uint64_t b; - uint8_t c; - } three_numbers; - - int main (void) - { - three_numbers xyz = { 1819042120, 2410670883059281007, 0 }; - printf ("%s\n", &xyz); - return 0; - } - \end{lstlisting} - - Das Programm wird für einen 32-Bit-Rechner compiliert und ausgeführt.\\ - (Die \lstinline[style=cmd]{gcc}-Option \lstinline[style=cmd]{-m32} sorgt dafür, - daß \lstinline[style=cmd]{gcc} Code für einen 32-Bit-Prozessor erzeugt.) - - \begin{lstlisting}[style=terminal] - $ ¡gcc -Wall -m32 aufgabe-2.c -o aufgabe-2¿ - aufgabe-2.c: In function "main": - aufgabe-2.c:14:13: warning: format "%s" expects argument of type "char *", but - argument 2 has type "three_numbers * {aka struct <anonymous> *}" [-Wformat=] - printf ("%s\n", &xyz); - ^ - $ ¡./aufgabe-2¿ - Hallo, Welt! - \end{lstlisting} - - \begin{enumerate}[\quad(a)] - \item - Erklären Sie die beim Compilieren auftretende Warnung. - \points{2} - \item - Erklären Sie die Ausgabe des Programms. - \points{4} - \item - Welche Endianness hat der verwendete Rechner? - Wie sähe die Ausgabe auf einem Rechner mit entgegengesetzter Endianness aus? - \points{2} - \item - Dasselbe Programm wird nun für einen 64-Bit-Rechner compiliert und ausgeführt.\\ - (Die \lstinline[style=cmd]{gcc}-Option \lstinline[style=cmd]{-m64} sorgt dafür, - daß \lstinline[style=cmd]{gcc} Code für einen 64-Bit-Prozessor erzeugt.) - \begin{lstlisting}[style=terminal,gobble=8] - $ ¡gcc -Wall -m64 aufgabe-2.c -o aufgabe-2¿ - aufgabe-2.c: In function "main": - aufgabe-2.c:14:13: warning: format "%s" expects argument of type "char *", - but argument 2 has type "three_numbers * {aka struct <anonymous> *}" - [-Wformat=] - printf ("%s\n", &xyz); - ^ - $ ¡./aufgabe-2¿ - Hall5V - \end{lstlisting} - (Es ist möglich, daß die konkrete Ausgabe auf Ihrem Rechner anders aussieht.)\par - Erklären Sie die geänderte Ausgabe des Programms. - \points{3} - \end{enumerate} - - \solution - - \begin{enumerate}[\quad(a)] - \item - \textbf{Erklären Sie die beim Compilieren auftretende Warnung.} - - Die Funktion \lstinline{printf()} mit der Formatspezifikation \lstinline{%s} - erwartet als Parameter einen String, d.\,h.\ einen Zeiger auf \lstinline{char}. - Die Adresse (\lstinline{&}) der Variablen \lstinline{xyz} - ist zwar ein Zeiger, aber nicht auf \lstinline{char}, - sondern auf einen \lstinline{struct} vom Typ \lstinline{three_numbers}. - Eine implizite Umwandlung des Zeigertyps ist zwar möglich, - aber normalerweise nicht das, was man beabsichtigt. - - \item - \textbf{Erklären Sie die Ausgabe des Programms.} - - Ein String in C ist ein Array von \lstinline{char}s - bzw.\ ein Zeiger auf \lstinline{char}. - Da die Funktion \lstinline{printf()} mit der Formatspezifikation \lstinline{%s} - einen String erwartet, wird sie das, worauf der übergebene Zeiger zeigt, - als ein Array von \lstinline{char}s interpretieren. - Ein \lstinline{char} entspricht einer 8-Bit-Speicherzelle. - Um die Ausgabe des Programms zu erklären, müssen wir daher - die Speicherung der Zahlen in den einzelnen 8-Bit-Speicherzellen betrachten. - - Hierfür wandeln wir zunächst die Zahlen von Dezimal nach Hexadezimal um. - Sofern nötig (hier nicht der Fall) füllen wir von links mit Nullen auf, - um den gesamten von der Variablen belegten Speicherplatz zu füllen - (hier: 32 Bit, 64 Bit, 8 Bit). - Jeweils 2 Hex-Ziffern stehen für 8 Bit. - \begin{center} - \begin{tabular}{rcl} - dezimal & & hexadezimal \\[\smallskipamount] - 1\,819\,042\,120 & = & 6C\,6C\,61\,48 \\ - 2\,410\,670\,883\,059\,281\,007 & = & 21\,74\,6C\,65\,57\,20\,2C\,6F \\ - 0 & = & 00 - \end{tabular} - \end{center} - Die Anordnung dieser 8-Bit-Zellen im Speicher lautet - \textbf{auf einem Big-Endian-Rechner} wie folgt: - \begin{center} - \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline - \raisebox{0.5ex}{\strut} - 6C & 6C & 61 & 48 & - 21 & 74 & 6C & 65 & 57 & 20 & 2C & 6F & - 00 - \\\hline - \end{tabular}\\[-4.2ex] - \kern1.7em% - $\underbrace{\rule{9.8em}{0pt}}_{\mbox{\lstinline{a}}}$\kern1pt% - $\underbrace{\rule{18.8em}{0pt}}_{\mbox{\lstinline{b}}}$\kern1pt% - $\underbrace{\rule{2.2em}{0pt}}_{\mbox{\lstinline{c}}}$% - \end{center} - \textbf{Auf einem Little-Endian-Rechner} lautet sie hingegen: - \begin{center} - \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline -% \raisebox{0.5ex}{\strut} -% H & a & l & l & -% o & , & & W & e & l & t & ! & \\\hline - \raisebox{0.5ex}{\strut} - 48 & 61 & 6C & 6C & - 6F & 2C & 20 & 57 & 65 & 6C & 74 & 21 & - 00 - \\\hline - \end{tabular}\\[-4.2ex] - \kern1.7em% - $\underbrace{\rule{9.8em}{0pt}}_{\mbox{\lstinline{a}}}$\kern1pt% - $\underbrace{\rule{18.8em}{0pt}}_{\mbox{\lstinline{b}}}$\kern1pt% - $\underbrace{\rule{2.2em}{0pt}}_{\mbox{\lstinline{c}}}$% - \end{center} - Anhand einer ASCII-Tabelle erkennt man, - daß die Big-Endian-Variante dem String \lstinline{"llaH!tleW ,o"} - und die Little-Endian-Variante dem String \lstinline{"Hallo, Welt!"} - entspricht -- jeweils mit einem Null-Symbol am Ende, - das von der Variablen \lstinline{c} herrührt. - - Auf einem Little-Endian-Rechner wird daher - \lstinline[style=terminal]{Hallo, Welt!} ausgegeben. - - \item - \textbf{Welche Endianness hat der verwendete Rechner?} - - Little-Endian (Begründung siehe oben) - - \textbf{Wie sähe die Ausgabe auf einem Rechner mit entgegengesetzter Endianness aus?} - - \lstinline[style=terminal]{llaH!tleW ,o} (Begründung siehe oben) - - \item - \textbf{Dasselbe Programm wird nun für einen 64-Bit-Rechner compiliert und ausgeführt.\\ - (Die \lstinline[style=cmd]{gcc}-Option \lstinline[style=cmd]{-m64} sorgt dafür, - daß \lstinline[style=cmd]{gcc} Code für einen 64-Bit-Prozessor erzeugt.)} - \begin{lstlisting}[style=terminal,gobble=8] - $ ¡gcc -Wall -m64 aufgabe-2.c -o aufgabe-2¿ - aufgabe-2.c: In function "main": - aufgabe-2.c:14:13: warning: format "%s" expects argument of type "char *", - but argument 2 has type "three_numbers * {aka struct <anonymous> *}" - [-Wformat=] - printf ("%s\n", &xyz); - ^ - $ ¡./aufgabe-2¿ - Hall5V - \end{lstlisting} - \textbf{(Es ist möglich, daß die konkrete Ausgabe auf Ihrem Rechner anders aussieht.)}\par - \textbf{Erklären Sie die geänderte Ausgabe des Programms.} - - \goodbreak - - Auf einem 64-Bit-Rechner hat eine 64-Bit-Variable - ein \textbf{64-Bit-Alignment}, - d.\,h.\ ihre Speicheradresse muß durch 8 teilbar sein. - - Der Compiler legt die Variablen daher wie folgt im Speicher ab (Little-Endian): - \begin{center} - \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline - \raisebox{0.5ex}{\strut} - 48 & 61 & 6C & 6C & ?? & ?? & ?? & ?? & - 6F & 2C & 20 & 57 & 65 & 6C & 74 & 21 & - 00 - \\\hline - \end{tabular}\\[-4.2ex] - \kern1.7em% - $\underbrace{\rule{9.8em}{0pt}}_{\mbox{\lstinline{a}}}$\kern1pt% - $\underbrace{\rule{9.1em}{0pt}}_{\mbox{Füll-Bytes}}$\kern1pt% - $\underbrace{\rule{18.8em}{0pt}}_{\mbox{\lstinline{b}}}$\kern1pt% - $\underbrace{\rule{2.2em}{0pt}}_{\mbox{\lstinline{c}}}$% - \end{center} - Der Inhalt der Füll-Bytes ist undefiniert. - Im Beispiel aus der Aufgabenstellung entsteht hier die Ausgabe - \lstinline[style=terminal]{5V}, was den (zufälligen) hexadezimalen Werten - 35 56 entspricht: - \begin{center} - \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline - \raisebox{0.5ex}{\strut} - 48 & 61 & 6C & 6C & 35 & 56 & 00 & ?? & - 6F & 2C & 20 & 57 & 65 & 6C & 74 & 21 & - 00 - \\\hline - \end{tabular}\\[-4.2ex] - \kern1.7em% - $\underbrace{\rule{9.8em}{0pt}}_{\mbox{\lstinline{a}}}$\kern1pt% - $\underbrace{\rule{9.1em}{0pt}}_{\mbox{Füll-Bytes}}$\kern1pt% - $\underbrace{\rule{18.8em}{0pt}}_{\mbox{\lstinline{b}}}$\kern1pt% - $\underbrace{\rule{2.2em}{0pt}}_{\mbox{\lstinline{c}}}$% - \end{center} - Da danach die Ausgabe aufhört, muß an der nächsten Stelle - ein Null-Symbol stehen, das das Ende des Strings anzeigt. - Der Inhalt der darauf folgenden Speicherzelle bleibt unbekannt. - \end{enumerate} - -\end{document} diff --git a/20221114/hp-uebung-20221114.pdf b/20221114/hp-uebung-20221114.pdf deleted file mode 100644 index 57a4c759a68b52b76d40bb817db8714a5d104115..0000000000000000000000000000000000000000 Binary files a/20221114/hp-uebung-20221114.pdf and /dev/null differ diff --git a/20221114/hp-uebung-20221114.tex b/20221114/hp-uebung-20221114.tex deleted file mode 100644 index 57dc0cae2dda333b357627600968f550e4573ddf..0000000000000000000000000000000000000000 --- a/20221114/hp-uebung-20221114.tex +++ /dev/null @@ -1,195 +0,0 @@ -% hp-uebung-20221114.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Trickprogrammierung, Thermometer-Baustein an I²C-Bus, Speicherformate von Zahlen - -\documentclass[a4paper]{article} - -\usepackage{pgscript} -\usepackage{gensymb} - -\newcommand{\ItwoC}{I\raisebox{0.5ex}{\footnotesize 2}C} -\newcommand{\ITWOC}{I\raisebox{0.5ex}{\normalsize 2}C} - -\begin{document} - - \thispagestyle{empty} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 14.\ November 2022} - - Diese Übung enthält Punkteangaben wie in einer Klausur. - Um zu "`bestehen"', müssen Sie innerhalb von 90 Minuten - unter Verwendung ausschließlich zugelassener Hilfsmittel - 15 Punkte (von insgesamt \totalpoints) erreichen. - - \exercise{Trickprogrammierung} - - Wir betrachten das folgende Programm (Datei: \gitfile{hp}{2022ws/20221114}{aufgabe-1.c}): - \begin{lstlisting} - #include <stdio.h> - #include <stdint.h> - - int main (void) - { - uint64_t x = 4262939000843297096; - char *s = &x; - printf ("%s\n", s); - return 0; - } - \end{lstlisting} - Das Programm wird compiliert und auf einem 64-Bit-Little-Endian-Computer ausgeführt: - \begin{lstlisting}[style=terminal] - $ ¡gcc -Wall -O aufgabe-1.c -o aufgabe-1¿ - aufgabe-1.c: In function `main': - aufgabe-1.c:7:13: warning: initialization from incompatible pointer type [...] - $ ¡./aufgabe-1¿ - Hallo - \end{lstlisting} - - \begin{itemize} - \item[(a)] - Erklären Sie die Warnung beim Compilieren. \points{2} - \item[(b)] - Erklären Sie die Ausgabe des Programms. \points{5} - \item[(c)] - Wie würde die Ausgabe des Programms auf einem 64-Bit-Big-Endian-Computer lauten? \points{3} - \end{itemize} - Hinweis: Modifizieren Sie das Programm - und lassen Sie sich Speicherinhalte ausgeben. - - \exercise{Thermometer-Baustein an \ITWOC-Bus} - - Eine Firma stellt einen elektronischen Thermometer-Baustein her, - den man über die serielle Schnittstelle (RS-232) an einen PC anschließen kann, - um die Temperatur auszulesen. - Nun wird eine Variante des Thermo"-meter-Bausteins entwickelt, - die die Temperatur zusätzlich über einen \ItwoC-Bus bereitstellt. - - Um das neue Thermometer zu testen, wird es in ein Gefäß mit heißem Wasser gelegt, - das langsam auf Zimmertemperatur abkühlt. - Alle 10 Minuten liest ein Programm, das auf dem PC läuft, - die gemessene Temperatur über beide Schnittstellen aus - und erzeugt daraus die folgende Tabelle: - - \begin{center} - \renewcommand{\arraystretch}{1.2} - \begin{tabular}{|c|c|c|}\hline - Zeit /\,min. & Temperatur per RS-232 /\,\degree C & Temperatur per \ItwoC\ /\,\degree C \\\hline\hline - \phantom{0}0 & 94 & 122 \\\hline - 10 & 47 & 244 \\\hline - 20 & 30 & 120 \\\hline - 30 & 24 & \phantom{0}24 \\\hline - 40 & 21 & 168 \\\hline - \end{tabular} - \end{center} - - \begin{itemize} - \item[(a)] - Aus dem Vergleich der Meßdaten läßt sich - auf einen Fehler bei der \ItwoC-Übertragung schließen.\\ - Um welchen Fehler handelt es sich, - und wie ergibt sich dies aus den Meßdaten? - \points{5} - \item[(b)] - Schreiben Sie eine C-Funktion \lstinline{uint8_t repair (uint8_t data)}, - die eine über den \ItwoC-Bus empfangene fehlerhafte Temperatur \lstinline{data} korrigiert. - \points{5} - \end{itemize} - - \exercise{Speicherformate von Zahlen} - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221114}{aufgabe-3.c}): - \begin{lstlisting} - #include <stdio.h> - #include <stdint.h> - - typedef struct - { - uint32_t a; - uint64_t b; - uint8_t c; - } three_numbers; - - int main (void) - { - three_numbers xyz = { 1819042120, 2410670883059281007, 0 }; - printf ("%s\n", &xyz); - return 0; - } - \end{lstlisting} - - Das Programm wird für einen 32-Bit-Rechner compiliert und ausgeführt.\\ - (Die \lstinline[style=cmd]{gcc}-Option \lstinline[style=cmd]{-m32} sorgt dafür, - daß \lstinline[style=cmd]{gcc} Code für einen 32-Bit-Prozessor erzeugt.) - - \begin{lstlisting}[style=terminal] - $ ¡gcc -Wall -m32 aufgabe-2.c -o aufgabe-2¿ - aufgabe-2.c: In function "main": - aufgabe-2.c:14:13: warning: format "%s" expects argument of type "char *", but - argument 2 has type "three_numbers * {aka struct <anonymous> *}" [-Wformat=] - printf ("%s\n", &xyz); - ^ - $ ¡./aufgabe-2¿ - Hallo, Welt! - \end{lstlisting} - - \begin{enumerate}[\quad(a)] - \item - Erklären Sie die beim Compilieren auftretende Warnung. - \points{2} - \item - Erklären Sie die Ausgabe des Programms. - \points{4} - \item - Welche Endianness hat der verwendete Rechner? - Wie sähe die Ausgabe auf einem Rechner mit entgegengesetzter Endianness aus? - \points{2} - \item - Dasselbe Programm wird nun für einen 64-Bit-Rechner compiliert und ausgeführt.\\ - (Die \lstinline[style=cmd]{gcc}-Option \lstinline[style=cmd]{-m64} sorgt dafür, - daß \lstinline[style=cmd]{gcc} Code für einen 64-Bit-Prozessor erzeugt.) - \begin{lstlisting}[style=terminal,gobble=8] - $ ¡gcc -Wall -m64 aufgabe-2.c -o aufgabe-2¿ - aufgabe-2.c: In function "main": - aufgabe-2.c:14:13: warning: format "%s" expects argument of type "char *", - but argument 2 has type "three_numbers * {aka struct <anonymous> *}" - [-Wformat=] - printf ("%s\n", &xyz); - ^ - $ ¡./aufgabe-2¿ - Hall5V - \end{lstlisting} - (Es ist möglich, daß die konkrete Ausgabe auf Ihrem Rechner anders aussieht.)\par - Erklären Sie die geänderte Ausgabe des Programms. - \points{3} - \end{enumerate} - - \begin{flushright} - \textit{Viel Erfolg!} - \end{flushright} - - \makeatletter - \immediate\write\@mainaux{\string\gdef\string\totalpoints{\arabic{points}}} - \makeatother - -\end{document} diff --git a/20221114/input-01.c b/20221114/input-01.c deleted file mode 100644 index 6a3d39ec2434d46f6a913da381a6b5e9504c7a49..0000000000000000000000000000000000000000 --- a/20221114/input-01.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -int main (void) -{ - uint8_t PINC = 0; - if (PINC & 0x02 == 0) - printf ("Input is OFF\n"); - else - printf ("Input is ON\n"); - return 0; -} diff --git a/20221114/input-02.c b/20221114/input-02.c deleted file mode 100644 index 92b2d6c6dcd4095fc0ba37a86e6d9670c89f9d61..0000000000000000000000000000000000000000 --- a/20221114/input-02.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -int main (void) -{ - uint8_t PINC = 0; - if ((PINC & 0x02) == 0) - printf ("Input is OFF\n"); - else - printf ("Input is ON\n"); - return 0; -} diff --git a/20221114/io-ports-and-interrupts.pdf b/20221114/io-ports-and-interrupts.pdf deleted file mode 120000 index bcd46f7afb35605b20bdb05637e6de0a039893ec..0000000000000000000000000000000000000000 --- a/20221114/io-ports-and-interrupts.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/io-ports-and-interrupts.pdf \ No newline at end of file diff --git a/20221114/loesung-1-1.c b/20221114/loesung-1-1.c deleted file mode 100644 index 26fcc817796b3da118b5dda92f45bfb870e315b6..0000000000000000000000000000000000000000 --- a/20221114/loesung-1-1.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> -#include <stdint.h> -#include <inttypes.h> - -int main (void) -{ - uint64_t x = 4262939000843297096; - char *s = &x; - printf ("%lx\n", x); - printf ("%" PRIx64 "\n", x); - printf ("%s\n", s); - return 0; -} diff --git a/20221114/loesung-1-2.c b/20221114/loesung-1-2.c deleted file mode 100644 index 7151db69b2e675f17517d7b7c3814bbda3b1fa89..0000000000000000000000000000000000000000 --- a/20221114/loesung-1-2.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <stdint.h> -#include <inttypes.h> - -int main (void) -{ - uint64_t x = 4262939000843297096; - char *s = &x; - printf ("%lx\n", x); - printf ("%" PRIx64 "\n", x); - printf ("%c %c %c %c %c %c %c %c\n", - 0x48, 0x61, 0x6c, 0x6c, 0x6f, 0x00, 0x29, 0x3b); - printf ("%s\n", s); - return 0; -} diff --git a/20221114/loesung-1-3.c b/20221114/loesung-1-3.c deleted file mode 100644 index fadccdef1155e4d16b5da0c8a82d8e7ae76ca3cc..0000000000000000000000000000000000000000 --- a/20221114/loesung-1-3.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> -#include <stdint.h> -#include <inttypes.h> - -int main (void) -{ - uint64_t x = 0x48616c6c6f00293b; - char *s = &x; - printf ("%s\n", s); - return 0; -} diff --git a/20221114/loesung-2.c b/20221114/loesung-2.c deleted file mode 100644 index b02d98b51b9bc525a567afea2f0dce5a8e6413a5..0000000000000000000000000000000000000000 --- a/20221114/loesung-2.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -uint8_t repair (uint8_t data) -{ - uint8_t result = 0; - uint8_t mask_data = 0x01; - uint8_t mask_result = 0x80; - while (mask_data) - { - if (data & mask_data) - result |= mask_result; - mask_data <<= 1; - mask_result >>= 1; - } - return result; -} - -int main (void) -{ - int data[] = { 122, 244, 120, 24, 168, -1 }; - int i = 0; - while (data[i] >= 0) - printf ("%d\n", repair (data[i++])); - return 0; -} diff --git a/20221114/logo-hochschule-bochum-cvh-text-v2.pdf b/20221114/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221114/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221114/logo-hochschule-bochum.pdf b/20221114/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221114/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221114/mic-on.au b/20221114/mic-on.au deleted file mode 100644 index f0b26945f1037a5c30c0a19bde51d06de22c75ed..0000000000000000000000000000000000000000 Binary files a/20221114/mic-on.au and /dev/null differ diff --git a/20221114/mic-on.wav b/20221114/mic-on.wav deleted file mode 100644 index 45f912ee264f52f888a63b94c37ec25123ad7f3a..0000000000000000000000000000000000000000 Binary files a/20221114/mic-on.wav and /dev/null differ diff --git a/20221114/pendulum-0.c b/20221114/pendulum-0.c deleted file mode 100644 index 6faebdc7ad779d89ab8e2eacd189240ace1fb406..0000000000000000000000000000000000000000 --- a/20221114/pendulum-0.c +++ /dev/null @@ -1,69 +0,0 @@ -#include <gtk/gtk.h> -#include <math.h> - -int width = 320; -int height = 240; -int gap = height / 20; -int r = gap; -double visual_length = height - 2 * gap - r; - -double phi0 = -0.5; -double omega0 = 0.0; -double t0 = 0.0; -double g = 9.81; -double l = 1.0; -double dt = 0.02; - -double t = t0; -double phi = phi0; -double omega = omega0; - -gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data) -{ - GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 }; - - int x = width / 2 + visual_length * sin (phi); - int y = gap + visual_length * cos (phi); - - gdk_cairo_set_source_rgba (c, &blue); - cairo_move_to (c, width / 2, gap); - cairo_line_to (c, x, y); - cairo_stroke (c); - cairo_arc (c, x, y, r, 0, 2 * G_PI); - cairo_fill (c); - - return FALSE; /* TRUE to stop other handlers from being invoked for the event. - FALSE to propagate the event further. */ -} - -gboolean timer (GtkWidget *widget) -{ - t += dt; - phi += omega * dt; - omega += - dt * g / l * sin (phi); - - 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_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_main (); - return 0; -} diff --git a/20221114/pendulum-1.c b/20221114/pendulum-1.c deleted file mode 100644 index 0024b2bc283c5d9b76a3148359254aab38fca282..0000000000000000000000000000000000000000 --- a/20221114/pendulum-1.c +++ /dev/null @@ -1,69 +0,0 @@ -#include <gtk/gtk.h> -#include <math.h> - -#define WIDTH 320 -#define HEIGHT 240 -#define GAP (HEIGHT / 20) -#define r GAP -#define visual_length (HEIGHT - 2 * GAP - r) - -#define phi0 (-0.5) -#define omega0 0.0 -#define t0 0.0 -#define g 9.81 -#define l 1.0 -#define dt 0.02 - -double t = t0; -double phi = phi0; -double omega = omega0; - -gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data) -{ - GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 }; - - int x = WIDTH / 2 + visual_length * sin (phi); - int y = GAP + visual_length * cos (phi); - - gdk_cairo_set_source_rgba (c, &blue); - cairo_move_to (c, WIDTH / 2, GAP); - cairo_line_to (c, x, y); - cairo_stroke (c); - cairo_arc (c, x, y, r, 0, 2 * G_PI); - cairo_fill (c); - - return FALSE; /* TRUE to stop other handlers from being invoked for the event. - FALSE to propagate the event further. */ -} - -gboolean timer (GtkWidget *widget) -{ - t += dt; - phi += omega * dt; - omega += - dt * g / l * sin (phi); - - 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_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_main (); - return 0; -} diff --git a/20221114/pendulum-2.c b/20221114/pendulum-2.c deleted file mode 100644 index 6c318a03cd89d21d09259201ffcccb673983fe3b..0000000000000000000000000000000000000000 --- a/20221114/pendulum-2.c +++ /dev/null @@ -1,69 +0,0 @@ -#include <gtk/gtk.h> -#include <math.h> - -#define WIDTH 320 -#define HEIGHT 240 -#define GAP (HEIGHT / 20) -#define r GAP -#define visual_length (HEIGHT - 2 * GAP - r) - -#define phi0 (-0.5) -#define omega0 0.0 -#define t0 0.0 -#define g 9.81 -#define l 1.0 -#define dt 0.02 - -double t = t0; -double phi = phi0; -double omega = omega0; - -gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data) -{ - GdkRGBA orange = { 1.0, 0.5, 0.0, 1.0 }; - - int x = WIDTH / 2 + visual_length * sin (phi); - int y = GAP + visual_length * cos (phi); - - gdk_cairo_set_source_rgba (c, &orange); - cairo_move_to (c, WIDTH / 2, GAP); - cairo_line_to (c, x, y); - cairo_stroke (c); - cairo_arc (c, x, y, r, 0, 2 * G_PI); - cairo_fill (c); - - return FALSE; /* TRUE to stop other handlers from being invoked for the event. - FALSE to propagate the event further. */ -} - -gboolean timer (GtkWidget *widget) -{ - t += dt; - phi += omega * dt; - omega += - dt * g / l * phi; - - 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_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_main (); - return 0; -} diff --git a/20221114/pendulum-3.c b/20221114/pendulum-3.c deleted file mode 100644 index b6bc9793b3b7c0166df678cccdf8a4ae9170d886..0000000000000000000000000000000000000000 --- a/20221114/pendulum-3.c +++ /dev/null @@ -1,87 +0,0 @@ -#include <gtk/gtk.h> -#include <math.h> - -#define WIDTH 320 -#define HEIGHT 240 -#define GAP (HEIGHT / 20) -#define r GAP -#define visual_length (HEIGHT - 2 * GAP - r) - -#define phi0 (-0.5) -#define omega0 0.0 -#define t0 0.0 -#define g 9.81 -#define l 1.0 -#define dt 0.02 - -double t = t0; -double phi_with_sin = phi0; -double omega_with_sin= omega0; -double phi_without_sin = phi0; -double omega_without_sin= omega0; - -void draw_pendulum (cairo_t *c, double phi, GdkRGBA *colour) -{ - int x = WIDTH / 2 + visual_length * sin (phi); - int y = GAP + visual_length * cos (phi); - - gdk_cairo_set_source_rgba (c, colour); - cairo_move_to (c, WIDTH / 2, GAP); - cairo_line_to (c, x, y); - cairo_stroke (c); - cairo_arc (c, x, y, r, 0, 2 * G_PI); - cairo_fill (c); -} - -gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data) -{ - GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 }; - GdkRGBA orange = { 1.0, 0.5, 0.0, 1.0 }; - GdkRGBA green = { 0.0, 0.5, 0.0, 1.0 }; - - double A = phi0; - double B = 0.5 * M_PI; /* 90° */ - double phi_analytic = A * sin (sqrt (g / l) * t + B); - - /* Näherungen: Kleinwinkel dt */ - draw_pendulum (c, phi_with_sin, &blue); /* blau nein ja */ - draw_pendulum (c, phi_without_sin, &orange); /* orange ja ja */ - draw_pendulum (c, phi_analytic, &green); /* grün ja nein */ - - return FALSE; /* TRUE to stop other handlers from being invoked for the event. - FALSE to propagate the event further. */ -} - -gboolean timer (GtkWidget *widget) -{ - t += dt; - phi_with_sin += omega_with_sin * dt; - omega_with_sin += - dt * g / l * sin (phi_with_sin); - phi_without_sin += omega_without_sin * dt; - omega_without_sin += - dt * g / l * phi_without_sin; - - 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_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_main (); - return 0; -} diff --git a/20221114/pendulum-4.c b/20221114/pendulum-4.c deleted file mode 100644 index 1a08e32735336064af72ce6f332299d14ff66218..0000000000000000000000000000000000000000 --- a/20221114/pendulum-4.c +++ /dev/null @@ -1,86 +0,0 @@ -#include <gtk/gtk.h> -#include <math.h> - -#define WIDTH 320 -#define HEIGHT 240 -#define GAP (HEIGHT / 20) -#define r GAP -#define visual_length (HEIGHT - 2 * GAP - r) - -#define phi0 (-5.0 / 180.0 * M_PI) -#define omega0 0.0 -#define t0 0.0 -#define g 9.81 -#define l 1.0 -#define dt 0.02 - -double t = t0; -double phi_with_sin = phi0; -double omega_with_sin= omega0; -double phi_without_sin = phi0; -double omega_without_sin= omega0; - -void draw_pendulum (cairo_t *c, double phi, GdkRGBA *colour) -{ - int x = WIDTH / 2 + visual_length * sin (phi); - int y = GAP + visual_length * cos (phi); - - gdk_cairo_set_source_rgba (c, colour); - cairo_move_to (c, WIDTH / 2, 10); - cairo_line_to (c, x, y); - cairo_stroke (c); - cairo_arc (c, x, y, r, 0, 2 * G_PI); - cairo_fill (c); -} - -gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data) -{ - GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 }; - GdkRGBA orange = { 1.0, 0.5, 0.0, 1.0 }; - GdkRGBA green = { 0.0, 0.5, 0.0, 1.0 }; - - double A = phi0; - double B = 0.5 * M_PI; /* 90° */ - double phi_analytic = A * sin (sqrt (g / l) * t + B); - - draw_pendulum (c, phi_with_sin, &blue); - draw_pendulum (c, phi_without_sin, &orange); - draw_pendulum (c, phi_analytic, &green); - - return FALSE; /* TRUE to stop other handlers from being invoked for the event. - FALSE to propagate the event further. */ -} - -gboolean timer (GtkWidget *widget) -{ - t += dt; - phi_with_sin += omega_with_sin * dt; - omega_with_sin += - dt * g / l * sin (phi_with_sin); - phi_without_sin += omega_without_sin * dt; - omega_without_sin += - dt * g / l * phi_without_sin; - - 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_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL); - - g_timeout_add (50, (GSourceFunc) timer, drawing_area); - - gtk_main (); - return 0; -} diff --git a/20221114/pendulum.pdf b/20221114/pendulum.pdf deleted file mode 120000 index 7d1d87305cdb8840a248ff2207538d758464f452..0000000000000000000000000000000000000000 --- a/20221114/pendulum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/pendulum.pdf \ No newline at end of file diff --git a/20221114/pgscript.sty b/20221114/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221114/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221114/pgslides.sty b/20221114/pgslides.sty deleted file mode 120000 index 5be1416f4216f076aa268901f52a15d775e43f64..0000000000000000000000000000000000000000 --- a/20221114/pgslides.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgslides.sty \ No newline at end of file diff --git a/20221121/Tower_of_Hanoi.jpeg b/20221121/Tower_of_Hanoi.jpeg deleted file mode 120000 index a1a794afda08596ffa2f46f278db53455de25b6c..0000000000000000000000000000000000000000 --- a/20221121/Tower_of_Hanoi.jpeg +++ /dev/null @@ -1 +0,0 @@ -../common/Tower_of_Hanoi.jpeg \ No newline at end of file diff --git a/20221121/aufgabe-2.c b/20221121/aufgabe-2.c deleted file mode 100644 index 47595ef0658e94d76a42263e82200f94895cdeea..0000000000000000000000000000000000000000 --- a/20221121/aufgabe-2.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> -#include <string.h> - -typedef struct -{ - char first_name[10]; - char family_name[20]; - char day, month; - int year; -} person; - -int main (void) -{ - person sls; - sls.day = 26; - sls.month = 7; - sls.year = 1951; - strcpy (sls.first_name, "Sabine"); - strcpy (sls.family_name, "Leutheusser-Schnarrenberger"); - printf ("%s %s wurde am %d.%d.%d geboren.\n", - sls.first_name, sls.family_name, sls.day, sls.month, sls.year); - return 0; -} diff --git a/20221121/aufgabe-3.c b/20221121/aufgabe-3.c deleted file mode 100644 index abbf364a3db17611e41d086591826e98a8a3672b..0000000000000000000000000000000000000000 --- a/20221121/aufgabe-3.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> - -int fak (int n) -{ - if (n <= 0) - return 1; - else - return n * fak (n - 1); -} - -int main (void) -{ - for (int n = 0; n <= 5; n++) - printf ("%d\n", fak (n)); - return 0; -} diff --git a/20221121/bsort-1.c b/20221121/bsort-1.c deleted file mode 100644 index 3c02adc72e6a7e702e2c7c68c838fc94cc8ef547..0000000000000000000000000000000000000000 --- a/20221121/bsort-1.c +++ /dev/null @@ -1,48 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -void sort (char **name) -{ - for (int i = 1; name[i]; i++) - if (compare (name, i - 1, i) > 0) - { - char *temp = name[i - 1]; - name[i - 1] = name[i]; - name[i] = temp; - } -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/bsort-1a.c b/20221121/bsort-1a.c deleted file mode 100644 index 348b638843002926f57cdcf1d4fbc9bd88d2a10c..0000000000000000000000000000000000000000 --- a/20221121/bsort-1a.c +++ /dev/null @@ -1,48 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -void sort (char **name) -{ - for (int i = 1; name[i]; i++) - if (compare (name, i - 1, i) > 0) - { - char *temp = name[i - 1]; - name[i - 1] = name[i]; - name[i] = temp; - } -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Zacharias", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", NULL }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/bsort-2.c b/20221121/bsort-2.c deleted file mode 100644 index d277be0182a40ecd0c66eaeef94d7aebac6aa542..0000000000000000000000000000000000000000 --- a/20221121/bsort-2.c +++ /dev/null @@ -1,55 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -void sort (char **name) -{ - int sorted = 0; - while (name[sorted]) - sorted++; - while (sorted > 0) - { - for (int i = 1; i < sorted; i++) - if (compare (name, i - 1, i) > 0) - { - char *temp = name[i - 1]; - name[i - 1] = name[i]; - name[i] = temp; - } - sorted--; - } -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/bsort-3.c b/20221121/bsort-3.c deleted file mode 100644 index 67d0097b913171b4523f4f04b6b6ff494046dabd..0000000000000000000000000000000000000000 --- a/20221121/bsort-3.c +++ /dev/null @@ -1,58 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -void sort (char **name) -{ - int done = 0; - int sorted = 0; - while (name[sorted]) - sorted++; - while (sorted > 0 && !done) - { - done = 1; - for (int i = 1; i < sorted; i++) - if (compare (name, i - 1, i) > 0) - { - done = 0; - char *temp = name[i - 1]; - name[i - 1] = name[i]; - name[i] = temp; - } - sorted--; - } -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/bsort-4.c b/20221121/bsort-4.c deleted file mode 100644 index 241270a46f4ffa005d252207d769c3c4059ed7e2..0000000000000000000000000000000000000000 --- a/20221121/bsort-4.c +++ /dev/null @@ -1,57 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -void sort (char **name) -{ - int sorted = 0; - while (name[sorted]) - sorted++; - while (sorted > 0) - { - int new_sorted = 0; - for (int i = 1; i < sorted; i++) - if (compare (name, i - 1, i) > 0) - { - new_sorted = i; - char *temp = name[i - 1]; - name[i - 1] = name[i]; - name[i] = temp; - } - sorted = new_sorted; - } -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/bsort-4a.c b/20221121/bsort-4a.c deleted file mode 100644 index b65fe873bdfdccd4bb20a96aba43d61746527267..0000000000000000000000000000000000000000 --- a/20221121/bsort-4a.c +++ /dev/null @@ -1,57 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -void sort (char **name) -{ - int sorted = 0; - while (name[sorted]) - sorted++; - while (sorted > 0) - { - int new_sorted = 0; - for (int i = 1; i < sorted; i++) - if (compare (name, i - 1, i) > 0) - { - new_sorted = i; - char *temp = name[i - 1]; - name[i - 1] = name[i]; - name[i] = temp; - } - sorted = new_sorted; - } -} - -int main (void) -{ - char *name[] = { "Zacharias", "Ulrich", "Thomas", "Siegfried", "Peter", "Otto", "Maria", - "Lisa", "Hugo", "Heinrich", "Hans", "Fritz", "Dieter", "Box", "Berta", - "Anna", NULL }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/bsort-4b.c b/20221121/bsort-4b.c deleted file mode 100644 index bc2b2d193a68f4a701fecceeeffbb77f9b8117c5..0000000000000000000000000000000000000000 --- a/20221121/bsort-4b.c +++ /dev/null @@ -1,57 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -void sort (char **name) -{ - int sorted = 0; - while (name[sorted]) - sorted++; - while (sorted > 0) - { - int new_sorted = 0; - for (int i = 1; i < sorted; i++) - if (compare (name, i - 1, i) > 0) - { - new_sorted = i; - char *temp = name[i - 1]; - name[i - 1] = name[i]; - name[i] = temp; - } - sorted = new_sorted; - } -} - -int main (void) -{ - char *name[] = { "Anna", "Berta", "Box", "Dieter", "Fritz", "Hans", "Heinrich", "Hugo", - "Lisa", "Maria", "Otto", "Peter", "Siegfried", "Thomas", "Ulrich", - "Zacharias", NULL }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/bsort-4c.c b/20221121/bsort-4c.c deleted file mode 100644 index 89bc0d302ce027d5c5ae6949f73aa91b9992ef24..0000000000000000000000000000000000000000 --- a/20221121/bsort-4c.c +++ /dev/null @@ -1,58 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; -// display (name, left, right); -// usleep (200000); - return result; -} - -void sort (char **name) -{ - int sorted = 0; - while (name[sorted]) - sorted++; - while (sorted > 0) - { - int new_sorted = 0; - for (int i = 1; i < sorted; i++) - if (compare (name, i - 1, i) > 0) - { - new_sorted = i; - char *temp = name[i - 1]; - name[i - 1] = name[i]; - name[i] = temp; - } - sorted = new_sorted; - } -} - -int main (void) -{ - char *name[] = { - #include "names.h" - NULL - }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/hanoi-9a.c b/20221121/hanoi-9a.c deleted file mode 100644 index 55e8d74db6d7284d6db225a6f8f3e08ab4efdc06..0000000000000000000000000000000000000000 --- a/20221121/hanoi-9a.c +++ /dev/null @@ -1,58 +0,0 @@ -#include <stdio.h> -#include <error.h> - -#define DISKS 32 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -void move (int from, int to, int disks) -{ - if (disks == 1) - { - if (n[from] <= 0) - error (1, 0, "trying to move disk from empty tower"); - if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1]) - error (1, 0, "trying to move larger disk on smaller one"); - tower[to][n[to]] = tower[from][n[from] - 1]; - n[to]++; - n[from]--; - static int counter = 1; - if (counter++ >= 100000000) - { - display (); - counter = 1; - } - } - else - { - int help = 0 + 1 + 2 - from - to; - move (from, help, disks - 1); - move (from, to, 1); - move (help, to, disks - 1); - } -} - -int main (void) -{ - n[0] = DISKS; - for (int i = 0; i < DISKS; i++) - tower[0][i] = DISKS - i; - n[1] = 0; - n[2] = 0; - display (); - move (0, 2, DISKS); - display (); - return 0; -} diff --git a/20221121/hanoi-9b.c b/20221121/hanoi-9b.c deleted file mode 100644 index 3f2322d75bdc4c3c24a65938b4b9f0b4ca544ef2..0000000000000000000000000000000000000000 --- a/20221121/hanoi-9b.c +++ /dev/null @@ -1,58 +0,0 @@ -#include <stdio.h> -#include <error.h> - -#define DISKS 32 - -int n[3], tower[3][DISKS]; - -void display (void) -{ - printf ("\n"); - for (int i = 0; i < 3; i++) - { - printf ("tower %d:", i); - for (int j = 0; j < n[i]; j++) - printf (" %d", tower[i][j]); - printf ("\n"); - } -} - -void move (int from, int to, int disks) -{ - if (disks == 1) - { -// if (n[from] <= 0) -// error (1, 0, "trying to move disk from empty tower"); -// if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1]) -// error (1, 0, "trying to move larger disk on smaller one"); - tower[to][n[to]] = tower[from][n[from] - 1]; - n[to]++; - n[from]--; - static int counter = 1; - if (counter++ >= 100000000) - { - display (); - counter = 1; - } - } - else - { - int help = 0 + 1 + 2 - from - to; - move (from, help, disks - 1); - move (from, to, 1); - move (help, to, disks - 1); - } -} - -int main (void) -{ - n[0] = DISKS; - for (int i = 0; i < DISKS; i++) - tower[0][i] = DISKS - i; - n[1] = 0; - n[2] = 0; - display (); - move (0, 2, DISKS); - display (); - return 0; -} diff --git a/20221121/hex-1.c b/20221121/hex-1.c deleted file mode 100644 index 5e212d63393e2f29faada3a5f8938bddc46b51b2..0000000000000000000000000000000000000000 --- a/20221121/hex-1.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf ("Die Antwort lautet: %x bzw. %X\n", 0xAffe, 0xaFfE); - return 0; -} diff --git a/20221121/hp-20221121.pdf b/20221121/hp-20221121.pdf deleted file mode 100644 index 7a6837e8bf0053fc389341ad0539d23760241dc7..0000000000000000000000000000000000000000 Binary files a/20221121/hp-20221121.pdf and /dev/null differ diff --git a/20221121/hp-20221121.tex b/20221121/hp-20221121.tex deleted file mode 100644 index b8f143461d1e9a947b3597d2a67c80ac382f81a1..0000000000000000000000000000000000000000 --- a/20221121/hp-20221121.tex +++ /dev/null @@ -1,1421 +0,0 @@ -% hp-20221121.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Aufwandsabschätzungen, Objektorientierte Programmierung - -\documentclass[10pt,t]{beamer} - -\usepackage{pgslides} -\usepackage{pdftricks} -\usepackage{tikz} -\usepackage{rotating} - -\begin{psinputs} - \usepackage[utf8]{inputenc} - \usepackage[german]{babel} - \usepackage[T1]{fontenc} - \usepackage{helvet} - \renewcommand*\familydefault{\sfdefault} - \usepackage{pstricks,pst-grad} -\end{psinputs} - -\newcommand{\redurl}[1]{\href{#1}{\color{red}\nolinkurl{#1}}} - -\title{Hardwarenahe Programmierung} -\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{21.\ November 2022} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \begin{itemize} - \item[4.1] Bit-Operationen - \item[4.2] I/O-Ports - \item[4.3] Interrupts - \item[4.4] volatile-Variable - \color{medgreen} - \item[4.5] Byte-Reihenfolge -- Endianness - \item[4.6] Binärdarstellung negativer Zahlen - \item[4.7] Speicherausrichtung -- Alignment - \end{itemize} - \item[\textbf{5}] \textbf{Algorithmen} - \begin{itemize} - \color{medgreen} - \item[5.1] Differentialgleichungen - \item[5.2] Rekursion - \color{red} - \item[5.3] Aufwandsabschätzungen - \end{itemize} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \item[\textbf{7}] \textbf{Datenstrukturen} - \end{itemize} - \vspace*{-1cm} - -\end{frame} - -\setcounter{section}{3} -\section{Hardwarenahe Programmierung} -\setcounter{subsection}{4} -\subsection{Byte-Reihenfolge -- Endianness} -\subsubsection{Konzept} - -\begin{frame}[fragile] - - \showsubsection - \showsubsubsection - - Eine Zahl geht über mehrere Speicherzellen.\\ - Beispiel: 16-Bit-Zahl in 2 8-Bit-Speicherzellen - - \smallskip - - Welche Bits liegen wo? - -% \pause - \bigskip - - $1027 = 1024 + 2 + 1 = 0000\,0100\,0000\,0011_2 = 0403_{16}$ - -% \pause - \bigskip - Speicherzellen: - - \medskip - \begin{tabular}{|c|c|l}\cline{1-2} - \raisebox{-0.25ex}{04} & \raisebox{-0.25ex}{03} & \strut Big-Endian "`großes Ende zuerst"' \\\cline{1-2} - \multicolumn{2}{c}{} & % \pause - für Menschen leichter lesbar % \pause - \\ - \multicolumn{3}{c}{} \\[-5pt]\cline{1-2} - \raisebox{-0.25ex}{03} & \raisebox{-0.25ex}{04} & \strut Little-Endian "`kleines Ende zuerst"' \\\cline{1-2} - \multicolumn{2}{c}{} & % \pause - bei Additionen effizienter - \end{tabular} - -% \pause - \medskip - \textarrow\ Geschmackssache -% \pause\\ - \quad\textbf{\dots\ außer bei Datenaustausch!} - -% \pause -% \bigskip -% -% Aber: nicht verwechseln! \qquad $0304_{16} = 772$ - -\end{frame} - -\begin{frame} - - \showsubsection - \showsubsubsection - - Eine Zahl geht über mehrere Speicherzellen.\\ - Beispiel: 16-Bit-Zahl in 2 8-Bit-Speicherzellen - - \smallskip - - Welche Bits liegen wo? - - \medskip - - \textarrow\ Geschmackssache\\ - \textbf{\dots\ außer bei Datenaustausch!} - - \begin{itemize} - \item - Dateiformate - \item - Datenübertragung - \end{itemize} - -\end{frame} - -\subsubsection{Dateiformate} - -\begin{frame} - - \showsubsection - \showsubsubsection - - Audio-Formate: Reihenfolge der Bytes in 16- und 32-Bit-Zahlen - \begin{itemize} - \item - RIFF-WAVE-Dateien (\file{.wav}): Little-Endian - \item - Au-Dateien (\file{.au}): Big-Endian -% \pause - \item - ältere AIFF-Dateien (\file{.aiff}): Big-Endian - \item - neuere AIFF-Dateien (\file{.aiff}): Little-Endian - \end{itemize} - -% \pause - \bigskip - - Grafik-Formate: Reihenfolge der Bits in den Bytes - \begin{itemize} - \item - PBM-Dateien: Big-Endian\only<1->{, MSB first} - \item - XBM-Dateien: Little-Endian\only<1->{, LSB first} - \end{itemize} - \only<1->{MSB/LSB = most/least significant bit} - -\end{frame} - -\subsubsection{Datenübertragung} - -\begin{frame} - - \showsubsection - \showsubsubsection - - \begin{itemize} - \item - RS-232 (serielle Schnittstelle): LSB first - \item - I$^2$C: MSB first - \item - USB: beides -% \pause - \medskip - \item - Ethernet: LSB first - \item - TCP/IP (Internet): Big-Endian - \end{itemize} - -\end{frame} - -\subsection{Binärdarstellung negativer Zahlen} - -\begin{frame}[fragile] - - \showsubsection - - Speicher ist begrenzt!\\ - \textarrow\ feste Anzahl von Bits - - \medskip - - 8-Bit-Zahlen ohne Vorzeichen: \lstinline{uint8_t}\\ - \textarrow\ Zahlenwerte von \lstinline{0x00} bis \lstinline{0xff} = 0 bis 255\\ -% \pause - \textarrow\ 255 + 1 = 0 - -% \pause - \medskip - - 8-Bit-Zahlen mit Vorzeichen: \lstinline{int8_t}\\ - \lstinline{0xff} = 255 ist die "`natürliche"' Schreibweise für $-1$.\\ -% \pause - \textarrow\ Zweierkomplement - -% \pause - \medskip - - Oberstes Bit = 1: negativ\\ - Oberstes Bit = 0: positiv\\ - \textarrow\ 127 + 1 = $-128$ - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Speicher ist begrenzt!\\ - \textarrow\ feste Anzahl von Bits - - \medskip - - 16-Bit-Zahlen ohne Vorzeichen: - \lstinline{uint16_t}\hfill\lstinline{uint8_t}\\ - \textarrow\ Zahlenwerte von \lstinline{0x0000} bis \lstinline{0xffff} - = 0 bis 65535\hfill 0 bis 255\\ - \textarrow\ 65535 + 1 = 0\hfill 255 + 1 = 0 - - \medskip - - 16-Bit-Zahlen mit Vorzeichen: - \lstinline{int16_t}\hfill\lstinline{int8_t}\\ - \lstinline{0xffff} = 66535 ist die "`natürliche"' Schreibweise für $-1$.\hfill - \lstinline{0xff} = 255 = $-1$\\ - \textarrow\ Zweierkomplement - - \medskip - - Oberstes Bit = 1: negativ\\ - Oberstes Bit = 0: positiv\\ - \textarrow\ 32767 + 1 = $-32768$ - - \bigskip - Literatur: \url{http://xkcd.com/571/} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Frage: \emph{Für welche Zahl steht der Speicherinhalt\, - \raisebox{2pt}{% - \tabcolsep0.25em - \begin{tabular}{|c|c|}\hline - \rule{0pt}{11pt}a3 & 90 \\\hline - \end{tabular}} - (hexadezimal)?} - -% \pause - \smallskip - Antwort: \emph{Das kommt darauf an.} ;--) - -% \pause - \medskip - Little-Endian: - - \smallskip - - \begin{tabular}{lrl} - als \lstinline,int8_t,: & $-93$ & (nur erstes Byte)\\ - als \lstinline,uint8_t,: & $163$ & (nur erstes Byte)\\ - als \lstinline,int16_t,: & $-28509$\\ - als \lstinline,uint16_t,: & $37027$\\ - \lstinline,int32_t, oder größer: & $37027$ - & (zusätzliche Bytes mit Nullen aufgefüllt) - \end{tabular} - -% \pause - \medskip - Big-Endian: - - \smallskip - - \begin{tabular}{lrl} - als \lstinline,int8_t,: & $-93$ & (nur erstes Byte)\\ - als \lstinline,uint8_t,: & $163$ & (nur erstes Byte)\\ - als \lstinline,int16_t,: & $-23664$\\ - als \lstinline,uint16_t,: & $41872$\\ als \lstinline,int32_t,: & $-1550843904$ & (zusätzliche Bytes\\ - als \lstinline,uint32_t,: & $2744123392$ & mit Nullen aufgefüllt)\\ - als \lstinline,int64_t,: & $-6660823848880963584$\\ - als \lstinline,uint64_t,: & $11785920224828588032$\\ - \end{tabular} - - \vspace*{-1cm} - -\end{frame} - -\subsection{Speicherausrichtung -- Alignment} - -\begin{frame}[fragile] - - \showsubsection - - \begin{lstlisting} - #include <stdint.h> - - uint8_t a; - uint16_t b; - uint8_t c; - \end{lstlisting} - -% \pause - \bigskip - - Speicheradresse durch 2 teilbar -- "`16-Bit-Alignment"' - \begin{itemize} - \item - 2-Byte-Operation: effizienter -% \pause - \item - \dots\ oder sogar nur dann erlaubt -% \pause - \arrowitem - Compiler optimiert Speicherausrichtung - \end{itemize} - - \medskip - -% \pause - \begin{minipage}{3cm} - \begin{lstlisting}[gobble=6] - ¡uint8_t a; - uint8_t dummy; - uint16_t b; - uint8_t c;¿ - \end{lstlisting} - \end{minipage} -% \pause - \begin{minipage}{3cm} - \begin{lstlisting}[gobble=6] - ¡uint8_t a; - uint8_t c; - uint16_t b;¿ - \end{lstlisting} - \end{minipage} - -% \pause - \vspace{-1.75cm} - \strut\hfill - \begin{minipage}{6.5cm} - Fazit: - \begin{itemize} - \item - \textbf{Adressen von Variablen\\ - sind systemabhängig} - \item - Bei Definition von Datenformaten\\ - Alignment beachten \textarrow\ effizienter - \end{itemize} - \end{minipage} - -\end{frame} - -\section{Algorithmen} -\subsection{Differentialgleichungen} - -\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<1->{\hfill$\Rightarrow$\hfill}% - \begin{onlyenv}<1> - \begin{minipage}{8.3cm} - \begin{align*} - x(t) &= \int v_x(t)\,dt - \visible<1->{= \int v_{0x}\,dt} - \visible<1->{= x_0 + v_{0x}\cdot t}\\[\medskipamount] - y(t) &= \int v_y(t)\,dt - \visible<1->{= \int v_{0y} - g\cdot t\,dt} - \visible<1->{= y_0 + v_{0y}\cdot t - - {\textstyle\frac12}gt^2}\\[\bigskipamount] - v_x(t) &= \int 0\,dt - \visible<1->{= v_{0x}} \\[\medskipamount] - v_y(t) &= \int -g\,dt - \visible<1->{= v_{0y} - g\cdot t} - \end{align*} - \end{minipage}% - \end{onlyenv}% - \begin{onlyenv}<2-> - \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}{4} -\section{Algorithmen} -\setcounter{subsection}{1} -\subsection{Rekursion} - -\begin{frame}[fragile] - - \showsubsection - - Vollständige Induktion: - \vspace*{-0.725cm} - \begin{displaymath} - \hspace*{4cm} - \left. - \begin{array}{r} - \mbox{Aussage gilt für $n = 1$}\\[2pt] - \mbox{Schluß von $n - 1$ auf $n$} - \end{array} - \right\} - \mbox{Aussage gilt für alle $n\in\mathbb{N}$} - \end{displaymath} - \vspace*{-0.5cm} - - \pause - - Türme von Hanoi - - \begin{onlyenv}<2> - \begin{center} - \includegraphics[width=12.2cm]{Tower_of_Hanoi.jpeg} - \end{center} - \end{onlyenv} - - \begin{onlyenv}<3-> - \begin{itemize} - \item - 64 Scheiben, 3 Plätze, - \only<3-4>{\hfill\makebox(0,0)[rt]{\includegraphics[width=6cm]{Tower_of_Hanoi.jpeg}}}\\ - immer 1 Scheibe verschieben - \item - Ziel: Turm verschieben - \item - Es dürfen nur kleinere Scheiben\\ - auf größeren liegen. - \bigskip - \pause - \pause - \item - $n = 1$ Scheibe: fertig - \item - Wenn $n - 1$ Scheiben verschiebbar:\\ - schiebe $n - 1$ Scheiben auf Hilfsplatz,\\ - verschiebe die darunterliegende,\\ - hole $n - 1$ Scheiben von Hilfsplatz - \end{itemize} - \begin{onlyenv}<5> - \vspace{-4.3cm} - \begin{lstlisting}[gobble=8,xleftmargin=6.4cm] - void move (int from, int to, int disks) - { - if (disks == 1) - move_one_disk (from, to); - else - { - int help = 0 + 1 + 2 - from - to; - move (from, help, disks - 1); - move (from, to, 1); - move (help, to, disks - 1); - } - } - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<6-> - \vspace{-5.0cm} - \hspace*{7.4cm}\begin{minipage}[t]{5cm} - 32 Scheiben: - \begin{lstlisting}[gobble=10,style=terminal] - $ ¡time ./hanoi-9b¿ - ... - real 0m30,672s - user 0m30,662s - sys 0m0,008s - \end{lstlisting} - \pause[7] - \begin{itemize} - \arrowitem - etwas über 1 Minute\\ - für 64 Scheiben - \end{itemize} - \pause - \vspace*{-0.5cm} - \begin{picture}(0,0) - \color{red} - \put(0,0){\makebox(0,0)[bl]{\tikz[line width=1pt]{\draw(0,0)--(4,0.8);}}} - \put(0,0.8){\makebox(0,0)[tl]{\tikz[line width=1pt]{\draw(0,0)--(4,-0.8);}}} - \end{picture} - - Für jede zusätzliche Scheibe\\verdoppelt sich die Rechenzeit! - % 30.672 * 2^32 / 3600 / 24 / 365.25 = 4174.43775518138261464750 - \begin{itemize} - \arrowitem - $\frac{30,672\,\text{s}\,\cdot\,2^{32}}{3600\,\cdot\,24\,\cdot\,365,25} \approx 4174$ - Jahre\\[\smallskipamount] - für 64 Scheiben - \end{itemize} - \end{minipage} - \end{onlyenv} - \end{onlyenv} - -\end{frame} - -\subsection{Aufwandsabschätzungen \protect\color{gray}-- Komplexitätsanalyse} - -\begin{frame}[fragile] - -% \newcommand{\w}{\hspace*{0.75pt}} - - \showsubsection - - \begin{picture}(0,0) - \put(7.6,-0.5){% - \begin{minipage}[t]{5.3cm} -% \vspace*{-1.0cm}\includegraphics{landau-symbols.pdf} - \vspace*{-1.0cm}\alt<16->{\includegraphics{landau-symbols-3.pdf}}% - {\alt<15->{\includegraphics{landau-symbols-2.pdf}}% - {\includegraphics{landau-symbols.pdf}}} - \small - \begin{description}\itemsep0pt\leftskip-0.5cm - \item[$n$:] Eingabedaten - \item[$g(n)$:] Rechenzeit - \end{description} - \end{minipage}} - \end{picture} - - \vspace*{-\bigskipamount} - - Wann ist ein Programm "`schnell"'? - - \medskip - - \begin{onlyenv}<1-2> - Türme von Hanoi: $\mathcal{O}(2^n)$ - \par\medskip - Für jede zusätzliche Scheibe\\verdoppelt sich die Rechenzeit! - \begin{itemize} - \arrowitem - $\frac{30,672\,\text{s}\,\cdot\,2^{32}}{3600\,\cdot\,24\,\cdot\,365,25} \approx 4174$ - Jahre\\[\smallskipamount] - für 64 Scheiben - \end{itemize} - - \bigskip - \end{onlyenv} - - \begin{onlyenv}<2-> - Faustregel:\\Schachtelung der Schleifen zählen\\ - $k$ Schleifen ineinander \textarrow\ $\mathcal{O}(n^k)$ - - \bigskip - \end{onlyenv} - - \begin{onlyenv}<3-13> - \textbf{Beispiel: Sortieralgorithmen} - - \smallskip - - Anzahl der Vergleiche bei $n$ Strings - \begin{itemize} - \item - Maximum suchen \pause[4]mit Schummeln\pause: $\mathcal{O}(1)$ - \pause - \item - Maximum suchen\pause: $\mathcal{O}(n)$ - \pause - \item - Selection-Sort\pause: $\mathcal{O}(n^2)$ - \pause - \item - Bubble-Sort\pause: $\mathcal{O}(n)$ bis $\mathcal{O}(n^2)$ - \pause - \item - Quicksort\pause: $\mathcal{O}(n\log n)$ bis $\mathcal{O}(n^2)$ - \end{itemize} - - \end{onlyenv} - - \begin{onlyenv}<14> - \textbf{Wie schnell ist RSA-Verschlüsselung?} - - \smallskip - - \begin{math} - c = m^e\,\%\,N - \end{math} - \quad - ("`$\%$"' = "`modulo"') - - \medskip - - \begin{lstlisting}[gobble=6,xleftmargin=2em] - int c = 1; - for (int i = 0; i < e; i++) - c = (c * m) % N; - \end{lstlisting} - - \smallskip - - \begin{itemize} - \item - $\mathcal{O}(e)$ Iterationen -% \item -% wenn $n$ die Anzahl der Binärziffern (Bits) von $e$ ist: -% $\mathcal{O}(2^n)$ Iterationen - \item - mit Trick: - $\mathcal{O}(\log e)$ Iterationen ($\log e$ = Anzahl der Ziffern von $e$) - \end{itemize} - - \smallskip - - Jede Iteration enthält eine Multiplikation und eine Division.\\ - Aufwand dafür: $\mathcal{O}(\log e)$\\ - \textarrow\ Gesamtaufwand: $\mathcal{O}\bigl((\log e)^2\bigr)$ - - \end{onlyenv} - - \begin{onlyenv}<15-> - - \textbf{Wie schnell ist RSA?}\\ - - \smallskip - - ($n$ = typische beteiligte Zahl, z.\,B. $e,p,q$) - - \begin{itemize} - \item - Ver- und Entschlüsselung (Exponentiation):\\ - \strut\hbox to 3.5cm{\color{red}$\mathcal{O}\!\left((\log n)^2\right)$\hss} - \only<16->{{\color{magenta}$\mathcal{O}(n^2)$}} - \item - Schlüsselerzeugung (Berechnung von $d$):\\ - \strut\hbox to 3.5cm{\color{red}$\mathcal{O}\!\left((\log n)^2\right)$\hss} - \only<16->{{\color{magenta}$\mathcal{O}(n^2)$}} - \item - Verschlüsselung brechen (Primfaktorzerlegung):\\ - \strut\hbox to 3.5cm{\color{red}$\mathcal{O}\bigl(2^{\sqrt{\log n\,\cdot\,\log\log n}}\bigr)$\hss} - \only<16->{{\color{magenta}$\mathcal{O}\bigl(2^{\sqrt{n\log n}}\bigr)$}} - \end{itemize} - - \vspace{0cm plus 1filll} - - \textbf{Die Sicherheit von RSA beruht darauf, - daß das Brechen der Verschlüsselung aufwendiger ist als - \boldmath$\mathcal{O}\bigl((\log n)^k\bigr)$ (für beliebiges $k$).} - - \vspace*{0.65cm} - - \end{onlyenv} - -\end{frame} - -\section{Objektorientierte Programmierung} - -\addtocounter{subsection}{-1} -\subsection{Dynamische Speicherverwaltung} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \begin{itemize} - \item - Array: feste Anzahl von Elementen desselben Typs (z.\,B.\ 3 ganze Zahlen) - \item - Dynamisches Array: variable Anzahl von Elementen desselben Typs - \end{itemize} - - \bigskip - - \begin{lstlisting} - char *name[] = { "Anna", "Berthold", "Caesar" }; - - ... - - name[3] = "Dieter"; - \end{lstlisting} - - \begin{picture}(0,0) - \color{red} - \put(0,0){\line(3,1){3.5}} - \put(0,1){\line(3,-1){3.5}} - \end{picture} - -\end{frame} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \bigskip - - \begin{lstlisting} - #include <stdlib.h> - - ... - - char **name = malloc (3 * sizeof (char *)); - /* Speicherplatz für 3 Zeiger anfordern */ - - ... - - free (name); - /* Speicherplatz freigeben */ - - \end{lstlisting} - -\end{frame} - -\subsection{Konzepte und Ziele} - -\begin{frame} - - \showsection - \showsubsection - - \begin{itemize} - \item -% Array: feste Anzahl von Elementen desselben Typs (z.\,B.\ 3 ganze Zahlen) - Array: Elemente desselben Typs (z.\,B.\ 3 ganze Zahlen) -% \item -% Dynamisches Array: variable Anzahl von Elementen desselben Typs - \item - Problem: Elemente unterschiedlichen Typs - \item - Lösung: den Typ des Elements zusätzlich speichern \textarrow\ \newterm{Objekt} - \item - Problem: Die Elemente sind unterschiedlich groß (Speicherplatz). - \item - Lösung: Im Array nicht die Objekte selbst speichern, sondern Zeiger darauf. - \end{itemize} - \begin{itemize} - \item - Funktionen, die mit dem Objekt arbeiten: \newterm{Methoden} - \begin{onlyenv}<1> - \item - Was die Funktion bewirkt,\\ - hängt vom Typ des Objekts ab - \item - Realisierung über endlose \lstinline{if}-Ketten - \end{onlyenv} - \begin{onlyenv}<2> - \item - Was die Funktion bewirkt - \begin{picture}(0,0) - \color{red} - \put(-4.00,-0.05){\tikz{\draw[thick](0,0.25)--(3.75,-0.05);% - \draw[thick](-0.1,-0.05)--(3.75,0.3);}} - \end{picture}% - Welche Funktion aufgerufen wird,\\ - hängt vom Typ des Objekts ab: \newterm{virtuelle Methode} - \item - Realisierung über endlose \lstinline{if}-Ketten% - \begin{picture}(0,0) - \color{red} - \put(-2.75,-0.05){\tikz{\draw[thick](0,0.25)--(2.5,-0.05);% - \draw[thick](-0.1,-0.05)--(2.5,0.3);}} - \put(1.5,-1.1){\begin{rotate}{7}\large\bf\textarrow\ -% kommt gleich - nächste Woche - \end{rotate}} - \end{picture} - Zeiger, die im Objekt gespeichert sind\\ - (Genaugenommen: Tabelle von Zeigern) - \end{onlyenv} - \end{itemize} - -\end{frame} - -\begin{frame} - - \showsection - \showsubsection - - \begin{itemize} - \item - Problem: Elemente unterschiedlichen Typs - \item - Lösung: den Typ des Elements zusätzlich speichern \textarrow\ \newterm{Objekt} - \item - \newterm{Methoden\/} und \newterm{virtuelle Methoden} - \end{itemize} - - \begin{itemize} - \item - Zeiger auf verschiedene Strukturen\\ - mit einem gemeinsamen Anteil von Datenfeldern\\ - \textarrow\ "`verwandte"' \newterm{Objekte}, \newterm{Klassenhierarchie} von Objekten - \item - Struktur, die \emph{nur\/} den gemeinsamen Anteil enthält\\ - \textarrow\ "`Vorfahr"', \newterm{Basisklasse}, \newterm{Vererbung} - \item -% Explizite Typumwandlung eines Zeigers auf die Basisklasse\\ -% in einen Zeiger auf die \newterm{abgeleitete Klasse}\\ -% \textarrow\ Man kann ein Array unterschiedlicher Objekte\\ -% \strut\phantom{\textarrow} in einer Schleife abarbeiten.\\ - Zeiger auf die Basisklasse dürfen auf Objekte\\ - der \newterm{abgeleiteten Klasse} zeigen\\ - \textarrow\ \newterm{Polymorphie} - \end{itemize} - -\end{frame} - -\subsection{Beispiel: Zahlen und Buchstaben} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - } t_base;¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\begin{frame}[fragile] - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - } t_base;¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage}\\[0.7cm] - \begin{onlyenv}<1> - \begin{minipage}{8cm} - \begin{lstlisting}[gobble=10] - ¡t_integer i = { 1, 42 }; - t_string s = { 2, "Hello, world!" }; - - t_base *object[] = { (t_base *) &i, (t_base *) &s };¿ - \end{lstlisting} - \end{minipage}% - \begin{picture}(0,0) - \color{red} - \put(-5.4,-0.8){\mbox{$\underbrace{\rule{1.45cm}{0pt}}_{\shortstack{\strut explizite\\Typumwandlung}}$}} - \end{picture} - \end{onlyenv} -% \begin{onlyenv}<2> -% \begin{minipage}{5cm} -% \begin{lstlisting}[gobble=10] -% ¡typedef union -% { -% t_base base; -% t_integer integer; -% t_string string; -% } t_object;¿ -% \end{lstlisting} -% \end{minipage} -% \end{onlyenv} - \end{center} - -\end{frame} - -\iffalse - -\subsection{Unions} - -\begin{frame}[fragile] - - \showsubsection - - Variable teilen sich denselben Speicherplatz. - - \medskip - - \begin{minipage}[t]{3.7cm} - \begin{lstlisting}[gobble=6] - ¡typedef union - { - int8_t i; - uint8_t u; - } num8_t;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{4.5cm} - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - num8_t test; - test.i = -1; - printf ("%d\n", test.u); - return 0; - }¿ - \end{lstlisting} - \end{minipage} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Variable teilen sich denselben Speicherplatz. - - \medskip - - \begin{minipage}[t]{3.7cm} - \begin{lstlisting}[gobble=6] - ¡typedef union - { - char s[8]; - uint64_t x; - } num_char_t;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{4.5cm} - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - num_char_t test = { "Hello!" }; - printf ("%lx\n", test.x); - return 0; - }¿ - \end{lstlisting} - \end{minipage} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Variable teilen sich denselben Speicherplatz. - - \medskip - - \begin{minipage}[t]{3.7cm} - \begin{lstlisting}[gobble=6] - ¡typedef union - { - t_base base; - t_integer integer; - t_string string; - } t_object;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{3.0cm} - \begin{lstlisting}[gobble=6] - - ¡typedef struct - { - int type; - } t_base;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{3.0cm} - \begin{lstlisting}[gobble=6] - - ¡typedef struct - { - int type; - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{3.0cm} - \begin{lstlisting}[gobble=6] - - ¡typedef struct - { - int type; - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage} - - \bigskip - - \begin{center} - \begin{minipage}{8.5cm} - \begin{lstlisting}[gobble=8] - ¡if (this->base.type == T_INTEGER) - printf ("Integer: %d\n", this->integer.content); - else if (this->base.type == T_STRING) - printf ("String: \"%s\"\n", this->string.content);¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\subsection{Virtuelle Methoden} - -\begin{frame}[fragile] - \showsubsection - - \begin{lstlisting} - void print_object (t_object *this) - { - if (this->base.type == T_INTEGER) - printf ("Integer: %d\n", this->integer.content); - else if (this->base.type == T_STRING) - printf ("String: \"%s\"\n", this->string.content); - } - \end{lstlisting} - - \begin{picture}(0,0) - \color{red} - \put(9,1.7){\shortstack[l]{if-Kette:\\\strut wird unübersichtlich}} - \put(1,-2){\mbox{\textarrow}} - \put(0,-3){\mbox{Zeiger auf Funktionen}} - \end{picture} - - \begin{lstlisting}[xleftmargin=4cm] - void print_integer (t_object *this) - { - printf ("Integer: %d\n", this->integer.content); - } - - void print_string (t_object *this) - { - printf ("String: \"%s\"\n", this->string.content); - } - \end{lstlisting} - -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - Zeiger auf Funktionen - - \medskip - - \begin{lstlisting} - void (* print) (t_object *this); - \end{lstlisting} - \begin{picture}(0,1.2)(0,-0.9) - \color{red} - \put(0.95,0.3){\mbox{$\underbrace{\rule{1cm}{0pt}}$}} - \put(0.2,-0.7){\shortstack{das, worauf print zeigt,\\ist eine Funktion}} - \end{picture} - - \begin{itemize} - \item - Objekt enthält Zeiger auf Funktion - \begin{onlyenv}<1> - \medskip - \begin{lstlisting}[gobble=10] - typedef struct - { - void (* print) (union t_object *this); - int content; - } t_integer; - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<2-> - \vspace*{-3.5cm} % Why doesn't a picture environment work here??? :-( - \begin{lstlisting}[gobble=10,xleftmargin=5.5cm] - typedef struct - { - void (* print) (union t_object *this); - int content; - } t_integer; - \end{lstlisting} - \vspace*{0.85cm} - \bigskip - \smallskip - \end{onlyenv} - \pause - \item - Konstruktor initialisiert diesen Zeiger - \begin{onlyenv}<2> - \medskip - \begin{lstlisting}[gobble=10] - t_object *new_integer (int i) - { - t_object *p = malloc (sizeof (t_integer)); - p->integer.print = print_integer; - p->integer.content = i; - return p; - } - \end{lstlisting} - \vspace*{-2cm} - \end{onlyenv} - \pause - \item - Aufruf: "`automatisch"' die richtige Funktion - \begin{onlyenv}<3> - \medskip - \begin{lstlisting}[gobble=10] - for (int i = 0; object[i]; i++) - object[i]->base.print (object[i]); - \end{lstlisting} - \end{onlyenv} - \pause - \medskip - \item - in größeren Projekten:\\ - Objekt enthält Zeiger auf Tabelle von Funktionen - \end{itemize} -\end{frame} - -\subsection{Beispiel: Graphische Benutzeroberfläche (GUI)} - -\begin{frame}[fragile] - - \showsubsection - - \scriptsize - \begin{lstlisting} - #include <gtk/gtk.h> - - int main (int argc, char **argv) - { - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); - GtkWidget *label = gtk_label_new ("Hello, world!"); - gtk_container_add (GTK_CONTAINER (vbox), label); - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - gtk_widget_show (button); - gtk_widget_show (label); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; - } - \end{lstlisting} - - \vspace*{-6cm}\strut\hfill - \includegraphics[scale=0.85]{hello-gtk.png}\\[2cm] - \begin{flushright} - \normalsize\bf Praktikumsversuch:\\ - Objektorientiertes Zeichenprogramm - \end{flushright} - -\end{frame} - -\subsection{Ausblick: C++} - -\begin{frame}[fragile] - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (* print) (union t_object *this); - } t_base;¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5.5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (* print) (...); - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (* print) (union t_object *this); - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡struct TBase - { - virtual void print (void); - };¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5.5cm} - \begin{lstlisting}[gobble=8] - ¡struct TInteger: public TBase - { - virtual void print (void); - int content; - };¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡struct TString: public TBase - { - virtual void print (void); - char *content; - };¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\fi - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \begin{itemize} - \item[5.1] Differentialgleichungen - \item[5.2] Rekursion - \color{medgreen} - \item[5.3] Aufwandsabschätzungen - \end{itemize} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \begin{itemize} - \color{medgreen} - \item[6.0] Dynamische Speicherverwaltung - \item[6.1] Konzepte und Ziele - \item[6.2] Beispiel: Zahlen und Buchstaben - \color{red} - \item[6.3] Unions - \item[6.4] Virtuelle Methoden - \item[6.5] Beispiel: Graphische Benutzeroberfläche (GUI) - \item[6.6] Ausblick: C++ - \end{itemize} - \item[\textbf{7}] \textbf{Datenstrukturen} - \vspace*{-1cm} - \end{itemize} - -\end{frame} - -\end{document} diff --git a/20221121/hp-musterloesung-20221121.pdf b/20221121/hp-musterloesung-20221121.pdf deleted file mode 100644 index 0212d7bf439848a345bd333663313bb13818b6c2..0000000000000000000000000000000000000000 Binary files a/20221121/hp-musterloesung-20221121.pdf and /dev/null differ diff --git a/20221121/hp-musterloesung-20221121.tex b/20221121/hp-musterloesung-20221121.tex deleted file mode 100644 index cdc410d755bc7e105d8711bdffa53b637cf3aa08..0000000000000000000000000000000000000000 --- a/20221121/hp-musterloesung-20221121.tex +++ /dev/null @@ -1,433 +0,0 @@ -% hp-musterloesung-20221121.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Kondensator, Personen-Datenbank, Fakultät - -\documentclass[a4paper]{article} - -\usepackage{pgscript} -\usepackage{gnuplot-lua-tikz} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 21.\ November 2022} - - \exercise{Kondensator} - - Ein Kondensator der Kapazität $C = 100\,\mu{\rm F}$ - ist auf die Spannung $U_0 = 5\,{\rm V}$ aufgeladen - und wird über einen Widerstand $R = 33\,{\rm k}\Omega$ entladen. - - \begin{enumerate}[(a)] - \item - Schreiben Sie ein C-Programm, das - den zeitlichen Spannungsverlauf in einer Tabelle darstellt. - \points{5} - \item - Schreiben Sie ein C-Programm, das ermittelt, - wie lange es dauert, bis die Spannung unter $0.1\,{\rm V}$ gefallen ist. - \points{4} - \item - Vergleichen Sie die berechneten Werte mit der exakten theoretischen Entladekurve: - \begin{math} - U(t) = U_0 \cdot e^{-\frac{t}{RC}} - \end{math}\\ - \points{3} - \end{enumerate} - - Hinweise: - \begin{itemize} - \item - Für die Simulation zerlegen wir den Entladevorgang in kurze Zeitintervalle $dt$. - Innerhalb jedes Zeitintervalls betrachten wir den Strom $I$ als konstant - und berechnen, wieviel Ladung $Q$ innerhalb des Zeitintervalls - aus dem Kondensator herausfließt. - Aus der neuen Ladung berechnen wir die Spannung am Ende des Zeitintervalls. - \item - Für den Vergleich mit der exakten theoretischen Entladekurve - benötigen Sie die Exponentialfunktion \lstinline{exp()}. - Diese finden Sie in der Mathematik-Bibliothek: - \lstinline{#include <math.h>} im Quelltext, - beim \lstinline[style=cmd]{gcc}-Aufruf \lstinline[style=cmd]{-lm} mit angeben. - \item - $Q = C \cdot U$,\quad $U = R \cdot I$,\quad $I = \frac{dQ}{dt}$ - \end{itemize} - - \solution - - \begin{itemize} - \item - \textbf{Schreiben Sie ein C-Programm, das - den zeitlichen Spannungsverlauf in einer Tabelle darstellt.} - - In dem Programm \gitfile{hp}{2022ws/20221121}{loesung-1a.c} - arbeiten wir, dem ersten Hinweis folgend, - mit einem Zeitintervall von \lstinline{dt = 0.01}. - Mit dieser Schrittweite lassen wir uns eine Tabelle ausgeben, - die jeweils die Zeit und durch die Simulation berechnete Spannung ausgibt. - - Wir simulieren, wie die Ladung $Q = C \cdot U$ des Kondensators - im Laufe der Zeit abfließt. - Dazu berechnen wir in jedem Zeitschritt zunächst den Strom $I = U / R$, - der aus dem Kondensator fließt. - Dieser Strom bewirkt, daß innerhalb des Zeitintervalls $dt$ - die Ladung $dQ = I \cdot dt$ aus dem Kondensator abfließt. - Am Ende des Zeitintervalls berechnen wir die zur neuen Ladung $Q$ - gehörende neue Spannung $U = Q / C$. - - Für eine einfache Ausgabe der Tabelle - verwenden wir die Formatspezifikationen \lstinline{%10.3lf} für drei - bzw.\ \lstinline{%15.8lf} für acht Nachkommastellen Genauigkeit. - Damit schreiben wir jeweils eine \emph{lange Fließkommazahl\/} (\lstinline{%lf}) - rechtsbündig in ein Feld der Breite 10 bzw.\ 15 - und lassen uns 3 bzw.\ 8 Nachkommastellen ausgeben. - - Wir compilieren das Programm mit: - \lstinline[style=cmd]{gcc -Wall -O loesung-1a.c -o loesung-1a} - - \item - \textbf{Schreiben Sie ein C-Programm, das ermittelt, - wie lange es dauert, bis die Spannung unter \boldmath $0.1\,{\rm V}$ gefallen ist.} - - Wir ändern das Programm \gitfile{hp}{2022ws/20221121}{loesung-1a.c} so ab, - daß zum einen die Schleife abbricht, sobald die Spannung - den Wert $0.1\,{\rm V}$ unterschreitet (\gitfile{hp}{2022ws/20221121}{loesung-1b.c}), - und daß zum anderen nicht jedesmal eine Zeile für die Tabelle ausgegeben wird, - sondern erst am Ende die Zeit (und die Spannung). - - Der Ausgabe entnehmen wir, daß die Spannung bei etwa $t = 12.90\,{\rm s}$ - den Wert $0.1\,{\rm V}$ unterschreitet. - - \item - \textbf{Vergleichen Sie die berechneten Werte - mit der exakten theoretischen Entladekurve:\\[0.5\smallskipamount] - \boldmath - \begin{math} - U(t) = U_0 \cdot e^{-\frac{t}{RC}} - \end{math}} - - Wir ändern das Programm \gitfile{hp}{2022ws/20221121}{loesung-1a.c} so ab, - daß es zusätzlich zur Zeit und zur simulierten Spannung - die exakte Spannung $U_0 \cdot e^{-\frac{t}{RC}}$ - gemäß der theoretischen Entladekurve ausgibt (\gitfile{hp}{2022ws/20221121}{loesung-1c.c}), - - Da dieses Programm die Exponentialfunktion verwendet, müssen wir nun - beim Compilieren zusätzlich \lstinline[style=cmd]{-lm}\hspace{1pt} - für das Einbinden der Mathematik-Bibliothek angeben. - - Der erweiterten Tabelle können wir entnehmen, - daß die durch die Simulation berechnete Spannung - mit der Spannung $U_0 \cdot e^{-\frac{t}{RC}}$ - gemäß der theoretischen Entladekurve - bis auf wenige Prozent übereinstimmt. - Dies ist für viele praktische Anwendungen ausreichend, - wenn auch nicht für Präzisionsmessungen. - - Wenn Sie die Ausgabe des Programms, z.\,B.\ mit - \lstinline[style=cmd]{./loesung-1c > loesung-1c.dat}, - in einer Datei \gitfile{hp}{2022ws/20221121}{loesung-1c.dat} speichern, - können Sie sich die beiden Kurven graphisch darstellen lassen, - z.\,B.\ mit \file{gnuplot} und dem folgenden Befehl: - \begin{lstlisting}[style=cmd,gobble=8] - plot "loesung-1c.dat" using 1:2 with lines title "Simulation", - "loesung-1c.dat" using 1:3 with lines title "Theorie" - \end{lstlisting} - \vspace*{-\bigskipamount} - \begin{center} - \input{loesung-1c.tikz} - \end{center} - Der Unterschied zwischen der simulierten und der theoretischen Entladungskurve - ist mit bloßem Auge nicht sichtbar. - \end{itemize} - - \exercise{Personen-Datenbank} - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221121}{aufgabe-2.c}): - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - typedef struct - { - char first_name[10]; - char family_name[20]; - char day, month; - int year; - } person; - - int main (void) - { - person sls; - sls.day = 26; - sls.month = 7; - sls.year = 1951; - strcpy (sls.first_name, "Sabine"); - strcpy (sls.family_name, "Leutheusser-Schnarrenberger"); - printf ("%s %s wurde am %d.%d.%d geboren.\n", - sls.first_name, sls.family_name, sls.day, sls.month, sls.year); - return 0; - } - \end{lstlisting} - - Die Standard-Funktion \lstinline{strcpy()} bewirkt ein Kopieren eines Strings - von rechts nach links, hier also z.\,B.\ die Zuweisung der String-Konstanten - \lstinline{"Sabine"} an die String-Variable \lstinline{sls.first_name[]}. - - Das Programm wird für einen 32-Bit-Rechner compiliert und ausgeführt.\\ - (Die \lstinline[style=cmd]{gcc}-Option \lstinline[style=cmd]{-m32} sorgt dafür, - daß \lstinline[style=cmd]{gcc} Code für einen 32-Bit-Prozessor erzeugt.) - - \begin{lstlisting}[style=terminal] - $ ¡gcc -Wall -O -m32 aufgabe-2.c -o aufgabe-2¿ - $ ¡./aufgabe-2¿ - Sabine Leutheusser-Schnarrenberger wurde am 110.98.1701278309 geboren. - Speicherzugriffsfehler - \end{lstlisting} - - \begin{enumerate}[\quad(a)] - \item - Erklären Sie die Ausgabe des Programms einschließlich der Zahlenwerte. - \points{4} - \item - Welche Endianness hat der verwendete Rechner? - Begründen Sie Ihre Antwort. - \points{1} - \item - Wie sähe die Ausgabe auf einem Rechner mit entgegengesetzter Endianness aus? - \points{2} - \item - Erklären Sie den Speicherzugriffsfehler. - (Es kann sein, daß sich der Fehler auf Ihrem Rechner nicht bemerkbar macht. - Er ist aber trotzdem vorhanden.) - \points{2} - \end{enumerate} - - \goodbreak - - \solution - - \begin{enumerate}[\quad(a)] - \item - \textbf{Erklären Sie die Ausgabe des Programms einschließlich der Zahlenwerte.} - - Der String \lstinline{"Leutheusser-Schnarrenberger"} - hat 27 Zeichen und daher mehr als die in der Variablen - \lstinline{sls.family_name} vorgesehenen 20 Zeichen. - Das \lstinline{"nberger"} paßt nicht mehr in die String-Variable. - - Die Zuweisung \lstinline{strcpy (sls.family_name, "Leutheusser-Schnarrenberger")} - überschreibt daher 8 Speicherzellen außerhalb der String-Variablen - \lstinline{sls.family_name} mit dem String \lstinline{"nberger"} - (7 Buchstaben zzgl.\ String-Ende-Symbol) -- und damit insbesondere die Variablen - \lstinline{sls.day}, \lstinline{sls.month} und \lstinline{sls.year}. - - Die überschriebenen Speicherzellen sehen demnach folgendermaßen aus: - \begin{center} - \begin{picture}(8,1.5)(0,-0.5) - \put(0,0){\line(1,0){8}} - \put(0,1){\line(1,0){8}} - \multiput(0,0)(1,0){9}{\line(0,1){1}} - \put(0.4,0.38){\lstinline{n}} - \put(1.4,0.38){\lstinline{b}} - \put(2.4,0.38){\lstinline{e}} - \put(3.4,0.38){\lstinline{r}} - \put(4.4,0.38){\lstinline{g}} - \put(5.4,0.38){\lstinline{e}} - \put(6.4,0.38){\lstinline{r}} - \put(7.5,0.5){\makebox(0,0){\lstinline{0x00}}} - \put(0.5,-0.1){\makebox(0,0)[t]{$\underbrace{\rule{0.95cm}{0pt}}_{\mbox{\lstinline{day}}}$}} - \put(1.5,-0.1){\makebox(0,0)[t]{$\underbrace{\rule{0.95cm}{0pt}}_{\mbox{\lstinline{month}}}$}} - \put(4.0,-0.1){\makebox(0,0)[t]{$\underbrace{\rule{3.95cm}{0pt}}_{\mbox{\lstinline{year}}}$}} - \put(7.0,-0.1){\makebox(0,0)[t]{$\underbrace{\rule{1.95cm}{0pt}}_{\mbox{?}}$}} - \end{picture} - \end{center} - ("`?"' steht für zwei Speicherzellen, von denen wir nicht wissen, - wofür sie genutzt werden.) - - Wenn wir die ASCII-Zeichen in Hexadezimalzahlen umrechnen, entspricht dies: - \begin{center} - \begin{picture}(7,1.5)(0,-0.5) - \put(0,0){\line(1,0){8}} - \put(0,1){\line(1,0){8}} - \multiput(0,0)(1,0){9}{\line(0,1){1}} - \put(0.5,0.5){\makebox(0,0){\lstinline{0x6e}}} - \put(1.5,0.5){\makebox(0,0){\lstinline{0x62}}} - \put(2.5,0.5){\makebox(0,0){\lstinline{0x65}}} - \put(3.5,0.5){\makebox(0,0){\lstinline{0x72}}} - \put(4.5,0.5){\makebox(0,0){\lstinline{0x67}}} - \put(5.5,0.5){\makebox(0,0){\lstinline{0x65}}} - \put(6.5,0.5){\makebox(0,0){\lstinline{0x72}}} - \put(7.5,0.5){\makebox(0,0){\lstinline{0x00}}} - \put(0.5,-0.1){\makebox(0,0)[t]{$\underbrace{\rule{0.95cm}{0pt}}_{\mbox{\lstinline{day}}}$}} - \put(1.5,-0.1){\makebox(0,0)[t]{$\underbrace{\rule{0.95cm}{0pt}}_{\mbox{\lstinline{month}}}$}} - \put(4.0,-0.1){\makebox(0,0)[t]{$\underbrace{\rule{3.95cm}{0pt}}_{\mbox{\lstinline{year}}}$}} - \put(7.0,-0.1){\makebox(0,0)[t]{$\underbrace{\rule{1.95cm}{0pt}}_{\mbox{?}}$}} - \end{picture} - \end{center} - Dies entspricht bereits genau den Werten \lstinline{110} und \lstinline{98} - für die Variablen \lstinline{sls.day} bzw.\ \lstinline{sls.month}. - - Für die Variable \lstinline{sls.year} müssen wir ihre vier Speicherzellen - unter der Berücksichtigung der Endianness des Rechners zusammenziehen. - Für Big-Endian ergibt dies \lstinline{0x65726765 == 1701996389}. - Für Little-Endian ergibt sich der Wert \lstinline{0x65677265 == 1701278309}, - der auch in der Ausgabe des Programms auftaucht. - - \item - \textbf{Welche Endianness hat der verwendete Rechner? - Begründen Sie Ihre Antwort.} - - Wie in (a) begründet, ergibt sich die Ausgabe von - \lstinline[style=terminal]{1701278309} für das Jahr - aus dem Speicherformat Little-Endian. - - \item - \textbf{Wie sähe die Ausgabe auf einem Rechner mit entgegengesetzter Endianness aus?} - - Wie in (a) begründet, ergäbe sich aus dem Speicherformat Big-Endian - die Ausgabe von \lstinline[style=terminal]{1701996389} für das Jahr. - - \item - \textbf{Erklären Sie den Speicherzugriffsfehler. - (Es kann sein, daß sich der Fehler auf Ihrem Rechner nicht bemerkbar macht. - Er ist aber trotzdem vorhanden.)} - - Die zwei in (a) mit "`?"' bezeichneten Speicherzellen - wurden ebenfalls überschrieben. - Dies ist in der Ausgabe zunächst nicht sichtbar, - bewirkt aber später den Speicherzugriffsfehler. - - (Tatsächlich handelt es sich bei den überschriebenen Speicherzellen - um einen Teil der Rücksprungadresse, die \lstinline{main()} verwendet, - um mit \lstinline{return 0} an das Betriebssystem zurückzugeben.) - - \end{enumerate} - - \textbf{Hinweis 1:} - Um auf einen solchen Lösungsweg zu kommen, wird empfohlen, - "`geheimnisvolle"' Zahlen nach hexadezimal umzurechnen - und in Speicherzellen (Zweiergruppen von Hex-Ziffern) zu zerlegen. - Oft erkennt man dann direkt ASCII-Zeichen: - Großbuchstaben beginnen mit der Hex-Ziffer \lstinline{4} oder \lstinline{5}, - Kleinbuchstaben mit \lstinline{6} oder \lstinline{7}. - - \textbf{Hinweis 2:} - Um derartige Programmierfehler in der Praxis von vorneherein zu vermeiden, - wird empfohlen, anstelle von \lstinline{strcpy()} - grundsätzlich die Funktion \lstinline{strncpy()} zu verwenden. - Diese erwartet einen zusätzlichen Parameter, - der die maximal zulässige Länge des Strings enthält. - Ohne einen derartigen expliziten Parameter kann die Funktion nicht wissen, - wie lang die Variable ist, in der der String gespeichert werden soll. - - \exercise{Fakultät} - - Die Fakultät $n!$ einer ganzen Zahl $n \ge 0$ ist definiert als: - \begin{eqnarray*} - 1 & \mbox{für} & n = 0, \\ - n \cdot (n-1)! & \mbox{für} & n > 0. - \end{eqnarray*} - - Mit anderen Worten: $n! = 1\cdot2\cdot3\cdot\dots\cdot n$. - - Die folgende Funktion \lstinline{fak()} berechnet die Fakultät \emph{rekursiv} - (Datei: \gitfile{hp}{2022ws/20221121}{aufgabe-3.c}): - - \begin{lstlisting} - int fak (int n) - { - if (n <= 0) - return 1; - else - return n * fak (n - 1); - } - \end{lstlisting} - - \begin{enumerate}[\quad(a)] - \item - Schreiben Sie eine Funktion, die die Fakultät \emph{iterativ} berechnet,\\ - d.\,h.\ mit Hilfe einer Schleife anstelle von Rekursion. - \points{3} - \item - Wie viele Multiplikationen (Landau-Symbol) - erfordern beide Versionen der Fakultätsfunktion\\ - in Abhängigkeit von \lstinline$n$? - Begründen Sie Ihre Antwort. - \points{2} - \item - Wieviel Speicherplatz (Landau-Symbol) - erfordern beide Versionen der Fakultätsfunktion\\ - in Abhängigkeit von \lstinline$n$? - Begründen Sie Ihre Antwort. - \points{3} - \end{enumerate} - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Schreiben Sie eine Funktion, die die Fakultät \emph{iterativ} berechnet,\\ - d.\,h.\ mit Hilfe einer Schleife anstelle von Rekursion.} - - Datei: \gitfile{hp}{2022ws/20221121}{loesung-3.c} - \begin{lstlisting}[gobble=8] - int fak (int n) - { - int f = 1; - for (int i = 2; i <= n; i++) - f *= i; - return f; - } - \end{lstlisting} - - \item[(b)] - \textbf{Wie viele Multiplikationen (Landau-Symbol) - erfordern beide Versionen der Fakultätsfunktion\\ - in Abhängigkeit von \lstinline$n$? - Begründen Sie Ihre Antwort.} - - In beiden Fällen werden $n$ Zahlen miteinander multipliziert -- - oder $n - 1$, wenn man Multiplikationen mit 1 ausspart. - In jedem Fall hängt die Anzahl der Multiplikationen - linear von $n$ ab; es sind $\mathcal{O}(n)$ Multiplikationen. - Insbesondere arbeiten also beide Versionen gleich schnell. - - \item[(c)] - \textbf{Wieviel Speicherplatz (Landau-Symbol) - erfordern beide Versionen der Fakultätsfunktion\\ - in Abhängigkeit von \lstinline$n$? - Begründen Sie Ihre Antwort.} - - Die iterative Version der Funktion benötigt 2 Variable vom Typ \lstinline{int}, - nämlich \lstinline{n} und \lstinline{f}. - Dies ist eine konstante Zahl; - der Speicherplatzverbrauch ist daher $\mathcal{O}(1)$. - - Die rekursive Version der Funktion erzeugt - jedesmal, wenn sie sich selbst aufruft, - eine zusätzliche Variable \lstinline{n}. - Es sind $n + 1$ Aufrufe; die Anzahl der Variablen \lstinline{n} - hängt linear von $n$ ab; der Speicherplatzverbrauch ist also $\mathcal{O}(n)$. - \end{itemize} - -\end{document} diff --git a/20221121/hp-uebung-20221121.pdf b/20221121/hp-uebung-20221121.pdf deleted file mode 100644 index ee7b3fedfbebeb8bb67b1b9bab08b5d60ad8563b..0000000000000000000000000000000000000000 Binary files a/20221121/hp-uebung-20221121.pdf and /dev/null differ diff --git a/20221121/hp-uebung-20221121.tex b/20221121/hp-uebung-20221121.tex deleted file mode 100644 index 0c3a7d5c188ef529c5652858f67158bb8f95ae91..0000000000000000000000000000000000000000 --- a/20221121/hp-uebung-20221121.tex +++ /dev/null @@ -1,194 +0,0 @@ -% hp-uebung-20221121.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Kondensator, Personen-Datenbank, Fakultät - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \thispagestyle{empty} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 21.\ November 2022} - - Diese Übung enthält Punkteangaben wie in einer Klausur. - Um zu "`bestehen"', müssen Sie innerhalb von 85 Minuten - unter Verwendung ausschließlich zugelassener Hilfsmittel - 15 Punkte (von insgesamt \totalpoints) erreichen. - - \exercise{Kondensator} - - Ein Kondensator der Kapazität $C = 100\,\mu{\rm F}$ - ist auf die Spannung $U_0 = 5\,{\rm V}$ aufgeladen - und wird über einen Widerstand $R = 33\,{\rm k}\Omega$ entladen. - - \begin{enumerate}[(a)] - \item - Schreiben Sie ein C-Programm, das - den zeitlichen Spannungsverlauf in einer Tabelle darstellt. - \points{5} - \item - Schreiben Sie ein C-Programm, das ermittelt, - wie lange es dauert, bis die Spannung unter $0.1\,{\rm V}$ gefallen ist. - \points{4} - \item - Vergleichen Sie die berechneten Werte mit der exakten theoretischen Entladekurve: - \begin{math} - U(t) = U_0 \cdot e^{-\frac{t}{RC}} - \end{math}\\ - \points{3} - \end{enumerate} - - Hinweise: - \begin{itemize} - \item - Für die Simulation zerlegen wir den Entladevorgang in kurze Zeitintervalle $dt$. - Innerhalb jedes Zeitintervalls betrachten wir den Strom $I$ als konstant - und berechnen, wieviel Ladung $Q$ innerhalb des Zeitintervalls - aus dem Kondensator herausfließt. - Aus der neuen Ladung berechnen wir die Spannung am Ende des Zeitintervalls. - \item - Für den Vergleich mit der exakten theoretischen Entladekurve - benötigen Sie die Exponentialfunktion \lstinline{exp()}. - Diese finden Sie in der Mathematik-Bibliothek: - \lstinline{#include <math.h>} im Quelltext, - beim \lstinline[style=cmd]{gcc}-Aufruf \lstinline[style=cmd]{-lm} mit angeben. - \item - $Q = C \cdot U$,\quad $U = R \cdot I$,\quad $I = \frac{dQ}{dt}$ - \end{itemize} - - \exercise{Personen-Datenbank} - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221121}{aufgabe-2.c}): - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - typedef struct - { - char first_name[10]; - char family_name[20]; - char day, month; - int year; - } person; - - int main (void) - { - person sls; - sls.day = 26; - sls.month = 7; - sls.year = 1951; - strcpy (sls.first_name, "Sabine"); - strcpy (sls.family_name, "Leutheusser-Schnarrenberger"); - printf ("%s %s wurde am %d.%d.%d geboren.\n", - sls.first_name, sls.family_name, sls.day, sls.month, sls.year); - return 0; - } - \end{lstlisting} - - Die Standard-Funktion \lstinline{strcpy()} bewirkt ein Kopieren eines Strings - von rechts nach links, hier also z.\,B.\ die Zuweisung der String-Konstanten - \lstinline{"Sabine"} an die String-Variable \lstinline{sls.first_name[]}. - - Das Programm wird für einen 32-Bit-Rechner compiliert und ausgeführt.\\ - (Die \lstinline[style=cmd]{gcc}-Option \lstinline[style=cmd]{-m32} sorgt dafür, - daß \lstinline[style=cmd]{gcc} Code für einen 32-Bit-Prozessor erzeugt.) - - \begin{lstlisting}[style=terminal] - $ ¡gcc -Wall -O -m32 aufgabe-2.c -o aufgabe-2¿ - $ ¡./aufgabe-2¿ - Sabine Leutheusser-Schnarrenberger wurde am 110.98.1701278309 geboren. - Speicherzugriffsfehler - \end{lstlisting} - - \begin{enumerate}[\quad(a)] - \item - Erklären Sie die Ausgabe des Programms einschließlich der Zahlenwerte. - \points{4} - \item - Welche Endianness hat der verwendete Rechner? - Begründen Sie Ihre Antwort. - \points{1} - \item - Wie sähe die Ausgabe auf einem Rechner mit entgegengesetzter Endianness aus? - \points{2} - \item - Erklären Sie den Speicherzugriffsfehler. - (Es kann sein, daß sich der Fehler auf Ihrem Rechner nicht bemerkbar macht. - Er ist aber trotzdem vorhanden.) - \points{2} - \end{enumerate} - - \exercise{Fakultät} - - Die Fakultät $n!$ einer ganzen Zahl $n \ge 0$ ist definiert als: - \begin{eqnarray*} - 1 & \mbox{für} & n = 0, \\ - n \cdot (n-1)! & \mbox{für} & n > 0. - \end{eqnarray*} - - Mit anderen Worten: $n! = 1\cdot2\cdot3\cdot\dots\cdot n$. - - Die folgende Funktion \lstinline{fak()} berechnet die Fakultät \emph{rekursiv} - (Datei: \gitfile{hp}{2022ws/20221121}{aufgabe-3.c}): - - \begin{lstlisting} - int fak (int n) - { - if (n <= 0) - return 1; - else - return n * fak (n - 1); - } - \end{lstlisting} - - \begin{enumerate}[\quad(a)] - \item - Schreiben Sie eine Funktion, die die Fakultät \emph{iterativ} berechnet,\\ - d.\,h.\ mit Hilfe einer Schleife anstelle von Rekursion. - \points{3} - \item - Wie viele Multiplikationen (Landau-Symbol) - erfordern beide Versionen der Fakultätsfunktion\\ - in Abhängigkeit von \lstinline$n$? - Begründen Sie Ihre Antwort. - \points{2} - \item - Wieviel Speicherplatz (Landau-Symbol) - erfordern beide Versionen der Fakultätsfunktion\\ - in Abhängigkeit von \lstinline$n$? - Begründen Sie Ihre Antwort. - \points{3} - \end{enumerate} - - \begin{flushright} - \textit{Viel Erfolg!} - \end{flushright} - - \makeatletter - \immediate\write\@mainaux{\string\gdef\string\totalpoints{\arabic{points}}} - \makeatother - -\end{document} diff --git a/20221121/landau-symbols-2.pdf b/20221121/landau-symbols-2.pdf deleted file mode 120000 index 6b458b6efd8e274824a6dfcaabc4b9c27d196dc4..0000000000000000000000000000000000000000 --- a/20221121/landau-symbols-2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/landau-symbols-2.pdf \ No newline at end of file diff --git a/20221121/landau-symbols-3.pdf b/20221121/landau-symbols-3.pdf deleted file mode 120000 index 46efa409b35ff5df763c744a423599cba515d886..0000000000000000000000000000000000000000 --- a/20221121/landau-symbols-3.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/landau-symbols-3.pdf \ No newline at end of file diff --git a/20221121/landau-symbols.pdf b/20221121/landau-symbols.pdf deleted file mode 120000 index ca145425bf07439c680632aa0663f84be601a565..0000000000000000000000000000000000000000 --- a/20221121/landau-symbols.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/landau-symbols.pdf \ No newline at end of file diff --git a/20221121/loesung-1a.c b/20221121/loesung-1a.c deleted file mode 100644 index f355706a6ff6f95bd72897123a985fb2b7ead7c3..0000000000000000000000000000000000000000 --- a/20221121/loesung-1a.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <stdio.h> -#include <math.h> - -int main (void) -{ - double C = 0.0001; - double U0 = 5.0; - double U = U0; - double R = 33000.0; - double t = 0.0; - double dt = 0.01; - double Q = C * U; - while (U > 0.09) - { - printf ("%10.3lf%15.8lf\n", t, U); - double I = U / R; - Q -= I * dt; - U = Q / C; - t += dt; - } - return 0; -} diff --git a/20221121/loesung-1b.c b/20221121/loesung-1b.c deleted file mode 100644 index f5fc22022ef10a1b986bbd11fba8298a7547792d..0000000000000000000000000000000000000000 --- a/20221121/loesung-1b.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <stdio.h> -#include <math.h> - -int main (void) -{ - double C = 0.0001; - double U0 = 5.0; - double U = U0; - double R = 33000.0; - double t = 0.0; - double dt = 0.01; - double Q = C * U; - while (U >= 0.1) - { - double I = U / R; - Q -= I * dt; - U = Q / C; - t += dt; - } - printf ("%10.3lf%15.8lf\n", t, U); - return 0; -} diff --git a/20221121/loesung-1c.c b/20221121/loesung-1c.c deleted file mode 100644 index 71802e036dd56534470028b61f646d297d1d8840..0000000000000000000000000000000000000000 --- a/20221121/loesung-1c.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <stdio.h> -#include <math.h> - -int main (void) -{ - double C = 0.0001; - double U0 = 5.0; - double U = U0; - double R = 33000.0; - double t = 0.0; - double dt = 0.01; - double Q = C * U; - while (U > 0.09) - { - printf ("%10.3lf%15.8lf%15.8lf\n", t, U, U0 * exp (-t / (R * C))); - double I = U / R; - Q -= I * dt; - U = Q / C; - t += dt; - } - return 0; -} diff --git a/20221121/loesung-1c.dat b/20221121/loesung-1c.dat deleted file mode 100644 index 4df706295bde25a74e025c5335f43617d93129a8..0000000000000000000000000000000000000000 --- a/20221121/loesung-1c.dat +++ /dev/null @@ -1,1324 +0,0 @@ - 0.000 5.00000000 5.00000000 - 0.010 4.98484848 4.98487142 - 0.020 4.96974288 4.96978861 - 0.030 4.95468306 4.95475144 - 0.040 4.93966887 4.93975977 - 0.050 4.92470017 4.92481346 - 0.060 4.90977684 4.90991237 - 0.070 4.89489873 4.89505637 - 0.080 4.88006570 4.88024532 - 0.090 4.86527762 4.86547908 - 0.100 4.85053436 4.85075752 - 0.110 4.83583577 4.83608050 - 0.120 4.82118172 4.82144789 - 0.130 4.80657208 4.80685956 - 0.140 4.79200671 4.79231537 - 0.150 4.77748548 4.77781518 - 0.160 4.76300825 4.76335887 - 0.170 4.74857489 4.74894630 - 0.180 4.73418527 4.73457733 - 0.190 4.71983925 4.72025184 - 0.200 4.70553671 4.70596970 - 0.210 4.69127751 4.69173077 - 0.220 4.67706151 4.67753493 - 0.230 4.66288860 4.66338203 - 0.240 4.64875864 4.64927196 - 0.250 4.63467149 4.63520458 - 0.260 4.62062703 4.62117977 - 0.270 4.60662513 4.60719739 - 0.280 4.59266566 4.59325732 - 0.290 4.57874849 4.57935942 - 0.300 4.56487349 4.56550358 - 0.310 4.55104054 4.55168966 - 0.320 4.53724951 4.53791754 - 0.330 4.52350027 4.52418709 - 0.340 4.50979269 4.51049818 - 0.350 4.49612666 4.49685070 - 0.360 4.48250203 4.48324450 - 0.370 4.46891869 4.46967948 - 0.380 4.45537651 4.45615549 - 0.390 4.44187537 4.44267243 - 0.400 4.42841514 4.42923016 - 0.410 4.41499570 4.41582857 - 0.420 4.40161693 4.40246753 - 0.430 4.38827870 4.38914691 - 0.440 4.37498088 4.37586660 - 0.450 4.36172336 4.36262646 - 0.460 4.34850602 4.34942639 - 0.470 4.33532873 4.33626626 - 0.480 4.32219137 4.32314595 - 0.490 4.30909382 4.31006534 - 0.500 4.29603596 4.29702430 - 0.510 4.28301767 4.28402273 - 0.520 4.27003883 4.27106049 - 0.530 4.25709932 4.25813747 - 0.540 4.24419901 4.24525356 - 0.550 4.23133781 4.23240862 - 0.560 4.21851557 4.21960256 - 0.570 4.20573219 4.20683524 - 0.580 4.19298755 4.19410655 - 0.590 4.18028152 4.18141637 - 0.600 4.16761400 4.16876459 - 0.610 4.15498487 4.15615109 - 0.620 4.14239401 4.14357576 - 0.630 4.12984130 4.13103847 - 0.640 4.11732663 4.11853912 - 0.650 4.10484988 4.10607759 - 0.660 4.09241094 4.09365377 - 0.670 4.08000970 4.08126753 - 0.680 4.06764603 4.06891877 - 0.690 4.05531983 4.05660738 - 0.700 4.04303098 4.04433324 - 0.710 4.03077937 4.03209623 - 0.720 4.01856489 4.01989625 - 0.730 4.00638742 4.00773319 - 0.740 3.99424685 3.99560692 - 0.750 3.98214307 3.98351735 - 0.760 3.97007597 3.97146436 - 0.770 3.95804544 3.95944783 - 0.780 3.94605136 3.94746767 - 0.790 3.93409363 3.93552375 - 0.800 3.92217214 3.92361597 - 0.810 3.91028677 3.91174422 - 0.820 3.89843741 3.89990839 - 0.830 3.88662397 3.88810838 - 0.840 3.87484632 3.87634406 - 0.850 3.86310436 3.86461535 - 0.860 3.85139798 3.85292212 - 0.870 3.83972708 3.84126427 - 0.880 3.82809154 3.82964169 - 0.890 3.81649127 3.81805428 - 0.900 3.80492614 3.80650193 - 0.910 3.79339606 3.79498454 - 0.920 3.78190092 3.78350199 - 0.930 3.77044062 3.77205419 - 0.940 3.75901504 3.76064102 - 0.950 3.74762408 3.74926239 - 0.960 3.73626765 3.73791819 - 0.970 3.72494562 3.72660831 - 0.980 3.71365791 3.71533265 - 0.990 3.70240440 3.70409110 - 1.000 3.69118499 3.69288357 - 1.010 3.67999958 3.68170996 - 1.020 3.66884807 3.67057015 - 1.030 3.65773035 3.65946404 - 1.040 3.64664632 3.64839154 - 1.050 3.63559587 3.63735255 - 1.060 3.62457892 3.62634695 - 1.070 3.61359534 3.61537465 - 1.080 3.60264506 3.60443555 - 1.090 3.59172795 3.59352955 - 1.100 3.58084393 3.58265655 - 1.110 3.56999288 3.57181645 - 1.120 3.55917472 3.56100915 - 1.130 3.54838934 3.55023454 - 1.140 3.53763665 3.53949254 - 1.150 3.52691654 3.52878304 - 1.160 3.51622891 3.51810594 - 1.170 3.50557367 3.50746115 - 1.180 3.49495072 3.49684857 - 1.190 3.48435996 3.48626810 - 1.200 3.47380130 3.47571964 - 1.210 3.46327463 3.46520310 - 1.220 3.45277985 3.45471838 - 1.230 3.44231689 3.44426538 - 1.240 3.43188562 3.43384401 - 1.250 3.42148597 3.42345417 - 1.260 3.41111783 3.41309577 - 1.270 3.40078111 3.40276871 - 1.280 3.39047571 3.39247290 - 1.290 3.38020154 3.38220824 - 1.300 3.36995851 3.37197464 - 1.310 3.35974651 3.36177200 - 1.320 3.34956546 3.35160023 - 1.330 3.33941526 3.34145924 - 1.340 3.32929582 3.33134893 - 1.350 3.31920705 3.32126921 - 1.360 3.30914885 3.31122000 - 1.370 3.29912112 3.30120118 - 1.380 3.28912378 3.29121269 - 1.390 3.27915674 3.28125441 - 1.400 3.26921990 3.27132626 - 1.410 3.25931318 3.26142816 - 1.420 3.24943647 3.25156000 - 1.430 3.23958969 3.24172171 - 1.440 3.22977276 3.23191317 - 1.450 3.21998557 3.22213432 - 1.460 3.21022803 3.21238506 - 1.470 3.20050007 3.20266529 - 1.480 3.19080158 3.19297494 - 1.490 3.18113249 3.18331390 - 1.500 3.17149269 3.17368209 - 1.510 3.16188211 3.16407943 - 1.520 3.15230065 3.15450583 - 1.530 3.14274822 3.14496119 - 1.540 3.13322474 3.13544543 - 1.550 3.12373012 3.12595846 - 1.560 3.11426427 3.11650019 - 1.570 3.10482711 3.10707055 - 1.580 3.09541854 3.09766944 - 1.590 3.08603849 3.08829677 - 1.600 3.07668685 3.07895246 - 1.610 3.06736356 3.06963642 - 1.620 3.05806852 3.06034857 - 1.630 3.04880164 3.05108882 - 1.640 3.03956285 3.04185710 - 1.650 3.03035206 3.03265330 - 1.660 3.02116917 3.02347735 - 1.670 3.01201411 3.01432917 - 1.680 3.00288680 3.00520866 - 1.690 2.99378714 2.99611575 - 1.700 2.98471506 2.98705036 - 1.710 2.97567047 2.97801239 - 1.720 2.96665328 2.96900177 - 1.730 2.95766343 2.96001841 - 1.740 2.94870081 2.95106223 - 1.750 2.93976535 2.94213316 - 1.760 2.93085697 2.93323110 - 1.770 2.92197559 2.92435597 - 1.780 2.91312112 2.91550770 - 1.790 2.90429348 2.90668620 - 1.800 2.89549259 2.89789139 - 1.810 2.88671837 2.88912320 - 1.820 2.87797074 2.88038153 - 1.830 2.86924961 2.87166631 - 1.840 2.86055492 2.86297746 - 1.850 2.85188657 2.85431491 - 1.860 2.84324449 2.84567856 - 1.870 2.83462859 2.83706834 - 1.880 2.82603881 2.82848418 - 1.890 2.81747506 2.81992599 - 1.900 2.80893725 2.81139369 - 1.910 2.80042532 2.80288721 - 1.920 2.79193919 2.79440647 - 1.930 2.78347876 2.78595139 - 1.940 2.77504398 2.77752189 - 1.950 2.76663476 2.76911790 - 1.960 2.75825101 2.76073933 - 1.970 2.74989268 2.75238612 - 1.980 2.74155967 2.74405818 - 1.990 2.73325191 2.73575544 - 2.000 2.72496933 2.72747782 - 2.010 2.71671185 2.71922525 - 2.020 2.70847939 2.71099764 - 2.030 2.70027187 2.70279493 - 2.040 2.69208923 2.69461704 - 2.050 2.68393139 2.68646389 - 2.060 2.67579826 2.67833542 - 2.070 2.66768978 2.67023153 - 2.080 2.65960587 2.66215217 - 2.090 2.65154646 2.65409725 - 2.100 2.64351147 2.64606671 - 2.110 2.63550083 2.63806046 - 2.120 2.62751447 2.63007844 - 2.130 2.61955230 2.62212057 - 2.140 2.61161426 2.61418677 - 2.150 2.60370028 2.60627699 - 2.160 2.59581028 2.59839113 - 2.170 2.58794419 2.59052914 - 2.180 2.58010193 2.58269093 - 2.190 2.57228344 2.57487644 - 2.200 2.56448864 2.56708560 - 2.210 2.55671747 2.55931832 - 2.220 2.54896984 2.55157455 - 2.230 2.54124569 2.54385421 - 2.240 2.53354494 2.53615723 - 2.250 2.52586753 2.52848354 - 2.260 2.51821339 2.52083306 - 2.270 2.51058244 2.51320574 - 2.280 2.50297461 2.50560149 - 2.290 2.49538984 2.49802025 - 2.300 2.48782805 2.49046195 - 2.310 2.48028918 2.48292652 - 2.320 2.47277315 2.47541389 - 2.330 2.46527990 2.46792399 - 2.340 2.45780936 2.46045675 - 2.350 2.45036145 2.45301211 - 2.360 2.44293611 2.44558999 - 2.370 2.43553328 2.43819033 - 2.380 2.42815287 2.43081305 - 2.390 2.42079483 2.42345810 - 2.400 2.41345909 2.41612541 - 2.410 2.40614558 2.40881490 - 2.420 2.39885423 2.40152651 - 2.430 2.39158497 2.39426017 - 2.440 2.38433775 2.38701582 - 2.450 2.37711248 2.37979338 - 2.460 2.36990911 2.37259280 - 2.470 2.36272757 2.36541401 - 2.480 2.35556778 2.35825694 - 2.490 2.34842970 2.35112152 - 2.500 2.34131325 2.34400770 - 2.510 2.33421836 2.33691539 - 2.520 2.32714497 2.32984455 - 2.530 2.32009302 2.32279510 - 2.540 2.31306243 2.31576698 - 2.550 2.30605315 2.30876013 - 2.560 2.29906511 2.30177448 - 2.570 2.29209825 2.29480996 - 2.580 2.28515249 2.28786652 - 2.590 2.27822779 2.28094408 - 2.600 2.27132407 2.27404259 - 2.610 2.26444127 2.26716198 - 2.620 2.25757933 2.26030219 - 2.630 2.25073818 2.25346316 - 2.640 2.24391776 2.24664482 - 2.650 2.23711801 2.23984711 - 2.660 2.23033886 2.23306997 - 2.670 2.22358026 2.22631333 - 2.680 2.21684214 2.21957714 - 2.690 2.21012443 2.21286133 - 2.700 2.20342709 2.20616584 - 2.710 2.19675003 2.19949061 - 2.720 2.19009322 2.19283557 - 2.730 2.18345657 2.18620067 - 2.740 2.17684003 2.17958585 - 2.750 2.17024355 2.17299104 - 2.760 2.16366705 2.16641619 - 2.770 2.15711049 2.15986123 - 2.780 2.15057379 2.15332610 - 2.790 2.14405690 2.14681075 - 2.800 2.13755976 2.14031511 - 2.810 2.13108230 2.13383912 - 2.820 2.12462448 2.12738273 - 2.830 2.11818622 2.12094587 - 2.840 2.11176748 2.11452849 - 2.850 2.10536818 2.10813053 - 2.860 2.09898828 2.10175192 - 2.870 2.09262771 2.09539262 - 2.880 2.08628641 2.08905255 - 2.890 2.07996433 2.08273167 - 2.900 2.07366141 2.07642992 - 2.910 2.06737759 2.07014723 - 2.920 2.06111280 2.06388355 - 2.930 2.05486701 2.05763883 - 2.940 2.04864014 2.05141299 - 2.950 2.04243214 2.04520600 - 2.960 2.03624295 2.03901779 - 2.970 2.03007252 2.03284830 - 2.980 2.02392078 2.02669748 - 2.990 2.01778769 2.02056526 - 3.000 2.01167318 2.01445161 - 3.010 2.00557720 2.00835645 - 3.020 1.99949969 2.00227973 - 3.030 1.99344060 1.99622140 - 3.040 1.98739988 1.99018140 - 3.050 1.98137745 1.98415968 - 3.060 1.97537328 1.97815617 - 3.070 1.96938730 1.97217083 - 3.080 1.96341946 1.96620360 - 3.090 1.95746970 1.96025443 - 3.100 1.95153798 1.95432326 - 3.110 1.94562422 1.94841003 - 3.120 1.93972839 1.94251469 - 3.130 1.93385043 1.93663719 - 3.140 1.92799028 1.93077748 - 3.150 1.92214788 1.92493549 - 3.160 1.91632319 1.91911119 - 3.170 1.91051615 1.91330450 - 3.180 1.90472671 1.90751538 - 3.190 1.89895481 1.90174378 - 3.200 1.89320040 1.89598965 - 3.210 1.88746343 1.89025292 - 3.220 1.88174384 1.88453355 - 3.230 1.87604159 1.87883149 - 3.240 1.87035661 1.87314668 - 3.250 1.86468887 1.86747906 - 3.260 1.85903829 1.86182860 - 3.270 1.85340484 1.85619524 - 3.280 1.84778847 1.85057892 - 3.290 1.84218911 1.84497959 - 3.300 1.83660672 1.83939721 - 3.310 1.83104124 1.83383171 - 3.320 1.82549263 1.82828306 - 3.330 1.81996084 1.82275119 - 3.340 1.81444580 1.81723606 - 3.350 1.80894748 1.81173762 - 3.360 1.80346582 1.80625582 - 3.370 1.79800078 1.80079060 - 3.380 1.79255229 1.79534192 - 3.390 1.78712031 1.78990972 - 3.400 1.78170480 1.78449397 - 3.410 1.77630569 1.77909459 - 3.420 1.77092295 1.77371156 - 3.430 1.76555651 1.76834481 - 3.440 1.76020634 1.76299430 - 3.450 1.75487238 1.75765998 - 3.460 1.74955459 1.75234180 - 3.470 1.74425291 1.74703971 - 3.480 1.73896729 1.74175366 - 3.490 1.73369769 1.73648361 - 3.500 1.72844406 1.73122950 - 3.510 1.72320636 1.72599129 - 3.520 1.71798452 1.72076893 - 3.530 1.71277850 1.71556238 - 3.540 1.70758827 1.71037157 - 3.550 1.70241376 1.70519647 - 3.560 1.69725493 1.70003703 - 3.570 1.69211173 1.69489320 - 3.580 1.68698412 1.68976494 - 3.590 1.68187205 1.68465219 - 3.600 1.67677546 1.67955491 - 3.610 1.67169433 1.67447305 - 3.620 1.66662859 1.66940657 - 3.630 1.66157820 1.66435542 - 3.640 1.65654311 1.65931955 - 3.650 1.65152328 1.65429892 - 3.660 1.64651867 1.64929348 - 3.670 1.64152922 1.64430319 - 3.680 1.63655489 1.63932799 - 3.690 1.63159563 1.63436785 - 3.700 1.62665140 1.62942272 - 3.710 1.62172215 1.62449255 - 3.720 1.61680784 1.61957729 - 3.730 1.61190842 1.61467691 - 3.740 1.60702385 1.60979136 - 3.750 1.60215408 1.60492059 - 3.760 1.59729907 1.60006455 - 3.770 1.59245877 1.59522321 - 3.780 1.58763314 1.59039652 - 3.790 1.58282213 1.58558443 - 3.800 1.57802570 1.58078690 - 3.810 1.57324380 1.57600389 - 3.820 1.56847640 1.57123535 - 3.830 1.56372344 1.56648123 - 3.840 1.55898488 1.56174151 - 3.850 1.55426069 1.55701612 - 3.860 1.54955081 1.55230503 - 3.870 1.54485520 1.54760820 - 3.880 1.54017382 1.54292557 - 3.890 1.53550662 1.53825712 - 3.900 1.53085357 1.53360279 - 3.910 1.52621462 1.52896254 - 3.920 1.52158973 1.52433633 - 3.930 1.51697885 1.51972412 - 3.940 1.51238195 1.51512587 - 3.950 1.50779897 1.51054153 - 3.960 1.50322988 1.50597106 - 3.970 1.49867464 1.50141442 - 3.980 1.49413320 1.49687156 - 3.990 1.48960553 1.49234246 - 4.000 1.48509157 1.48782705 - 4.010 1.48059129 1.48332531 - 4.020 1.47610465 1.47883719 - 4.030 1.47163161 1.47436264 - 4.040 1.46717212 1.46990164 - 4.050 1.46272614 1.46545414 - 4.060 1.45829364 1.46102009 - 4.070 1.45387457 1.45659946 - 4.080 1.44946889 1.45219220 - 4.090 1.44507656 1.44779828 - 4.100 1.44069754 1.44341765 - 4.110 1.43633179 1.43905028 - 4.120 1.43197927 1.43469612 - 4.130 1.42763994 1.43035514 - 4.140 1.42331375 1.42602729 - 4.150 1.41900068 1.42171253 - 4.160 1.41470068 1.41741084 - 4.170 1.41041371 1.41312215 - 4.180 1.40613973 1.40884645 - 4.190 1.40187870 1.40458368 - 4.200 1.39763058 1.40033380 - 4.210 1.39339534 1.39609679 - 4.220 1.38917293 1.39187260 - 4.230 1.38496331 1.38766119 - 4.240 1.38076645 1.38346252 - 4.250 1.37658231 1.37927655 - 4.260 1.37241085 1.37510325 - 4.270 1.36825203 1.37094258 - 4.280 1.36410581 1.36679450 - 4.290 1.35997216 1.36265897 - 4.300 1.35585103 1.35853595 - 4.310 1.35174239 1.35442540 - 4.320 1.34764620 1.35032729 - 4.330 1.34356242 1.34624159 - 4.340 1.33949102 1.34216824 - 4.350 1.33543196 1.33810722 - 4.360 1.33138520 1.33405849 - 4.370 1.32735070 1.33002201 - 4.380 1.32332842 1.32599774 - 4.390 1.31931833 1.32198564 - 4.400 1.31532040 1.31798569 - 4.410 1.31133458 1.31399784 - 4.420 1.30736084 1.31002206 - 4.430 1.30339914 1.30605830 - 4.440 1.29944945 1.30210654 - 4.450 1.29551172 1.29816673 - 4.460 1.29158593 1.29423885 - 4.470 1.28767203 1.29032285 - 4.480 1.28376999 1.28641870 - 4.490 1.27987978 1.28252636 - 4.500 1.27600136 1.27864580 - 4.510 1.27213469 1.27477698 - 4.520 1.26827973 1.27091987 - 4.530 1.26443646 1.26707442 - 4.540 1.26060484 1.26324062 - 4.550 1.25678482 1.25941841 - 4.560 1.25297638 1.25560777 - 4.570 1.24917948 1.25180865 - 4.580 1.24539409 1.24802103 - 4.590 1.24162017 1.24424488 - 4.600 1.23785769 1.24048015 - 4.610 1.23410660 1.23672680 - 4.620 1.23036688 1.23298482 - 4.630 1.22663850 1.22925416 - 4.640 1.22292141 1.22553478 - 4.650 1.21921559 1.22182666 - 4.660 1.21552100 1.21812976 - 4.670 1.21183760 1.21444405 - 4.680 1.20816537 1.21076948 - 4.690 1.20450426 1.20710604 - 4.700 1.20085425 1.20345368 - 4.710 1.19721529 1.19981237 - 4.720 1.19358737 1.19618208 - 4.730 1.18997044 1.19256277 - 4.740 1.18636447 1.18895441 - 4.750 1.18276942 1.18535697 - 4.760 1.17918527 1.18177042 - 4.770 1.17561198 1.17819472 - 4.780 1.17204952 1.17462984 - 4.790 1.16849786 1.17107574 - 4.800 1.16495696 1.16753240 - 4.810 1.16142678 1.16399977 - 4.820 1.15790731 1.16047784 - 4.830 1.15439850 1.15696656 - 4.840 1.15090032 1.15346591 - 4.850 1.14741274 1.14997585 - 4.860 1.14393574 1.14649635 - 4.870 1.14046926 1.14302738 - 4.880 1.13701330 1.13956890 - 4.890 1.13356780 1.13612089 - 4.900 1.13013275 1.13268331 - 4.910 1.12670810 1.12925613 - 4.920 1.12329384 1.12583932 - 4.930 1.11988992 1.12243285 - 4.940 1.11649631 1.11903669 - 4.950 1.11311299 1.11565080 - 4.960 1.10973992 1.11227516 - 4.970 1.10637707 1.10890973 - 4.980 1.10302441 1.10555448 - 4.990 1.09968191 1.10220939 - 5.000 1.09634954 1.09887442 - 5.010 1.09302727 1.09554953 - 5.020 1.08971507 1.09223471 - 5.030 1.08641290 1.08892992 - 5.040 1.08312074 1.08563513 - 5.050 1.07983856 1.08235030 - 5.060 1.07656632 1.07907542 - 5.070 1.07330400 1.07581044 - 5.080 1.07005156 1.07255534 - 5.090 1.06680898 1.06931010 - 5.100 1.06357623 1.06607467 - 5.110 1.06035327 1.06284903 - 5.120 1.05714008 1.05963315 - 5.130 1.05393662 1.05642700 - 5.140 1.05074287 1.05323055 - 5.150 1.04755880 1.05004377 - 5.160 1.04438438 1.04686664 - 5.170 1.04121958 1.04369912 - 5.180 1.03806437 1.04054118 - 5.190 1.03491872 1.03739280 - 5.200 1.03178261 1.03425394 - 5.210 1.02865599 1.03112458 - 5.220 1.02553885 1.02800469 - 5.230 1.02243116 1.02489424 - 5.240 1.01933288 1.02179320 - 5.250 1.01624399 1.01870155 - 5.260 1.01316447 1.01561924 - 5.270 1.01009427 1.01254627 - 5.280 1.00703338 1.00948259 - 5.290 1.00398176 1.00642818 - 5.300 1.00093939 1.00338302 - 5.310 0.99790625 1.00034706 - 5.320 0.99488229 0.99732030 - 5.330 0.99186749 0.99430269 - 5.340 0.98886183 0.99129421 - 5.350 0.98586528 0.98829484 - 5.360 0.98287781 0.98530454 - 5.370 0.97989939 0.98232328 - 5.380 0.97693000 0.97935105 - 5.390 0.97396961 0.97638781 - 5.400 0.97101818 0.97343354 - 5.410 0.96807571 0.97048821 - 5.420 0.96514214 0.96755179 - 5.430 0.96221747 0.96462425 - 5.440 0.95930166 0.96170557 - 5.450 0.95639468 0.95879572 - 5.460 0.95349652 0.95589468 - 5.470 0.95060714 0.95300241 - 5.480 0.94772651 0.95011890 - 5.490 0.94485461 0.94724411 - 5.500 0.94199141 0.94437801 - 5.510 0.93913689 0.94152059 - 5.520 0.93629102 0.93867182 - 5.530 0.93345378 0.93583167 - 5.540 0.93062513 0.93300010 - 5.550 0.92780505 0.93017711 - 5.560 0.92499352 0.92736266 - 5.570 0.92219051 0.92455672 - 5.580 0.91939600 0.92175928 - 5.590 0.91660995 0.91897029 - 5.600 0.91383234 0.91618975 - 5.610 0.91106315 0.91341762 - 5.620 0.90830236 0.91065388 - 5.630 0.90554992 0.90789850 - 5.640 0.90280583 0.90515145 - 5.650 0.90007006 0.90241272 - 5.660 0.89734257 0.89968228 - 5.670 0.89462335 0.89696009 - 5.680 0.89191237 0.89424615 - 5.690 0.88920961 0.89154041 - 5.700 0.88651503 0.88884286 - 5.710 0.88382863 0.88615348 - 5.720 0.88115036 0.88347223 - 5.730 0.87848020 0.88079909 - 5.740 0.87581814 0.87813404 - 5.750 0.87316415 0.87547706 - 5.760 0.87051820 0.87282811 - 5.770 0.86788026 0.87018718 - 5.780 0.86525032 0.86755424 - 5.790 0.86262835 0.86492927 - 5.800 0.86001433 0.86231224 - 5.810 0.85740822 0.85970313 - 5.820 0.85481002 0.85710191 - 5.830 0.85221968 0.85450856 - 5.840 0.84963720 0.85192306 - 5.850 0.84706254 0.84934539 - 5.860 0.84449568 0.84677551 - 5.870 0.84193661 0.84421341 - 5.880 0.83938528 0.84165906 - 5.890 0.83684169 0.83911243 - 5.900 0.83430581 0.83657352 - 5.910 0.83177761 0.83404228 - 5.920 0.82925707 0.83151871 - 5.930 0.82674417 0.82900277 - 5.940 0.82423888 0.82649444 - 5.950 0.82174119 0.82399370 - 5.960 0.81925107 0.82150053 - 5.970 0.81676849 0.81901490 - 5.980 0.81429343 0.81653680 - 5.990 0.81182588 0.81406619 - 6.000 0.80936580 0.81160306 - 6.010 0.80691317 0.80914738 - 6.020 0.80446798 0.80669912 - 6.030 0.80203020 0.80425828 - 6.040 0.79959981 0.80182482 - 6.050 0.79717678 0.79939873 - 6.060 0.79476109 0.79697998 - 6.070 0.79235272 0.79456854 - 6.080 0.78995165 0.79216440 - 6.090 0.78755786 0.78976754 - 6.100 0.78517132 0.78737793 - 6.110 0.78279201 0.78499554 - 6.120 0.78041992 0.78262037 - 6.130 0.77805501 0.78025238 - 6.140 0.77569727 0.77789156 - 6.150 0.77334667 0.77553788 - 6.160 0.77100319 0.77319132 - 6.170 0.76866682 0.77085187 - 6.180 0.76633753 0.76851949 - 6.190 0.76401529 0.76619416 - 6.200 0.76170009 0.76387588 - 6.210 0.75939191 0.76156461 - 6.220 0.75709072 0.75926033 - 6.230 0.75479651 0.75696302 - 6.240 0.75250925 0.75467267 - 6.250 0.75022892 0.75238924 - 6.260 0.74795550 0.75011272 - 6.270 0.74568896 0.74784310 - 6.280 0.74342930 0.74558034 - 6.290 0.74117648 0.74332442 - 6.300 0.73893049 0.74107533 - 6.310 0.73669131 0.73883305 - 6.320 0.73445891 0.73659755 - 6.330 0.73223328 0.73436881 - 6.340 0.73001439 0.73214682 - 6.350 0.72780223 0.72993155 - 6.360 0.72559677 0.72772299 - 6.370 0.72339799 0.72552110 - 6.380 0.72120587 0.72332588 - 6.390 0.71902040 0.72113730 - 6.400 0.71684155 0.71895535 - 6.410 0.71466930 0.71677999 - 6.420 0.71250364 0.71461122 - 6.430 0.71034454 0.71244901 - 6.440 0.70819198 0.71029334 - 6.450 0.70604594 0.70814419 - 6.460 0.70390641 0.70600155 - 6.470 0.70177336 0.70386539 - 6.480 0.69964677 0.70173569 - 6.490 0.69752663 0.69961244 - 6.500 0.69541291 0.69749561 - 6.510 0.69330560 0.69538519 - 6.520 0.69120468 0.69328115 - 6.530 0.68911012 0.69118348 - 6.540 0.68702190 0.68909215 - 6.550 0.68494002 0.68700715 - 6.560 0.68286444 0.68492847 - 6.570 0.68079516 0.68285607 - 6.580 0.67873214 0.68078994 - 6.590 0.67667538 0.67873006 - 6.600 0.67462485 0.67667642 - 6.610 0.67258053 0.67462899 - 6.620 0.67054241 0.67258775 - 6.630 0.66851046 0.67055269 - 6.640 0.66648467 0.66852379 - 6.650 0.66446502 0.66650102 - 6.660 0.66245149 0.66448438 - 6.670 0.66044406 0.66247384 - 6.680 0.65844271 0.66046938 - 6.690 0.65644743 0.65847099 - 6.700 0.65445820 0.65647864 - 6.710 0.65247499 0.65449232 - 6.720 0.65049780 0.65251202 - 6.730 0.64852659 0.65053770 - 6.740 0.64656136 0.64856936 - 6.750 0.64460208 0.64660697 - 6.760 0.64264874 0.64465052 - 6.770 0.64070132 0.64269999 - 6.780 0.63875980 0.64075536 - 6.790 0.63682417 0.63881662 - 6.800 0.63489440 0.63688374 - 6.810 0.63297047 0.63495671 - 6.820 0.63105238 0.63303551 - 6.830 0.62914010 0.63112013 - 6.840 0.62723362 0.62921054 - 6.850 0.62533291 0.62730673 - 6.860 0.62343796 0.62540867 - 6.870 0.62154875 0.62351636 - 6.880 0.61966527 0.62162978 - 6.890 0.61778750 0.61974890 - 6.900 0.61591542 0.61787372 - 6.910 0.61404901 0.61600421 - 6.920 0.61218825 0.61414036 - 6.930 0.61033313 0.61228214 - 6.940 0.60848364 0.61042955 - 6.950 0.60663975 0.60858256 - 6.960 0.60480145 0.60674116 - 6.970 0.60296872 0.60490534 - 6.980 0.60114154 0.60307507 - 6.990 0.59931990 0.60125033 - 7.000 0.59750378 0.59943112 - 7.010 0.59569316 0.59761741 - 7.020 0.59388803 0.59580919 - 7.030 0.59208837 0.59400644 - 7.040 0.59029416 0.59220915 - 7.050 0.58850539 0.59041729 - 7.060 0.58672204 0.58863085 - 7.070 0.58494410 0.58684982 - 7.080 0.58317154 0.58507418 - 7.090 0.58140435 0.58330391 - 7.100 0.57964252 0.58153900 - 7.110 0.57788603 0.57977943 - 7.120 0.57613486 0.57802518 - 7.130 0.57438899 0.57627624 - 7.140 0.57264842 0.57453259 - 7.150 0.57091312 0.57279422 - 7.160 0.56918308 0.57106111 - 7.170 0.56745829 0.56933324 - 7.180 0.56573872 0.56761060 - 7.190 0.56402436 0.56589317 - 7.200 0.56231519 0.56418094 - 7.210 0.56061121 0.56247389 - 7.220 0.55891238 0.56077200 - 7.230 0.55721871 0.55907526 - 7.240 0.55553017 0.55738366 - 7.250 0.55384674 0.55569717 - 7.260 0.55216842 0.55401579 - 7.270 0.55049518 0.55233950 - 7.280 0.54882702 0.55066827 - 7.290 0.54716390 0.54900211 - 7.300 0.54550583 0.54734098 - 7.310 0.54385278 0.54568489 - 7.320 0.54220474 0.54403380 - 7.330 0.54056170 0.54238771 - 7.340 0.53892363 0.54074659 - 7.350 0.53729053 0.53911045 - 7.360 0.53566238 0.53747925 - 7.370 0.53403916 0.53585299 - 7.380 0.53242086 0.53423165 - 7.390 0.53080746 0.53261522 - 7.400 0.52919895 0.53100368 - 7.410 0.52759532 0.52939701 - 7.420 0.52599655 0.52779521 - 7.430 0.52440262 0.52619825 - 7.440 0.52281352 0.52460612 - 7.450 0.52122924 0.52301881 - 7.460 0.51964975 0.52143631 - 7.470 0.51807506 0.51985859 - 7.480 0.51650513 0.51828564 - 7.490 0.51493997 0.51671746 - 7.500 0.51337954 0.51515402 - 7.510 0.51182385 0.51359531 - 7.520 0.51027287 0.51204131 - 7.530 0.50872658 0.51049202 - 7.540 0.50718499 0.50894742 - 7.550 0.50564806 0.50740749 - 7.560 0.50411580 0.50587222 - 7.570 0.50258817 0.50434159 - 7.580 0.50106518 0.50281560 - 7.590 0.49954680 0.50129422 - 7.600 0.49803302 0.49977744 - 7.610 0.49652383 0.49826526 - 7.620 0.49501921 0.49675765 - 7.630 0.49351915 0.49525460 - 7.640 0.49202364 0.49375610 - 7.650 0.49053266 0.49226214 - 7.660 0.48904620 0.49077269 - 7.670 0.48756424 0.48928775 - 7.680 0.48608677 0.48780731 - 7.690 0.48461378 0.48633134 - 7.700 0.48314526 0.48485984 - 7.710 0.48168118 0.48339279 - 7.720 0.48022154 0.48193018 - 7.730 0.47876632 0.48047200 - 7.740 0.47731552 0.47901823 - 7.750 0.47586911 0.47756885 - 7.760 0.47442708 0.47612386 - 7.770 0.47298942 0.47468325 - 7.780 0.47155612 0.47324699 - 7.790 0.47012716 0.47181508 - 7.800 0.46870253 0.47038750 - 7.810 0.46728222 0.46896424 - 7.820 0.46586622 0.46754529 - 7.830 0.46445450 0.46613063 - 7.840 0.46304706 0.46472025 - 7.850 0.46164389 0.46331414 - 7.860 0.46024497 0.46191228 - 7.870 0.45885029 0.46051467 - 7.880 0.45745983 0.45912128 - 7.890 0.45607359 0.45773211 - 7.900 0.45469155 0.45634714 - 7.910 0.45331369 0.45496637 - 7.920 0.45194002 0.45358977 - 7.930 0.45057050 0.45221733 - 7.940 0.44920514 0.45084905 - 7.950 0.44784391 0.44948491 - 7.960 0.44648681 0.44812490 - 7.970 0.44513382 0.44676900 - 7.980 0.44378493 0.44541720 - 7.990 0.44244012 0.44406949 - 8.000 0.44109939 0.44272587 - 8.010 0.43976273 0.44138630 - 8.020 0.43843012 0.44005079 - 8.030 0.43710154 0.43871933 - 8.040 0.43577699 0.43739188 - 8.050 0.43445645 0.43606846 - 8.060 0.43313992 0.43474904 - 8.070 0.43182737 0.43343361 - 8.080 0.43051881 0.43212217 - 8.090 0.42921420 0.43081469 - 8.100 0.42791355 0.42951117 - 8.110 0.42661685 0.42821159 - 8.120 0.42532407 0.42691594 - 8.130 0.42403521 0.42562421 - 8.140 0.42275025 0.42433639 - 8.150 0.42146919 0.42305247 - 8.160 0.42019201 0.42177244 - 8.170 0.41891870 0.42049627 - 8.180 0.41764925 0.41922397 - 8.190 0.41638365 0.41795552 - 8.200 0.41512188 0.41669090 - 8.210 0.41386393 0.41543011 - 8.220 0.41260980 0.41417314 - 8.230 0.41135947 0.41291997 - 8.240 0.41011292 0.41167059 - 8.250 0.40887016 0.41042499 - 8.260 0.40763116 0.40918316 - 8.270 0.40639591 0.40794509 - 8.280 0.40516441 0.40671077 - 8.290 0.40393664 0.40548017 - 8.300 0.40271259 0.40425331 - 8.310 0.40149225 0.40303015 - 8.320 0.40027560 0.40181070 - 8.330 0.39906265 0.40059493 - 8.340 0.39785337 0.39938284 - 8.350 0.39664775 0.39817442 - 8.360 0.39544579 0.39696966 - 8.370 0.39424747 0.39576854 - 8.380 0.39305278 0.39457106 - 8.390 0.39186171 0.39337720 - 8.400 0.39067425 0.39218695 - 8.410 0.38949039 0.39100031 - 8.420 0.38831011 0.38981725 - 8.430 0.38713342 0.38863777 - 8.440 0.38596028 0.38746187 - 8.450 0.38479071 0.38628952 - 8.460 0.38362467 0.38512071 - 8.470 0.38246218 0.38395545 - 8.480 0.38130320 0.38279371 - 8.490 0.38014774 0.38163548 - 8.500 0.37899577 0.38048076 - 8.510 0.37784730 0.37932953 - 8.520 0.37670231 0.37818179 - 8.530 0.37556079 0.37703752 - 8.540 0.37442272 0.37589671 - 8.550 0.37328811 0.37475936 - 8.560 0.37215693 0.37362544 - 8.570 0.37102918 0.37249496 - 8.580 0.36990485 0.37136789 - 8.590 0.36878393 0.37024424 - 8.600 0.36766640 0.36912398 - 8.610 0.36655226 0.36800712 - 8.620 0.36544150 0.36689363 - 8.630 0.36433410 0.36578352 - 8.640 0.36323006 0.36467676 - 8.650 0.36212936 0.36357335 - 8.660 0.36103200 0.36247328 - 8.670 0.35993796 0.36137654 - 8.680 0.35884724 0.36028312 - 8.690 0.35775982 0.35919300 - 8.700 0.35667570 0.35810619 - 8.710 0.35559487 0.35702266 - 8.720 0.35451731 0.35594241 - 8.730 0.35344301 0.35486543 - 8.740 0.35237197 0.35379171 - 8.750 0.35130418 0.35272123 - 8.760 0.35023962 0.35165400 - 8.770 0.34917829 0.35058999 - 8.780 0.34812017 0.34952921 - 8.790 0.34706526 0.34847163 - 8.800 0.34601355 0.34741726 - 8.810 0.34496503 0.34636607 - 8.820 0.34391968 0.34531806 - 8.830 0.34287750 0.34427323 - 8.840 0.34183847 0.34323156 - 8.850 0.34080260 0.34219304 - 8.860 0.33976986 0.34115766 - 8.870 0.33874026 0.34012541 - 8.880 0.33771377 0.33909629 - 8.890 0.33669040 0.33807028 - 8.900 0.33567012 0.33704737 - 8.910 0.33465294 0.33602756 - 8.920 0.33363884 0.33501084 - 8.930 0.33262781 0.33399719 - 8.940 0.33161985 0.33298661 - 8.950 0.33061494 0.33197909 - 8.960 0.32961308 0.33097461 - 8.970 0.32861425 0.32997318 - 8.980 0.32761845 0.32897477 - 8.990 0.32662567 0.32797939 - 9.000 0.32563589 0.32698702 - 9.010 0.32464912 0.32599765 - 9.020 0.32366533 0.32501127 - 9.030 0.32268453 0.32402788 - 9.040 0.32170670 0.32304746 - 9.050 0.32073183 0.32207001 - 9.060 0.31975991 0.32109552 - 9.070 0.31879094 0.32012398 - 9.080 0.31782491 0.31915537 - 9.090 0.31686181 0.31818970 - 9.100 0.31590162 0.31722695 - 9.110 0.31494434 0.31626711 - 9.120 0.31398996 0.31531017 - 9.130 0.31303848 0.31435613 - 9.140 0.31208988 0.31340498 - 9.150 0.31114415 0.31245671 - 9.160 0.31020129 0.31151130 - 9.170 0.30926129 0.31056876 - 9.180 0.30832413 0.30962906 - 9.190 0.30738981 0.30869221 - 9.200 0.30645833 0.30775820 - 9.210 0.30552967 0.30682701 - 9.220 0.30460382 0.30589864 - 9.230 0.30368078 0.30497308 - 9.240 0.30276053 0.30405031 - 9.250 0.30184308 0.30313034 - 9.260 0.30092840 0.30221316 - 9.270 0.30001650 0.30129875 - 9.280 0.29910736 0.30038710 - 9.290 0.29820097 0.29947821 - 9.300 0.29729733 0.29857208 - 9.310 0.29639643 0.29766868 - 9.320 0.29549826 0.29676802 - 9.330 0.29460281 0.29587009 - 9.340 0.29371007 0.29497487 - 9.350 0.29282004 0.29408236 - 9.360 0.29193271 0.29319255 - 9.370 0.29104807 0.29230543 - 9.380 0.29016610 0.29142100 - 9.390 0.28928681 0.29053924 - 9.400 0.28841018 0.28966015 - 9.410 0.28753621 0.28878372 - 9.420 0.28666489 0.28790994 - 9.430 0.28579621 0.28703881 - 9.440 0.28493016 0.28617031 - 9.450 0.28406674 0.28530444 - 9.460 0.28320593 0.28444119 - 9.470 0.28234773 0.28358055 - 9.480 0.28149213 0.28272252 - 9.490 0.28063912 0.28186708 - 9.500 0.27978870 0.28101423 - 9.510 0.27894086 0.28016396 - 9.520 0.27809558 0.27931627 - 9.530 0.27725287 0.27847113 - 9.540 0.27641271 0.27762856 - 9.550 0.27557509 0.27678853 - 9.560 0.27474002 0.27595105 - 9.570 0.27390747 0.27511610 - 9.580 0.27307745 0.27428368 - 9.590 0.27224994 0.27345377 - 9.600 0.27142494 0.27262638 - 9.610 0.27060244 0.27180149 - 9.620 0.26978243 0.27097909 - 9.630 0.26896491 0.27015919 - 9.640 0.26814987 0.26934176 - 9.650 0.26733729 0.26852681 - 9.660 0.26652718 0.26771433 - 9.670 0.26571952 0.26690430 - 9.680 0.26491431 0.26609672 - 9.690 0.26411154 0.26529159 - 9.700 0.26331120 0.26448889 - 9.710 0.26251329 0.26368862 - 9.720 0.26171779 0.26289078 - 9.730 0.26092471 0.26209534 - 9.740 0.26013403 0.26130232 - 9.750 0.25934574 0.26051169 - 9.760 0.25855985 0.25972346 - 9.770 0.25777633 0.25893761 - 9.780 0.25699519 0.25815413 - 9.790 0.25621642 0.25737303 - 9.800 0.25544001 0.25659430 - 9.810 0.25466594 0.25581791 - 9.820 0.25389423 0.25504388 - 9.830 0.25312485 0.25427219 - 9.840 0.25235781 0.25350284 - 9.850 0.25159309 0.25273581 - 9.860 0.25083068 0.25197110 - 9.870 0.25007059 0.25120871 - 9.880 0.24931280 0.25044862 - 9.890 0.24855731 0.24969084 - 9.900 0.24780410 0.24893534 - 9.910 0.24705318 0.24818213 - 9.920 0.24630454 0.24743121 - 9.930 0.24555816 0.24668255 - 9.940 0.24481404 0.24593616 - 9.950 0.24407218 0.24519202 - 9.960 0.24333257 0.24445014 - 9.970 0.24259520 0.24371051 - 9.980 0.24186006 0.24297311 - 9.990 0.24112715 0.24223794 - 10.000 0.24039646 0.24150500 - 10.010 0.23966799 0.24077427 - 10.020 0.23894172 0.24004576 - 10.030 0.23821766 0.23931945 - 10.040 0.23749579 0.23859533 - 10.050 0.23677610 0.23787341 - 10.060 0.23605860 0.23715367 - 10.070 0.23534327 0.23643611 - 10.080 0.23463011 0.23572073 - 10.090 0.23391911 0.23500750 - 10.100 0.23321026 0.23429644 - 10.110 0.23250356 0.23358752 - 10.120 0.23179901 0.23288075 - 10.130 0.23109659 0.23217612 - 10.140 0.23039629 0.23147362 - 10.150 0.22969812 0.23077325 - 10.160 0.22900207 0.23007499 - 10.170 0.22830812 0.22937885 - 10.180 0.22761628 0.22868482 - 10.190 0.22692653 0.22799288 - 10.200 0.22623888 0.22730304 - 10.210 0.22555331 0.22661528 - 10.220 0.22486981 0.22592961 - 10.230 0.22418839 0.22524601 - 10.240 0.22350903 0.22456448 - 10.250 0.22283173 0.22388501 - 10.260 0.22215648 0.22320760 - 10.270 0.22148328 0.22253224 - 10.280 0.22081212 0.22185892 - 10.290 0.22014299 0.22118764 - 10.300 0.21947589 0.22051839 - 10.310 0.21881081 0.21985116 - 10.320 0.21814775 0.21918595 - 10.330 0.21748669 0.21852276 - 10.340 0.21682764 0.21786157 - 10.350 0.21617059 0.21720238 - 10.360 0.21551553 0.21654519 - 10.370 0.21486245 0.21588998 - 10.380 0.21421135 0.21523676 - 10.390 0.21356223 0.21458552 - 10.400 0.21291507 0.21393624 - 10.410 0.21226987 0.21328893 - 10.420 0.21162663 0.21264358 - 10.430 0.21098534 0.21200018 - 10.440 0.21034599 0.21135873 - 10.450 0.20970858 0.21071922 - 10.460 0.20907309 0.21008164 - 10.470 0.20843954 0.20944599 - 10.480 0.20780790 0.20881227 - 10.490 0.20717818 0.20818046 - 10.500 0.20655037 0.20755057 - 10.510 0.20592446 0.20692258 - 10.520 0.20530045 0.20629649 - 10.530 0.20467833 0.20567229 - 10.540 0.20405809 0.20504999 - 10.550 0.20343973 0.20442957 - 10.560 0.20282325 0.20381102 - 10.570 0.20220863 0.20319435 - 10.580 0.20159588 0.20257954 - 10.590 0.20098498 0.20196659 - 10.600 0.20037593 0.20135550 - 10.610 0.19976873 0.20074625 - 10.620 0.19916337 0.20013885 - 10.630 0.19855985 0.19953329 - 10.640 0.19795815 0.19892956 - 10.650 0.19735828 0.19832765 - 10.660 0.19676022 0.19772757 - 10.670 0.19616398 0.19712930 - 10.680 0.19556954 0.19653284 - 10.690 0.19497691 0.19593819 - 10.700 0.19438607 0.19534534 - 10.710 0.19379702 0.19475428 - 10.720 0.19320976 0.19416501 - 10.730 0.19262427 0.19357752 - 10.740 0.19204056 0.19299181 - 10.750 0.19145862 0.19240787 - 10.760 0.19087845 0.19182570 - 10.770 0.19030003 0.19124529 - 10.780 0.18972336 0.19066663 - 10.790 0.18914844 0.19008973 - 10.800 0.18857526 0.18951457 - 10.810 0.18800382 0.18894115 - 10.820 0.18743411 0.18836947 - 10.830 0.18686613 0.18779952 - 10.840 0.18629987 0.18723129 - 10.850 0.18573533 0.18666478 - 10.860 0.18517249 0.18609999 - 10.870 0.18461136 0.18553690 - 10.880 0.18405193 0.18497552 - 10.890 0.18349420 0.18441584 - 10.900 0.18293816 0.18385785 - 10.910 0.18238380 0.18330155 - 10.920 0.18183112 0.18274693 - 10.930 0.18128012 0.18219399 - 10.940 0.18073079 0.18164272 - 10.950 0.18018312 0.18109312 - 10.960 0.17963711 0.18054518 - 10.970 0.17909275 0.17999890 - 10.980 0.17855005 0.17945428 - 10.990 0.17800899 0.17891130 - 11.000 0.17746956 0.17836997 - 11.010 0.17693178 0.17783027 - 11.020 0.17639562 0.17729221 - 11.030 0.17586109 0.17675577 - 11.040 0.17532818 0.17622096 - 11.050 0.17479688 0.17568776 - 11.060 0.17426719 0.17515618 - 11.070 0.17373911 0.17462621 - 11.080 0.17321263 0.17409784 - 11.090 0.17268774 0.17357107 - 11.100 0.17216444 0.17304589 - 11.110 0.17164273 0.17252230 - 11.120 0.17112260 0.17200030 - 11.130 0.17060405 0.17147988 - 11.140 0.17008707 0.17096103 - 11.150 0.16957165 0.17044375 - 11.160 0.16905780 0.16992803 - 11.170 0.16854550 0.16941388 - 11.180 0.16803476 0.16890128 - 11.190 0.16752556 0.16839023 - 11.200 0.16701791 0.16788073 - 11.210 0.16651180 0.16737277 - 11.220 0.16600721 0.16686635 - 11.230 0.16550416 0.16636146 - 11.240 0.16500263 0.16585810 - 11.250 0.16450263 0.16535626 - 11.260 0.16400413 0.16485594 - 11.270 0.16350715 0.16435713 - 11.280 0.16301167 0.16385983 - 11.290 0.16251770 0.16336404 - 11.300 0.16202522 0.16286974 - 11.310 0.16153424 0.16237695 - 11.320 0.16104474 0.16188564 - 11.330 0.16055672 0.16139582 - 11.340 0.16007019 0.16090748 - 11.350 0.15958513 0.16042062 - 11.360 0.15910154 0.15993523 - 11.370 0.15861941 0.15945132 - 11.380 0.15813875 0.15896886 - 11.390 0.15765954 0.15848787 - 11.400 0.15718178 0.15800833 - 11.410 0.15670547 0.15753024 - 11.420 0.15623061 0.15705360 - 11.430 0.15575718 0.15657840 - 11.440 0.15528519 0.15610464 - 11.450 0.15481463 0.15563231 - 11.460 0.15434549 0.15516141 - 11.470 0.15387778 0.15469193 - 11.480 0.15341148 0.15422388 - 11.490 0.15294660 0.15375724 - 11.500 0.15248313 0.15329202 - 11.510 0.15202106 0.15282820 - 11.520 0.15156039 0.15236578 - 11.530 0.15110111 0.15190477 - 11.540 0.15064323 0.15144515 - 11.550 0.15018674 0.15098692 - 11.560 0.14973162 0.15053007 - 11.570 0.14927789 0.15007461 - 11.580 0.14882553 0.14962053 - 11.590 0.14837455 0.14916782 - 11.600 0.14792493 0.14871648 - 11.610 0.14747667 0.14826651 - 11.620 0.14702977 0.14781789 - 11.630 0.14658423 0.14737064 - 11.640 0.14614003 0.14692474 - 11.650 0.14569718 0.14648018 - 11.660 0.14525568 0.14603698 - 11.670 0.14481551 0.14559511 - 11.680 0.14437667 0.14515458 - 11.690 0.14393917 0.14471538 - 11.700 0.14350299 0.14427752 - 11.710 0.14306813 0.14384097 - 11.720 0.14263459 0.14340575 - 11.730 0.14220237 0.14297185 - 11.740 0.14177145 0.14253925 - 11.750 0.14134184 0.14210797 - 11.760 0.14091353 0.14167799 - 11.770 0.14048652 0.14124932 - 11.780 0.14006080 0.14082194 - 11.790 0.13963638 0.14039585 - 11.800 0.13921324 0.13997105 - 11.810 0.13879138 0.13954754 - 11.820 0.13837080 0.13912531 - 11.830 0.13795149 0.13870435 - 11.840 0.13753346 0.13828467 - 11.850 0.13711669 0.13786626 - 11.860 0.13670118 0.13744912 - 11.870 0.13628694 0.13703324 - 11.880 0.13587395 0.13661861 - 11.890 0.13546221 0.13620524 - 11.900 0.13505172 0.13579312 - 11.910 0.13464247 0.13538225 - 11.920 0.13423446 0.13497262 - 11.930 0.13382769 0.13456424 - 11.940 0.13342215 0.13415708 - 11.950 0.13301784 0.13375116 - 11.960 0.13261476 0.13334647 - 11.970 0.13221290 0.13294300 - 11.980 0.13181225 0.13254075 - 11.990 0.13141282 0.13213972 - 12.000 0.13101460 0.13173990 - 12.010 0.13061758 0.13134130 - 12.020 0.13022177 0.13094389 - 12.030 0.12982716 0.13054770 - 12.040 0.12943375 0.13015270 - 12.050 0.12904152 0.12975889 - 12.060 0.12865049 0.12936628 - 12.070 0.12826064 0.12897485 - 12.080 0.12787197 0.12858461 - 12.090 0.12748448 0.12819555 - 12.100 0.12709816 0.12780767 - 12.110 0.12671302 0.12742096 - 12.120 0.12632904 0.12703542 - 12.130 0.12594622 0.12665104 - 12.140 0.12556457 0.12626783 - 12.150 0.12518407 0.12588578 - 12.160 0.12480472 0.12550489 - 12.170 0.12442653 0.12512515 - 12.180 0.12404948 0.12474655 - 12.190 0.12367357 0.12436911 - 12.200 0.12329880 0.12399280 - 12.210 0.12292517 0.12361763 - 12.220 0.12255267 0.12324360 - 12.230 0.12218130 0.12287070 - 12.240 0.12181105 0.12249893 - 12.250 0.12144192 0.12212828 - 12.260 0.12107392 0.12175876 - 12.270 0.12070703 0.12139035 - 12.280 0.12034125 0.12102306 - 12.290 0.11997658 0.12065687 - 12.300 0.11961301 0.12029180 - 12.310 0.11925055 0.11992783 - 12.320 0.11888918 0.11956496 - 12.330 0.11852891 0.11920319 - 12.340 0.11816974 0.11884252 - 12.350 0.11781165 0.11848294 - 12.360 0.11745464 0.11812444 - 12.370 0.11709872 0.11776703 - 12.380 0.11674387 0.11741070 - 12.390 0.11639010 0.11705545 - 12.400 0.11603741 0.11670127 - 12.410 0.11568578 0.11634817 - 12.420 0.11533522 0.11599613 - 12.430 0.11498571 0.11564516 - 12.440 0.11463727 0.11529525 - 12.450 0.11428989 0.11494640 - 12.460 0.11394355 0.11459860 - 12.470 0.11359827 0.11425186 - 12.480 0.11325403 0.11390617 - 12.490 0.11291084 0.11356152 - 12.500 0.11256869 0.11321791 - 12.510 0.11222757 0.11287535 - 12.520 0.11188748 0.11253382 - 12.530 0.11154843 0.11219332 - 12.540 0.11121041 0.11185386 - 12.550 0.11087340 0.11151542 - 12.560 0.11053742 0.11117801 - 12.570 0.11020246 0.11084161 - 12.580 0.10986852 0.11050624 - 12.590 0.10953558 0.11017188 - 12.600 0.10920366 0.10983853 - 12.610 0.10887274 0.10950619 - 12.620 0.10854282 0.10917485 - 12.630 0.10821390 0.10884452 - 12.640 0.10788598 0.10851519 - 12.650 0.10755905 0.10818685 - 12.660 0.10723312 0.10785951 - 12.670 0.10690817 0.10753316 - 12.680 0.10658420 0.10720779 - 12.690 0.10626122 0.10688341 - 12.700 0.10593922 0.10656001 - 12.710 0.10561819 0.10623759 - 12.720 0.10529813 0.10591615 - 12.730 0.10497905 0.10559568 - 12.740 0.10466093 0.10527617 - 12.750 0.10434378 0.10495764 - 12.760 0.10402758 0.10464007 - 12.770 0.10371235 0.10432346 - 12.780 0.10339807 0.10400780 - 12.790 0.10308474 0.10369310 - 12.800 0.10277236 0.10337936 - 12.810 0.10246093 0.10306656 - 12.820 0.10215044 0.10275471 - 12.830 0.10184090 0.10244380 - 12.840 0.10153229 0.10213384 - 12.850 0.10122461 0.10182481 - 12.860 0.10091787 0.10151672 - 12.870 0.10061206 0.10120956 - 12.880 0.10030718 0.10090333 - 12.890 0.10000321 0.10059802 - 12.900 0.09970017 0.10029364 - 12.910 0.09939805 0.09999018 - 12.920 0.09909685 0.09968764 - 12.930 0.09879655 0.09938601 - 12.940 0.09849717 0.09908530 - 12.950 0.09819869 0.09878549 - 12.960 0.09790112 0.09848660 - 12.970 0.09760445 0.09818860 - 12.980 0.09730868 0.09789151 - 12.990 0.09701381 0.09759532 - 13.000 0.09671982 0.09730003 - 13.010 0.09642673 0.09700562 - 13.020 0.09613453 0.09671211 - 13.030 0.09584321 0.09641949 - 13.040 0.09555278 0.09612775 - 13.050 0.09526323 0.09583690 - 13.060 0.09497455 0.09554692 - 13.070 0.09468675 0.09525782 - 13.080 0.09439982 0.09496960 - 13.090 0.09411376 0.09468225 - 13.100 0.09382857 0.09439577 - 13.110 0.09354424 0.09411015 - 13.120 0.09326077 0.09382540 - 13.130 0.09297816 0.09354151 - 13.140 0.09269641 0.09325848 - 13.150 0.09241551 0.09297631 - 13.160 0.09213546 0.09269499 - 13.170 0.09185627 0.09241452 - 13.180 0.09157791 0.09213490 - 13.190 0.09130040 0.09185613 - 13.200 0.09102374 0.09157819 - 13.210 0.09074791 0.09130110 - 13.220 0.09047291 0.09102485 - 13.230 0.09019875 0.09074944 diff --git a/20221121/loesung-1c.tikz b/20221121/loesung-1c.tikz deleted file mode 100644 index e97073c442cd1f84adf842357e3cb254fb05e54c..0000000000000000000000000000000000000000 --- a/20221121/loesung-1c.tikz +++ /dev/null @@ -1,521 +0,0 @@ -\begin{tikzpicture}[gnuplot] -%% generated with GNUPLOT 5.0p5 (Lua 5.1; terminal rev. 99, script rev. 100) -%% Mi 14 Nov 2018 19:24:42 CET -\path (0.000,0.000) rectangle (12.500,8.750); -\gpcolor{color=gp lt color border} -\gpsetlinetype{gp lt border} -\gpsetdashtype{gp dt solid} -\gpsetlinewidth{1.00} -\draw[gp path] (1.012,0.616)--(1.192,0.616); -\draw[gp path] (11.947,0.616)--(11.767,0.616); -\node[gp node right] at (0.828,0.616) {$0$}; -\draw[gp path] (1.012,1.393)--(1.192,1.393); -\draw[gp path] (11.947,1.393)--(11.767,1.393); -\node[gp node right] at (0.828,1.393) {$0.5$}; -\draw[gp path] (1.012,2.169)--(1.192,2.169); -\draw[gp path] (11.947,2.169)--(11.767,2.169); -\node[gp node right] at (0.828,2.169) {$1$}; -\draw[gp path] (1.012,2.946)--(1.192,2.946); -\draw[gp path] (11.947,2.946)--(11.767,2.946); -\node[gp node right] at (0.828,2.946) {$1.5$}; -\draw[gp path] (1.012,3.722)--(1.192,3.722); -\draw[gp path] (11.947,3.722)--(11.767,3.722); -\node[gp node right] at (0.828,3.722) {$2$}; -\draw[gp path] (1.012,4.499)--(1.192,4.499); -\draw[gp path] (11.947,4.499)--(11.767,4.499); -\node[gp node right] at (0.828,4.499) {$2.5$}; -\draw[gp path] (1.012,5.275)--(1.192,5.275); -\draw[gp path] (11.947,5.275)--(11.767,5.275); -\node[gp node right] at (0.828,5.275) {$3$}; -\draw[gp path] (1.012,6.052)--(1.192,6.052); -\draw[gp path] (11.947,6.052)--(11.767,6.052); -\node[gp node right] at (0.828,6.052) {$3.5$}; -\draw[gp path] (1.012,6.828)--(1.192,6.828); -\draw[gp path] (11.947,6.828)--(11.767,6.828); -\node[gp node right] at (0.828,6.828) {$4$}; -\draw[gp path] (1.012,7.605)--(1.192,7.605); -\draw[gp path] (11.947,7.605)--(11.767,7.605); -\node[gp node right] at (0.828,7.605) {$4.5$}; -\draw[gp path] (1.012,8.381)--(1.192,8.381); -\draw[gp path] (11.947,8.381)--(11.767,8.381); -\node[gp node right] at (0.828,8.381) {$5$}; -\draw[gp path] (1.012,0.616)--(1.012,0.796); -\draw[gp path] (1.012,8.381)--(1.012,8.201); -\node[gp node center] at (1.012,0.308) {$0$}; -\draw[gp path] (2.574,0.616)--(2.574,0.796); -\draw[gp path] (2.574,8.381)--(2.574,8.201); -\node[gp node center] at (2.574,0.308) {$2$}; -\draw[gp path] (4.136,0.616)--(4.136,0.796); -\draw[gp path] (4.136,8.381)--(4.136,8.201); -\node[gp node center] at (4.136,0.308) {$4$}; -\draw[gp path] (5.698,0.616)--(5.698,0.796); -\draw[gp path] (5.698,8.381)--(5.698,8.201); -\node[gp node center] at (5.698,0.308) {$6$}; -\draw[gp path] (7.261,0.616)--(7.261,0.796); -\draw[gp path] (7.261,8.381)--(7.261,8.201); -\node[gp node center] at (7.261,0.308) {$8$}; -\draw[gp path] (8.823,0.616)--(8.823,0.796); -\draw[gp path] (8.823,8.381)--(8.823,8.201); -\node[gp node center] at (8.823,0.308) {$10$}; -\draw[gp path] (10.385,0.616)--(10.385,0.796); -\draw[gp path] (10.385,8.381)--(10.385,8.201); -\node[gp node center] at (10.385,0.308) {$12$}; -\draw[gp path] (11.947,0.616)--(11.947,0.796); -\draw[gp path] (11.947,8.381)--(11.947,8.201); -\node[gp node center] at (11.947,0.308) {$14$}; -\draw[gp path] (1.012,8.381)--(1.012,0.616)--(11.947,0.616)--(11.947,8.381)--cycle; -\node[gp node right] at (10.479,7.8) {Simulation}; -\gpcolor{rgb color={0.580,0.000,0.827}} -\draw[gp path] (10.663,7.8)--(11.579,7.8); -\draw[gp path] (1.012,8.381)--(1.020,8.358)--(1.028,8.334)--(1.035,8.311)--(1.043,8.288)% - --(1.051,8.265)--(1.059,8.241)--(1.067,8.218)--(1.074,8.195)--(1.082,8.171)--(1.090,8.150)% - --(1.098,8.126)--(1.106,8.103)--(1.114,8.081)--(1.121,8.058)--(1.129,8.035)--(1.137,8.013)% - --(1.145,7.991)--(1.153,7.968)--(1.160,7.946)--(1.168,7.924)--(1.176,7.901)--(1.184,7.879)% - --(1.192,7.858)--(1.199,7.836)--(1.207,7.814)--(1.215,7.792)--(1.223,7.771)--(1.231,7.749)% - --(1.239,7.727)--(1.246,7.705)--(1.254,7.684)--(1.262,7.662)--(1.270,7.642)--(1.278,7.620)% - --(1.285,7.598)--(1.293,7.578)--(1.301,7.556)--(1.309,7.535)--(1.317,7.514)--(1.324,7.493)% - --(1.332,7.472)--(1.340,7.452)--(1.348,7.431)--(1.356,7.410)--(1.363,7.390)--(1.371,7.370)% - --(1.379,7.348)--(1.387,7.328)--(1.395,7.308)--(1.403,7.288)--(1.410,7.267)--(1.418,7.247)% - --(1.426,7.227)--(1.434,7.207)--(1.442,7.187)--(1.449,7.168)--(1.457,7.148)--(1.465,7.128)% - --(1.473,7.108)--(1.481,7.089)--(1.488,7.069)--(1.496,7.049)--(1.504,7.030)--(1.512,7.010)% - --(1.520,6.991)--(1.528,6.971)--(1.535,6.952)--(1.543,6.934)--(1.551,6.913)--(1.559,6.895)% - --(1.567,6.876)--(1.574,6.858)--(1.582,6.837)--(1.590,6.819)--(1.598,6.800)--(1.606,6.781)% - --(1.613,6.763)--(1.621,6.744)--(1.629,6.726)--(1.637,6.707)--(1.645,6.688)--(1.652,6.670)% - --(1.660,6.653)--(1.668,6.634)--(1.676,6.615)--(1.684,6.597)--(1.692,6.580)--(1.699,6.561)% - --(1.707,6.542)--(1.715,6.525)--(1.723,6.507)--(1.731,6.489)--(1.738,6.471)--(1.746,6.454)% - --(1.754,6.437)--(1.762,6.418)--(1.770,6.401)--(1.777,6.384)--(1.785,6.365)--(1.793,6.348)% - --(1.801,6.331)--(1.809,6.314)--(1.817,6.297)--(1.824,6.280)--(1.832,6.263)--(1.840,6.246)% - --(1.848,6.229)--(1.856,6.211)--(1.863,6.194)--(1.871,6.177)--(1.879,6.160)--(1.887,6.143)% - --(1.895,6.126)--(1.902,6.111)--(1.910,6.093)--(1.918,6.076)--(1.926,6.061)--(1.934,6.044)% - --(1.941,6.027)--(1.949,6.011)--(1.957,5.994)--(1.965,5.979)--(1.973,5.961)--(1.981,5.946)% - --(1.988,5.929)--(1.996,5.913)--(2.004,5.898)--(2.012,5.881)--(2.020,5.865)--(2.027,5.850)% - --(2.035,5.834)--(2.043,5.819)--(2.051,5.801)--(2.059,5.786)--(2.066,5.770)--(2.074,5.755)% - --(2.082,5.739)--(2.090,5.724)--(2.098,5.708)--(2.106,5.693)--(2.113,5.677)--(2.121,5.662)% - --(2.129,5.648)--(2.137,5.632)--(2.145,5.617)--(2.152,5.601)--(2.160,5.587)--(2.168,5.572)% - --(2.176,5.556)--(2.184,5.541)--(2.191,5.527)--(2.199,5.511)--(2.207,5.497)--(2.215,5.482)% - --(2.223,5.468)--(2.230,5.452)--(2.238,5.438)--(2.246,5.423)--(2.254,5.409)--(2.262,5.395)% - --(2.270,5.379)--(2.277,5.365)--(2.285,5.351)--(2.293,5.337)--(2.301,5.322)--(2.309,5.308)% - --(2.316,5.294)--(2.324,5.280)--(2.332,5.266)--(2.340,5.252)--(2.348,5.238)--(2.355,5.224)% - --(2.363,5.210)--(2.371,5.196)--(2.379,5.182)--(2.387,5.168)--(2.394,5.154)--(2.402,5.140)% - --(2.410,5.126)--(2.418,5.112)--(2.426,5.100)--(2.434,5.086)--(2.441,5.072)--(2.449,5.059)% - --(2.457,5.045)--(2.465,5.031)--(2.473,5.019)--(2.480,5.005)--(2.488,4.991)--(2.496,4.978)% - --(2.504,4.964)--(2.512,4.952)--(2.519,4.938)--(2.527,4.926)--(2.535,4.913)--(2.543,4.899)% - --(2.551,4.887)--(2.559,4.874)--(2.566,4.860)--(2.574,4.848)--(2.582,4.836)--(2.590,4.822)% - --(2.598,4.809)--(2.605,4.797)--(2.613,4.784)--(2.621,4.772)--(2.629,4.759)--(2.637,4.747)% - --(2.644,4.735)--(2.652,4.722)--(2.660,4.710)--(2.668,4.697)--(2.676,4.685)--(2.683,4.672)% - --(2.691,4.660)--(2.699,4.648)--(2.707,4.635)--(2.715,4.623)--(2.723,4.610)--(2.730,4.598)% - --(2.738,4.587)--(2.746,4.575)--(2.754,4.562)--(2.762,4.551)--(2.769,4.539)--(2.777,4.526)% - --(2.785,4.516)--(2.793,4.503)--(2.801,4.491)--(2.808,4.480)--(2.816,4.467)--(2.824,4.457)% - --(2.832,4.444)--(2.840,4.433)--(2.848,4.421)--(2.855,4.410)--(2.863,4.399)--(2.871,4.387)% - --(2.879,4.376)--(2.887,4.363)--(2.894,4.353)--(2.902,4.342)--(2.910,4.331)--(2.918,4.318)% - --(2.926,4.307)--(2.933,4.297)--(2.941,4.286)--(2.949,4.275)--(2.957,4.262)--(2.965,4.252)% - --(2.972,4.241)--(2.980,4.230)--(2.988,4.219)--(2.996,4.208)--(3.004,4.197)--(3.012,4.186)% - --(3.019,4.175)--(3.027,4.165)--(3.035,4.154)--(3.043,4.143)--(3.051,4.132)--(3.058,4.123)% - --(3.066,4.112)--(3.074,4.101)--(3.082,4.090)--(3.090,4.079)--(3.097,4.070)--(3.105,4.059)% - --(3.113,4.048)--(3.121,4.037)--(3.129,4.028)--(3.137,4.017)--(3.144,4.006)--(3.152,3.997)% - --(3.160,3.986)--(3.168,3.977)--(3.176,3.966)--(3.183,3.957)--(3.191,3.946)--(3.199,3.936)% - --(3.207,3.925)--(3.215,3.916)--(3.222,3.905)--(3.230,3.896)--(3.238,3.885)--(3.246,3.876)% - --(3.254,3.866)--(3.261,3.856)--(3.269,3.846)--(3.277,3.837)--(3.285,3.826)--(3.293,3.817)% - --(3.301,3.807)--(3.308,3.798)--(3.316,3.787)--(3.324,3.778)--(3.332,3.769)--(3.340,3.759)% - --(3.347,3.750)--(3.355,3.741)--(3.363,3.731)--(3.371,3.720)--(3.379,3.711)--(3.386,3.702)% - --(3.394,3.692)--(3.402,3.683)--(3.410,3.674)--(3.418,3.665)--(3.426,3.655)--(3.433,3.647)% - --(3.441,3.638)--(3.449,3.629)--(3.457,3.620)--(3.465,3.610)--(3.472,3.601)--(3.480,3.592)% - --(3.488,3.584)--(3.496,3.574)--(3.504,3.565)--(3.511,3.556)--(3.519,3.547)--(3.527,3.539)% - --(3.535,3.529)--(3.543,3.520)--(3.550,3.512)--(3.558,3.503)--(3.566,3.494)--(3.574,3.486)% - --(3.582,3.477)--(3.590,3.469)--(3.597,3.460)--(3.605,3.450)--(3.613,3.442)--(3.621,3.433)% - --(3.629,3.425)--(3.636,3.416)--(3.644,3.408)--(3.652,3.401)--(3.660,3.391)--(3.668,3.383)% - --(3.675,3.374)--(3.683,3.366)--(3.691,3.359)--(3.699,3.349)--(3.707,3.342)--(3.715,3.334)% - --(3.722,3.324)--(3.730,3.317)--(3.738,3.309)--(3.746,3.300)--(3.754,3.292)--(3.761,3.284)% - --(3.769,3.276)--(3.777,3.269)--(3.785,3.259)--(3.793,3.251)--(3.800,3.244)--(3.808,3.236)% - --(3.816,3.228)--(3.824,3.220)--(3.832,3.213)--(3.839,3.205)--(3.847,3.197)--(3.855,3.189)% - --(3.863,3.182)--(3.871,3.174)--(3.879,3.166)--(3.886,3.158)--(3.894,3.150)--(3.902,3.143)% - --(3.910,3.135)--(3.918,3.127)--(3.925,3.119)--(3.933,3.112)--(3.941,3.104)--(3.949,3.096)% - --(3.957,3.088)--(3.964,3.082)--(3.972,3.074)--(3.980,3.067)--(3.988,3.059)--(3.996,3.051)% - --(4.004,3.045)--(4.011,3.037)--(4.019,3.029)--(4.027,3.023)--(4.035,3.015)--(4.043,3.008)% - --(4.050,3.001)--(4.058,2.994)--(4.066,2.986)--(4.074,2.980)--(4.082,2.972)--(4.089,2.964)% - --(4.097,2.958)--(4.105,2.950)--(4.113,2.944)--(4.121,2.936)--(4.128,2.930)--(4.136,2.922)% - --(4.144,2.916)--(4.152,2.908)--(4.160,2.902)--(4.168,2.894)--(4.175,2.888)--(4.183,2.880)% - --(4.191,2.874)--(4.199,2.866)--(4.207,2.860)--(4.214,2.854)--(4.222,2.846)--(4.230,2.840)% - --(4.238,2.834)--(4.246,2.826)--(4.253,2.820)--(4.261,2.813)--(4.269,2.806)--(4.277,2.800)% - --(4.285,2.793)--(4.293,2.787)--(4.300,2.779)--(4.308,2.773)--(4.316,2.767)--(4.324,2.761)% - --(4.332,2.754)--(4.339,2.747)--(4.347,2.741)--(4.355,2.734)--(4.363,2.728)--(4.371,2.722)% - --(4.378,2.716)--(4.386,2.709)--(4.394,2.703)--(4.402,2.695)--(4.410,2.689)--(4.417,2.683)% - --(4.425,2.677)--(4.433,2.671)--(4.441,2.664)--(4.449,2.658)--(4.457,2.652)--(4.464,2.646)% - --(4.472,2.640)--(4.480,2.633)--(4.488,2.629)--(4.496,2.622)--(4.503,2.616)--(4.511,2.610)% - --(4.519,2.604)--(4.527,2.598)--(4.535,2.591)--(4.542,2.585)--(4.550,2.579)--(4.558,2.574)% - --(4.566,2.568)--(4.574,2.562)--(4.581,2.556)--(4.589,2.549)--(4.597,2.545)--(4.605,2.539)% - --(4.613,2.532)--(4.621,2.526)--(4.628,2.522)--(4.636,2.515)--(4.644,2.509)--(4.652,2.504)% - --(4.660,2.498)--(4.667,2.492)--(4.675,2.487)--(4.683,2.481)--(4.691,2.475)--(4.699,2.470)% - --(4.706,2.464)--(4.714,2.458)--(4.722,2.453)--(4.730,2.447)--(4.738,2.442)--(4.746,2.436)% - --(4.753,2.430)--(4.761,2.425)--(4.769,2.419)--(4.777,2.414)--(4.785,2.408)--(4.792,2.404)% - --(4.800,2.397)--(4.808,2.393)--(4.816,2.386)--(4.824,2.382)--(4.831,2.377)--(4.839,2.371)% - --(4.847,2.366)--(4.855,2.360)--(4.863,2.355)--(4.870,2.349)--(4.878,2.344)--(4.886,2.340)% - --(4.894,2.334)--(4.902,2.329)--(4.910,2.324)--(4.917,2.318)--(4.925,2.313)--(4.933,2.309)% - --(4.941,2.303)--(4.949,2.298)--(4.956,2.293)--(4.964,2.289)--(4.972,2.282)--(4.980,2.278)% - --(4.988,2.273)--(4.995,2.268)--(5.003,2.262)--(5.011,2.258)--(5.019,2.253)--(5.027,2.248)% - --(5.035,2.244)--(5.042,2.237)--(5.050,2.233)--(5.058,2.228)--(5.066,2.223)--(5.074,2.219)% - --(5.081,2.214)--(5.089,2.209)--(5.097,2.203)--(5.105,2.199)--(5.113,2.194)--(5.120,2.189)% - --(5.128,2.185)--(5.136,2.180)--(5.144,2.175)--(5.152,2.171)--(5.159,2.166)--(5.167,2.161)% - --(5.175,2.157)--(5.183,2.152)--(5.191,2.147)--(5.199,2.143)--(5.206,2.138)--(5.214,2.133)% - --(5.222,2.129)--(5.230,2.124)--(5.238,2.119)--(5.245,2.115)--(5.253,2.110)--(5.261,2.105)% - --(5.269,2.101)--(5.277,2.096)--(5.284,2.093)--(5.292,2.088)--(5.300,2.084)--(5.308,2.079)% - --(5.316,2.074)--(5.324,2.070)--(5.331,2.065)--(5.339,2.062)--(5.347,2.057)--(5.355,2.053)% - --(5.363,2.048)--(5.370,2.043)--(5.378,2.040)--(5.386,2.035)--(5.394,2.031)--(5.402,2.026)% - --(5.409,2.023)--(5.417,2.018)--(5.425,2.014)--(5.433,2.009)--(5.441,2.006)--(5.448,2.001)% - --(5.456,1.997)--(5.464,1.994)--(5.472,1.989)--(5.480,1.984)--(5.488,1.980)--(5.495,1.976)% - --(5.503,1.972)--(5.511,1.969)--(5.519,1.964)--(5.527,1.959)--(5.534,1.956)--(5.542,1.952)% - --(5.550,1.947)--(5.558,1.944)--(5.566,1.939)--(5.573,1.936)--(5.581,1.931)--(5.589,1.927)% - --(5.597,1.924)--(5.605,1.919)--(5.613,1.916)--(5.620,1.911)--(5.628,1.908)--(5.636,1.903)% - --(5.644,1.900)--(5.652,1.896)--(5.659,1.893)--(5.667,1.888)--(5.675,1.885)--(5.683,1.880)% - --(5.691,1.877)--(5.698,1.872)--(5.706,1.869)--(5.714,1.865)--(5.722,1.862)--(5.730,1.858)% - --(5.737,1.854)--(5.745,1.851)--(5.753,1.846)--(5.761,1.843)--(5.769,1.840)--(5.777,1.835)% - --(5.784,1.832)--(5.792,1.827)--(5.800,1.824)--(5.808,1.821)--(5.816,1.816)--(5.823,1.813)% - --(5.831,1.810)--(5.839,1.806)--(5.847,1.802)--(5.855,1.799)--(5.862,1.795)--(5.870,1.792)% - --(5.878,1.789)--(5.886,1.785)--(5.894,1.781)--(5.902,1.778)--(5.909,1.775)--(5.917,1.770)% - --(5.925,1.767)--(5.933,1.764)--(5.941,1.761)--(5.948,1.756)--(5.956,1.753)--(5.964,1.750)% - --(5.972,1.747)--(5.980,1.743)--(5.987,1.739)--(5.995,1.736)--(6.003,1.733)--(6.011,1.730)% - --(6.019,1.726)--(6.026,1.723)--(6.034,1.719)--(6.042,1.716)--(6.050,1.712)--(6.058,1.709)% - --(6.066,1.706)--(6.073,1.703)--(6.081,1.700)--(6.089,1.695)--(6.097,1.692)--(6.105,1.689)% - --(6.112,1.686)--(6.120,1.683)--(6.128,1.680)--(6.136,1.677)--(6.144,1.674)--(6.151,1.670)% - --(6.159,1.667)--(6.167,1.664)--(6.175,1.661)--(6.183,1.658)--(6.191,1.655)--(6.198,1.650)% - --(6.206,1.647)--(6.214,1.644)--(6.222,1.641)--(6.230,1.638)--(6.237,1.635)--(6.245,1.632)% - --(6.253,1.629)--(6.261,1.625)--(6.269,1.624)--(6.276,1.621)--(6.284,1.618)--(6.292,1.615)% - --(6.300,1.611)--(6.308,1.608)--(6.315,1.605)--(6.323,1.602)--(6.331,1.599)--(6.339,1.596)% - --(6.347,1.593)--(6.355,1.590)--(6.362,1.587)--(6.370,1.584)--(6.378,1.582)--(6.386,1.579)% - --(6.394,1.576)--(6.401,1.573)--(6.409,1.570)--(6.417,1.566)--(6.425,1.563)--(6.433,1.560)% - --(6.440,1.559)--(6.448,1.556)--(6.456,1.552)--(6.464,1.549)--(6.472,1.546)--(6.480,1.545)% - --(6.487,1.542)--(6.495,1.538)--(6.503,1.535)--(6.511,1.532)--(6.519,1.531)--(6.526,1.528)% - --(6.534,1.525)--(6.542,1.521)--(6.550,1.518)--(6.558,1.517)--(6.565,1.514)--(6.573,1.511)% - --(6.581,1.507)--(6.589,1.506)--(6.597,1.503)--(6.604,1.500)--(6.612,1.497)--(6.620,1.495)% - --(6.628,1.492)--(6.636,1.489)--(6.644,1.487)--(6.651,1.484)--(6.659,1.481)--(6.667,1.479)% - --(6.675,1.476)--(6.683,1.473)--(6.690,1.470)--(6.698,1.469)--(6.706,1.465)--(6.714,1.464)% - --(6.722,1.461)--(6.729,1.458)--(6.737,1.456)--(6.745,1.453)--(6.753,1.450)--(6.761,1.448)% - --(6.768,1.445)--(6.776,1.442)--(6.784,1.441)--(6.792,1.438)--(6.800,1.436)--(6.808,1.433)% - --(6.815,1.430)--(6.823,1.428)--(6.831,1.425)--(6.839,1.424)--(6.847,1.420)--(6.854,1.419)% - --(6.862,1.416)--(6.870,1.413)--(6.878,1.411)--(6.886,1.408)--(6.893,1.406)--(6.901,1.403)% - --(6.909,1.402)--(6.917,1.399)--(6.925,1.397)--(6.933,1.394)--(6.940,1.393)--(6.948,1.389)% - --(6.956,1.388)--(6.964,1.385)--(6.972,1.383)--(6.979,1.380)--(6.987,1.379)--(6.995,1.375)% - --(7.003,1.374)--(7.011,1.371)--(7.018,1.369)--(7.026,1.366)--(7.034,1.365)--(7.042,1.361)% - --(7.050,1.360)--(7.057,1.357)--(7.065,1.355)--(7.073,1.352)--(7.081,1.351)--(7.089,1.349)% - --(7.097,1.346)--(7.104,1.344)--(7.112,1.341)--(7.120,1.340)--(7.128,1.337)--(7.136,1.335)% - --(7.143,1.333)--(7.151,1.330)--(7.159,1.329)--(7.167,1.326)--(7.175,1.324)--(7.182,1.323)% - --(7.190,1.320)--(7.198,1.318)--(7.206,1.316)--(7.214,1.313)--(7.222,1.312)--(7.229,1.309)% - --(7.237,1.307)--(7.245,1.306)--(7.253,1.302)--(7.261,1.301)--(7.268,1.299)--(7.276,1.296)% - --(7.284,1.295)--(7.292,1.293)--(7.300,1.290)--(7.307,1.288)--(7.315,1.287)--(7.323,1.285)% - --(7.331,1.282)--(7.339,1.281)--(7.346,1.279)--(7.354,1.276)--(7.362,1.274)--(7.370,1.273)% - --(7.378,1.270)--(7.386,1.268)--(7.393,1.267)--(7.401,1.265)--(7.409,1.262)--(7.417,1.260)% - --(7.425,1.259)--(7.432,1.257)--(7.440,1.254)--(7.448,1.253)--(7.456,1.251)--(7.464,1.250)% - --(7.471,1.247)--(7.479,1.245)--(7.487,1.243)--(7.495,1.242)--(7.503,1.239)--(7.511,1.237)% - --(7.518,1.236)--(7.526,1.234)--(7.534,1.233)--(7.542,1.229)--(7.550,1.228)--(7.557,1.226)% - --(7.565,1.225)--(7.573,1.223)--(7.581,1.220)--(7.589,1.219)--(7.596,1.217)--(7.604,1.215)% - --(7.612,1.214)--(7.620,1.212)--(7.628,1.209)--(7.635,1.208)--(7.643,1.206)--(7.651,1.205)% - --(7.659,1.203)--(7.667,1.201)--(7.675,1.200)--(7.682,1.197)--(7.690,1.195)--(7.698,1.194)% - --(7.706,1.192)--(7.714,1.191)--(7.721,1.189)--(7.729,1.188)--(7.737,1.186)--(7.745,1.183)% - --(7.753,1.181)--(7.760,1.180)--(7.768,1.178)--(7.776,1.177)--(7.784,1.175)--(7.792,1.174)% - --(7.800,1.172)--(7.807,1.170)--(7.815,1.169)--(7.823,1.167)--(7.831,1.164)--(7.839,1.163)% - --(7.846,1.161)--(7.854,1.160)--(7.862,1.158)--(7.870,1.156)--(7.878,1.155)--(7.885,1.153)% - --(7.893,1.152)--(7.901,1.150)--(7.909,1.149)--(7.917,1.147)--(7.924,1.146)--(7.932,1.144)% - --(7.940,1.142)--(7.948,1.141)--(7.956,1.139)--(7.964,1.138)--(7.971,1.136)--(7.979,1.135)% - --(7.987,1.133)--(7.995,1.132)--(8.003,1.130)--(8.010,1.128)--(8.018,1.127)--(8.026,1.125)% - --(8.034,1.124)--(8.042,1.122)--(8.049,1.121)--(8.057,1.119)--(8.065,1.118)--(8.073,1.116)% - --(8.081,1.115)--(8.089,1.113)--(8.096,1.111)--(8.104,1.110)--(8.112,1.108)--(8.120,1.107)% - --(8.128,1.105)--(8.135,1.104)--(8.143,1.102)--(8.151,1.101)--(8.159,1.099)--(8.167,1.097)% - --(8.174,1.096)--(8.182,1.094)--(8.190,1.093)--(8.198,1.091)--(8.206,1.091)--(8.213,1.090)% - --(8.221,1.088)--(8.229,1.087)--(8.237,1.085)--(8.245,1.083)--(8.253,1.082)--(8.260,1.080)% - --(8.268,1.079)--(8.276,1.077)--(8.284,1.076)--(8.292,1.074)--(8.299,1.074)--(8.307,1.073)% - --(8.315,1.071)--(8.323,1.069)--(8.331,1.068)--(8.338,1.066)--(8.346,1.065)--(8.354,1.063)% - --(8.362,1.063)--(8.370,1.062)--(8.378,1.060)--(8.385,1.059)--(8.393,1.057)--(8.401,1.055)% - --(8.409,1.054)--(8.417,1.052)--(8.424,1.052)--(8.432,1.051)--(8.440,1.049)--(8.448,1.048)% - --(8.456,1.046)--(8.463,1.045)--(8.471,1.045)--(8.479,1.043)--(8.487,1.042)--(8.495,1.040)% - --(8.502,1.038)--(8.510,1.037)--(8.518,1.037)--(8.526,1.035)--(8.534,1.034)--(8.542,1.032)% - --(8.549,1.031)--(8.557,1.031)--(8.565,1.029)--(8.573,1.028)--(8.581,1.026)--(8.588,1.024)% - --(8.596,1.024)--(8.604,1.023)--(8.612,1.021)--(8.620,1.020)--(8.627,1.018)--(8.635,1.018)% - --(8.643,1.017)--(8.651,1.015)--(8.659,1.014)--(8.667,1.012)--(8.674,1.012)--(8.682,1.010)% - --(8.690,1.009)--(8.698,1.007)--(8.706,1.007)--(8.713,1.006)--(8.721,1.004)--(8.729,1.003)% - --(8.737,1.003)--(8.745,1.001)--(8.752,1.000)--(8.760,0.998)--(8.768,0.998)--(8.776,0.996)% - --(8.784,0.995)--(8.791,0.993)--(8.799,0.993)--(8.807,0.992)--(8.815,0.990)--(8.823,0.989)% - --(8.831,0.989)--(8.838,0.987)--(8.846,0.986)--(8.854,0.984)--(8.862,0.984)--(8.870,0.983)% - --(8.877,0.981)--(8.885,0.981)--(8.893,0.979)--(8.901,0.978)--(8.909,0.978)--(8.916,0.976)% - --(8.924,0.975)--(8.932,0.973)--(8.940,0.973)--(8.948,0.972)--(8.955,0.970)--(8.963,0.970)% - --(8.971,0.969)--(8.979,0.967)--(8.987,0.967)--(8.995,0.965)--(9.002,0.964)--(9.010,0.964)% - --(9.018,0.962)--(9.026,0.961)--(9.034,0.959)--(9.041,0.959)--(9.049,0.958)--(9.057,0.956)% - --(9.065,0.956)--(9.073,0.955)--(9.080,0.953)--(9.088,0.953)--(9.096,0.951)--(9.104,0.951)% - --(9.112,0.950)--(9.120,0.948)--(9.127,0.948)--(9.135,0.947)--(9.143,0.945)--(9.151,0.945)% - --(9.159,0.944)--(9.166,0.942)--(9.174,0.942)--(9.182,0.941)--(9.190,0.939)--(9.198,0.939)% - --(9.205,0.937)--(9.213,0.937)--(9.221,0.936)--(9.229,0.934)--(9.237,0.934)--(9.244,0.933)% - --(9.252,0.931)--(9.260,0.931)--(9.268,0.930)--(9.276,0.930)--(9.284,0.928)--(9.291,0.927)% - --(9.299,0.927)--(9.307,0.925)--(9.315,0.925)--(9.323,0.923)--(9.330,0.922)--(9.338,0.922)% - --(9.346,0.920)--(9.354,0.920)--(9.362,0.919)--(9.369,0.917)--(9.377,0.917)--(9.385,0.916)% - --(9.393,0.916)--(9.401,0.914)--(9.409,0.913)--(9.416,0.913)--(9.424,0.911)--(9.432,0.911)% - --(9.440,0.910)--(9.448,0.910)--(9.455,0.908)--(9.463,0.906)--(9.471,0.906)--(9.479,0.905)% - --(9.487,0.905)--(9.494,0.903)--(9.502,0.903)--(9.510,0.902)--(9.518,0.900)--(9.526,0.900)% - --(9.533,0.899)--(9.541,0.899)--(9.549,0.897)--(9.557,0.897)--(9.565,0.896)--(9.573,0.896)% - --(9.580,0.894)--(9.588,0.894)--(9.596,0.892)--(9.604,0.891)--(9.612,0.891)--(9.619,0.889)% - --(9.627,0.889)--(9.635,0.888)--(9.643,0.888)--(9.651,0.886)--(9.658,0.886)--(9.666,0.885)% - --(9.674,0.885)--(9.682,0.883)--(9.690,0.883)--(9.698,0.882)--(9.705,0.882)--(9.713,0.880)% - --(9.721,0.880)--(9.729,0.878)--(9.737,0.878)--(9.744,0.877)--(9.752,0.877)--(9.760,0.875)% - --(9.768,0.875)--(9.776,0.874)--(9.783,0.874)--(9.791,0.872)--(9.799,0.872)--(9.807,0.871)% - --(9.815,0.871)--(9.822,0.869)--(9.830,0.869)--(9.838,0.868)--(9.846,0.868)--(9.854,0.866)% - --(9.862,0.866)--(9.869,0.864)--(9.877,0.864)--(9.885,0.863)--(9.893,0.863)--(9.901,0.861)% - --(9.908,0.861)--(9.916,0.860)--(9.924,0.860)--(9.932,0.858)--(9.940,0.858)--(9.947,0.857)% - --(9.955,0.857)--(9.963,0.855)--(9.971,0.855)--(9.979,0.854)--(9.987,0.854)--(9.994,0.852)% - --(10.002,0.852)--(10.010,0.852)--(10.018,0.851)--(10.026,0.851)--(10.033,0.849)--(10.041,0.849)% - --(10.049,0.847)--(10.057,0.847)--(10.065,0.846)--(10.072,0.846)--(10.080,0.844)--(10.088,0.844)% - --(10.096,0.844)--(10.104,0.843)--(10.111,0.843)--(10.119,0.841)--(10.127,0.841)--(10.135,0.840)% - --(10.143,0.840)--(10.151,0.840)--(10.158,0.838)--(10.166,0.838)--(10.174,0.837)--(10.182,0.837)% - --(10.190,0.835)--(10.197,0.835)--(10.205,0.833)--(10.213,0.833)--(10.221,0.833)--(10.229,0.832)% - --(10.236,0.832)--(10.244,0.830)--(10.252,0.830)--(10.260,0.830)--(10.268,0.829)--(10.276,0.829)% - --(10.283,0.827)--(10.291,0.827)--(10.299,0.826)--(10.307,0.826)--(10.315,0.826)--(10.322,0.824)% - --(10.330,0.824)--(10.338,0.823)--(10.346,0.823)--(10.354,0.823)--(10.361,0.821)--(10.369,0.821)% - --(10.377,0.819)--(10.385,0.819)--(10.393,0.819)--(10.400,0.818)--(10.408,0.818)--(10.416,0.816)% - --(10.424,0.816)--(10.432,0.816)--(10.440,0.815)--(10.447,0.815)--(10.455,0.813)--(10.463,0.813)% - --(10.471,0.813)--(10.479,0.812)--(10.486,0.812)--(10.494,0.812)--(10.502,0.810)--(10.510,0.810)% - --(10.518,0.809)--(10.525,0.809)--(10.533,0.809)--(10.541,0.807)--(10.549,0.807)--(10.557,0.807)% - --(10.565,0.805)--(10.572,0.805)--(10.580,0.804)--(10.588,0.804)--(10.596,0.804)--(10.604,0.802)% - --(10.611,0.802)--(10.619,0.802)--(10.627,0.801)--(10.635,0.801)--(10.643,0.801)--(10.650,0.799)% - --(10.658,0.799)--(10.666,0.798)--(10.674,0.798)--(10.682,0.798)--(10.689,0.796)--(10.697,0.796)% - --(10.705,0.796)--(10.713,0.795)--(10.721,0.795)--(10.729,0.795)--(10.736,0.793)--(10.744,0.793)% - --(10.752,0.793)--(10.760,0.791)--(10.768,0.791)--(10.775,0.791)--(10.783,0.790)--(10.791,0.790)% - --(10.799,0.790)--(10.807,0.788)--(10.814,0.788)--(10.822,0.788)--(10.830,0.787)--(10.838,0.787)% - --(10.846,0.787)--(10.854,0.785)--(10.861,0.785)--(10.869,0.785)--(10.877,0.784)--(10.885,0.784)% - --(10.893,0.784)--(10.900,0.782)--(10.908,0.782)--(10.916,0.782)--(10.924,0.781)--(10.932,0.781)% - --(10.939,0.781)--(10.947,0.779)--(10.955,0.779)--(10.963,0.779)--(10.971,0.778)--(10.978,0.778)% - --(10.986,0.778)--(10.994,0.776)--(11.002,0.776)--(11.010,0.776)--(11.018,0.774)--(11.025,0.774)% - --(11.033,0.774)--(11.041,0.774)--(11.049,0.773)--(11.057,0.773)--(11.064,0.773)--(11.072,0.771)% - --(11.080,0.771)--(11.088,0.771)--(11.096,0.770)--(11.103,0.770)--(11.111,0.770)--(11.119,0.768)% - --(11.127,0.768)--(11.135,0.768)--(11.142,0.768)--(11.150,0.767)--(11.158,0.767)--(11.166,0.767)% - --(11.174,0.765)--(11.182,0.765)--(11.189,0.765)--(11.197,0.765)--(11.205,0.764)--(11.213,0.764)% - --(11.221,0.764)--(11.228,0.762)--(11.236,0.762)--(11.244,0.762)--(11.252,0.762)--(11.260,0.760)% - --(11.267,0.760)--(11.275,0.760)--(11.283,0.759)--(11.291,0.759)--(11.299,0.759)--(11.307,0.759)% - --(11.314,0.757)--(11.322,0.757)--(11.330,0.757)--(11.338,0.756)--(11.346,0.756); -\gpcolor{color=gp lt color border} -\node[gp node right] at (10.479,7.35) {Theorie}; -\gpcolor{rgb color={0.000,0.620,0.451}} -\draw[gp path] (10.663,7.35)--(11.579,7.35); -\draw[gp path] (1.012,8.381)--(1.020,8.358)--(1.028,8.334)--(1.035,8.311)--(1.043,8.288)% - --(1.051,8.265)--(1.059,8.241)--(1.067,8.218)--(1.074,8.195)--(1.082,8.171)--(1.090,8.150)% - --(1.098,8.126)--(1.106,8.103)--(1.114,8.081)--(1.121,8.058)--(1.129,8.036)--(1.137,8.013)% - --(1.145,7.991)--(1.153,7.969)--(1.160,7.946)--(1.168,7.924)--(1.176,7.903)--(1.184,7.881)% - --(1.192,7.858)--(1.199,7.836)--(1.207,7.814)--(1.215,7.792)--(1.223,7.771)--(1.231,7.749)% - --(1.239,7.727)--(1.246,7.707)--(1.254,7.685)--(1.262,7.664)--(1.270,7.642)--(1.278,7.620)% - --(1.285,7.600)--(1.293,7.578)--(1.301,7.558)--(1.309,7.536)--(1.317,7.516)--(1.324,7.494)% - --(1.332,7.474)--(1.340,7.452)--(1.348,7.432)--(1.356,7.412)--(1.363,7.392)--(1.371,7.370)% - --(1.379,7.350)--(1.387,7.330)--(1.395,7.309)--(1.403,7.289)--(1.410,7.269)--(1.418,7.249)% - --(1.426,7.229)--(1.434,7.208)--(1.442,7.188)--(1.449,7.170)--(1.457,7.149)--(1.465,7.129)% - --(1.473,7.109)--(1.481,7.090)--(1.488,7.070)--(1.496,7.052)--(1.504,7.031)--(1.512,7.013)% - --(1.520,6.993)--(1.528,6.974)--(1.535,6.954)--(1.543,6.935)--(1.551,6.917)--(1.559,6.896)% - --(1.567,6.878)--(1.574,6.859)--(1.582,6.840)--(1.590,6.822)--(1.598,6.803)--(1.606,6.783)% - --(1.613,6.764)--(1.621,6.746)--(1.629,6.729)--(1.637,6.710)--(1.645,6.691)--(1.652,6.673)% - --(1.660,6.654)--(1.668,6.635)--(1.676,6.618)--(1.684,6.600)--(1.692,6.581)--(1.699,6.564)% - --(1.707,6.545)--(1.715,6.528)--(1.723,6.510)--(1.731,6.493)--(1.738,6.474)--(1.746,6.457)% - --(1.754,6.438)--(1.762,6.421)--(1.770,6.404)--(1.777,6.385)--(1.785,6.368)--(1.793,6.351)% - --(1.801,6.334)--(1.809,6.317)--(1.817,6.298)--(1.824,6.281)--(1.832,6.264)--(1.840,6.247)% - --(1.848,6.230)--(1.856,6.213)--(1.863,6.197)--(1.871,6.180)--(1.879,6.163)--(1.887,6.146)% - --(1.895,6.129)--(1.902,6.112)--(1.910,6.097)--(1.918,6.079)--(1.926,6.062)--(1.934,6.047)% - --(1.941,6.030)--(1.949,6.014)--(1.957,5.997)--(1.965,5.982)--(1.973,5.965)--(1.981,5.949)% - --(1.988,5.932)--(1.996,5.916)--(2.004,5.901)--(2.012,5.884)--(2.020,5.868)--(2.027,5.853)% - --(2.035,5.837)--(2.043,5.822)--(2.051,5.805)--(2.059,5.789)--(2.066,5.774)--(2.074,5.758)% - --(2.082,5.742)--(2.090,5.727)--(2.098,5.711)--(2.106,5.696)--(2.113,5.680)--(2.121,5.666)% - --(2.129,5.651)--(2.137,5.635)--(2.145,5.620)--(2.152,5.604)--(2.160,5.590)--(2.168,5.575)% - --(2.176,5.559)--(2.184,5.545)--(2.191,5.530)--(2.199,5.516)--(2.207,5.500)--(2.215,5.485)% - --(2.223,5.471)--(2.230,5.457)--(2.238,5.441)--(2.246,5.427)--(2.254,5.412)--(2.262,5.398)% - --(2.270,5.384)--(2.277,5.368)--(2.285,5.354)--(2.293,5.340)--(2.301,5.326)--(2.309,5.311)% - --(2.316,5.297)--(2.324,5.283)--(2.332,5.269)--(2.340,5.255)--(2.348,5.241)--(2.355,5.227)% - --(2.363,5.213)--(2.371,5.199)--(2.379,5.185)--(2.387,5.171)--(2.394,5.157)--(2.402,5.145)% - --(2.410,5.131)--(2.418,5.117)--(2.426,5.103)--(2.434,5.089)--(2.441,5.076)--(2.449,5.062)% - --(2.457,5.048)--(2.465,5.036)--(2.473,5.022)--(2.480,5.008)--(2.488,4.995)--(2.496,4.981)% - --(2.504,4.969)--(2.512,4.955)--(2.519,4.943)--(2.527,4.930)--(2.535,4.916)--(2.543,4.904)% - --(2.551,4.890)--(2.559,4.877)--(2.566,4.865)--(2.574,4.851)--(2.582,4.839)--(2.590,4.826)% - --(2.598,4.814)--(2.605,4.801)--(2.613,4.787)--(2.621,4.775)--(2.629,4.763)--(2.637,4.750)% - --(2.644,4.738)--(2.652,4.725)--(2.660,4.713)--(2.668,4.700)--(2.676,4.688)--(2.683,4.676)% - --(2.691,4.663)--(2.699,4.651)--(2.707,4.640)--(2.715,4.627)--(2.723,4.615)--(2.730,4.603)% - --(2.738,4.590)--(2.746,4.579)--(2.754,4.567)--(2.762,4.554)--(2.769,4.542)--(2.777,4.531)% - --(2.785,4.519)--(2.793,4.508)--(2.801,4.495)--(2.808,4.483)--(2.816,4.472)--(2.824,4.460)% - --(2.832,4.449)--(2.840,4.436)--(2.848,4.426)--(2.855,4.415)--(2.863,4.402)--(2.871,4.391)% - --(2.879,4.379)--(2.887,4.368)--(2.894,4.357)--(2.902,4.346)--(2.910,4.334)--(2.918,4.323)% - --(2.926,4.312)--(2.933,4.301)--(2.941,4.289)--(2.949,4.278)--(2.957,4.267)--(2.965,4.256)% - --(2.972,4.245)--(2.980,4.234)--(2.988,4.224)--(2.996,4.213)--(3.004,4.202)--(3.012,4.191)% - --(3.019,4.180)--(3.027,4.169)--(3.035,4.158)--(3.043,4.148)--(3.051,4.137)--(3.058,4.126)% - --(3.066,4.115)--(3.074,4.106)--(3.082,4.095)--(3.090,4.084)--(3.097,4.073)--(3.105,4.064)% - --(3.113,4.053)--(3.121,4.042)--(3.129,4.031)--(3.137,4.022)--(3.144,4.011)--(3.152,4.002)% - --(3.160,3.991)--(3.168,3.980)--(3.176,3.970)--(3.183,3.960)--(3.191,3.950)--(3.199,3.939)% - --(3.207,3.930)--(3.215,3.919)--(3.222,3.910)--(3.230,3.901)--(3.238,3.890)--(3.246,3.880)% - --(3.254,3.870)--(3.261,3.860)--(3.269,3.851)--(3.277,3.840)--(3.285,3.831)--(3.293,3.821)% - --(3.301,3.812)--(3.308,3.801)--(3.316,3.792)--(3.324,3.783)--(3.332,3.773)--(3.340,3.764)% - --(3.347,3.755)--(3.355,3.744)--(3.363,3.734)--(3.371,3.725)--(3.379,3.716)--(3.386,3.706)% - --(3.394,3.697)--(3.402,3.688)--(3.410,3.679)--(3.418,3.669)--(3.426,3.660)--(3.433,3.651)% - --(3.441,3.641)--(3.449,3.633)--(3.457,3.624)--(3.465,3.615)--(3.472,3.606)--(3.480,3.596)% - --(3.488,3.587)--(3.496,3.579)--(3.504,3.570)--(3.511,3.560)--(3.519,3.551)--(3.527,3.543)% - --(3.535,3.534)--(3.543,3.525)--(3.550,3.515)--(3.558,3.508)--(3.566,3.498)--(3.574,3.491)% - --(3.582,3.481)--(3.590,3.472)--(3.597,3.464)--(3.605,3.455)--(3.613,3.447)--(3.621,3.438)% - --(3.629,3.430)--(3.636,3.421)--(3.644,3.413)--(3.652,3.404)--(3.660,3.396)--(3.668,3.387)% - --(3.675,3.379)--(3.683,3.371)--(3.691,3.362)--(3.699,3.354)--(3.707,3.346)--(3.715,3.337)% - --(3.722,3.329)--(3.730,3.321)--(3.738,3.312)--(3.746,3.304)--(3.754,3.296)--(3.761,3.289)% - --(3.769,3.281)--(3.777,3.272)--(3.785,3.264)--(3.793,3.256)--(3.800,3.248)--(3.808,3.241)% - --(3.816,3.233)--(3.824,3.225)--(3.832,3.216)--(3.839,3.208)--(3.847,3.200)--(3.855,3.192)% - --(3.863,3.185)--(3.871,3.177)--(3.879,3.169)--(3.886,3.161)--(3.894,3.154)--(3.902,3.146)% - --(3.910,3.138)--(3.918,3.132)--(3.925,3.124)--(3.933,3.116)--(3.941,3.109)--(3.949,3.101)% - --(3.957,3.093)--(3.964,3.085)--(3.972,3.079)--(3.980,3.071)--(3.988,3.064)--(3.996,3.056)% - --(4.004,3.048)--(4.011,3.042)--(4.019,3.034)--(4.027,3.026)--(4.035,3.020)--(4.043,3.012)% - --(4.050,3.005)--(4.058,2.998)--(4.066,2.991)--(4.074,2.983)--(4.082,2.977)--(4.089,2.969)% - --(4.097,2.963)--(4.105,2.955)--(4.113,2.947)--(4.121,2.941)--(4.128,2.933)--(4.136,2.927)% - --(4.144,2.919)--(4.152,2.913)--(4.160,2.905)--(4.168,2.899)--(4.175,2.891)--(4.183,2.885)% - --(4.191,2.879)--(4.199,2.871)--(4.207,2.865)--(4.214,2.857)--(4.222,2.851)--(4.230,2.845)% - --(4.238,2.837)--(4.246,2.831)--(4.253,2.824)--(4.261,2.817)--(4.269,2.810)--(4.277,2.804)% - --(4.285,2.798)--(4.293,2.790)--(4.300,2.784)--(4.308,2.778)--(4.316,2.772)--(4.324,2.764)% - --(4.332,2.758)--(4.339,2.751)--(4.347,2.745)--(4.355,2.739)--(4.363,2.733)--(4.371,2.727)% - --(4.378,2.719)--(4.386,2.713)--(4.394,2.706)--(4.402,2.700)--(4.410,2.694)--(4.417,2.688)% - --(4.425,2.681)--(4.433,2.675)--(4.441,2.669)--(4.449,2.663)--(4.457,2.657)--(4.464,2.650)% - --(4.472,2.644)--(4.480,2.638)--(4.488,2.632)--(4.496,2.626)--(4.503,2.619)--(4.511,2.613)% - --(4.519,2.608)--(4.527,2.602)--(4.535,2.596)--(4.542,2.590)--(4.550,2.584)--(4.558,2.577)% - --(4.566,2.571)--(4.574,2.567)--(4.581,2.560)--(4.589,2.554)--(4.597,2.548)--(4.605,2.542)% - --(4.613,2.537)--(4.621,2.531)--(4.628,2.525)--(4.636,2.520)--(4.644,2.514)--(4.652,2.508)% - --(4.660,2.501)--(4.667,2.497)--(4.675,2.490)--(4.683,2.484)--(4.691,2.480)--(4.699,2.473)% - --(4.706,2.469)--(4.714,2.463)--(4.722,2.456)--(4.730,2.452)--(4.738,2.445)--(4.746,2.441)% - --(4.753,2.435)--(4.761,2.430)--(4.769,2.424)--(4.777,2.417)--(4.785,2.413)--(4.792,2.407)% - --(4.800,2.402)--(4.808,2.396)--(4.816,2.391)--(4.824,2.386)--(4.831,2.380)--(4.839,2.376)% - --(4.847,2.369)--(4.855,2.365)--(4.863,2.358)--(4.870,2.354)--(4.878,2.349)--(4.886,2.343)% - --(4.894,2.338)--(4.902,2.334)--(4.910,2.327)--(4.917,2.323)--(4.925,2.318)--(4.933,2.312)% - --(4.941,2.307)--(4.949,2.303)--(4.956,2.296)--(4.964,2.292)--(4.972,2.287)--(4.980,2.282)% - --(4.988,2.276)--(4.995,2.271)--(5.003,2.267)--(5.011,2.262)--(5.019,2.256)--(5.027,2.251)% - --(5.035,2.247)--(5.042,2.242)--(5.050,2.237)--(5.058,2.233)--(5.066,2.226)--(5.074,2.222)% - --(5.081,2.217)--(5.089,2.212)--(5.097,2.208)--(5.105,2.203)--(5.113,2.199)--(5.120,2.194)% - --(5.128,2.189)--(5.136,2.183)--(5.144,2.178)--(5.152,2.174)--(5.159,2.169)--(5.167,2.164)% - --(5.175,2.160)--(5.183,2.155)--(5.191,2.150)--(5.199,2.146)--(5.206,2.141)--(5.214,2.136)% - --(5.222,2.132)--(5.230,2.127)--(5.238,2.122)--(5.245,2.119)--(5.253,2.115)--(5.261,2.110)% - --(5.269,2.105)--(5.277,2.101)--(5.284,2.096)--(5.292,2.091)--(5.300,2.087)--(5.308,2.082)% - --(5.316,2.079)--(5.324,2.074)--(5.331,2.070)--(5.339,2.065)--(5.347,2.060)--(5.355,2.056)% - --(5.363,2.053)--(5.370,2.048)--(5.378,2.043)--(5.386,2.039)--(5.394,2.034)--(5.402,2.031)% - --(5.409,2.026)--(5.417,2.021)--(5.425,2.017)--(5.433,2.014)--(5.441,2.009)--(5.448,2.004)% - --(5.456,2.001)--(5.464,1.997)--(5.472,1.992)--(5.480,1.987)--(5.488,1.984)--(5.495,1.980)% - --(5.503,1.975)--(5.511,1.972)--(5.519,1.967)--(5.527,1.964)--(5.534,1.959)--(5.542,1.955)% - --(5.550,1.952)--(5.558,1.947)--(5.566,1.944)--(5.573,1.939)--(5.581,1.934)--(5.589,1.931)% - --(5.597,1.927)--(5.605,1.924)--(5.613,1.919)--(5.620,1.916)--(5.628,1.911)--(5.636,1.908)% - --(5.644,1.903)--(5.652,1.899)--(5.659,1.896)--(5.667,1.893)--(5.675,1.888)--(5.683,1.885)% - --(5.691,1.880)--(5.698,1.877)--(5.706,1.872)--(5.714,1.869)--(5.722,1.865)--(5.730,1.862)% - --(5.737,1.857)--(5.745,1.854)--(5.753,1.851)--(5.761,1.846)--(5.769,1.843)--(5.777,1.838)% - --(5.784,1.835)--(5.792,1.832)--(5.800,1.827)--(5.808,1.824)--(5.816,1.821)--(5.823,1.816)% - --(5.831,1.813)--(5.839,1.810)--(5.847,1.806)--(5.855,1.802)--(5.862,1.799)--(5.870,1.795)% - --(5.878,1.792)--(5.886,1.789)--(5.894,1.784)--(5.902,1.781)--(5.909,1.778)--(5.917,1.775)% - --(5.925,1.770)--(5.933,1.767)--(5.941,1.764)--(5.948,1.761)--(5.956,1.756)--(5.964,1.753)% - --(5.972,1.750)--(5.980,1.747)--(5.987,1.743)--(5.995,1.739)--(6.003,1.736)--(6.011,1.733)% - --(6.019,1.730)--(6.026,1.726)--(6.034,1.722)--(6.042,1.719)--(6.050,1.716)--(6.058,1.712)% - --(6.066,1.709)--(6.073,1.706)--(6.081,1.703)--(6.089,1.698)--(6.097,1.695)--(6.105,1.692)% - --(6.112,1.689)--(6.120,1.686)--(6.128,1.683)--(6.136,1.680)--(6.144,1.677)--(6.151,1.674)% - --(6.159,1.670)--(6.167,1.667)--(6.175,1.664)--(6.183,1.661)--(6.191,1.658)--(6.198,1.655)% - --(6.206,1.652)--(6.214,1.647)--(6.222,1.644)--(6.230,1.641)--(6.237,1.638)--(6.245,1.635)% - --(6.253,1.632)--(6.261,1.630)--(6.269,1.627)--(6.276,1.624)--(6.284,1.621)--(6.292,1.618)% - --(6.300,1.615)--(6.308,1.611)--(6.315,1.608)--(6.323,1.605)--(6.331,1.602)--(6.339,1.599)% - --(6.347,1.596)--(6.355,1.593)--(6.362,1.590)--(6.370,1.587)--(6.378,1.585)--(6.386,1.582)% - --(6.394,1.579)--(6.401,1.576)--(6.409,1.573)--(6.417,1.570)--(6.425,1.566)--(6.433,1.563)% - --(6.440,1.562)--(6.448,1.559)--(6.456,1.556)--(6.464,1.552)--(6.472,1.549)--(6.480,1.546)% - --(6.487,1.545)--(6.495,1.542)--(6.503,1.538)--(6.511,1.535)--(6.519,1.532)--(6.526,1.531)% - --(6.534,1.528)--(6.542,1.525)--(6.550,1.521)--(6.558,1.520)--(6.565,1.517)--(6.573,1.514)% - --(6.581,1.511)--(6.589,1.509)--(6.597,1.506)--(6.604,1.503)--(6.612,1.500)--(6.620,1.498)% - --(6.628,1.495)--(6.636,1.492)--(6.644,1.489)--(6.651,1.487)--(6.659,1.484)--(6.667,1.481)% - --(6.675,1.479)--(6.683,1.476)--(6.690,1.473)--(6.698,1.472)--(6.706,1.469)--(6.714,1.465)% - --(6.722,1.464)--(6.729,1.461)--(6.737,1.458)--(6.745,1.456)--(6.753,1.453)--(6.761,1.450)% - --(6.768,1.448)--(6.776,1.445)--(6.784,1.444)--(6.792,1.441)--(6.800,1.438)--(6.808,1.436)% - --(6.815,1.433)--(6.823,1.431)--(6.831,1.428)--(6.839,1.425)--(6.847,1.424)--(6.854,1.420)% - --(6.862,1.419)--(6.870,1.416)--(6.878,1.414)--(6.886,1.411)--(6.893,1.408)--(6.901,1.406)% - --(6.909,1.403)--(6.917,1.402)--(6.925,1.399)--(6.933,1.397)--(6.940,1.394)--(6.948,1.393)% - --(6.956,1.389)--(6.964,1.388)--(6.972,1.385)--(6.979,1.383)--(6.987,1.380)--(6.995,1.379)% - --(7.003,1.375)--(7.011,1.374)--(7.018,1.371)--(7.026,1.369)--(7.034,1.366)--(7.042,1.365)% - --(7.050,1.361)--(7.057,1.360)--(7.065,1.358)--(7.073,1.355)--(7.081,1.354)--(7.089,1.351)% - --(7.097,1.349)--(7.104,1.346)--(7.112,1.344)--(7.120,1.343)--(7.128,1.340)--(7.136,1.338)% - --(7.143,1.335)--(7.151,1.333)--(7.159,1.332)--(7.167,1.329)--(7.175,1.327)--(7.182,1.324)% - --(7.190,1.323)--(7.198,1.321)--(7.206,1.318)--(7.214,1.316)--(7.222,1.313)--(7.229,1.312)% - --(7.237,1.310)--(7.245,1.307)--(7.253,1.306)--(7.261,1.304)--(7.268,1.301)--(7.276,1.299)% - --(7.284,1.298)--(7.292,1.295)--(7.300,1.293)--(7.307,1.292)--(7.315,1.288)--(7.323,1.287)% - --(7.331,1.285)--(7.339,1.284)--(7.346,1.281)--(7.354,1.279)--(7.362,1.278)--(7.370,1.274)% - --(7.378,1.273)--(7.386,1.271)--(7.393,1.268)--(7.401,1.267)--(7.409,1.265)--(7.417,1.264)% - --(7.425,1.260)--(7.432,1.259)--(7.440,1.257)--(7.448,1.256)--(7.456,1.253)--(7.464,1.251)% - --(7.471,1.250)--(7.479,1.248)--(7.487,1.245)--(7.495,1.243)--(7.503,1.242)--(7.511,1.240)% - --(7.518,1.239)--(7.526,1.236)--(7.534,1.234)--(7.542,1.233)--(7.550,1.231)--(7.557,1.229)% - --(7.565,1.226)--(7.573,1.225)--(7.581,1.223)--(7.589,1.222)--(7.596,1.220)--(7.604,1.217)% - --(7.612,1.215)--(7.620,1.214)--(7.628,1.212)--(7.635,1.211)--(7.643,1.209)--(7.651,1.206)% - --(7.659,1.205)--(7.667,1.203)--(7.675,1.201)--(7.682,1.200)--(7.690,1.198)--(7.698,1.197)% - --(7.706,1.194)--(7.714,1.192)--(7.721,1.191)--(7.729,1.189)--(7.737,1.188)--(7.745,1.186)% - --(7.753,1.184)--(7.760,1.183)--(7.768,1.181)--(7.776,1.178)--(7.784,1.177)--(7.792,1.175)% - --(7.800,1.174)--(7.807,1.172)--(7.815,1.170)--(7.823,1.169)--(7.831,1.167)--(7.839,1.166)% - --(7.846,1.164)--(7.854,1.163)--(7.862,1.161)--(7.870,1.160)--(7.878,1.156)--(7.885,1.155)% - --(7.893,1.153)--(7.901,1.152)--(7.909,1.150)--(7.917,1.149)--(7.924,1.147)--(7.932,1.146)% - --(7.940,1.144)--(7.948,1.142)--(7.956,1.141)--(7.964,1.139)--(7.971,1.138)--(7.979,1.136)% - --(7.987,1.135)--(7.995,1.133)--(8.003,1.132)--(8.010,1.130)--(8.018,1.128)--(8.026,1.127)% - --(8.034,1.125)--(8.042,1.124)--(8.049,1.122)--(8.057,1.121)--(8.065,1.119)--(8.073,1.118)% - --(8.081,1.116)--(8.089,1.115)--(8.096,1.113)--(8.104,1.111)--(8.112,1.110)--(8.120,1.108)% - --(8.128,1.107)--(8.135,1.105)--(8.143,1.104)--(8.151,1.102)--(8.159,1.101)--(8.167,1.101)% - --(8.174,1.099)--(8.182,1.097)--(8.190,1.096)--(8.198,1.094)--(8.206,1.093)--(8.213,1.091)% - --(8.221,1.090)--(8.229,1.088)--(8.237,1.087)--(8.245,1.085)--(8.253,1.083)--(8.260,1.082)% - --(8.268,1.080)--(8.276,1.080)--(8.284,1.079)--(8.292,1.077)--(8.299,1.076)--(8.307,1.074)% - --(8.315,1.073)--(8.323,1.071)--(8.331,1.069)--(8.338,1.068)--(8.346,1.068)--(8.354,1.066)% - --(8.362,1.065)--(8.370,1.063)--(8.378,1.062)--(8.385,1.060)--(8.393,1.059)--(8.401,1.057)% - --(8.409,1.057)--(8.417,1.055)--(8.424,1.054)--(8.432,1.052)--(8.440,1.051)--(8.448,1.049)% - --(8.456,1.048)--(8.463,1.048)--(8.471,1.046)--(8.479,1.045)--(8.487,1.043)--(8.495,1.042)% - --(8.502,1.040)--(8.510,1.040)--(8.518,1.038)--(8.526,1.037)--(8.534,1.035)--(8.542,1.034)% - --(8.549,1.034)--(8.557,1.032)--(8.565,1.031)--(8.573,1.029)--(8.581,1.028)--(8.588,1.026)% - --(8.596,1.026)--(8.604,1.024)--(8.612,1.023)--(8.620,1.021)--(8.627,1.021)--(8.635,1.020)% - --(8.643,1.018)--(8.651,1.017)--(8.659,1.015)--(8.667,1.015)--(8.674,1.014)--(8.682,1.012)% - --(8.690,1.010)--(8.698,1.010)--(8.706,1.009)--(8.713,1.007)--(8.721,1.006)--(8.729,1.004)% - --(8.737,1.004)--(8.745,1.003)--(8.752,1.001)--(8.760,1.000)--(8.768,1.000)--(8.776,0.998)% - --(8.784,0.996)--(8.791,0.995)--(8.799,0.995)--(8.807,0.993)--(8.815,0.992)--(8.823,0.992)% - --(8.831,0.990)--(8.838,0.989)--(8.846,0.987)--(8.854,0.987)--(8.862,0.986)--(8.870,0.984)% - --(8.877,0.983)--(8.885,0.983)--(8.893,0.981)--(8.901,0.979)--(8.909,0.979)--(8.916,0.978)% - --(8.924,0.976)--(8.932,0.975)--(8.940,0.975)--(8.948,0.973)--(8.955,0.972)--(8.963,0.972)% - --(8.971,0.970)--(8.979,0.969)--(8.987,0.969)--(8.995,0.967)--(9.002,0.965)--(9.010,0.965)% - --(9.018,0.964)--(9.026,0.962)--(9.034,0.962)--(9.041,0.961)--(9.049,0.959)--(9.057,0.959)% - --(9.065,0.958)--(9.073,0.956)--(9.080,0.956)--(9.088,0.955)--(9.096,0.953)--(9.104,0.953)% - --(9.112,0.951)--(9.120,0.950)--(9.127,0.950)--(9.135,0.948)--(9.143,0.947)--(9.151,0.947)% - --(9.159,0.945)--(9.166,0.944)--(9.174,0.944)--(9.182,0.942)--(9.190,0.941)--(9.198,0.941)% - --(9.205,0.939)--(9.213,0.939)--(9.221,0.937)--(9.229,0.936)--(9.237,0.936)--(9.244,0.934)% - --(9.252,0.933)--(9.260,0.933)--(9.268,0.931)--(9.276,0.931)--(9.284,0.930)--(9.291,0.928)% - --(9.299,0.928)--(9.307,0.927)--(9.315,0.927)--(9.323,0.925)--(9.330,0.923)--(9.338,0.923)% - --(9.346,0.922)--(9.354,0.922)--(9.362,0.920)--(9.369,0.919)--(9.377,0.919)--(9.385,0.917)% - --(9.393,0.917)--(9.401,0.916)--(9.409,0.914)--(9.416,0.914)--(9.424,0.913)--(9.432,0.913)% - --(9.440,0.911)--(9.448,0.911)--(9.455,0.910)--(9.463,0.908)--(9.471,0.908)--(9.479,0.906)% - --(9.487,0.906)--(9.494,0.905)--(9.502,0.905)--(9.510,0.903)--(9.518,0.902)--(9.526,0.902)% - --(9.533,0.900)--(9.541,0.900)--(9.549,0.899)--(9.557,0.899)--(9.565,0.897)--(9.573,0.897)% - --(9.580,0.896)--(9.588,0.894)--(9.596,0.894)--(9.604,0.892)--(9.612,0.892)--(9.619,0.891)% - --(9.627,0.891)--(9.635,0.889)--(9.643,0.889)--(9.651,0.888)--(9.658,0.888)--(9.666,0.886)% - --(9.674,0.886)--(9.682,0.885)--(9.690,0.885)--(9.698,0.883)--(9.705,0.882)--(9.713,0.882)% - --(9.721,0.880)--(9.729,0.880)--(9.737,0.878)--(9.744,0.878)--(9.752,0.877)--(9.760,0.877)% - --(9.768,0.875)--(9.776,0.875)--(9.783,0.874)--(9.791,0.874)--(9.799,0.872)--(9.807,0.872)% - --(9.815,0.871)--(9.822,0.871)--(9.830,0.869)--(9.838,0.869)--(9.846,0.868)--(9.854,0.868)% - --(9.862,0.866)--(9.869,0.866)--(9.877,0.864)--(9.885,0.864)--(9.893,0.863)--(9.901,0.863)% - --(9.908,0.861)--(9.916,0.861)--(9.924,0.861)--(9.932,0.860)--(9.940,0.860)--(9.947,0.858)% - --(9.955,0.858)--(9.963,0.857)--(9.971,0.857)--(9.979,0.855)--(9.987,0.855)--(9.994,0.854)% - --(10.002,0.854)--(10.010,0.852)--(10.018,0.852)--(10.026,0.851)--(10.033,0.851)--(10.041,0.851)% - --(10.049,0.849)--(10.057,0.849)--(10.065,0.847)--(10.072,0.847)--(10.080,0.846)--(10.088,0.846)% - --(10.096,0.844)--(10.104,0.844)--(10.111,0.843)--(10.119,0.843)--(10.127,0.843)--(10.135,0.841)% - --(10.143,0.841)--(10.151,0.840)--(10.158,0.840)--(10.166,0.838)--(10.174,0.838)--(10.182,0.838)% - --(10.190,0.837)--(10.197,0.837)--(10.205,0.835)--(10.213,0.835)--(10.221,0.833)--(10.229,0.833)% - --(10.236,0.833)--(10.244,0.832)--(10.252,0.832)--(10.260,0.830)--(10.268,0.830)--(10.276,0.829)% - --(10.283,0.829)--(10.291,0.829)--(10.299,0.827)--(10.307,0.827)--(10.315,0.826)--(10.322,0.826)% - --(10.330,0.826)--(10.338,0.824)--(10.346,0.824)--(10.354,0.823)--(10.361,0.823)--(10.369,0.823)% - --(10.377,0.821)--(10.385,0.821)--(10.393,0.819)--(10.400,0.819)--(10.408,0.819)--(10.416,0.818)% - --(10.424,0.818)--(10.432,0.816)--(10.440,0.816)--(10.447,0.816)--(10.455,0.815)--(10.463,0.815)% - --(10.471,0.813)--(10.479,0.813)--(10.486,0.813)--(10.494,0.812)--(10.502,0.812)--(10.510,0.812)% - --(10.518,0.810)--(10.525,0.810)--(10.533,0.809)--(10.541,0.809)--(10.549,0.809)--(10.557,0.807)% - --(10.565,0.807)--(10.572,0.805)--(10.580,0.805)--(10.588,0.805)--(10.596,0.804)--(10.604,0.804)% - --(10.611,0.804)--(10.619,0.802)--(10.627,0.802)--(10.635,0.802)--(10.643,0.801)--(10.650,0.801)% - --(10.658,0.799)--(10.666,0.799)--(10.674,0.799)--(10.682,0.798)--(10.689,0.798)--(10.697,0.798)% - --(10.705,0.796)--(10.713,0.796)--(10.721,0.796)--(10.729,0.795)--(10.736,0.795)--(10.744,0.795)% - --(10.752,0.793)--(10.760,0.793)--(10.768,0.793)--(10.775,0.791)--(10.783,0.791)--(10.791,0.791)% - --(10.799,0.790)--(10.807,0.790)--(10.814,0.790)--(10.822,0.788)--(10.830,0.788)--(10.838,0.788)% - --(10.846,0.787)--(10.854,0.787)--(10.861,0.787)--(10.869,0.785)--(10.877,0.785)--(10.885,0.785)% - --(10.893,0.784)--(10.900,0.784)--(10.908,0.784)--(10.916,0.782)--(10.924,0.782)--(10.932,0.782)% - --(10.939,0.781)--(10.947,0.781)--(10.955,0.781)--(10.963,0.779)--(10.971,0.779)--(10.978,0.779)% - --(10.986,0.778)--(10.994,0.778)--(11.002,0.778)--(11.010,0.776)--(11.018,0.776)--(11.025,0.776)% - --(11.033,0.774)--(11.041,0.774)--(11.049,0.774)--(11.057,0.774)--(11.064,0.773)--(11.072,0.773)% - --(11.080,0.773)--(11.088,0.771)--(11.096,0.771)--(11.103,0.771)--(11.111,0.770)--(11.119,0.770)% - --(11.127,0.770)--(11.135,0.768)--(11.142,0.768)--(11.150,0.768)--(11.158,0.768)--(11.166,0.767)% - --(11.174,0.767)--(11.182,0.767)--(11.189,0.765)--(11.197,0.765)--(11.205,0.765)--(11.213,0.765)% - --(11.221,0.764)--(11.228,0.764)--(11.236,0.764)--(11.244,0.762)--(11.252,0.762)--(11.260,0.762)% - --(11.267,0.762)--(11.275,0.760)--(11.283,0.760)--(11.291,0.760)--(11.299,0.759)--(11.307,0.759)% - --(11.314,0.759)--(11.322,0.759)--(11.330,0.757)--(11.338,0.757)--(11.346,0.757); -\gpcolor{color=gp lt color border} -\draw[gp path] (1.012,8.381)--(1.012,0.616)--(11.947,0.616)--(11.947,8.381)--cycle; -%% coordinates of the plot area -\gpdefrectangularnode{gp plot 1}{\pgfpoint{1.012cm}{0.616cm}}{\pgfpoint{11.947cm}{8.381cm}} -\end{tikzpicture} -%% gnuplot variables diff --git a/20221121/logo-hochschule-bochum-cvh-text-v2.pdf b/20221121/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221121/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221121/logo-hochschule-bochum.pdf b/20221121/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221121/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221121/names.h b/20221121/names.h deleted file mode 100644 index a265ff4141a2cc578d3f6f402822a2dbbd5cea90..0000000000000000000000000000000000000000 --- a/20221121/names.h +++ /dev/null @@ -1,50 +0,0 @@ -"Michael", "Laura", -"Elias", "Julia", -"Luca", "Anna", -"Liam", "Emma", -"Alexander", "Lena", -"Noah", "Vanessa", -"Jonas", "Lea", -"Marcel", "Mila", -"Daniel", "Lisa", -"David", "Lina", -"Milan", "Sarah", -"Julian", "Alina", -"Linus", "Emilia", -"Thomas", "Nina", -"Samuel", "Elena", -"Levin", "Lara", -"Levi", "Melanie", -"Jan", "Hannah", -"Lukas", "Sandra", -"Tim", "Leonie", -"Patrick", "Sophie", -"Marvin", "Mia", -"Andreas", "Amelie", -"Leon", "Selina", -"Tobias", "Luisa", -"Simon", "Maria", -"Valentin", "Jana", -"Robin", "Johanna", -"Paul", "Marie", -"Markus", "Milena", -"Benjamin", "Melina", -"Stefan", "Michelle", -"Felix", "Emily", -"Florian", "Renesmee", -"Fabian", "Aylin", -"Emil", "Jessica", -"Aaron", "Franziska", -"Manuel", "Jasmin", -"Christian", "Fiona", -"Dominik", "Sina", -"Joshua", "Jennifer", -"Moritz", "Claudia", -"Sebastian", "Nicole", -"Peter", "Annika", -"Philipp", "Sophia", -"Max", "Katharina", -"Johannes", "Isabella", -"Finn", "Nele", -"Adrian", "Elisabeth", -"Martin", "Pia", diff --git a/20221121/pendulum.pdf b/20221121/pendulum.pdf deleted file mode 120000 index 7d1d87305cdb8840a248ff2207538d758464f452..0000000000000000000000000000000000000000 --- a/20221121/pendulum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/pendulum.pdf \ No newline at end of file diff --git a/20221121/pgscript.sty b/20221121/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221121/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221121/pgslides.sty b/20221121/pgslides.sty deleted file mode 120000 index 5be1416f4216f076aa268901f52a15d775e43f64..0000000000000000000000000000000000000000 --- a/20221121/pgslides.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgslides.sty \ No newline at end of file diff --git a/20221121/qsort-1.c b/20221121/qsort-1.c deleted file mode 100644 index c5431b853862e62812016f4fd3a031eeb0b5c9df..0000000000000000000000000000000000000000 --- a/20221121/qsort-1.c +++ /dev/null @@ -1,70 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, char *pivot, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (name[i] == pivot) - printf (" <=="); - else if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, char *pivot, int left, int right) -{ - int result = strcmp (name[left], pivot); - comparisons++; - display (name, pivot, left, right); - usleep (200000); - return result; -} - -void quicksort (char **name, int left, int right) -{ - int p = (left + right) / 2; - char *pivot = name[p]; - int l = left; - int r = right; - while (l < r) - { - while (l < r && compare (name, pivot, l, r - 1) < 0) - l++; - while (l < r && compare (name, pivot, r - 1, l) > 0) - r--; - if (l < r) - { - char *temp = name[r - 1]; - name[r - 1] = name[l]; - name[l] = temp; - l++; - r--; - } - } -} - -void sort (char **name) -{ - int r = 0; - while (name[r]) - r++; - quicksort (name, 0, r); -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, NULL, -1, -1); - return 0; -} diff --git a/20221121/qsort-1a.c b/20221121/qsort-1a.c deleted file mode 100644 index a3d4d0011834aa3d85907c2a0d0e90e3bf80799e..0000000000000000000000000000000000000000 --- a/20221121/qsort-1a.c +++ /dev/null @@ -1,70 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, char *pivot, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (name[i] == pivot) - printf (" <=="); - else if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, char *pivot, int left, int right) -{ - int result = strcmp (name[left], pivot); - comparisons++; - display (name, pivot, left, right); - usleep (200000); - return result; -} - -void quicksort (char **name, int left, int right) -{ - int p = (left + right) / 2 - 1; - char *pivot = name[p]; - int l = left; - int r = right; - while (l < r) - { - while (l < r && compare (name, pivot, l, r - 1) < 0) - l++; - while (l < r && compare (name, pivot, r - 1, l) > 0) - r--; - if (l < r) - { - char *temp = name[r - 1]; - name[r - 1] = name[l]; - name[l] = temp; - l++; - r--; - } - } -} - -void sort (char **name) -{ - int r = 0; - while (name[r]) - r++; - quicksort (name, 0, r); -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, NULL, -1, -1); - return 0; -} diff --git a/20221121/qsort-2.c b/20221121/qsort-2.c deleted file mode 100644 index cfdc2ec11a92a4292c9443e01453cce818e9e73a..0000000000000000000000000000000000000000 --- a/20221121/qsort-2.c +++ /dev/null @@ -1,72 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, char *pivot, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (name[i] == pivot) - printf (" <=="); - else if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, char *pivot, int left, int right) -{ - int result = strcmp (name[left], pivot); - comparisons++; - display (name, pivot, left, right); - usleep (200000); - return result; -} - -void quicksort (char **name, int left, int right) -{ - int p = (left + right) / 2; - char *pivot = name[p]; - int l = left; - int r = right; - while (l < r) - { - while (l < r && compare (name, pivot, l, r - 1) < 0) - l++; - while (l < r && compare (name, pivot, r - 1, l) > 0) - r--; - if (l < r) - { - char *temp = name[r - 1]; - name[r - 1] = name[l]; - name[l] = temp; - l++; - r--; - } - } - if (l < right) - quicksort (name, l, right); -} - -void sort (char **name) -{ - int r = 0; - while (name[r]) - r++; - quicksort (name, 0, r); -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, NULL, -1, -1); - return 0; -} diff --git a/20221121/qsort-3.c b/20221121/qsort-3.c deleted file mode 100644 index e6b7d9909473af6d8c13d3745dc6b07e8ea75699..0000000000000000000000000000000000000000 --- a/20221121/qsort-3.c +++ /dev/null @@ -1,74 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, char *pivot, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (name[i] == pivot) - printf (" <=="); - else if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, char *pivot, int left, int right) -{ - int result = strcmp (name[left], pivot); - comparisons++; - display (name, pivot, left, right); - usleep (200000); - return result; -} - -void quicksort (char **name, int left, int right) -{ - int p = (left + right) / 2; - char *pivot = name[p]; - int l = left; - int r = right; - while (l < r) - { - while (l < r && compare (name, pivot, l, r - 1) < 0) - l++; - while (l < r && compare (name, pivot, r - 1, l) > 0) - r--; - if (l < r) - { - char *temp = name[r - 1]; - name[r - 1] = name[l]; - name[l] = temp; - l++; - r--; - } - } - if (r > left) - quicksort (name, left, r); - if (l < right) - quicksort (name, l, right); -} - -void sort (char **name) -{ - int r = 0; - while (name[r]) - r++; - quicksort (name, 0, r); -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, NULL, -1, -1); - return 0; -} diff --git a/20221121/qsort-3.txt b/20221121/qsort-3.txt deleted file mode 100644 index e6db54a62799d42b0328a7ba75d80615aec5164b..0000000000000000000000000000000000000000 --- a/20221121/qsort-3.txt +++ /dev/null @@ -1,16 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221121> bc -bc 1.07.1 -Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc. -This is free software with ABSOLUTELY NO WARRANTY. -For details type `warranty'. - -16 / 2 -8 -8 / 2 -4 -4 / 2 -2 -2 / 2 -1 - -cassini/home/peter/bo/2022ws/hp/20221121> diff --git a/20221121/qsort-3a.c b/20221121/qsort-3a.c deleted file mode 100644 index ef4d709f21246b7d8e604dc56047483216f837b8..0000000000000000000000000000000000000000 --- a/20221121/qsort-3a.c +++ /dev/null @@ -1,74 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, char *pivot, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (name[i] == pivot) - printf (" <=="); - else if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, char *pivot, int left, int right) -{ - int result = strcmp (name[left], pivot); - comparisons++; - display (name, pivot, left, right); - usleep (200000); - return result; -} - -void quicksort (char **name, int left, int right) -{ - int p = (left + right) / 2; - char *pivot = name[p]; - int l = left; - int r = right; - while (l < r) - { - while (l < r && compare (name, pivot, l, r - 1) < 0) - l++; - while (l < r && compare (name, pivot, r - 1, l) > 0) - r--; - if (l < r) - { - char *temp = name[r - 1]; - name[r - 1] = name[l]; - name[l] = temp; - l++; - r--; - } - } - if (r > left) - quicksort (name, left, r); - if (l < right) - quicksort (name, l, right); -} - -void sort (char **name) -{ - int r = 0; - while (name[r]) - r++; - quicksort (name, 0, r); -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Berta", "Hugo", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, NULL, -1, -1); - return 0; -} diff --git a/20221121/qsort-3b.c b/20221121/qsort-3b.c deleted file mode 100644 index 333d7f000b82d8f7708272103ca58442c2165bc3..0000000000000000000000000000000000000000 --- a/20221121/qsort-3b.c +++ /dev/null @@ -1,75 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, char *pivot, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (name[i] == pivot) - printf (" <=="); - else if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, char *pivot, int left, int right) -{ - int result = strcmp (name[left], pivot); - comparisons++; -// display (name, pivot, left, right); -// usleep (200000); - return result; -} - -void quicksort (char **name, int left, int right) -{ - int p = (left + right) / 2; - char *pivot = name[p]; - int l = left; - int r = right; - while (l < r) - { - while (l < r && compare (name, pivot, l, r - 1) < 0) - l++; - while (l < r && compare (name, pivot, r - 1, l) > 0) - r--; - if (l < r) - { - char *temp = name[r - 1]; - name[r - 1] = name[l]; - name[l] = temp; - l++; - r--; - } - } - if (r > left) - quicksort (name, left, r); - if (l < right) - quicksort (name, l, right); -} - -void sort (char **name) -{ - int r = 0; - while (name[r]) - r++; - quicksort (name, 0, r); -} - -int main (void) -{ - char *name[] = { - #include "names.h" - NULL - }; - sort (name); - display (name, NULL, -1, -1); - return 0; -} diff --git a/20221121/qsort-3b.txt b/20221121/qsort-3b.txt deleted file mode 100644 index 9b48b9628ed885419183ba3b4d786e8754b7fc9e..0000000000000000000000000000000000000000 --- a/20221121/qsort-3b.txt +++ /dev/null @@ -1,6 +0,0 @@ -cassini/home/peter/bo/2022ws/hp/20221121> ./sort-6 | tail -1 -4950 -cassini/home/peter/bo/2022ws/hp/20221121> ./bsort-4c | tail -1 -4792 -cassini/home/peter/bo/2022ws/hp/20221121> ./qsort-3b | tail -1 -1130 diff --git a/20221121/sort-0.c b/20221121/sort-0.c deleted file mode 100644 index 70e0e717cbfd42a27bf90f419c216fa18b0783c7..0000000000000000000000000000000000000000 --- a/20221121/sort-0.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> - -int find_first (char **name) -{ - return 2; -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - int first = find_first (name); - printf ("%s\n", name[first]); - return 0; -} diff --git a/20221121/sort-1.c b/20221121/sort-1.c deleted file mode 100644 index 3f009d45657f84e462db48a67fa22821819216ad..0000000000000000000000000000000000000000 --- a/20221121/sort-1.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <stdio.h> -#include <string.h> - -int find_first (char **name) -{ - int first = 0; - for (int i = 1; name[i]; i++) - if (strcmp (name[i], name[first]) < 0) - first = i; - return first; -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - int first = find_first (name); - printf ("%s\n", name[first]); - return 0; -} diff --git a/20221121/sort-2.c b/20221121/sort-2.c deleted file mode 100644 index 638e6e2caa670ceace0a854d0827292dfcb59ca5..0000000000000000000000000000000000000000 --- a/20221121/sort-2.c +++ /dev/null @@ -1,46 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -int find_first (char **name) -{ - int first = 0; - for (int i = 1; name[i]; i++) - if (compare (name, i, first) < 0) - first = i; - return first; -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - int first = find_first (name); - display (name, first, -1); - return 0; -} diff --git a/20221121/sort-3.c b/20221121/sort-3.c deleted file mode 100644 index 430a6fc0e95fcb9bc225e3572566c8d187016130..0000000000000000000000000000000000000000 --- a/20221121/sort-3.c +++ /dev/null @@ -1,46 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -int find_first (char **name, int i0) -{ - int first = i0; - for (int i = i0 + 1; name[i]; i++) - if (compare (name, i, first) < 0) - first = i; - return first; -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - int first = find_first (name, 0); - display (name, first, -1); - return 0; -} diff --git a/20221121/sort-4.c b/20221121/sort-4.c deleted file mode 100644 index 19d4f416a2d30c5181ad289fe1d0dcba91ee81cf..0000000000000000000000000000000000000000 --- a/20221121/sort-4.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -int find_first (char **name, int i0) -{ - int first = i0; - for (int i = i0 + 1; name[i]; i++) - if (compare (name, i, first) < 0) - first = i; - return first; -} - -void sort (char **name) -{ - int sorted = 0; - while (name[sorted]) - { - int first = find_first (name, sorted); - char *temp = name[sorted]; - name[sorted] = name[first]; - name[first] = temp; - sorted++; - } -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/sort-5.c b/20221121/sort-5.c deleted file mode 100644 index f0742bc8665d0b13edf4ad4ad3fe4790c1e6b929..0000000000000000000000000000000000000000 --- a/20221121/sort-5.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200); - return result; -} - -int find_first (char **name, int i0) -{ - int first = i0; - for (int i = i0 + 1; name[i]; i++) - if (compare (name, i, first) < 0) - first = i; - return first; -} - -void sort (char **name) -{ - int sorted = 0; - while (name[sorted]) - { - int first = find_first (name, sorted); - char *temp = name[sorted]; - name[sorted] = name[first]; - name[first] = temp; - sorted++; - } -} - -int main (void) -{ - char *name[] = { - #include "names.h" - NULL - }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/sort-6.c b/20221121/sort-6.c deleted file mode 100644 index 94a1a16abfacda7bb728f8d3317cd00b4cf8ccde..0000000000000000000000000000000000000000 --- a/20221121/sort-6.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; -// display (name, left, right); -// usleep (200); - return result; -} - -int find_first (char **name, int i0) -{ - int first = i0; - for (int i = i0 + 1; name[i]; i++) - if (compare (name, i, first) < 0) - first = i; - return first; -} - -void sort (char **name) -{ - int sorted = 0; - while (name[sorted]) - { - int first = find_first (name, sorted); - char *temp = name[sorted]; - name[sorted] = name[first]; - name[first] = temp; - sorted++; - } -} - -int main (void) -{ - char *name[] = { - #include "names.h" - NULL - }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221121/sort-7.c b/20221121/sort-7.c deleted file mode 100644 index 46132dd247a061dda0e5ebade9c5b818a1a74fcb..0000000000000000000000000000000000000000 --- a/20221121/sort-7.c +++ /dev/null @@ -1,53 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -int comparisons = 0; - -void display (char **name, int left, int right) -{ - printf ("\e[H\e[J"); - for (int i = 0; name[i]; i++) - { - printf ("%s", name[i]); - if (i == left || i == right) - printf (" <--"); - printf ("\n"); - } - printf ("%d\n", comparisons); -} - -int compare (char **name, int left, int right) -{ - int result = strcmp (name[left], name[right]); - comparisons++; - display (name, left, right); - usleep (200000); - return result; -} - -void sort (char **name) -{ - int sorted = 0; - while (name[sorted]) - { - int first = sorted; - for (int i = sorted + 1; name[i]; i++) - if (compare (name, i, first) < 0) - first = i; - char *temp = name[sorted]; - name[sorted] = name[first]; - name[first] = temp; - sorted++; - } -} - -int main (void) -{ - char *name[] = { "Otto", "Lisa", "Anna", "Heinrich", "Siegfried", "Peter", - "Dieter", "Hugo", "Berta", "Maria", "Fritz", "Box", "Hans", - "Thomas", "Ulrich", "Zacharias", NULL }; - sort (name); - display (name, -1, -1); - return 0; -} diff --git a/20221128/Tower_of_Hanoi.jpeg b/20221128/Tower_of_Hanoi.jpeg deleted file mode 120000 index a1a794afda08596ffa2f46f278db53455de25b6c..0000000000000000000000000000000000000000 --- a/20221128/Tower_of_Hanoi.jpeg +++ /dev/null @@ -1 +0,0 @@ -../common/Tower_of_Hanoi.jpeg \ No newline at end of file diff --git a/20221128/aufgabe-1.c b/20221128/aufgabe-1.c deleted file mode 100644 index 15c90561b94d5a0c1a136f0e6479d3633dc242b1..0000000000000000000000000000000000000000 --- a/20221128/aufgabe-1.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void insert_into_string (char src, char *target, int pos) -{ - int len = strlen (target); - for (int i = pos; i < len; i++) - target[i + 1] = target[i]; - target[pos] = src; -} - -int main (void) -{ - char test[100] = "Hochshule Bochum"; - insert_into_string ('c', test, 5); - printf ("%s\n", test); - return 0; -} diff --git a/20221128/aufgabe-3a.c b/20221128/aufgabe-3a.c deleted file mode 100644 index 61b6e79400afbb8ac0609eb1b72c04b83a0fce41..0000000000000000000000000000000000000000 --- a/20221128/aufgabe-3a.c +++ /dev/null @@ -1,50 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int wings; -} with_wings; - -typedef struct with_legs -{ - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - a[0]->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - a[1]->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; -} diff --git a/20221128/aufgabe-3b.c b/20221128/aufgabe-3b.c deleted file mode 100644 index 2cf3b56f4540f399d3761b0de929d80a1f1de611..0000000000000000000000000000000000000000 --- a/20221128/aufgabe-3b.c +++ /dev/null @@ -1,50 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int wings; -} with_wings; - -typedef struct with_legs -{ - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - ((with_wings *) a[0])->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; -} diff --git a/20221128/dynmem-01.c b/20221128/dynmem-01.c deleted file mode 100644 index 0ffe355084006090fc13a895516ab80938df25be..0000000000000000000000000000000000000000 --- a/20221128/dynmem-01.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -char *name[] = { "Anna", "Berthold", "Caesar" }; - -int main (void) -{ - name[3] = "Dieter"; - for (int i = 0; i < 4; i++) - printf ("%s\n", name[i]); - return 0; -} diff --git a/20221128/dynmem-02.c b/20221128/dynmem-02.c deleted file mode 100644 index d8f71409680d6ecfd8ae175cc44aa2ab3d28fc15..0000000000000000000000000000000000000000 --- a/20221128/dynmem-02.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -int main (void) -{ - char **name = malloc (3 * sizeof (char *)); /* Speicherplatz für 3 Zeiger anfordern */ - name[0] = "Anna"; - name[1] = "Berthold"; - name[2] = "Caesar"; - name[3] = "Dieter"; /* immer noch unzulässig */ - for (int i = 0; i < 4; i++) - printf ("%s\n", name[i]); - free (name); - return 0; -} diff --git a/20221128/dynmem-03.c b/20221128/dynmem-03.c deleted file mode 100644 index d4edee601a4fb7f5e796964e287f7856e78bad7a..0000000000000000000000000000000000000000 --- a/20221128/dynmem-03.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -int main (void) -{ - char **name = malloc (3 * sizeof (char *)); /* Speicherplatz für 3 Zeiger anfordern */ - name[0] = "Anna"; - name[1] = "Berthold"; - name[2] = "Caesar"; -// name[3] = "Dieter"; /* immer noch unzulässig */ - for (int i = 0; i < 4; i++) - printf ("%s\n", name[i]); - free (name); - return 0; -} diff --git a/20221128/dynmem-04.c b/20221128/dynmem-04.c deleted file mode 100644 index 5b154ef182bed0c1c32c7d454a34a22a94fcb44c..0000000000000000000000000000000000000000 --- a/20221128/dynmem-04.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -int main (void) -{ - char **name = malloc (3 * sizeof (char *)); /* Speicherplatz für 3 Zeiger anfordern */ - name[0] = "Anna"; - name[1] = "Berthold"; - name[2] = "Caesar"; - - char **new_name = malloc (4 * sizeof (char *)); /* Speicherplatz für 4 Zeiger anfordern */ - for (int i = 0; i < 3; i++) - new_name[i] = name[i]; - new_name[3] = "Dieter"; - - free (name); /* altes Array */ - name = new_name; /* alter Zeiger zeigt auf neues Array */ - - for (int i = 0; i < 4; i++) - printf ("%s\n", name[i]); - free (name); - return 0; -} diff --git a/20221128/dynmem-05.c b/20221128/dynmem-05.c deleted file mode 100644 index fc53998df034d3b3c06a87a9372be2daf9c71aae..0000000000000000000000000000000000000000 --- a/20221128/dynmem-05.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -int main (void) -{ - char **name = malloc (3 * sizeof (char *)); /* Speicherplatz für 3 Zeiger anfordern */ - name[0] = "Anna"; - name[1] = "Berthold"; - name[2] = "Caesar"; - - char **new_name = malloc (4 * sizeof (char *)); /* Speicherplatz für 4 Zeiger anfordern */ - for (int i = 0; i < 3; i++) - new_name[i] = name[i]; - new_name[3] = "Dieter"; - - free (name); /* altes Array */ - name = new_name; /* alter Zeiger zeigt auf neues Array */ - - for (int i = 0; i < 4; i++) - printf ("%s\n", name[i]); - free (name); - free (new_name); /* zeigt auf denselben Speicherplatz wie name --> Fehler */ - return 0; -} diff --git a/20221128/dynmem-06.c b/20221128/dynmem-06.c deleted file mode 100644 index 226f12f62f02dafed072eefe32503188168bb668..0000000000000000000000000000000000000000 --- a/20221128/dynmem-06.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -int main (void) -{ - char **name = malloc (3 * sizeof (char *)); /* Speicherplatz für 3 Zeiger anfordern */ - name[0] = "Anna"; - name[1] = "Berthold"; - name[2] = "Caesar"; - - name = realloc (name, 4 * sizeof (char *)); /* Speicherplatz für 4 Zeiger anfordern */ - name[3] = "Dieter"; - - for (int i = 0; i < 4; i++) - printf ("%s\n", name[i]); - free (name); - return 0; -} diff --git a/20221128/hp-20221128.pdf b/20221128/hp-20221128.pdf deleted file mode 100644 index 8c19cf5a2cea843243b7344dc1e90292e199391c..0000000000000000000000000000000000000000 Binary files a/20221128/hp-20221128.pdf and /dev/null differ diff --git a/20221128/hp-20221128.tex b/20221128/hp-20221128.tex deleted file mode 100644 index dcbe6a043b09312d2d53acfd65826631a7ff6270..0000000000000000000000000000000000000000 --- a/20221128/hp-20221128.tex +++ /dev/null @@ -1,986 +0,0 @@ -% hp-20221128.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Objektorientierte Programmierung - -\documentclass[10pt,t]{beamer} - -\usepackage{pgslides} -\usepackage{pdftricks} -\usepackage{tikz} -\usepackage{rotating} - -\begin{psinputs} - \usepackage[utf8]{inputenc} - \usepackage[german]{babel} - \usepackage[T1]{fontenc} - \usepackage{helvet} - \renewcommand*\familydefault{\sfdefault} - \usepackage{pstricks,pst-grad} -\end{psinputs} - -\newcommand{\redurl}[1]{\href{#1}{\color{red}\nolinkurl{#1}}} - -\title{Hardwarenahe Programmierung} -\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{28.\ November 2022} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \begin{itemize} - \item[5.1] Differentialgleichungen - \item[5.2] Rekursion - \color{medgreen} - \item[5.3] Aufwandsabschätzungen - \end{itemize} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \begin{itemize} - \color{red} - \item[6.0] Dynamische Speicherverwaltung - \color{orange} - \item[6.1] Konzepte und Ziele - \color{red} - \item[6.2] Beispiel: Zahlen und Buchstaben - \item[6.3] Unions - \item[6.4] Virtuelle Methoden - \color{black} - \item[6.5] Beispiel: Graphische Benutzeroberfläche (GUI) - \item[6.6] Ausblick: C++ - \end{itemize} - \item[\textbf{7}] \textbf{Datenstrukturen} - \end{itemize} - \vspace*{-1cm} - -\end{frame} - -\setcounter{section}{4} -\section{Algorithmen} -\setcounter{subsection}{1} -\subsection{Rekursion} - -\begin{frame}[fragile] - - \showsubsection - - Vollständige Induktion: - \vspace*{-0.725cm} - \begin{displaymath} - \hspace*{4cm} - \left. - \begin{array}{r} - \mbox{Aussage gilt für $n = 1$}\\[2pt] - \mbox{Schluß von $n - 1$ auf $n$} - \end{array} - \right\} - \mbox{Aussage gilt für alle $n\in\mathbb{N}$} - \end{displaymath} - \vspace*{-0.5cm} - -% \pause - - Türme von Hanoi - - \begin{onlyenv}<1> - \begin{center} - \includegraphics[width=12.2cm]{Tower_of_Hanoi.jpeg} - \end{center} - \end{onlyenv} - - \begin{onlyenv}<2-> - \begin{itemize} - \item - 64 Scheiben, 3 Plätze, - \only<2>{\hfill\makebox(0,0)[rt]{\includegraphics[width=6cm]{Tower_of_Hanoi.jpeg}}}\\ - immer 1 Scheibe verschieben - \item - Ziel: Turm verschieben - \item - Es dürfen nur kleinere Scheiben\\ - auf größeren liegen. - \bigskip -% \pause - \pause - \item - $n = 1$ Scheibe: fertig - \item - Wenn $n - 1$ Scheiben verschiebbar:\\ - schiebe $n - 1$ Scheiben auf Hilfsplatz,\\ - verschiebe die darunterliegende,\\ - hole $n - 1$ Scheiben von Hilfsplatz - \end{itemize} - \begin{onlyenv}<3> - \vspace{-4.3cm} - \begin{lstlisting}[gobble=8,xleftmargin=6.4cm] - void move (int from, int to, int disks) - { - if (disks == 1) - move_one_disk (from, to); - else - { - int help = 0 + 1 + 2 - from - to; - move (from, help, disks - 1); - move (from, to, 1); - move (help, to, disks - 1); - } - } - \end{lstlisting} - \end{onlyenv} - \begin{onlyenv}<4-> - \vspace{-5.0cm} - \hspace*{7.4cm}\begin{minipage}[t]{5cm} - 32 Scheiben: - \begin{lstlisting}[gobble=10,style=terminal] - $ ¡time ./hanoi-9b¿ - ... - real 0m30,672s - user 0m30,662s - sys 0m0,008s - \end{lstlisting} -% \pause[7] - \begin{itemize} - \arrowitem - etwas über 1 Minute\\ - für 64 Scheiben - \end{itemize} -% \pause - \vspace*{-0.5cm} - \begin{picture}(0,0) - \color{red} - \put(0,0){\makebox(0,0)[bl]{\tikz[line width=1pt]{\draw(0,0)--(4,0.8);}}} - \put(0,0.8){\makebox(0,0)[tl]{\tikz[line width=1pt]{\draw(0,0)--(4,-0.8);}}} - \end{picture} - - Für jede zusätzliche Scheibe\\verdoppelt sich die Rechenzeit! - % 30.672 * 2^32 / 3600 / 24 / 365.25 = 4174.43775518138261464750 - \begin{itemize} - \arrowitem - $\frac{30,672\,\text{s}\,\cdot\,2^{32}}{3600\,\cdot\,24\,\cdot\,365,25} \approx 4174$ - Jahre\\[\smallskipamount] - für 64 Scheiben - \end{itemize} - \end{minipage} - \end{onlyenv} - \end{onlyenv} - -\end{frame} - -\subsection{Aufwandsabschätzungen \protect\color{gray}-- Komplexitätsanalyse} - -\begin{frame}[fragile] - -% \newcommand{\w}{\hspace*{0.75pt}} - - \showsubsection - - \begin{picture}(0,0) - \put(7.6,-0.5){% - \begin{minipage}[t]{5.3cm} -% \vspace*{-1.0cm}\includegraphics{landau-symbols.pdf} - \vspace*{-1.0cm}\alt<5->{\includegraphics{landau-symbols-3.pdf}}% - {\alt<4->{\includegraphics{landau-symbols-2.pdf}}% - {\includegraphics{landau-symbols.pdf}}} - \small - \begin{description}\itemsep0pt\leftskip-0.5cm - \item[$n$:] Eingabedaten - \item[$g(n)$:] Rechenzeit - \end{description} - \end{minipage}} - \end{picture} - - \vspace*{-\bigskipamount} - - Wann ist ein Programm "`schnell"'? - - \medskip - - \begin{onlyenv}<1> - Türme von Hanoi: $\mathcal{O}(2^n)$ - \par\medskip - Für jede zusätzliche Scheibe\\verdoppelt sich die Rechenzeit! - \begin{itemize} - \arrowitem - $\frac{30,672\,\text{s}\,\cdot\,2^{32}}{3600\,\cdot\,24\,\cdot\,365,25} \approx 4174$ - Jahre\\[\smallskipamount] - für 64 Scheiben - \end{itemize} - - \bigskip - \end{onlyenv} - - \begin{onlyenv}<1-> - Faustregel:\\Schachtelung der Schleifen zählen\\ - $k$ Schleifen ineinander \textarrow\ $\mathcal{O}(n^k)$ - - \bigskip - \end{onlyenv} - - \begin{onlyenv}<2> - \textbf{Beispiel: Sortieralgorithmen} - - \smallskip - - Anzahl der Vergleiche bei $n$ Strings - \begin{itemize} - \item - Maximum suchen mit Schummeln: $\mathcal{O}(1)$ -% \pause - \item - Maximum suchen: $\mathcal{O}(n)$ -% \pause - \item - Selection-Sort: $\mathcal{O}(n^2)$ -% \pause - \item - Bubble-Sort: $\mathcal{O}(n)$ bis $\mathcal{O}(n^2)$ -% \pause - \item - Quicksort: $\mathcal{O}(n\log n)$ bis $\mathcal{O}(n^2)$ - \end{itemize} - - \end{onlyenv} - - \begin{onlyenv}<3> - \textbf{Wie schnell ist RSA-Verschlüsselung?} - - \smallskip - - \begin{math} - c = m^e\,\%\,N - \end{math} - \quad - ("`$\%$"' = "`modulo"') - - \medskip - - \begin{lstlisting}[gobble=6,xleftmargin=2em] - int c = 1; - for (int i = 0; i < e; i++) - c = (c * m) % N; - \end{lstlisting} - - \smallskip - - \begin{itemize} - \item - $\mathcal{O}(e)$ Iterationen -% \item -% wenn $n$ die Anzahl der Binärziffern (Bits) von $e$ ist: -% $\mathcal{O}(2^n)$ Iterationen - \item - mit Trick: - $\mathcal{O}(\log e)$ Iterationen ($\log e$ = Anzahl der Ziffern von $e$) - \end{itemize} - - \smallskip - - Jede Iteration enthält eine Multiplikation und eine Division.\\ - Aufwand dafür: $\mathcal{O}(\log e)$\\ - \textarrow\ Gesamtaufwand: $\mathcal{O}\bigl((\log e)^2\bigr)$ - - \end{onlyenv} - - \begin{onlyenv}<4-> - - \textbf{Wie schnell ist RSA?}\\ - - \smallskip - - ($n$ = typische beteiligte Zahl, z.\,B. $e,p,q$) - - \begin{itemize} - \item - Ver- und Entschlüsselung (Exponentiation):\\ - \strut\hbox to 3.5cm{\color{red}$\mathcal{O}\!\left((\log n)^2\right)$\hss} - \only<5->{{\color{magenta}$\mathcal{O}(n^2)$}} - \item - Schlüsselerzeugung (Berechnung von $d$):\\ - \strut\hbox to 3.5cm{\color{red}$\mathcal{O}\!\left((\log n)^2\right)$\hss} - \only<5->{{\color{magenta}$\mathcal{O}(n^2)$}} - \item - Verschlüsselung brechen (Primfaktorzerlegung):\\ - \strut\hbox to 3.5cm{\color{red}$\mathcal{O}\bigl(2^{\sqrt{\log n\,\cdot\,\log\log n}}\bigr)$\hss} - \only<5->{{\color{magenta}$\mathcal{O}\bigl(2^{\sqrt{n\log n}}\bigr)$}} - \end{itemize} - - \vspace{0cm plus 1filll} - - \textbf{Die Sicherheit von RSA beruht darauf, - daß das Brechen der Verschlüsselung aufwendiger ist als - \boldmath$\mathcal{O}\bigl((\log n)^k\bigr)$ (für beliebiges $k$).} - - \vspace*{0.65cm} - - \end{onlyenv} - -\end{frame} - -\section{Objektorientierte Programmierung} - -\addtocounter{subsection}{-1} -\subsection{Dynamische Speicherverwaltung} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \begin{itemize} - \item - Array: feste Anzahl von Elementen desselben Typs (z.\,B.\ 3 ganze Zahlen) - \item - Dynamisches Array: variable Anzahl von Elementen desselben Typs - \end{itemize} - - \bigskip - - \begin{lstlisting} - char *name[] = { "Anna", "Berthold", "Caesar" }; - - ... - - name[3] = "Dieter"; - \end{lstlisting} - - \begin{picture}(0,0) - \color{red} - \put(0,0){\line(3,1){3.5}} - \put(0,1){\line(3,-1){3.5}} - \end{picture} - -\end{frame} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \bigskip - - \begin{lstlisting} - #include <stdlib.h> - - ... - - char **name = malloc (3 * sizeof (char *)); - /* Speicherplatz für 3 Zeiger anfordern */ - - ... - - free (name); - /* Speicherplatz freigeben */ - - \end{lstlisting} - -\end{frame} - -\subsection{Konzepte und Ziele} - -\begin{frame} - - \showsection - \showsubsection - - \begin{itemize} - \item -% Array: feste Anzahl von Elementen desselben Typs (z.\,B.\ 3 ganze Zahlen) - Array: Elemente desselben Typs (z.\,B.\ 3 ganze Zahlen) -% \item -% Dynamisches Array: variable Anzahl von Elementen desselben Typs - \item - Problem: Elemente unterschiedlichen Typs - \item - Lösung: den Typ des Elements zusätzlich speichern \textarrow\ \newterm{Objekt} - \item - Problem: Die Elemente sind unterschiedlich groß (Speicherplatz). - \item - Lösung: Im Array nicht die Objekte selbst speichern, sondern Zeiger darauf. - \end{itemize} - \begin{itemize} - \item - Funktionen, die mit dem Objekt arbeiten: \newterm{Methoden} - \begin{onlyenv}<1> - \item - Was die Funktion bewirkt,\\ - hängt vom Typ des Objekts ab - \item - Realisierung über endlose \lstinline{if}-Ketten - \end{onlyenv} - \begin{onlyenv}<2> - \item - Was die Funktion bewirkt - \begin{picture}(0,0) - \color{red} - \put(-4.00,-0.05){\tikz{\draw[thick](0,0.25)--(3.75,-0.05);% - \draw[thick](-0.1,-0.05)--(3.75,0.3);}} - \end{picture}% - Welche Funktion aufgerufen wird,\\ - hängt vom Typ des Objekts ab: \newterm{virtuelle Methode} - \item - Realisierung über endlose \lstinline{if}-Ketten% - \begin{picture}(0,0) - \color{red} - \put(-2.75,-0.05){\tikz{\draw[thick](0,0.25)--(2.5,-0.05);% - \draw[thick](-0.1,-0.05)--(2.5,0.3);}} - \put(1.5,-1.1){\begin{rotate}{7}\large\bf\textarrow\ - kommt gleich -% nächste Woche - \end{rotate}} - \end{picture} - Zeiger, die im Objekt gespeichert sind\\ - (Genaugenommen: Tabelle von Zeigern) - \end{onlyenv} - \end{itemize} - -\end{frame} - -\begin{frame} - - \showsection - \showsubsection - - \begin{itemize} - \item - Problem: Elemente unterschiedlichen Typs - \item - Lösung: den Typ des Elements zusätzlich speichern \textarrow\ \newterm{Objekt} - \item - \newterm{Methoden\/} und \newterm{virtuelle Methoden} - \end{itemize} - - \begin{itemize} - \item - Zeiger auf verschiedene Strukturen\\ - mit einem gemeinsamen Anteil von Datenfeldern\\ - \textarrow\ "`verwandte"' \newterm{Objekte}, \newterm{Klassenhierarchie} von Objekten - \item - Struktur, die \emph{nur\/} den gemeinsamen Anteil enthält\\ - \textarrow\ "`Vorfahr"', \newterm{Basisklasse}, \newterm{Vererbung} - \item -% Explizite Typumwandlung eines Zeigers auf die Basisklasse\\ -% in einen Zeiger auf die \newterm{abgeleitete Klasse}\\ -% \textarrow\ Man kann ein Array unterschiedlicher Objekte\\ -% \strut\phantom{\textarrow} in einer Schleife abarbeiten.\\ - Zeiger auf die Basisklasse dürfen auf Objekte\\ - der \newterm{abgeleiteten Klasse} zeigen\\ - \textarrow\ \newterm{Polymorphie} - \end{itemize} - -\end{frame} - -\subsection{Beispiel: Zahlen und Buchstaben} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - } t_base;¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\begin{frame}[fragile] - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - } t_base;¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage}\\[0.7cm] - \begin{onlyenv}<1> - \begin{minipage}{8cm} - \begin{lstlisting}[gobble=10] - ¡t_integer i = { 1, 42 }; - t_string s = { 2, "Hello, world!" }; - - t_base *object[] = { (t_base *) &i, (t_base *) &s };¿ - \end{lstlisting} - \end{minipage}% - \begin{picture}(0,0) - \color{red} - \put(-5.4,-0.8){\mbox{$\underbrace{\rule{1.45cm}{0pt}}_{\shortstack{\strut explizite\\Typumwandlung}}$}} - \end{picture} - \end{onlyenv} -% \begin{onlyenv}<2> -% \begin{minipage}{5cm} -% \begin{lstlisting}[gobble=10] -% ¡typedef union -% { -% t_base base; -% t_integer integer; -% t_string string; -% } t_object;¿ -% \end{lstlisting} -% \end{minipage} -% \end{onlyenv} - \end{center} - -\end{frame} - -\subsection{Unions} - -\begin{frame}[fragile] - - \showsubsection - - Variable teilen sich denselben Speicherplatz. - - \medskip - - \begin{minipage}[t]{3.7cm} - \begin{lstlisting}[gobble=6] - ¡typedef union - { - int8_t i; - uint8_t u; - } num8_t;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{4.5cm} - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - num8_t test; - test.i = -1; - printf ("%d\n", test.u); - return 0; - }¿ - \end{lstlisting} - \end{minipage} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Variable teilen sich denselben Speicherplatz. - - \medskip - - \begin{minipage}[t]{3.7cm} - \begin{lstlisting}[gobble=6] - ¡typedef union - { - char s[8]; - uint64_t x; - } num_char_t;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{4.5cm} - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - num_char_t test = { "Hello!" }; - printf ("%lx\n", test.x); - return 0; - }¿ - \end{lstlisting} - \end{minipage} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Variable teilen sich denselben Speicherplatz. - - \medskip - - \begin{minipage}[t]{3.7cm} - \begin{lstlisting}[gobble=6] - ¡typedef union - { - t_base base; - t_integer integer; - t_string string; - } t_object;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{3.0cm} - \begin{lstlisting}[gobble=6] - - ¡typedef struct - { - int type; - } t_base;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{3.0cm} - \begin{lstlisting}[gobble=6] - - ¡typedef struct - { - int type; - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{3.0cm} - \begin{lstlisting}[gobble=6] - - ¡typedef struct - { - int type; - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage} - - \bigskip - - \begin{center} - \begin{minipage}{8.5cm} - \begin{lstlisting}[gobble=8] - ¡if (this->base.type == T_INTEGER) - printf ("Integer: %d\n", this->integer.content); - else if (this->base.type == T_STRING) - printf ("String: \"%s\"\n", this->string.content);¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\subsection{Virtuelle Methoden} - -\begin{frame}[fragile] - \showsubsection - - \begin{lstlisting} - void print_object (t_object *this) - { - if (this->base.type == T_INTEGER) - printf ("Integer: %d\n", this->integer.content); - else if (this->base.type == T_STRING) - printf ("String: \"%s\"\n", this->string.content); - } - \end{lstlisting} - - \begin{picture}(0,0) - \color{red} - \put(9,1.7){\shortstack[l]{if-Kette:\\\strut wird unübersichtlich}} - \put(1,-2){\mbox{\textarrow}} - \put(0,-3){\mbox{Zeiger auf Funktionen}} - \end{picture} - - \begin{lstlisting}[xleftmargin=4cm] - void print_integer (t_object *this) - { - printf ("Integer: %d\n", this->integer.content); - } - - void print_string (t_object *this) - { - printf ("String: \"%s\"\n", this->string.content); - } - \end{lstlisting} - -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - Zeiger auf Funktionen - - \medskip - - \begin{lstlisting} - void (* print) (t_object *this); - \end{lstlisting} - \begin{picture}(0,1.2)(0,-0.9) - \color{red} - \put(0.95,0.3){\mbox{$\underbrace{\rule{1cm}{0pt}}$}} - \put(0.2,-0.7){\shortstack{das, worauf print zeigt,\\ist eine Funktion}} - \end{picture} - - \begin{itemize} - \item - Objekt enthält Zeiger auf Funktion - \begin{onlyenv}<1> - \medskip - \begin{lstlisting}[gobble=10] - typedef struct - { - void (* print) (union t_object *this); - int content; - } t_integer; - \end{lstlisting} - \vspace*{-2cm} - \end{onlyenv} - \begin{onlyenv}<2-> - \vspace*{-3.5cm} % Why doesn't a picture environment work here??? :-( - \begin{lstlisting}[gobble=10,xleftmargin=5.5cm] - typedef struct - { - void (* print) (union t_object *this); - int content; - } t_integer; - \end{lstlisting} - \vspace*{0.85cm} - \bigskip - \smallskip - \end{onlyenv} - \pause - \item - Konstruktor initialisiert diesen Zeiger - \begin{onlyenv}<2> - \medskip - \begin{lstlisting}[gobble=10] - t_object *new_integer (int i) - { - t_object *p = malloc (sizeof (t_integer)); - p->integer.print = print_integer; - p->integer.content = i; - return p; - } - \end{lstlisting} - \vspace*{-2cm} - \end{onlyenv} - \pause - \item - Aufruf: "`automatisch"' die richtige Funktion - \begin{onlyenv}<3> - \medskip - \begin{lstlisting}[gobble=10] - for (int i = 0; object[i]; i++) - object[i]->base.print (object[i]); - \end{lstlisting} - \end{onlyenv} - \pause - \medskip - \item - in größeren Projekten:\\ - Objekt enthält Zeiger auf Tabelle von Funktionen - \end{itemize} -\end{frame} - -\iffalse - -\subsection{Beispiel: Graphische Benutzeroberfläche (GUI)} - -\begin{frame}[fragile] - - \showsubsection - - \scriptsize - \begin{lstlisting} - #include <gtk/gtk.h> - - int main (int argc, char **argv) - { - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); - GtkWidget *label = gtk_label_new ("Hello, world!"); - gtk_container_add (GTK_CONTAINER (vbox), label); - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - gtk_widget_show (button); - gtk_widget_show (label); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; - } - \end{lstlisting} - - \vspace*{-6cm}\strut\hfill - \includegraphics[scale=0.85]{hello-gtk.png}\\[2cm] - \begin{flushright} - \normalsize\bf Praktikumsversuch:\\ - Objektorientiertes Zeichenprogramm - \end{flushright} - -\end{frame} - -\subsection{Ausblick: C++} - -\begin{frame}[fragile] - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (* print) (union t_object *this); - } t_base;¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5.5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (* print) (...); - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (* print) (union t_object *this); - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡struct TBase - { - virtual void print (void); - };¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5.5cm} - \begin{lstlisting}[gobble=8] - ¡struct TInteger: public TBase - { - virtual void print (void); - int content; - };¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡struct TString: public TBase - { - virtual void print (void); - char *content; - };¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\fi - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \begin{itemize} - \color{medgreen} - \item[6.0] Dynamische Speicherverwaltung - \item[6.1] Konzepte und Ziele - \item[6.2] Beispiel: Zahlen und Buchstaben - \item[6.3] Unions - \item[6.4] Virtuelle Methoden - \color{red} - \item[6.5] Beispiel: Graphische Benutzeroberfläche (GUI) - \item[6.6] Ausblick: C++ - \end{itemize} - \item[\textbf{7}] \textbf{Datenstrukturen} - \vspace*{-1cm} - \end{itemize} - -\end{frame} - -\end{document} diff --git a/20221128/hp-musterloesung-20221128.pdf b/20221128/hp-musterloesung-20221128.pdf deleted file mode 100644 index a113dc6303fd8897fb08f0f87b2a8d81c31d8e99..0000000000000000000000000000000000000000 Binary files a/20221128/hp-musterloesung-20221128.pdf and /dev/null differ diff --git a/20221128/hp-musterloesung-20221128.tex b/20221128/hp-musterloesung-20221128.tex deleted file mode 100644 index 4b0817bf918ab8b9c398c3cb1c75e3b4f0098aca..0000000000000000000000000000000000000000 --- a/20221128/hp-musterloesung-20221128.tex +++ /dev/null @@ -1,707 +0,0 @@ -% hp-musterloesung-20221128.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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ügen in Strings (Ergänzung), dynamisches Bit-Array, objektorientierte Tier-Datenbank - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 28.\ November 2022} - - \exercise{Einfügen in Strings (Ergänzung)} - - Diese Aufgabe ist eine Ergänzung von Aufgabe 3 der Übung vom 31.\ Oktober - 2022 um die Teilaufgaben (e), (f) und (g). Für den "`Klausur-Modus"' können - Sie die Teilaufgaben (a) bis (d) als "`bereits gelöst"' voraussetzen. - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221128}{aufgabe-1.c}): -% \begin{lstlisting}[style=numbered] - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - void insert_into_string (char src, char *target, int pos) - { - int len = strlen (target); - for (int i = pos; i < len; i++) - target[i+1] = target[i]; - target[pos] = src; - } - - int main (void) - { - char test[100] = "Hochshule Bochum"; - insert_into_string ('c', test, 5); - printf ("%s\n", test); - return 0; - } - \end{lstlisting} - Die Ausgabe des Programms lautet: - \lstinline[style=terminal]{Hochschhhhhhhhhhh} - - \begin{enumerate}[\quad(a)] - \item - Erklären Sie, wie die Ausgabe zustandekommt. -% \points{3} -% \workspace{12} - \item - Schreiben Sie die Funktion \lstinline|insert_into_string()| so um, - daß sie den Buchstaben \lstinline{src} an der Stelle \lstinline{pos} - in den String \lstinline{target} einfügt.\par - Die Ausgabe des Programms müßte dann - \lstinline[style=terminal]{Hochschule Bochum} lauten. -% \points{2} -% \workspace{13} - \item - Was kann passieren, wenn Sie die Zeile - \lstinline{char test[100] = "Hochshule Bochum";}\\ - durch - \lstinline{char test[] = "Hochshule Bochum";} ersetzen? - Begründen Sie Ihre Antwort. -% \points{2} -% \workspace{10} - \item - Was kann passieren, wenn Sie die Zeile - \lstinline{char test[100] = "Hochshule Bochum";}\\ - durch - \lstinline{char *test = "Hochshule Bochum";} ersetzen? - Begründen Sie Ihre Antwort. -% \points{2} -% \workspace{10} - \item - Schreiben Sie eine Funktion - \lstinline{void insert_into_string_sorted (char src, char *target)}, - die voraussetzt, daß der String \lstinline{target} alphabetisch sortiert ist - und den Buchstaben \lstinline{src} an der alphabetisch richtigen Stelle - einfügt. Diese Funktion darf die bereits vorhandene Funktion - \lstinline|insert_into_string()| aufrufen.\\ - \points{4}\par - Zum Testen eignen sich die folgenden Zeilen im Hauptprogramm: - \begin{lstlisting}[gobble=8] - char test[100] = ""; - insert_into_string_sorted ('c', test); - insert_into_string_sorted ('a', test); - insert_into_string_sorted ('d', test); - insert_into_string_sorted ('b', test); - \end{lstlisting} - Danach sollte \lstinline{test[]} die Zeichenfolge \lstinline{"abcd"} enthalten. -% \workspace{14} - \goodbreak - \item - Wie schnell (Landau-Symbol in Abhängigkeit von der Länge $n$ des Strings) - arbeitet Ihre Funktion - \lstinline{void insert_into_string_sorted (char src, char *target)}? - Begründen Sie Ihre Antwort. - \points{1} -% \workspace{10} - \item - Beschreiben Sie -- in Worten oder als C-Quelltext --, wie man die Funktion\\ - \lstinline{void insert_into_string_sorted (char src, char *target)} - so gestalten kann,\\ - daß sie in $\mathcal{O}(\log n)$ arbeitet. - \points{3} -% \workspace{35} - \end{enumerate} - - \solution - - \textbf{Bemerkung:} Die in dieser Aufgabe und ihrer Musterlösung vorkommenden - Funktionen prüfen nicht, ob durch das Einfügen eines Zeichens der für den - String reservierte Speicherplatz überläuft. Ein derartiges Verhalten wäre - in einem "`echten"' Programm ein \textbf{Fehler}, der katastrophale Folgen - haben kann. Wenn dergleichen hier nicht berücksichtigt wird, dann nur, um - in einer Klausur nicht den zeitlichen Rahmen zu sprengen. - - \begin{enumerate}[\quad(a)] - \setcounter{enumi}{4} - \item - \textbf{Schreiben Sie eine Funktion - \lstinline{void insert_into_string_sorted (char src, char *target)}, - die voraussetzt, daß der String \lstinline{target} alphabetisch sortiert ist - und den Buchstaben \lstinline{src} an der\break alphabetisch richtigen Stelle - einfügt. Diese Funktion darf die bereits vorhandene Funktion\break - \lstinline|insert_into_string()| aufrufen.} - \begin{lstlisting}{gobble=8} - void insert_into_string_sorted (char src, char *target) - { - int i = 0; - while (target[i] && target[i] < src) - i++; - insert_into_string (src, target, i); - } - \end{lstlisting} - - Die Datei \gitfile{hp}{20221128}{loesung-1e.c} enthält die o.\,a.\ Funktion - sowie zusätzliche Tests. - - \item - \textbf{Wie schnell (Landau-Symbol in Abhängigkeit von der Länge $n$ des Strings) - arbeitet Ihre Funktion - \lstinline{void insert_into_string_sorted (char src, char *target)}? - Begründen Sie Ihre Antwort.} - - Die Funktion sucht im Array \textbf{mittels einer Schleife} - nach der korrekten Position zum Einfügen des Zeichens - und hat daher von sich aus $\mathcal{O}(n)$. - - Anschließend ruft sie die Funktion \lstinline{insert_into_string()} auf, - die ebenfalls eine Schleife verwendet, um im Array Platz zu Einfügen zu schaffen, - und daher ebenfalls $\mathcal{O}(n)$ hat. - - Es bleibt daher bei $\mathcal{O}(n)$. - - \item - \textbf{Beschreiben Sie -- in Worten oder als C-Quelltext --, wie man die Funktion\\ - \lstinline{void insert_into_string_sorted (char src, char *target)} - so gestalten kann,\\ - daß sie in $\mathcal{O}(\log n)$ arbeitet.} - - In einem alphabetisch sortierten Array kann man die Suche in der Mitte beginnen - und sich durch Halbieren der Intervalle an die gesuchte Position herantasten. - Wegen des fortwährenden Halbierens geschieht dies in $\mathcal{O}(\log n)$. - (Für eine derartige Antwort gäbe es in der Klausur die volle Punktzahl.) - - Wenn wir allerdings anschließend für das eigentliche Einfügen die Funktion - \lstinline{insert_into_string()} verwenden, die dafür $\mathcal{O}(n)$ benötigt, - kommen wir insgesamt auf $\mathcal{O}(n)$. Ein sortiertes Einfügen in ein Array - ist daher in $\mathcal{O}(\log n)$ nicht möglich. - (Wer dies bemerkt, kann zum einen während der Klausur nachfragen, - wie denn die Aufgabenstellung genau gemeint ist, und sich zum anderen - für die besondere Sorgfalt Zusatzpunkte verdienen.) - - Die Datei \gitfile{hp}{20221128}{loesung-1g.c} enthält einen C-Quelltext, - die den o.\,a.\ Algorithmus als Funktion implementiert. - Man beachte die Behandlung des Spezialfalls, - daß das einzufügende Zeichen am Ende angehängt werden muß. - - \end{enumerate} - - \clearpage - - \exercise{Dynamisches Bit-Array} - - Schreiben Sie die folgenden Funktionen zur Verwaltung eines dynamischen Bit-Arrays: - \begin{itemize} - \item - \lstinline{void bit_array_init (int n)}\\ - Das Array initialisieren, so daß man \lstinline{n} Bits darin speichern kann.\\ - Die Array-Größe \lstinline{n} ist keine Konstante, sondern erst im laufenden Programm bekannt.\\ - Die Bits sollen auf den Anfangswert 0 initialisiert werden. - \item - \lstinline{void bit_array_set (int i, int value)}\\ - Das Bit mit dem Index \lstinline{i} auf den Wert \lstinline{value} setzen.\\ - Der Index \lstinline{i} darf von \lstinline{0} bis \lstinline{n - 1} gehen; - der Wert \lstinline{value} darf 1 oder 0 sein. - \item - \lstinline{void bit_array_flip (int i)}\\ - Das Bit mit dem Index \lstinline{i} auf den entgegengesetzten Wert setzen,\\ - also auf 1, wenn er vorher 0 ist, bzw.\ auf 0, wenn er vorher 1 ist.\\ - Der Index \lstinline{i} darf von \lstinline{0} bis \lstinline{n - 1} gehen. - \item - \lstinline{int bit_array_get (int i)}\\ - Den Wert des Bit mit dem Index \lstinline{i} zurückliefern.\\ - Der Index \lstinline{i} darf von \lstinline{0} bis \lstinline{n - 1} gehen. - \item - \lstinline{void bit_array_resize (int new_n)}\\ - Die Größe des Arrays auf \lstinline{new_n} Bits ändern.\\ - Dabei soll der Inhalt des Arrays, soweit er in die neue Größe paßt, erhalten bleiben.\\ - Neu hinzukommende Bits sollen auf 0 initialisiert werden. - \item - \lstinline{void bit_array_done (void)}\\ - Den vom Array belegten Speicherplatz wieder freigeben. - \end{itemize} - Bei Bedarf dürfen Sie den Funktionen zusätzliche Parameter mitgeben, - beispielsweise um mehrere Arrays parallel verwalten zu können. - (In der objektorientierten Programmierung wäre dies der implizite Parameter \lstinline{this}, - der auf die Objekt-Struktur zeigt.) - - Die Bits sollen möglichst effizient gespeichert werden, - z.\,B.\ jeweils 8 Bits in einer \lstinline{uint8_t}-Variablen. - - Die Funktionen sollen möglichst robust sein, - d.\,h.\ das Programm darf auch bei unsinnigen Parameterwerten nicht abstürzen, - sondern soll eine Fehlermeldung ausgeben. - - \medskip - - Die folgenden \textbf{Hinweise} beschreiben - einen möglichen Weg, die Aufgabe zu lösen. - Es seht Ihnen frei, die Aufgabe auch auf andere Weise zu lösen. - \begin{itemize} - \item - Setzen Sie zunächst voraus, daß das Array die konstante Länge 8 hat, - und schreiben Sie zunächst nur die Funktionen - \lstinline{bit_array_set()}, \lstinline{bit_array_flip()} und - \lstinline{bit_array_get()}. - \item - Verallgemeinern Sie nun auf eine konstante Länge, - bei der es sich um ein Vielfaches von 8 handelt. - \item - Implementieren Sie nun die Überprüfung auf unsinnige Parameterwerte. - Damit können Sie sich gleichzeitig von der Bedingung lösen, - daß die Länge des Arrays ein Vielfaches von 8 sein muß. - \item - Gehen Sie nun von einem statischen zu einem dynamischen Array über, - und implementieren sie die Funktionen \lstinline{bit_array_init()}, - \lstinline{bit_array_done()} und \lstinline{bit_array_resize()}. - \end{itemize} - -% \points{14} -% -% \medskip -% -% (Hinweis für die Klausur: -% Abgabe in digitaler Form ist erwünscht, aber nicht zwingend.) - - \clearpage - - \solution - - Die hier vorgestellte Lösung folgt den Hinweisen. - \begin{itemize} - \item - \textbf{Setzen Sie zunächst voraus, daß das Array die konstante Länge 8 hat, - und schreiben Sie zunächst nur die Funktionen - \lstinline{bit_array_set()}, \lstinline{bit_array_flip()} und - \lstinline{bit_array_get()}.} - - Siehe: \gitfile{hp}{2022ws/20221128}{loesung-2-1.c} - - Wir speichern in jedem der acht Bit einer \lstinline{uint8_t}-Variablen - jeweils eine Zahl, die 0 oder 1 sein kann. - Dies geschieht durch Setzen bzw.\ Löschen bzw.\ Umklappen einzelner Bits - in der Variablen. - - Das Programm enthält zusätzlich eine Funktion \lstinline{output()}, - mit der man sich den Inhalt des Arrays anzeigen lassen kann, - sowie ein Hauptprogramm \lstinline{main()}, um die Funktionen zu testen. - - \item - \textbf{Verallgemeinern Sie nun auf eine konstante Länge, - bei der es sich um ein Vielfaches von 8 handelt.} - - Siehe: \gitfile{hp}{2022ws/20221128}{loesung-2-2.c} - - In diesem Programm setzen wir die Länge auf konstant \lstinline{LENGTH} Bits, - wobei es sich um eine Präprozessor-Konstante mit dem Wert 32 handelt. - - Um \lstinline{LENGTH} Bits zu speichern, benötigen wir ein Array - der Länge \lstinline{LENGTH / 8} Bytes. - - Um auf ein einzelnes Bit zuzugreifen, müssen wir zunächst ermitteln, - in welchem der Bytes sich befindet. Außerdem interessieren wir uns - für die Nummer des Bits innerhalb des Bytes. - Den Array-Index des Bytes erhalten wir, indem wir den Index des Bits - durch 8 dividieren. Der bei dieser Division verbleibende Rest ist die - Nummer des Bits innerhalb des Bytes. - - Diese Rechnungen führen wir in den drei Funktionen - \lstinline{bit_array_set()}, \lstinline{bit_array_flip()} und - \lstinline{bit_array_get()} durch. - (Diese ist eine eher unelegante Code-Verdopplung -- hier sogar eine Verdreifachung. - Für den Produktiveinsatz lohnt es sich, darüber nachzudenken, - wie man diese vermeiden kann, ohne gleichzeitig an Effizienz einzubüßen. - Hierfür käme z.\,B.\ ein Präprozessor-Makro in Frage. - Für die Lösung der Übungsaufgabe wird dies hingegen nicht verlangt.) - - \item - \textbf{Implementieren Sie nun die Überprüfung auf unsinnige Parameterwerte. - Damit können Sie sich gleichzeitig von der Bedingung lösen, - daß die Länge des Arrays ein Vielfaches von 8 sein muß.} - - Siehe: \gitfile{hp}{2022ws/20221128}{loesung-2-3.c} - - Um weitere Code-Verdopplungen zu vermeiden, - führen wir eine Funktion \lstinline{check_index()} ein, - die alle Prüfungen durchführt. - - Wenn die Länge des Arrays kein Vielfaches von 8 ist, - wird das letzte Byte nicht vollständig genutzt. - Die einzige Schwierigkeit besteht darin, die korrekte Anzahl von Bytes - zu ermitteln, nämlich die Länge dividiert durch 8, aber nicht ab-, sondern - aufgerundet. Am elegantesten geht dies durch vorherige Addition von 7: - \lstinline{#define BYTES ((LENGTH + 7) / 8)}. - Es ist aber auch zulässig, die Anzahl der Bytes mit Hilfe einer - \lstinline{if}-Anweisung zu ermitteln: Länge durch 8 teilen und abrunden; - falls die Division nicht glatt aufging, um 1 erhöhen. - - \item - \textbf{Gehen Sie nun von einem statischen zu einem dynamischen Array über, - und implementieren sie die Funktionen \lstinline{bit_array_init()}, - \lstinline{bit_array_done()} und \lstinline{bit_array_resize()}.} - - Siehe: \gitfile{hp}{2022ws/20221128}{loesung-2-4.c}. - Damit ist die Aufgabe gelöst. - - Aus den Präprozessor-Konstanten \lstinline{LENGTH} und \lstinline{BYTES} - werden nun globale \lstinline{int}-Variable. - Die Funktion \lstinline{bit_array_init()} berechnet die korrekten Werte - für diese Variablen und legt das Array mittels \lstinline{malloc()} dynamisch - an. Eine Größenänderung des Arrays erfolgt mittels \lstinline{realloc()}, - das Freigeben mittels \lstinline{free()}. - - Das Programm setzt Variable, die aktuell nicht verwendet werden, - auf den Wert \lstinline{0} bzw.\ \lstinline{NULL}. - Dies ermöglicht es der Funktion \lstinline{check_index()}, - auch zu prüfen, ob das Array vorher korrekt mit \lstinline{bit_array_init()} - erzeugt wurde -- oder ob es vielleicht schon wieder mit - \lstinline{bit_array_done()} freigegeben wurde. - - \end{itemize} - - \clearpage - - \exercise{Objektorientierte Tier-Datenbank} - - Das unten dargestellte Programm (Datei: \gitfile{hp}{2022ws/20221128}{aufgabe-3a.c}) - soll Daten von Tieren verwalten. - - Beim Compilieren erscheinen die folgende Fehlermeldungen: - \begin{lstlisting}[style=terminal] - $ ¡gcc -std=c99 -Wall -O aufgabe-2a.c -o aufgabe-2a¿ - aufgabe-2a.c: In function 'main': - aufgabe-2a.c:31: error: 'animal' has no member named 'wings' - aufgabe-2a.c:37: error: 'animal' has no member named 'legs' - \end{lstlisting} - - Der Programmierer nimmt die in Rot dargestellten Ersetzungen vor\\ - (Datei: \gitfile{hp}{2022ws/20221128}{aufgabe-3b.c}). - Daraufhin gelingt das Compilieren, und die Ausgabe des Programms lautet: - \begin{lstlisting}[style=terminal] - $ ¡gcc -std=c99 -Wall -O aufgabe-2b.c -o aufgabe-2b¿ - $ ¡./aufgabe-2b¿ - A duck has 2 legs. - Error in animal: cow - \end{lstlisting} - - \begin{itemize} - \item[(a)] - Erklären Sie die o.\,a.\ Compiler-Fehlermeldungen. - \points{2} - \item[(b)] - Wieso verschwinden die Fehlermeldungen nach den o.\,a.\ Ersetzungen? - \points{3} - \item[(c)] - Erklären Sie die Ausgabe des Programms. - \points{5} - \item[(d)] - Beschreiben Sie -- in Worten und/oder als C-Quelltext -- einen Weg, - das Programm so zu berichtigen, daß es die Eingabedaten - (``A duck has 2 wings. A cow has 4 legs.'') korrekt speichert und ausgibt.\\ - \points{4} -% \item[(e)] -% Schreiben Sie das Programm so um, -% daß es keine expliziten Typumwandlungen mehr benötigt.\par -% Hinweis: Verwenden Sie \lstinline{union}. -% \points{4} -% \item[(f)] -% Schreiben Sie das Programm weiter um, -% so daß es die Objektinstanzen \lstinline{duck} und \lstinline{cow} -% dynamisch erzeugt.\par -% Hinweis: Verwenden Sie \lstinline{malloc()} und schreiben Sie Konstruktoren. -% \points{4} -% \item[(g)] -% Schreiben Sie das Programm weiter um, -% so daß die Ausgabe nicht mehr direkt im Hauptprogramm erfolgt, -% sondern stattdessen eine virtuelle Methode \lstinline{print()} -% aufgerufen wird.\par -% Hinweis: Verwenden Sie in den Objekten Zeiger auf Funktionen, -% und initialisieren Sie diese in den Konstruktoren. -% \points{4} - \end{itemize} - - \begin{minipage}[t]{0.34\textwidth} - \begin{lstlisting}[gobble=6,xleftmargin=0pt] - #include <stdio.h> - - #define ANIMAL 0 - #define WITH_WINGS 1 - #define WITH_LEGS 2 - - typedef struct animal - { - int type; - char *name; - } animal; - - typedef struct with_wings - { - int wings; - } with_wings; - - typedef struct with_legs - { - int legs; - } with_legs; - \end{lstlisting} - \end{minipage}\hfill - \begin{minipage}[t]{0.65\textwidth} - \begin{lstlisting}[gobble=6,xleftmargin=0pt] - int main (void) - { - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - a[0]->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - a[1]->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; - } - \end{lstlisting} - \begin{picture}(0,0) - \color{red} - \put(3.7,6.207){\vector(-1,0){0.7}} - \put(3.8,6.207){\makebox(0,0)[l]{\lstinline[basicstyle=\color{red}]{((with_legs *) a[1])->legs = 4;}}} - \put(4.0,8.735){\vector(-1,0){0.7}} - \put(4.1,8.735){\makebox(0,0)[l]{\lstinline[basicstyle=\color{red}]{((with_wings *) a[0])->wings = 2;}}} - \end{picture} - \end{minipage} - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Erklären Sie die o.\,a.\ Compiler-Fehlermeldungen.} - - \lstinline{a[0]} und \lstinline{a[1]} - sind gemäß der Deklaration \lstinline{animal *a[2]} - Zeiger auf Variablen vom Typ \lstinline{animal} (ein \lstinline{struct}). - Wenn man diesen Zeiger dereferenziert (\lstinline{->}), - erhält man eine \lstinline{animal}-Variable. - Diese enthält keine Datenfelder \lstinline{wings} bzw.\ \lstinline{legs}. - - \item[(b)] - \textbf{Wieso verschwinden die Fehlermeldungen nach den o.\,a.\ Ersetzungen?} - - Durch die \emph{explizite Typumwandlung des Zeigers\/} - erhalten wir einen Zeiger auf eine \lstinline{with_wings}- - bzw.\ auf eine \lstinline{with_legs}-Variable. - Diese enthalten die Datenfelder \lstinline{wings} bzw.\ \lstinline{legs}. - - \item[(c)] - \textbf{Erklären Sie die Ausgabe des Programms.} - - Durch die explizite Typumwandlung des Zeigers - zeigt \lstinline{a[0]} auf eine \lstinline{with_wings}-Variable. - Diese enthält nur ein einziges Datenfeld \lstinline{wings}, - das an genau derselben Stelle im Speicher liegt - wie \lstinline{a[0]->type}, also das Datenfeld \lstinline{type} - der \lstinline{animal}-Variable, auf die der Zeiger \lstinline{a[0]} zeigt. - Durch die Zuweisung der Zahl \lstinline{2} - an \lstinline{((with_wings *) a[0])->wings} - überschreiben wir also \lstinline{a[0]->type}, - so daß das \lstinline{if} in der \lstinline{for}-Schleife - \lstinline{a[0]} als \lstinline{WITH_LEGS} erkennt. - - Bei der Ausgabe \lstinline[style=terminal]{A duck has 2 legs.} - wird das Datenfeld \lstinline{((with_legs *)a[0])->legs} als Zahl ausgegeben. - Dieses Datenfeld befindet sich in denselben Speicherzellen wie - \lstinline{a[0]->type} und \lstinline{((with_wings *)} % :-( - \lstinline{a[0]->wings} - und hat daher ebenfalls den Wert 2. - - Auf die gleiche Weise überschreiben wir durch die Zuweisung der Zahl 4 - an \lstinline{((with_legs *) a[1])->legs} - das Datenfeld \lstinline{a[0]->type}, - so daß das \lstinline{if} in der \lstinline{for}-Schleife - \lstinline{a[1]} als unbekanntes Tier (Nr.\ 4) erkennt und - \lstinline[style=terminal]{Error in animal: cow} ausgibt. - - \item[(d)] - \textbf{Beschreiben Sie -- in Worten und/oder als C-Quelltext -- einen Weg, - das Programm so zu berichtigen, daß es die Eingabedaten - (``A duck has 2 wings. A cow has 4 legs.'') korrekt speichert und ausgibt.} - - Damit die \emph{Vererbung\/} zwischen den Objekten - \lstinline{animal}, \lstinline{with_wings} und \lstinline{with_legs} - funktioniert, müssen die abgeleiteten Klassen \lstinline{with_wings} und \lstinline{with_legs} - alle Datenfelder der Basisklasse \lstinline{animal} erben. - In C geschieht dies explizit; die Datenfelder müssen in den - abgeleiteten Klassen neu angegeben werden - (siehe \gitfile{hp}{2022ws/20221128}{loesung-3d-1.c}): - - \begin{lstlisting}[gobble=8] - typedef struct animal - { - int type; - char *name; - } animal; - - typedef struct with_wings - { - int type; - char *name; - int wings; - } with_wings; - - typedef struct with_legs - { - int type; - char *name; - int legs; - } with_legs; - \end{lstlisting} - - Zusätzlich ist es notwendig, - die Instanzen \lstinline{duck} und \lstinline{cow} - der abgeleiteten Klassen \lstinline{with_wings} und \lstinline{with_legs} - auch als solche zu deklarieren, - damit für sie genügend Speicher reserviert wird: - - \begin{lstlisting}[gobble=8] - animal *a[2]; - - with_wings duck; - a[0] = (animal *) &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - ((with_wings *) a[0])->wings = 2; - - with_legs cow; - a[1] = (animal *) &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - \end{lstlisting} - - Wenn man dies vergißt und sie nur als \lstinline{animal} deklariert, - wird auch nur Speicherplatz für (kleinere) - \lstinline{animal}-Variable angelegt. - Dadurch kommt es zu Speicherzugriffen außerhalb der - deklarierten Variablen, was letztlich zu einem Absturz führt - (siehe \gitfile{hp}{2022ws/20221128}{loesung-3d-0f.c}). - - Für die Zuweisung eines Zeigers auf \lstinline{duck} - an \lstinline{a[0]}, also an einen Zeiger auf \lstinline{animal} - wird eine weitere explizite Typumwandlung notwendig. - Entsprechendes gilt für die Zuweisung eines Zeigers auf \lstinline{cow} - an \lstinline{a[1]}. - - Es ist sinnvoll, explizite Typumwandlungen so weit wie möglich zu vermeiden. - Es ist einfacher und gleichzeitig sicherer, - direkt in die Variablen \lstinline{duck} und \lstinline{cow} - zu schreiben, anstatt dies über die Zeiger \lstinline{a[0]} - und \lstinline{a[1]} zu tun - (siehe \gitfile{hp}{2022ws/20221128}{loesung-3d-2.c}): - - \begin{lstlisting}[gobble=8] - animal *a[2]; - - with_wings duck; - a[0] = (animal *) &duck; - duck.type = WITH_WINGS; - duck.name = "duck"; - duck.wings = 2; - - with_legs cow; - a[1] = (animal *) &cow; - cow.type = WITH_LEGS; - cow.name = "cow"; - cow.legs = 4; - \end{lstlisting} - - \item[(e)] - \textbf{Schreiben Sie das Programm so um, - daß es keine expliziten Typumwandlungen mehr benötigt.}\par - \textbf{Hinweis: Verwenden Sie \lstinline{union}.} - - Siehe \gitfile{hp}{2022ws/20221128}{loesung-3e.c}. - - Diese Lösung basiert auf \gitfile{hp}{2022ws/20221128}{loesung-3d-2.c}, - da diese bereits weniger explizite Typumwandlungen enthält - als \gitfile{hp}{2022ws/20221128}{loesung-3d-1.c}. - - Arbeitsschritte: - \begin{itemize} - \item - Umbenennen des Basistyps \lstinline{animal} in \lstinline{base}, - damit wir den Bezeichner \lstinline{animal} - für die \lstinline{union} verwenden können - \item - Schreiben einer \lstinline{union animal}, - die die drei Klassen \lstinline{base}, - \lstinline{with_wings} und \lstinline{with_legs} - als Datenfelder enthält - \item - Umschreiben der Initialisierungen: - Zugriff auf Datenfelder erfolgt nun durch - z.\,B.\ \lstinline{a[0]->b.name}. - Hierbei ist \lstinline{b} der Name des \lstinline{base}-Datenfelds - innerhalb der \lstinline{union animal}. - \item - Auf gleiche Weise schreiben wir die \lstinline{if}-Bedingungen - innerhalb der \lstinline{for}-Schleife - sowie die Parameter der \lstinline{printf()}-Aufrufe um. - \end{itemize} - Explizite Typumwandlungen sind nun nicht mehr nötig. - - Nachteil dieser Lösung: - Jede Objekt-Variable belegt nun Speicherplatz - für die gesamte \lstinline{union animal}, - anstatt nur für die benötigte Variable vom Typ - \lstinline{with_wings} oder \lstinline{with_legs}. - Dies kann zu einer Verschwendung von Speicherplatz führen, - auch wenn dies in diesem Beispielprogramm tatsächlich nicht der Fall ist. - - \item[(f)] - \textbf{Schreiben Sie das Programm weiter um, - so daß es die Objektinstanzen \lstinline{duck} und \lstinline{cow} - dynamisch erzeugt.}\par - \textbf{Hinweis: Verwenden Sie \lstinline{malloc()} und schreiben Sie Konstruktoren.} - - Siehe \gitfile{hp}{2022ws/20221128}{loesung-3f.c}. - - \item[(g)] - \textbf{Schreiben Sie das Programm weiter um, - so daß die Ausgabe nicht mehr direkt im Hauptprogramm erfolgt, - sondern stattdessen eine virtuelle Methode \lstinline{print()} - aufgerufen wird.}\par - \textbf{Hinweis: Verwenden Sie in den Objekten Zeiger auf Funktionen, - und initialisieren Sie diese in den Konstruktoren.} - - Siehe \gitfile{hp}{2022ws/20221128}{loesung-3g.c}. - - \end{itemize} - -\end{document} diff --git a/20221128/hp-uebung-20221128.pdf b/20221128/hp-uebung-20221128.pdf deleted file mode 100644 index 6e4c328cbab5b424929eb4e28f4fd03eb9b506b9..0000000000000000000000000000000000000000 Binary files a/20221128/hp-uebung-20221128.pdf and /dev/null differ diff --git a/20221128/hp-uebung-20221128.tex b/20221128/hp-uebung-20221128.tex deleted file mode 100644 index a104f3ab348bbeee242d1d5d705e93ca5d924f8e..0000000000000000000000000000000000000000 --- a/20221128/hp-uebung-20221128.tex +++ /dev/null @@ -1,342 +0,0 @@ -% hp-uebung-20221128.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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ügen in Strings (Ergänzung), dynamisches Bit-Array, objektorientierte Tier-Datenbank - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 28.\ November 2022} - - Diese Übung enthält Punkteangaben wie in einer Klausur. - Um zu "`bestehen"', müssen Sie innerhalb von 65 Minuten - unter Verwendung ausschließlich zugelassener Hilfsmittel - 11 Punkte (von insgesamt \totalpoints) erreichen. - - \exercise{Einfügen in Strings (Ergänzung)} - - Diese Aufgabe ist eine Ergänzung von Aufgabe 3 der Übung vom 31.\ Oktober - 2022 um die Teilaufgaben (e), (f) und (g). Für den "`Klausur-Modus"' können - Sie die Teilaufgaben (a) bis (d) als "`bereits gelöst"' voraussetzen. - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221128}{aufgabe-1.c}): -% \begin{lstlisting}[style=numbered] - \begin{lstlisting} - #include <stdio.h> - #include <string.h> - - void insert_into_string (char src, char *target, int pos) - { - int len = strlen (target); - for (int i = pos; i < len; i++) - target[i+1] = target[i]; - target[pos] = src; - } - - int main (void) - { - char test[100] = "Hochshule Bochum"; - insert_into_string ('c', test, 5); - printf ("%s\n", test); - return 0; - } - \end{lstlisting} - Die Ausgabe des Programms lautet: - \lstinline[style=terminal]{Hochschhhhhhhhhhh} - - \begin{enumerate}[\quad(a)] - \item - Erklären Sie, wie die Ausgabe zustandekommt. -% \points{3} -% \workspace{12} - \item - Schreiben Sie die Funktion \lstinline|insert_into_string()| so um, - daß sie den Buchstaben \lstinline{src} an der Stelle \lstinline{pos} - in den String \lstinline{target} einfügt.\par - Die Ausgabe des Programms müßte dann - \lstinline[style=terminal]{Hochschule Bochum} lauten. -% \points{2} -% \workspace{13} - \item - Was kann passieren, wenn Sie die Zeile - \lstinline{char test[100] = "Hochshule Bochum";}\\ - durch - \lstinline{char test[] = "Hochshule Bochum";} ersetzen? - Begründen Sie Ihre Antwort. -% \points{2} -% \workspace{10} - \item - Was kann passieren, wenn Sie die Zeile - \lstinline{char test[100] = "Hochshule Bochum";}\\ - durch - \lstinline{char *test = "Hochshule Bochum";} ersetzen? - Begründen Sie Ihre Antwort. -% \points{2} -% \workspace{10} - \item - Schreiben Sie eine Funktion - \lstinline{void insert_into_string_sorted (char src, char *target)}, - die voraussetzt, daß der String \lstinline{target} alphabetisch sortiert ist - und den Buchstaben \lstinline{src} an der alphabetisch richtigen Stelle - einfügt. Diese Funktion darf die bereits vorhandene Funktion - \lstinline|insert_into_string()| aufrufen.\\ - \points{4}\par - Zum Testen eignen sich die folgenden Zeilen im Hauptprogramm: - \begin{lstlisting}[gobble=8] - char test[100] = ""; - insert_into_string_sorted ('c', test); - insert_into_string_sorted ('a', test); - insert_into_string_sorted ('d', test); - insert_into_string_sorted ('b', test); - \end{lstlisting} - Danach sollte \lstinline{test[]} die Zeichenfolge \lstinline{"abcd"} enthalten. -% \workspace{14} - \goodbreak - \item - Wie schnell (Landau-Symbol in Abhängigkeit von der Länge $n$ des Strings) - arbeitet Ihre Funktion - \lstinline{void insert_into_string_sorted (char src, char *target)}? - Begründen Sie Ihre Antwort. - \points{1} -% \workspace{10} - \item - Beschreiben Sie -- in Worten oder als C-Quelltext --, wie man die Funktion\\ - \lstinline{void insert_into_string_sorted (char src, char *target)} - so gestalten kann,\\ - daß sie in $\mathcal{O}(\log n)$ arbeitet. - \points{3} -% \workspace{35} - \end{enumerate} - - \exercise{Dynamisches Bit-Array} - - Schreiben Sie die folgenden Funktionen zur Verwaltung eines dynamischen Bit-Arrays: - \begin{itemize} - \item - \lstinline{void bit_array_init (int n)}\\ - Das Array initialisieren, so daß man \lstinline{n} Bits darin speichern kann.\\ - Die Array-Größe \lstinline{n} ist keine Konstante, sondern erst im laufenden Programm bekannt.\\ - Die Bits sollen auf den Anfangswert 0 initialisiert werden. - \item - \lstinline{void bit_array_set (int i, int value)}\\ - Das Bit mit dem Index \lstinline{i} auf den Wert \lstinline{value} setzen.\\ - Der Index \lstinline{i} darf von \lstinline{0} bis \lstinline{n - 1} gehen; - der Wert \lstinline{value} darf 1 oder 0 sein. - \item - \lstinline{void bit_array_flip (int i)}\\ - Das Bit mit dem Index \lstinline{i} auf den entgegengesetzten Wert setzen,\\ - also auf 1, wenn er vorher 0 ist, bzw.\ auf 0, wenn er vorher 1 ist.\\ - Der Index \lstinline{i} darf von \lstinline{0} bis \lstinline{n - 1} gehen. - \item - \lstinline{int bit_array_get (int i)}\\ - Den Wert des Bit mit dem Index \lstinline{i} zurückliefern.\\ - Der Index \lstinline{i} darf von \lstinline{0} bis \lstinline{n - 1} gehen. - \item - \lstinline{void bit_array_resize (int new_n)}\\ - Die Größe des Arrays auf \lstinline{new_n} Bits ändern.\\ - Dabei soll der Inhalt des Arrays, soweit er in die neue Größe paßt, erhalten bleiben.\\ - Neu hinzukommende Bits sollen auf 0 initialisiert werden. - \item - \lstinline{void bit_array_done (void)}\\ - Den vom Array belegten Speicherplatz wieder freigeben. - \end{itemize} - Bei Bedarf dürfen Sie den Funktionen zusätzliche Parameter mitgeben, - beispielsweise um mehrere Arrays parallel verwalten zu können. - (In der objektorientierten Programmierung wäre dies der implizite Parameter \lstinline{this}, - der auf die Objekt-Struktur zeigt.) - - Die Bits sollen möglichst effizient gespeichert werden, - z.\,B.\ jeweils 8 Bits in einer \lstinline{uint8_t}-Variablen. - - Die Funktionen sollen möglichst robust sein, - d.\,h.\ das Programm darf auch bei unsinnigen Parameterwerten nicht abstürzen, - sondern soll eine Fehlermeldung ausgeben. - - \medskip - - Die folgenden \textbf{Hinweise} beschreiben - einen möglichen Weg, die Aufgabe zu lösen. - Es seht Ihnen frei, die Aufgabe auch auf andere Weise zu lösen. - \begin{itemize} - \item - Setzen Sie zunächst voraus, daß das Array die konstante Länge 8 hat, - und schreiben Sie zunächst nur die Funktionen - \lstinline{bit_array_set()}, \lstinline{bit_array_flip()} und - \lstinline{bit_array_get()}. - \item - Verallgemeinern Sie nun auf eine konstante Länge, - bei der es sich um ein Vielfaches von 8 handelt. - \item - Implementieren Sie nun die Überprüfung auf unsinnige Parameterwerte. - Damit können Sie sich gleichzeitig von der Bedingung lösen, - daß die Länge des Arrays ein Vielfaches von 8 sein muß. - \item - Gehen Sie nun von einem statischen zu einem dynamischen Array über, - und implementieren Sie die Funktionen \lstinline{bit_array_init()}, - \lstinline{bit_array_done()} und \lstinline{bit_array_resize()}. - \end{itemize} - -% \points{14} -% -% \medskip -% -% (Hinweis für die Klausur: -% Abgabe in digitaler Form ist erwünscht, aber nicht zwingend.) - - \clearpage - \exercise{Objektorientierte Tier-Datenbank} - - Das unten dargestellte Programm (Datei: \gitfile{hp}{2022ws/20221128}{aufgabe-3a.c}) - soll Daten von Tieren verwalten. - - Beim Compilieren erscheinen die folgende Fehlermeldungen: - \begin{lstlisting}[style=terminal] - $ ¡gcc -std=c99 -Wall -O aufgabe-2a.c -o aufgabe-2a¿ - aufgabe-2a.c: In function 'main': - aufgabe-2a.c:31: error: 'animal' has no member named 'wings' - aufgabe-2a.c:37: error: 'animal' has no member named 'legs' - \end{lstlisting} - - Der Programmierer nimmt die in Rot dargestellten Ersetzungen vor - (Datei: \gitfile{hp}{2022ws/20221128}{aufgabe-3b.c}). - Daraufhin gelingt das Compilieren, und die Ausgabe des Programms lautet: - \begin{lstlisting}[style=terminal] - $ ¡gcc -std=c99 -Wall -O aufgabe-2b.c -o aufgabe-2b¿ - $ ¡./aufgabe-2b¿ - A duck has 2 legs. - Error in animal: cow - \end{lstlisting} - - \begin{itemize} - \item[(a)] - Erklären Sie die o.\,a.\ Compiler-Fehlermeldungen. - \points{2} - \item[(b)] - Wieso verschwinden die Fehlermeldungen nach den o.\,a.\ Ersetzungen? - \points{3} - \item[(c)] - Erklären Sie die Ausgabe des Programms. - \points{5} - \item[(d)] - Beschreiben Sie -- in Worten und/oder als C-Quelltext -- einen Weg, - das Programm so zu berichtigen, daß es die Eingabedaten - (``A duck has 2 wings. A cow has 4 legs.'') korrekt speichert und ausgibt.\\ - \points{4} -% \item[(e)] -% Schreiben Sie das Programm so um, -% daß es keine expliziten Typumwandlungen mehr benötigt.\par -% Hinweis: Verwenden Sie \lstinline{union}. -% \points{4} -% \item[(f)] -% Schreiben Sie das Programm weiter um, -% so daß es die Objektinstanzen \lstinline{duck} und \lstinline{cow} -% dynamisch erzeugt.\par -% Hinweis: Verwenden Sie \lstinline{malloc()} und schreiben Sie Konstruktoren. -% \points{4} -% \item[(g)] -% Schreiben Sie das Programm weiter um, -% so daß die Ausgabe nicht mehr direkt im Hauptprogramm erfolgt, -% sondern stattdessen eine virtuelle Methode \lstinline{print()} -% aufgerufen wird.\par -% Hinweis: Verwenden Sie in den Objekten Zeiger auf Funktionen, -% und initialisieren Sie diese in den Konstruktoren. -% \points{4} - \end{itemize} - - \begin{minipage}[t]{0.34\textwidth} - \begin{lstlisting}[gobble=6,xleftmargin=0pt] - #include <stdio.h> - - #define ANIMAL 0 - #define WITH_WINGS 1 - #define WITH_LEGS 2 - - typedef struct animal - { - int type; - char *name; - } animal; - - typedef struct with_wings - { - int wings; - } with_wings; - - typedef struct with_legs - { - int legs; - } with_legs; - \end{lstlisting} - \end{minipage}\hfill - \begin{minipage}[t]{0.65\textwidth} - \begin{lstlisting}[gobble=6,xleftmargin=0pt] - int main (void) - { - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - a[0]->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - a[1]->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; - } - \end{lstlisting} - \begin{picture}(0,0) - \color{red} - \put(3.7,6.207){\vector(-1,0){0.7}} - \put(3.8,6.207){\makebox(0,0)[l]{\lstinline[basicstyle=\color{red}]{((with_legs *) a[1])->legs = 4;}}} - \put(4.0,8.735){\vector(-1,0){0.7}} - \put(4.1,8.735){\makebox(0,0)[l]{\lstinline[basicstyle=\color{red}]{((with_wings *) a[0])->wings = 2;}}} - \end{picture} - \end{minipage} - - \begin{flushright} - \textit{Viel Erfolg!} - \end{flushright} - - \makeatletter - \immediate\write\@mainaux{\string\gdef\string\totalpoints{\arabic{points}}} - \makeatother - -\end{document} diff --git a/20221128/landau-symbols-2.pdf b/20221128/landau-symbols-2.pdf deleted file mode 120000 index 6b458b6efd8e274824a6dfcaabc4b9c27d196dc4..0000000000000000000000000000000000000000 --- a/20221128/landau-symbols-2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/landau-symbols-2.pdf \ No newline at end of file diff --git a/20221128/landau-symbols-3.pdf b/20221128/landau-symbols-3.pdf deleted file mode 120000 index 46efa409b35ff5df763c744a423599cba515d886..0000000000000000000000000000000000000000 --- a/20221128/landau-symbols-3.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/landau-symbols-3.pdf \ No newline at end of file diff --git a/20221128/landau-symbols.pdf b/20221128/landau-symbols.pdf deleted file mode 120000 index ca145425bf07439c680632aa0663f84be601a565..0000000000000000000000000000000000000000 --- a/20221128/landau-symbols.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/landau-symbols.pdf \ No newline at end of file diff --git a/20221128/loesung-1e.c b/20221128/loesung-1e.c deleted file mode 100644 index bc41fb0e1f5f826a427038a18798e280fd1a096d..0000000000000000000000000000000000000000 --- a/20221128/loesung-1e.c +++ /dev/null @@ -1,33 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void insert_into_string (char src, char *target, int pos) -{ - int len = strlen (target); - for (int i = len; i >= pos; i--) - target[i + 1] = target[i]; - target[pos] = src; -} - -void insert_into_string_sorted (char src, char *target) -{ - int i = 0; - while (target[i] && target[i] < src) - i++; - insert_into_string (src, target, i); -} - -int main (void) -{ - char test[100] = ""; - insert_into_string_sorted ('c', test); - insert_into_string_sorted ('a', test); - insert_into_string_sorted ('d', test); - insert_into_string_sorted ('b', test); - printf ("test = \"%s\"\n", test); - for (char ch = 'e'; ch < 'z'; ch += 2) - insert_into_string_sorted (ch, test); - insert_into_string_sorted ('n', test); - printf ("test = \"%s\"\n", test); - return 0; -} diff --git a/20221128/loesung-1g.c b/20221128/loesung-1g.c deleted file mode 100644 index 4b0c29dfc223fa961cdbf930683e6d79610b002b..0000000000000000000000000000000000000000 --- a/20221128/loesung-1g.c +++ /dev/null @@ -1,46 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void insert_into_string (char src, char *target, int pos) -{ - int len = strlen (target); - for (int i = len; i >= pos; i--) - target[i + 1] = target[i]; - target[pos] = src; -} - -void insert_into_string_sorted (char src, char *target) -{ - int l = 0; - int r = 0; - while (target[r]) - r++; - int m = (l + r) / 2; - while (m > l) - { - if (src < target[m]) - r = m; - else - l = m; - m = (l + r) / 2; - } - if (target[m] == 0 || src < target[m]) - insert_into_string (src, target, m); - else - insert_into_string (src, target, m + 1); -} - -int main (void) -{ - char test[100] = ""; - insert_into_string_sorted ('c', test); - insert_into_string_sorted ('a', test); - insert_into_string_sorted ('d', test); - insert_into_string_sorted ('b', test); - printf ("test = \"%s\"\n", test); - for (char ch = 'e'; ch < 'z'; ch += 2) - insert_into_string_sorted (ch, test); - insert_into_string_sorted ('n', test); - printf ("test = \"%s\"\n", test); - return 0; -} diff --git a/20221128/loesung-2-1.c b/20221128/loesung-2-1.c deleted file mode 100644 index 11ad08a28a2c16e645e4b55c1b0f4556246fd692..0000000000000000000000000000000000000000 --- a/20221128/loesung-2-1.c +++ /dev/null @@ -1,50 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -uint8_t buffer = 0; - -void bit_array_set (int i, int value) -{ - uint8_t mask = 1 << i; - if (value) - buffer |= mask; - else - buffer &= ~mask; -} - -void bit_array_flip (int i) -{ - uint8_t mask = 1 << i; - buffer ^= mask; -} - -int bit_array_get (int i) -{ - uint8_t mask = 1 << i; - if (buffer & mask) - return 1; - else - return 0; -} - -void output (void) -{ - for (int i = 0; i < 8; i++) - { - if (i % 4 == 0) - printf (" "); - printf ("%d", bit_array_get (i)); - } - printf ("\n"); -} - -int main (void) -{ - output (); - bit_array_set (2, 1); - output (); - bit_array_flip (7); - output (); - bit_array_set (2, 0); - output (); -} diff --git a/20221128/loesung-2-2.c b/20221128/loesung-2-2.c deleted file mode 100644 index e510904b033cf7d55737cee55ad08ecb9510f324..0000000000000000000000000000000000000000 --- a/20221128/loesung-2-2.c +++ /dev/null @@ -1,58 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -#define LENGTH 32 - -uint8_t buffer[LENGTH / 8] = { 0, 0, 0, 0 }; - -void bit_array_set (int i, int value) -{ - int byte_index = i / 8; - int bit_index = i % 8; - uint8_t mask = 1 << bit_index; - if (value) - buffer[byte_index] |= mask; - else - buffer[byte_index] &= ~mask; -} - -void bit_array_flip (int i) -{ - int byte_index = i / 8; - int bit_index = i % 8; - uint8_t mask = 1 << bit_index; - buffer[byte_index] ^= mask; -} - -int bit_array_get (int i) -{ - int byte_index = i / 8; - int bit_index = i % 8; - uint8_t mask = 1 << bit_index; - if (buffer[byte_index] & mask) - return 1; - else - return 0; -} - -void output (void) -{ - for (int i = 0; i < LENGTH; i++) - { - if (i % 4 == 0) - printf (" "); - printf ("%d", bit_array_get (i)); - } - printf ("\n"); -} - -int main (void) -{ - output (); - bit_array_set (12, 1); - output (); - bit_array_flip (31); - output (); - bit_array_set (12, 0); - output (); -} diff --git a/20221128/loesung-2-3.c b/20221128/loesung-2-3.c deleted file mode 100644 index 4177464aebf41205169a6bb02b27ac972e3a4f4e..0000000000000000000000000000000000000000 --- a/20221128/loesung-2-3.c +++ /dev/null @@ -1,71 +0,0 @@ -#include <stdio.h> -#include <stdint.h> -#include <error.h> - -#define LENGTH 29 -#define BYTES ((LENGTH + 7) / 8) - -uint8_t buffer[BYTES] = { 0, 0, 0, 0 }; - -void check_index (int i) -{ - if (i < 0 || i >= LENGTH) - error (1, 0, "index %d out of range (0, ..., %d)", i, LENGTH - 1); -} - -void bit_array_set (int i, int value) -{ - check_index (i); - int byte_index = i / 8; - int bit_index = i % 8; - uint8_t mask = 1 << bit_index; - if (value) - buffer[byte_index] |= mask; - else - buffer[byte_index] &= ~mask; -} - -void bit_array_flip (int i) -{ - check_index (i); - int byte_index = i / 8; - int bit_index = i % 8; - uint8_t mask = 1 << bit_index; - buffer[byte_index] ^= mask; -} - -int bit_array_get (int i) -{ - check_index (i); - int byte_index = i / 8; - int bit_index = i % 8; - uint8_t mask = 1 << bit_index; - if (buffer[byte_index] & mask) - return 1; - else - return 0; -} - -void output (void) -{ - for (int i = 0; i < LENGTH; i++) - { - if (i % 4 == 0) - printf (" "); - printf ("%d", bit_array_get (i)); - } - printf ("\n"); -} - -int main (void) -{ - output (); - bit_array_set (12, 1); - output (); - bit_array_flip (28); - output (); - bit_array_set (12, 0); - output (); - bit_array_flip (31); - output (); -} diff --git a/20221128/loesung-2-4.c b/20221128/loesung-2-4.c deleted file mode 100644 index 1930580aae8e8b24528852d1dacf58051f6bd6cc..0000000000000000000000000000000000000000 --- a/20221128/loesung-2-4.c +++ /dev/null @@ -1,101 +0,0 @@ -#include <stdio.h> -#include <stdint.h> -#include <error.h> -#include <stdlib.h> - -int length = 0; -int bytes = 0; -uint8_t *buffer = NULL; - -void bit_array_init (int n) -{ - length = n; - bytes = (length + 7) / 8; - if (buffer) - free (buffer); - buffer = malloc (bytes * sizeof (uint8_t)); - for (int i = 0; i < bytes; i++) - buffer[i] = 0; -} - -void bit_array_resize (int new_n) -{ - length = new_n; - bytes = (length + 7) / 8; - buffer = realloc (buffer, bytes * sizeof (uint8_t)); -} - -void bit_array_done (void) -{ - free (buffer); - buffer = NULL; - length = 0; - bytes = 0; -} - -void check_index (int i) -{ - if (!buffer) - error (1, 0, "array not initialised"); - if (i < 0 || i >= length) - error (1, 0, "index %d out of range (0, ..., %d)", i, length - 1); -} - -void bit_array_set (int i, int value) -{ - check_index (i); - int byte_index = i / 8; - int bit_index = i % 8; - uint8_t mask = 1 << bit_index; - if (value) - buffer[byte_index] |= mask; - else - buffer[byte_index] &= ~mask; -} - -void bit_array_flip (int i) -{ - check_index (i); - int byte_index = i / 8; - int bit_index = i % 8; - uint8_t mask = 1 << bit_index; - buffer[byte_index] ^= mask; -} - -int bit_array_get (int i) -{ - check_index (i); - int byte_index = i / 8; - int bit_index = i % 8; - uint8_t mask = 1 << bit_index; - if (buffer[byte_index] & mask) - return 1; - else - return 0; -} - -void output (void) -{ - for (int i = 0; i < length; i++) - { - if (i % 4 == 0) - printf (" "); - printf ("%d", bit_array_get (i)); - } - printf ("\n"); -} - -int main (void) -{ - bit_array_init (29); - output (); - bit_array_set (12, 1); - output (); - bit_array_flip (28); - output (); - bit_array_set (12, 0); - output (); - bit_array_flip (31); - output (); - bit_array_done (); -} diff --git a/20221128/loesung-3d-0f.c b/20221128/loesung-3d-0f.c deleted file mode 100644 index 04b2d3e8956f4790b3f2ffdf3a314994c640513e..0000000000000000000000000000000000000000 --- a/20221128/loesung-3d-0f.c +++ /dev/null @@ -1,54 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - char *name; - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - ((with_wings *) a[0])->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; -} diff --git a/20221128/loesung-3d-1.c b/20221128/loesung-3d-1.c deleted file mode 100644 index 349523a7d99e33ba81094ffbc8907773b5a3a251..0000000000000000000000000000000000000000 --- a/20221128/loesung-3d-1.c +++ /dev/null @@ -1,54 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - char *name; - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - with_wings duck; - a[0] = (animal *) &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - ((with_wings *) a[0])->wings = 2; - - with_legs cow; - a[1] = (animal *) &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; -} diff --git a/20221128/loesung-3d-2.c b/20221128/loesung-3d-2.c deleted file mode 100644 index f831a75eda1f3e784c8e6c1f24a83d9d6b55ee6c..0000000000000000000000000000000000000000 --- a/20221128/loesung-3d-2.c +++ /dev/null @@ -1,54 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - char *name; - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - with_wings duck; - a[0] = (animal *) &duck; - duck.type = WITH_WINGS; - duck.name = "duck"; - duck.wings = 2; - - with_legs cow; - a[1] = (animal *) &cow; - cow.type = WITH_LEGS; - cow.name = "cow"; - cow.legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; -} diff --git a/20221128/loesung-3e.c b/20221128/loesung-3e.c deleted file mode 100644 index b984d9253b9c379a88f0fc0ca130c88c3103f8f3..0000000000000000000000000000000000000000 --- a/20221128/loesung-3e.c +++ /dev/null @@ -1,61 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct -{ - int type; - char *name; -} base; - -typedef struct -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct -{ - int type; - char *name; - int legs; -} with_legs; - -typedef union -{ - base b; - with_wings w; - with_legs l; -} animal; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - duck.b.type = WITH_WINGS; - duck.b.name = "duck"; - duck.w.wings = 2; - - animal cow; - a[1] = &cow; - cow.b.type = WITH_LEGS; - cow.b.name = "cow"; - cow.l.legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->b.type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->b.name, - a[i]->l.legs); - else if (a[i]->b.type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->b.name, - a[i]->w.wings); - else - printf ("Error in animal: %s\n", a[i]->b.name); - - return 0; -} diff --git a/20221128/loesung-3f.c b/20221128/loesung-3f.c deleted file mode 100644 index 7b949e6365fc3839e6adc7661e0f8b4dd0c059df..0000000000000000000000000000000000000000 --- a/20221128/loesung-3f.c +++ /dev/null @@ -1,69 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct -{ - int type; - char *name; -} base; - -typedef struct -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct -{ - int type; - char *name; - int legs; -} with_legs; - -typedef union -{ - base b; - with_wings w; - with_legs l; -} animal; - -animal *new_with_wings (char *name, int wings) -{ - animal *a = malloc (sizeof (with_wings)); - a->b.type = WITH_WINGS; - a->b.name = name; - a->w.wings = wings; - return a; -} - -animal *new_with_legs (char *name, int legs) -{ - animal *a = malloc (sizeof (with_legs)); - a->b.type = WITH_LEGS; - a->b.name = name; - a->l.legs = legs; - return a; -} - -int main (void) -{ - animal *a[2] = { new_with_wings ("duck", 2), - new_with_legs ("cow", 4) }; - - for (int i = 0; i < 2; i++) - if (a[i]->b.type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->b.name, - a[i]->l.legs); - else if (a[i]->b.type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->b.name, - a[i]->w.wings); - else - printf ("Error in animal: %s\n", a[i]->b.name); - - return 0; -} diff --git a/20221128/loesung-3g.c b/20221128/loesung-3g.c deleted file mode 100644 index b453a52dbe0ef27399255819808b3f6e562ba3ef..0000000000000000000000000000000000000000 --- a/20221128/loesung-3g.c +++ /dev/null @@ -1,77 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -union animal; - -typedef struct -{ - int type; - char *name; - void (*print) (union animal *this); -} base; - -typedef struct -{ - int type; - char *name; - void (*print) (union animal *this); - int wings; -} with_wings; - -typedef struct -{ - int type; - char *name; - void (*print) (union animal *this); - int legs; -} with_legs; - -typedef union animal -{ - base b; - with_wings w; - with_legs l; -} animal; - -void print_with_wings (animal *this) -{ - printf ("A %s has %d wings.\n", this->b.name, this->w.wings); -} - -void print_with_legs (animal *this) -{ - printf ("A %s has %d legs.\n", this->b.name, this->l.legs); -} - -animal *new_with_wings (char *name, int wings) -{ - animal *a = malloc (sizeof (with_wings)); - a->b.type = WITH_WINGS; - a->b.name = name; - a->b.print = print_with_wings; - a->w.wings = wings; - return a; -} - -animal *new_with_legs (char *name, int legs) -{ - animal *a = malloc (sizeof (with_legs)); - a->b.type = WITH_LEGS; - a->b.name = name; - a->b.print = print_with_legs; - a->l.legs = legs; - return a; -} - -int main (void) -{ - animal *a[2] = { new_with_wings ("duck", 2), - new_with_legs ("cow", 4) }; - for (int i = 0; i < 2; i++) - a[i]->b.print (a[i]); - return 0; -} diff --git a/20221128/logo-hochschule-bochum-cvh-text-v2.pdf b/20221128/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221128/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221128/logo-hochschule-bochum.pdf b/20221128/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221128/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221128/mathe-20221128-logarithmus.png b/20221128/mathe-20221128-logarithmus.png deleted file mode 100644 index 1c2cc02a7a06a56707822680c1de37b63b70e7b1..0000000000000000000000000000000000000000 Binary files a/20221128/mathe-20221128-logarithmus.png and /dev/null differ diff --git a/20221128/mathe-20221128-potenz.png b/20221128/mathe-20221128-potenz.png deleted file mode 100644 index bd76cb60b73a31b3d70fae3726b543653fce512a..0000000000000000000000000000000000000000 Binary files a/20221128/mathe-20221128-potenz.png and /dev/null differ diff --git a/20221128/mathe-20221128.xcf.gz b/20221128/mathe-20221128.xcf.gz deleted file mode 100644 index c1671252bf32db5deb192f767980e9c3f7a26019..0000000000000000000000000000000000000000 Binary files a/20221128/mathe-20221128.xcf.gz and /dev/null differ diff --git a/20221128/objects-01.c b/20221128/objects-01.c deleted file mode 100644 index 1a628668fd7b8fb3a0d9886ac14e8e909bc23793..0000000000000000000000000000000000000000 --- a/20221128/objects-01.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int type; -} t_base; - -typedef struct -{ - int type; - int content; -} t_integer; - -typedef struct -{ - int type; - char *content; -} t_string; - -int main (void) -{ - t_integer i = { 1, 42 }; - t_string s = { 2, "Hello, world!" }; - - t_base *object[] = { &i, &s }; - - return 0; -} diff --git a/20221128/objects-02.c b/20221128/objects-02.c deleted file mode 100644 index a47cfb4276085399afb86795d04b1f6ae20c95bf..0000000000000000000000000000000000000000 --- a/20221128/objects-02.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int type; -} t_base; - -typedef struct -{ - int type; - int content; -} t_integer; - -typedef struct -{ - int type; - char *content; -} t_string; - -int main (void) -{ - t_integer i = { 1, 42 }; - t_string s = { 2, "Hello, world!" }; - - t_base *object[] = { (t_base *) &i, (t_base *) &s }; - - return 0; -} diff --git a/20221128/objects-03.c b/20221128/objects-03.c deleted file mode 100644 index ff9224c0767ccad39f5b1396720ee73b6a0455fb..0000000000000000000000000000000000000000 --- a/20221128/objects-03.c +++ /dev/null @@ -1,34 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int type; -} t_base; - -typedef struct -{ - int type; - int content; -} t_integer; - -typedef struct -{ - int type; - char *content; -} t_string; - -int main (void) -{ - t_integer i = { 1, 42 }; - t_string s = { 2, "Hello, world!" }; - - t_base *object[] = { (t_base *) &i, (t_base *) &s }; - - for (int i = 0; i < 2; i++) - if (object[i]->type == 1) - printf ("Integer: %d\n", object[i]->content); - else if (object[i]->type == 2) - printf ("String: \"%s\"\n", object[i]->content); - - return 0; -} diff --git a/20221128/objects-04.c b/20221128/objects-04.c deleted file mode 100644 index ef7bffe80471d4b014258824421dce0557fc41dd..0000000000000000000000000000000000000000 --- a/20221128/objects-04.c +++ /dev/null @@ -1,34 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int type; -} t_base; - -typedef struct -{ - int type; - int content; -} t_integer; - -typedef struct -{ - int type; - char *content; -} t_string; - -int main (void) -{ - t_integer i = { 1, 42 }; - t_string s = { 2, "Hello, world!" }; - - t_base *object[] = { (t_base *) &i, (t_base *) &s }; - - for (int i = 0; i < 2; i++) - if (object[i]->type == 1) - printf ("Integer: %d\n", (t_integer *) object[i]->content); - else if (object[i]->type == 2) - printf ("String: \"%s\"\n", (t_string *) object[i]->content); - - return 0; -} diff --git a/20221128/objects-05.c b/20221128/objects-05.c deleted file mode 100644 index 820181d87e2a04b81cd2e03aa7980d970cd6c1a6..0000000000000000000000000000000000000000 --- a/20221128/objects-05.c +++ /dev/null @@ -1,34 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int type; -} t_base; - -typedef struct -{ - int type; - int content; -} t_integer; - -typedef struct -{ - int type; - char *content; -} t_string; - -int main (void) -{ - t_integer i = { 1, 42 }; - t_string s = { 2, "Hello, world!" }; - - t_base *object[] = { (t_base *) &i, (t_base *) &s }; - - for (int i = 0; i < 2; i++) - if (object[i]->type == 1) - printf ("Integer: %d\n", ((t_integer *) object[i])->content); - else if (object[i]->type == 2) - printf ("String: \"%s\"\n", ((t_string *) object[i])->content); - - return 0; -} diff --git a/20221128/objects-06.c b/20221128/objects-06.c deleted file mode 100644 index 86847c9085083e2d5093026619550fb272b5f4ec..0000000000000000000000000000000000000000 --- a/20221128/objects-06.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int type; -} t_base; - -typedef struct -{ - int type; - int content; -} t_integer; - -typedef struct -{ - int type; - char *content; -} t_string; - -void print_object (t_base *this) -{ - if (this->type == 1) - printf ("Integer: %d\n", ((t_integer *) this)->content); - else if (this->type == 2) - printf ("String: \"%s\"\n", ((t_string *) this)->content); -} - -int main (void) -{ - t_integer i = { 1, 42 }; - t_string s = { 2, "Hello, world!" }; - - t_base *object[] = { (t_base *) &i, (t_base *) &s }; - - for (int i = 0; i < 2; i++) - print_object (object[i]); - - return 0; -} diff --git a/20221128/objects-07.c b/20221128/objects-07.c deleted file mode 100644 index b9b24ad65f650aeda194e4570ae853e1a5ad8f11..0000000000000000000000000000000000000000 --- a/20221128/objects-07.c +++ /dev/null @@ -1,43 +0,0 @@ -#include <stdio.h> - -#define T_BASE 0 -#define T_INTEGER 1 -#define T_STRING 2 - -typedef struct -{ - int type; -} t_base; - -typedef struct -{ - int type; - int content; -} t_integer; - -typedef struct -{ - int type; - char *content; -} t_string; - -void print_object (t_base *this) -{ - if (this->type == T_INTEGER) - printf ("Integer: %d\n", ((t_integer *) this)->content); - else if (this->type == T_STRING) - printf ("String: \"%s\"\n", ((t_string *) this)->content); -} - -int main (void) -{ - t_integer i = { T_INTEGER, 42 }; - t_string s = { T_STRING, "Hello, world!" }; - - t_base *object[] = { (t_base *) &i, (t_base *) &s, NULL }; - - for (int i = 0; object[i]; i++) - print_object (object[i]); - - return 0; -} diff --git a/20221128/objects-08.c b/20221128/objects-08.c deleted file mode 100644 index 0c93e8f6c3c4b5e504c758dfa87b8510e98c0692..0000000000000000000000000000000000000000 --- a/20221128/objects-08.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define T_BASE 0 -#define T_INTEGER 1 -#define T_STRING 2 - -typedef struct -{ - int type; -} t_base; - -typedef struct -{ - int type; - int content; -} t_integer; - -typedef struct -{ - int type; - char *content; -} t_string; - -void print_object (t_base *this) -{ - if (this->type == T_INTEGER) - printf ("Integer: %d\n", ((t_integer *) this)->content); - else if (this->type == T_STRING) - printf ("String: \"%s\"\n", ((t_string *) this)->content); -} - -t_integer *new_integer (int i) -{ - t_integer *p = malloc (sizeof (t_integer)); - p->type = T_INTEGER; - p->content = i; - return p; -} - -t_string *new_string (char *s) -{ - t_string *p = malloc (sizeof (t_string)); - p->type = T_STRING; - p->content = s; - return p; -} - -int main (void) -{ - t_base *object[] = { (t_base *) new_integer (42), - (t_base *) new_string ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - print_object (object[i]); - - return 0; -} diff --git a/20221128/objects-09.c b/20221128/objects-09.c deleted file mode 100644 index 3355ce354278e9839db0952c6de0d7acca172157..0000000000000000000000000000000000000000 --- a/20221128/objects-09.c +++ /dev/null @@ -1,69 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define T_BASE 0 -#define T_INTEGER 1 -#define T_STRING 2 - -typedef struct -{ - int type; -} t_base; - -typedef struct -{ - int type; - int content; -} t_integer; - -typedef struct -{ - int type; - char *content; -} t_string; - -typedef union -{ - t_base base; - t_integer integer; - t_string string; -} t_object; - -void print_object (t_object *this) -{ - if (this->base.type == T_INTEGER) - printf ("Integer: %d\n", this->integer.content); - else if (this->base.type == T_STRING) - printf ("String: \"%s\"\n", this->string.content); -} - -t_object *new_integer (int i) -{ - t_object *p = malloc (sizeof (t_integer)); - p->integer.type = T_INTEGER; - p->integer.content = i; - return p; -} - -t_object *new_string (char *s) -{ - t_object *p = malloc (sizeof (t_string)); - p->string.type = T_STRING; - p->string.content = s; - return p; -} - -int main (void) -{ - t_object *object[] = { new_integer (42), - new_string ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - print_object (object[i]); - - for (int i = 0; object[i]; i++) - free (object[i]); - - return 0; -} diff --git a/20221128/objects-09a.c b/20221128/objects-09a.c deleted file mode 100644 index e98c5bd7f08421834d3322d1d7cdd568707ed4ba..0000000000000000000000000000000000000000 --- a/20221128/objects-09a.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct -{ -} t_base; - -typedef struct -{ - int content; -} t_integer; - -typedef struct -{ - char *content; -} t_string; - -typedef union -{ - t_base base; - t_integer integer; - t_string string; -} t_object; - -void print_object (t_object *this) -{ -// if (this->base.type == T_INTEGER) -// printf ("Integer: %d\n", this->integer.content); -// else if (this->base.type == T_STRING) -// printf ("String: \"%s\"\n", this->string.content); -} - -t_object *new_integer (int i) -{ - t_object *p = malloc (sizeof (t_integer)); - p->integer.content = i; - return p; -} - -t_object *new_string (char *s) -{ - t_object *p = malloc (sizeof (t_string)); - p->string.content = s; - return p; -} - -int main (void) -{ - t_object *object[] = { new_integer (42), - new_string ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - print_object (object[i]); - - for (int i = 0; object[i]; i++) - free (object[i]); - - return 0; -} diff --git a/20221128/objects-09b.c b/20221128/objects-09b.c deleted file mode 100644 index f1d8678839e5b2fc66bebf77074a1a2195440444..0000000000000000000000000000000000000000 --- a/20221128/objects-09b.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -typedef struct -{ -} t_base; - -typedef struct -{ - int content; -} t_integer; - -typedef struct -{ - char *content; -} t_string; - -typedef union -{ - t_base base; - t_integer integer; - t_string string; -} t_object; - -void print_object (t_object *this) -{ - printf ("Wenn dies eine Integer ist, dann lautet sie: %d.\n", this->integer.content); - printf ("Wenn dies ein String ist, ist er %zu Zeichen lang.\n", - strlen (this->string.content)); -} - -t_object *new_integer (int i) -{ - t_object *p = malloc (sizeof (t_integer)); - p->integer.content = i; - return p; -} - -t_object *new_string (char *s) -{ - t_object *p = malloc (sizeof (t_string)); - p->string.content = s; - return p; -} - -int main (void) -{ - t_object *object[] = { new_integer (42), - new_string ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - print_object (object[i]); - - for (int i = 0; object[i]; i++) - free (object[i]); - - return 0; -} diff --git a/20221128/objects-09c.c b/20221128/objects-09c.c deleted file mode 100644 index 6eeff4f335112fea7ef6f4d5b8384a8242f4515b..0000000000000000000000000000000000000000 --- a/20221128/objects-09c.c +++ /dev/null @@ -1,61 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -typedef struct -{ -} t_base; - -typedef struct -{ - int content; -} t_integer; - -typedef struct -{ - char *content; -} t_string; - -typedef union -{ - t_base base; - t_integer integer; - t_string string; -} t_object; - -void print_object (t_object *this) -{ - if (this->integer.content < 1000) /* Heuristik --> Aua! =8-O */ - printf ("Integer: %d\n", this->integer.content); - else - printf ("String: \"%s\"\n", this->string.content); -} - -t_object *new_integer (int i) -{ - t_object *p = malloc (sizeof (t_integer)); - p->integer.content = i; - return p; -} - -t_object *new_string (char *s) -{ - t_object *p = malloc (sizeof (t_string)); - p->string.content = s; - return p; -} - -int main (void) -{ - t_object *object[] = { new_integer (42), - new_string ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - print_object (object[i]); - - for (int i = 0; object[i]; i++) - free (object[i]); - - return 0; -} diff --git a/20221128/objects-10.c b/20221128/objects-10.c deleted file mode 100644 index 86787f3d0339bda54baefd062392d8792cd4b2be..0000000000000000000000000000000000000000 --- a/20221128/objects-10.c +++ /dev/null @@ -1,76 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define T_BASE 0 -#define T_INTEGER 1 -#define T_STRING 2 - -typedef struct -{ - int type; - void (*print) (t_object *this); -} t_base; - -typedef struct -{ - int type; - void (*print) (t_object *this); - int content; -} t_integer; - -typedef struct -{ - int type; - void (*print) (t_object *this); - char *content; -} t_string; - -typedef union -{ - t_base base; - t_integer integer; - t_string string; -} t_object; - -void print_integer (t_object *this) -{ - printf ("Integer: %d\n", this->integer.content); -} - -void print_string (t_object *this) -{ - printf ("String: \"%s\"\n", this->string.content); -} - -t_object *new_integer (int i) -{ - t_object *p = malloc (sizeof (t_integer)); - p->integer.type = T_INTEGER; - p->integer.print = print_integer; - p->integer.content = i; - return p; -} - -t_object *new_string (char *s) -{ - t_object *p = malloc (sizeof (t_string)); - p->string.type = T_STRING; - p->string.print = print_string; - p->string.content = s; - return p; -} - -int main (void) -{ - t_object *object[] = { new_integer (42), - new_string ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - object[i]->base.print (object[i]); - - for (int i = 0; object[i]; i++) - free (object[i]); - - return 0; -} diff --git a/20221128/objects-11.c b/20221128/objects-11.c deleted file mode 100644 index 0a921d8b5c88198cdd07aeb409da6b2a57be33ac..0000000000000000000000000000000000000000 --- a/20221128/objects-11.c +++ /dev/null @@ -1,78 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define T_BASE 0 -#define T_INTEGER 1 -#define T_STRING 2 - -union t_object; - -typedef struct -{ - int type; - void (*print) (union t_object *this); -} t_base; - -typedef struct -{ - int type; - void (*print) (union t_object *this); - int content; -} t_integer; - -typedef struct -{ - int type; - void (*print) (union t_object *this); - char *content; -} t_string; - -typedef union t_object -{ - t_base base; - t_integer integer; - t_string string; -} t_object; - -void print_integer (t_object *this) -{ - printf ("Integer: %d\n", this->integer.content); -} - -void print_string (t_object *this) -{ - printf ("String: \"%s\"\n", this->string.content); -} - -t_object *new_integer (int i) -{ - t_object *p = malloc (sizeof (t_integer)); - p->integer.type = T_INTEGER; - p->integer.print = print_integer; - p->integer.content = i; - return p; -} - -t_object *new_string (char *s) -{ - t_object *p = malloc (sizeof (t_string)); - p->string.type = T_STRING; - p->string.print = print_string; - p->string.content = s; - return p; -} - -int main (void) -{ - t_object *object[] = { new_integer (42), - new_string ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - object[i]->base.print (object[i]); - - for (int i = 0; object[i]; i++) - free (object[i]); - - return 0; -} diff --git a/20221128/objects-12.c b/20221128/objects-12.c deleted file mode 100644 index 3b0dddd0b7eda19d8b0545906dabd76bc9c8a378..0000000000000000000000000000000000000000 --- a/20221128/objects-12.c +++ /dev/null @@ -1,69 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -union t_object; - -typedef struct -{ - void (* print) (union t_object *this); -} t_base; - -typedef struct -{ - void (* print) (union t_object *this); - int content; -} t_integer; - -typedef struct -{ - void (* print) (union t_object *this); - char *content; -} t_string; - -typedef union t_object -{ - t_base base; - t_integer integer; - t_string string; -} t_object; - -void print_integer (t_object *this) -{ - printf ("Integer: %d\n", this->integer.content); -} - -void print_string (t_object *this) -{ - printf ("String: \"%s\"\n", this->string.content); -} - -t_object *new_integer (int i) -{ - t_object *p = malloc (sizeof (t_integer)); - p->integer.print = print_integer; - p->integer.content = i; - return p; -} - -t_object *new_string (char *s) -{ - t_object *p = malloc (sizeof (t_string)); - p->string.print = print_string; - p->string.content = s; - return p; -} - -int main (void) -{ - t_object *object[] = { new_integer (42), - new_string ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - object[i]->base.print (object[i]); - - for (int i = 0; object[i]; i++) - free (object[i]); - - return 0; -} diff --git a/20221128/objects-14.cpp b/20221128/objects-14.cpp deleted file mode 100644 index 90329346afd7d1cfd1caad1d267781b25300b4ca..0000000000000000000000000000000000000000 --- a/20221128/objects-14.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include <stdio.h> - -struct TBase -{ - virtual void print () = 0; -}; - -struct TInteger: TBase -{ - int content; - virtual void print (); - TInteger (int i); -}; - -struct TString: TBase -{ - char *content; - virtual void print (); - TString (char *s); -}; - -void TInteger::print () -{ - printf ("Integer: %d\n", content); -} - -void TString::print () -{ - printf ("String: \"%s\"\n", content); -} - -TInteger::TInteger (int i) -{ - content = i; -} - -TString::TString (char *s) -{ - content = s; -} - -int main (void) -{ - TBase *object[] = { new TInteger (42), - new TString ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - object[i]->print (); - - for (int i = 0; object[i]; i++) - delete object[i]; - - return 0; -} diff --git a/20221128/pgscript.sty b/20221128/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221128/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221128/pgslides.sty b/20221128/pgslides.sty deleted file mode 120000 index 5be1416f4216f076aa268901f52a15d775e43f64..0000000000000000000000000000000000000000 --- a/20221128/pgslides.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgslides.sty \ No newline at end of file diff --git a/20221128/pow-01.c b/20221128/pow-01.c deleted file mode 100644 index 68429658875b95cfc3204d432abe48276e95ab29..0000000000000000000000000000000000000000 --- a/20221128/pow-01.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> -#include <math.h> - -int main (void) -{ - double x = 3.0; - printf ("x^2 = %lf\n", pow (x, 2.0)); - return 0; -} diff --git a/20221128/pow-02.c b/20221128/pow-02.c deleted file mode 100644 index 23d68909428cc7d04d7269c992e20133a918c2fa..0000000000000000000000000000000000000000 --- a/20221128/pow-02.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> -#include <math.h> - -int main (void) -{ - double x = 3.0; - printf ("sin x = %lf\n", sin (x)); - return 0; -} diff --git a/20221128/pow-03.c b/20221128/pow-03.c deleted file mode 100644 index b83b61b32eb1f9ffca055648bad65e091047199e..0000000000000000000000000000000000000000 --- a/20221128/pow-03.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> -#include <math.h> - -int main (void) -{ - double x = 3.0; - printf ("x^3.5 = %lf\n", pow (x, 3.5)); - return 0; -} diff --git a/20221128/pow-04.c b/20221128/pow-04.c deleted file mode 100644 index 0617af43310580d0acbca2e99b5ff3e1de95c177..0000000000000000000000000000000000000000 --- a/20221128/pow-04.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> -#include <math.h> - -int main (void) -{ - double x = 9.0; - printf ("x^0.5 = %lf\n", pow (x, 0.5)); - return 0; -} diff --git a/20221128/pow-05.c b/20221128/pow-05.c deleted file mode 100644 index 9808de6fda92539fb3f0a80bb46e913edfc71302..0000000000000000000000000000000000000000 --- a/20221128/pow-05.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> -#include <math.h> - -double my_pow (double x, double a) -{ - return exp (a * log (x)); -} - -int main (void) -{ - double x = 9.0; - printf ("x^0.5 = %lf\n", my_pow (x, 0.5)); - return 0; -} diff --git a/20221128/pow-06.c b/20221128/pow-06.c deleted file mode 100644 index 83468217f81917c65fa472c419c14d3c07608209..0000000000000000000000000000000000000000 --- a/20221128/pow-06.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdio.h> -#include <math.h> - -int main (void) -{ - double x = 3.0; - printf ("x^2 = %lf\n", x * x); - return 0; -} diff --git a/20221128/pow-07.c b/20221128/pow-07.c deleted file mode 100644 index ca18127007fed147135436b911b9045bef8d3da6..0000000000000000000000000000000000000000 --- a/20221128/pow-07.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> -#include <math.h> - -double sqr (double x ) -{ - return x * x; -} - -int main (void) -{ - double x = 3.0; - printf ("x^2 = %lf\n", sqr (x)); - return 0; -} diff --git a/20221128/pow-08.c b/20221128/pow-08.c deleted file mode 100644 index 700c632053e97b3adae0ab9f69aa7832678a1232..0000000000000000000000000000000000000000 --- a/20221128/pow-08.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> -#include <math.h> - -#define G (6.67 * pow (10.0, -11.0)) - -int main (void) -{ - printf ("G = %lf\n", G); - return 0; -} diff --git a/20221128/pow-09.c b/20221128/pow-09.c deleted file mode 100644 index b774b6089add30a68008f561b8652220a6c49ffb..0000000000000000000000000000000000000000 --- a/20221128/pow-09.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> -#include <math.h> - -#define G (6.67 * pow (10.0, -11.0)) - -int main (void) -{ - printf ("G = %lg\n", G); - return 0; -} diff --git a/20221128/pow-10.c b/20221128/pow-10.c deleted file mode 100644 index c77e6959c14acf7718a0b7a2d5d0c3a148760698..0000000000000000000000000000000000000000 --- a/20221128/pow-10.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> -#include <math.h> - -#define G 6.67e-11 - -int main (void) -{ - printf ("G = %lg\n", G); - return 0; -} diff --git a/20221128/unions-1.c b/20221128/unions-1.c deleted file mode 100644 index b75a6063b50193e13e9a2fd0ce140db6a8827499..0000000000000000000000000000000000000000 --- a/20221128/unions-1.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -typedef union -{ - int8_t i; - uint8_t u; -} num8_t; - -int main (void) -{ - num8_t test; - test.i = -1; - printf ("%d\n", test.u); - return 0; -} diff --git a/20221128/unions-2.c b/20221128/unions-2.c deleted file mode 100644 index ad96e60b3a4c74f1f77e95aecee657171e288bdd..0000000000000000000000000000000000000000 --- a/20221128/unions-2.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -typedef union -{ - int64_t i; - uint64_t u; -} num8_t; - -int main (void) -{ - num8_t test; - test.i = -1; - printf ("%lu\n", test.u); - return 0; -} diff --git a/20221128/unions-3.c b/20221128/unions-3.c deleted file mode 100644 index be8562a50395e50e007dc1c0b19b98a476935670..0000000000000000000000000000000000000000 --- a/20221128/unions-3.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -typedef union -{ - char s[8]; - uint64_t x; -} num_char_t; - -int main (void) -{ - num_char_t test = { "Hello!" }; - printf ("%lx\n", test.x); - return 0; -} diff --git a/20221128/unions-4.c b/20221128/unions-4.c deleted file mode 100644 index 85ca115d1eebef66b56a7db908f524dd2cc18e1f..0000000000000000000000000000000000000000 --- a/20221128/unions-4.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -typedef union -{ - char s[8]; - uint64_t x; -} num_char_t; - -int main (void) -{ - num_char_t test = { "Hello!" }; - printf ("%s\n", test.s); - return 0; -} diff --git a/20221128/unions-5.c b/20221128/unions-5.c deleted file mode 100644 index e9e8ab798c320a72ac7c08e8e10215b027364aa2..0000000000000000000000000000000000000000 --- a/20221128/unions-5.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -typedef union -{ - char s[8]; - uint64_t x; -} num_char_t; - -int main (void) -{ - num_char_t test = { 36762444129608 }; - printf ("%lu\n", test.x); - return 0; -} diff --git a/20221128/unions-6.c b/20221128/unions-6.c deleted file mode 100644 index dcd1821068bb00db66038bbd8472215469209ea3..0000000000000000000000000000000000000000 --- a/20221128/unions-6.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -typedef union -{ - char s[8]; - uint64_t x; -} num_char_t; - -int main (void) -{ - num_char_t test = { x: 36762444129608lu }; - printf ("%s\n", test.s); - return 0; -} diff --git a/20221128/unions-7.c b/20221128/unions-7.c deleted file mode 100644 index 9c689ec6965d16f8dbf79e9d292e2150ec144440..0000000000000000000000000000000000000000 --- a/20221128/unions-7.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -typedef union -{ - char s[8]; - uint64_t x; -} num_char_t; - -int main (void) -{ - num_char_t test; - test.x = 36762444129608lu; - printf ("%s\n", test.s); - return 0; -} diff --git a/20221128/unions-8.c b/20221128/unions-8.c deleted file mode 100644 index e5b6b01db5d8c88b335e4d01728cb976a0afcc0a..0000000000000000000000000000000000000000 --- a/20221128/unions-8.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -typedef union -{ - char s[8]; - uint64_t x; -} num_char_t; - -int main (void) -{ - num_char_t test; - test.x = 36762444129608; - printf ("%s\n", test.s); - return 0; -} diff --git a/20221205/Makefile-01 b/20221205/Makefile-01 deleted file mode 100644 index 45ab22bf999a86d0681ed79a7f18faa5dd6d4717..0000000000000000000000000000000000000000 --- a/20221205/Makefile-01 +++ /dev/null @@ -1,2 +0,0 @@ -hello-gtk: hello-gtk.c - gcc -Wall -O $(pkg-config --cflags gtk+-3.0) hello-gtk.c $(pkg-config --libs gtk+-3.0) -lm -o hello-gtk diff --git a/20221205/Makefile-02 b/20221205/Makefile-02 deleted file mode 100644 index d7b97c659d91beb4aba4430550ca46fb5a40b0e2..0000000000000000000000000000000000000000 --- a/20221205/Makefile-02 +++ /dev/null @@ -1,2 +0,0 @@ -hello-gtk: hello-gtk.c - gcc -Wall -O $(shell pkg-config --cflags gtk+-3.0) hello-gtk.c $(shell pkg-config --libs gtk+-3.0) -lm -o hello-gtk diff --git a/20221205/aufgabe-1a.c b/20221205/aufgabe-1a.c deleted file mode 100644 index 61b6e79400afbb8ac0609eb1b72c04b83a0fce41..0000000000000000000000000000000000000000 --- a/20221205/aufgabe-1a.c +++ /dev/null @@ -1,50 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int wings; -} with_wings; - -typedef struct with_legs -{ - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - a[0]->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - a[1]->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; -} diff --git a/20221205/aufgabe-1b.c b/20221205/aufgabe-1b.c deleted file mode 100644 index 2cf3b56f4540f399d3761b0de929d80a1f1de611..0000000000000000000000000000000000000000 --- a/20221205/aufgabe-1b.c +++ /dev/null @@ -1,50 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int wings; -} with_wings; - -typedef struct with_legs -{ - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - ((with_wings *) a[0])->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; -} diff --git a/20221205/aufgabe-2.c b/20221205/aufgabe-2.c deleted file mode 100644 index a1054f2b601850a402dccb6f4878437d1bb6909c..0000000000000000000000000000000000000000 --- a/20221205/aufgabe-2.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <stdio.h> - -void foreach (int *a, void (*fun) (int x)) -{ - for (int *p = a; *p >= 0; p++) - fun (*p); -} - -void even_or_odd (int x) -{ - if (x % 2) - printf ("%d ist ungerade.\n", x); - else - printf ("%d ist gerade.\n", x); -} - -int main (void) -{ - int numbers[] = { 12, 17, 32, 1, 3, 16, 19, 18, -1 }; - foreach (numbers, even_or_odd); - return 0; -} diff --git a/20221205/aufgabe-3.c b/20221205/aufgabe-3.c deleted file mode 100644 index 82e5b1ca9e2f896bcbec98bc5c34cdf15d086e26..0000000000000000000000000000000000000000 --- a/20221205/aufgabe-3.c +++ /dev/null @@ -1,53 +0,0 @@ -#include <stdio.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - stack[stack_pointer++] = x; -} - -void show (void) -{ - printf ("stack content:"); - for (int i = 0; i < stack_pointer; i++) - printf (" %d", stack[i]); - if (stack_pointer) - printf ("\n"); - else - printf (" (empty)\n"); -} - -void insert (int x, int pos) -{ - for (int i = pos; i < stack_pointer; i++) - stack[i + 1] = stack[i]; - stack[pos] = x; - stack_pointer++; -} - -void insert_sorted (int x) -{ - int i = 0; - while (i < stack_pointer && x < stack[i]) - i++; - insert (x, i); -} - -int main (void) -{ - push (3); - push (7); - push (137); - show (); - insert (5, 1); - show (); - insert_sorted (42); - show (); - insert_sorted (2); - show (); - return 0; -} diff --git a/20221205/fifo-01.c b/20221205/fifo-01.c deleted file mode 100644 index 8bce6c07c152381c11ce367027b980a9330be3e0..0000000000000000000000000000000000000000 --- a/20221205/fifo-01.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdio.h> - -#define FIFO_SIZE 10 - -int fifo[FIFO_SIZE]; -int fifo_pointer = 0; - -void push (int x) -{ - fifo[fifo_pointer++] = x; -} - -int pop (void) -{ - return fifo[0]; - fifo[0] = fifo[1]; - fifo[1] = fifo[2]; - fifo[2] = fifo[3]; - /* ... */ -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/fifo-02.c b/20221205/fifo-02.c deleted file mode 100644 index f95579893f62180b408ecb10756ac8938b3c9848..0000000000000000000000000000000000000000 --- a/20221205/fifo-02.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdio.h> - -#define FIFO_SIZE 10 - -int fifo[FIFO_SIZE]; -int fifo_pointer = 0; - -void push (int x) -{ - fifo[fifo_pointer++] = x; -} - -int pop (void) -{ - fifo[0] = fifo[1]; - fifo[1] = fifo[2]; - fifo[2] = fifo[3]; - /* ... */ - return fifo[0]; -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/fifo-03.c b/20221205/fifo-03.c deleted file mode 100644 index 5214e1b28fb1b060bdaeea7be09e346a644e7f5d..0000000000000000000000000000000000000000 --- a/20221205/fifo-03.c +++ /dev/null @@ -1,32 +0,0 @@ -#include <stdio.h> - -#define FIFO_SIZE 10 - -int fifo[FIFO_SIZE]; -int fifo_pointer = 0; - -void push (int x) -{ - fifo[fifo_pointer++] = x; -} - -int pop (void) -{ - int result = fifo[0]; - fifo[0] = fifo[1]; - fifo[1] = fifo[2]; - fifo[2] = fifo[3]; - /* ... */ - return result; -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/fifo-04.c b/20221205/fifo-04.c deleted file mode 100644 index 957d5f18f6c8fe9d7c057db3d2467221b9dc463e..0000000000000000000000000000000000000000 --- a/20221205/fifo-04.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <stdio.h> - -#define FIFO_SIZE 10 - -int fifo[FIFO_SIZE]; -int fifo_pointer = 0; - -void push (int x) -{ - fifo[fifo_pointer++] = x; -} - -int pop (void) -{ - int result = fifo[0]; - for (int i = 1; i < FIFO_SIZE; i++) - fifo[i - 1] = fifo[i]; - return result; -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/fifo-05.c b/20221205/fifo-05.c deleted file mode 100644 index 092c1cdb5863d5c7bdac98f48ca8527ca3520e6b..0000000000000000000000000000000000000000 --- a/20221205/fifo-05.c +++ /dev/null @@ -1,32 +0,0 @@ -#include <stdio.h> - -#define FIFO_SIZE 10 - -int fifo[FIFO_SIZE]; -int fifo_pointer = 0; - -void push (int x) -{ - fifo[fifo_pointer++] = x; -} - -int pop (void) -{ - int result = fifo[0]; - for (int i = 1; i < FIFO_SIZE; i++) - fifo[i - 1] = fifo[i]; - return result; -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - push (42); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/fifo-06.c b/20221205/fifo-06.c deleted file mode 100644 index 2f055d6ce6df4c2fca950192053a6e008bed38b4..0000000000000000000000000000000000000000 --- a/20221205/fifo-06.c +++ /dev/null @@ -1,33 +0,0 @@ -#include <stdio.h> - -#define FIFO_SIZE 10 - -int fifo[FIFO_SIZE]; -int fifo_pointer = 0; - -void push (int x) -{ - fifo[fifo_pointer++] = x; -} - -int pop (void) -{ - int result = fifo[0]; - for (int i = 1; i < FIFO_SIZE; i++) - fifo[i - 1] = fifo[i]; - fifo_pointer--; - return result; -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - push (42); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/fifo-06a.c b/20221205/fifo-06a.c deleted file mode 100644 index 6a7b2d3c138908cb7eb06379b9c574f262717af0..0000000000000000000000000000000000000000 --- a/20221205/fifo-06a.c +++ /dev/null @@ -1,33 +0,0 @@ -#include <stdio.h> - -#define FIFO_SIZE 10 - -int fifo[FIFO_SIZE]; -int fifo_pointer = 0; - -void push (int x) -{ - fifo[fifo_pointer++] = x; -} - -int pop (void) -{ - int result = fifo[0]; - for (int i = 1; i < fifo_pointer; i++) - fifo[i - 1] = fifo[i]; - fifo_pointer--; - return result; -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - push (42); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/fifo-07.c b/20221205/fifo-07.c deleted file mode 100644 index 0d739115c136639f64c4d98c439af7e4d72fe420..0000000000000000000000000000000000000000 --- a/20221205/fifo-07.c +++ /dev/null @@ -1,35 +0,0 @@ -#include <stdio.h> - -#define FIFO_SIZE 10 - -int fifo[FIFO_SIZE]; -int fifo_write_pointer = 0; -int fifo_read_pointer = 0; - -void push (int x) -{ - fifo[fifo_write_pointer++] = x; - if (fifo_write_pointer >= FIFO_SIZE) - fifo_write_pointer = 0; -} - -int pop (void) -{ - int result = fifo[fifo_read_pointer++]; - if (fifo_read_pointer >= FIFO_SIZE) - fifo_read_pointer = 0; - return result; -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - push (42); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/fifo-08.c b/20221205/fifo-08.c deleted file mode 100644 index b4ff68713645e0a5782b516071022bf71a8c50ac..0000000000000000000000000000000000000000 --- a/20221205/fifo-08.c +++ /dev/null @@ -1,50 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define FIFO_SIZE 10 - -int fifo[FIFO_SIZE]; -int fifo_write_pointer = 0; -int fifo_read_pointer = 0; - -void push (int x) -{ - fifo[fifo_write_pointer++] = x; - if (fifo_write_pointer >= FIFO_SIZE) - fifo_write_pointer = 0; - if (fifo_write_pointer == fifo_read_pointer) - { - fprintf (stderr, "fifo overflow\n"); - exit (1); - } -} - -int pop (void) -{ - if (fifo_read_pointer == fifo_write_pointer) - { - fprintf (stderr, "fifo underflow\n"); - exit (1); - } - else - { - int result = fifo[fifo_read_pointer++]; - if (fifo_read_pointer >= FIFO_SIZE) - fifo_read_pointer = 0; - return result; - } -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - push (42); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/fifo-09.c b/20221205/fifo-09.c deleted file mode 100644 index 27f77412bac52fd70c52378c25531f03bd93d734..0000000000000000000000000000000000000000 --- a/20221205/fifo-09.c +++ /dev/null @@ -1,55 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define FIFO_SIZE 10 - -int fifo[FIFO_SIZE]; -int fifo_write_pointer = 0; -int fifo_read_pointer = 0; - -void push (int x) -{ - int old_fifo_write_pointer = fifo_write_pointer; - fifo_write_pointer++; - if (fifo_write_pointer >= FIFO_SIZE) - fifo_write_pointer = 0; - if (fifo_write_pointer == fifo_read_pointer) - { - fprintf (stderr, "fifo overflow\n"); - exit (1); - } - else - fifo[old_fifo_write_pointer] = x; -} - -int pop (void) -{ - if (fifo_read_pointer == fifo_write_pointer) - { - fprintf (stderr, "fifo underflow\n"); - exit (1); - } - else - { - int result = fifo[fifo_read_pointer++]; - if (fifo_read_pointer >= FIFO_SIZE) - fifo_read_pointer = 0; - return result; - } -} - -int main (void) -{ - push (3); - push (7); - push (137); - for (int i = 0; i < 42; i++) - push (i); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - push (42); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/hello-gtk.c b/20221205/hello-gtk.c deleted file mode 100644 index 016867d41e42de57390a21653de467c061e5ded0..0000000000000000000000000000000000000000 --- a/20221205/hello-gtk.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <gtk/gtk.h> - -int main (int argc, char **argv) -{ - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); - GtkWidget *label = gtk_label_new ("Hello, world!"); - gtk_container_add (GTK_CONTAINER (vbox), label); - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - gtk_widget_show (button); - gtk_widget_show (label); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; -} diff --git a/20221205/hello-gtk.png b/20221205/hello-gtk.png deleted file mode 120000 index cca99209d86683a9a3b0f70bbc149780bae10ba6..0000000000000000000000000000000000000000 --- a/20221205/hello-gtk.png +++ /dev/null @@ -1 +0,0 @@ -../common/hello-gtk.png \ No newline at end of file diff --git a/20221205/hp-20221205.pdf b/20221205/hp-20221205.pdf deleted file mode 100644 index ca3a72255a00f7d3a062ac86a4c0fc4b0fe0ce6f..0000000000000000000000000000000000000000 Binary files a/20221205/hp-20221205.pdf and /dev/null differ diff --git a/20221205/hp-20221205.tex b/20221205/hp-20221205.tex deleted file mode 100644 index 9427a3cdf8f5e13f7ef8819c2d8724f98f5f29cc..0000000000000000000000000000000000000000 --- a/20221205/hp-20221205.tex +++ /dev/null @@ -1,1184 +0,0 @@ -% hp-20221205.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Objektorientierte Programmierung, Datenstrukturen - -\documentclass[10pt,t]{beamer} - -\usepackage{pgslides} -\usepackage{pdftricks} -\usepackage{tikz} -\usepackage{rotating} - -\begin{psinputs} - \usepackage[utf8]{inputenc} - \usepackage[german]{babel} - \usepackage[T1]{fontenc} - \usepackage{helvet} - \renewcommand*\familydefault{\sfdefault} - \usepackage{pstricks,pst-grad} -\end{psinputs} - -\newcommand{\redurl}[1]{\href{#1}{\color{red}\nolinkurl{#1}}} - -\title{Hardwarenahe Programmierung} -\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{5.\ Dezember 2022} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \begin{itemize} - \color{medgreen} - \item[6.0] Dynamische Speicherverwaltung - \item[6.1] Konzepte und Ziele - \item[6.2] Beispiel: Zahlen und Buchstaben - \item[6.3] Unions - \color{orange} - \item[6.4] Virtuelle Methoden - \color{red} - \item[6.5] Beispiel: Graphische Benutzeroberfläche (GUI) - \item[6.6] Ausblick: C++ - \end{itemize} - \item[\textbf{7}] \textbf{Datenstrukturen} - \end{itemize} - \vspace*{-1cm} - -\end{frame} - -\setcounter{section}{5} -\section{Objektorientierte Programmierung} - -\addtocounter{subsection}{-1} -\subsection{Dynamische Speicherverwaltung} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \begin{itemize} - \item - Array: feste Anzahl von Elementen desselben Typs (z.\,B.\ 3 ganze Zahlen) - \item - Dynamisches Array: variable Anzahl von Elementen desselben Typs - \end{itemize} - - \bigskip - - \begin{lstlisting} - char *name[] = { "Anna", "Berthold", "Caesar" }; - - ... - - name[3] = "Dieter"; - \end{lstlisting} - - \begin{picture}(0,0) - \color{red} - \put(0,0){\line(3,1){3.5}} - \put(0,1){\line(3,-1){3.5}} - \end{picture} - -\end{frame} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \bigskip - - \begin{lstlisting} - #include <stdlib.h> - - ... - - char **name = malloc (3 * sizeof (char *)); - /* Speicherplatz für 3 Zeiger anfordern */ - - ... - - free (name); - /* Speicherplatz freigeben */ - - \end{lstlisting} - -\end{frame} - -\subsection{Konzepte und Ziele} - -\begin{frame} - - \showsection - \showsubsection - - \begin{itemize} - \item -% Array: feste Anzahl von Elementen desselben Typs (z.\,B.\ 3 ganze Zahlen) - Array: Elemente desselben Typs (z.\,B.\ 3 ganze Zahlen) -% \item -% Dynamisches Array: variable Anzahl von Elementen desselben Typs - \item - Problem: Elemente unterschiedlichen Typs - \item - Lösung: den Typ des Elements zusätzlich speichern \textarrow\ \newterm{Objekt} - \item - Problem: Die Elemente sind unterschiedlich groß (Speicherplatz). - \item - Lösung: Im Array nicht die Objekte selbst speichern, sondern Zeiger darauf. - \end{itemize} - \begin{itemize} - \item - Funktionen, die mit dem Objekt arbeiten: \newterm{Methoden} - \begin{onlyenv}<1> - \item - Was die Funktion bewirkt,\\ - hängt vom Typ des Objekts ab - \item - Realisierung über endlose \lstinline{if}-Ketten - \end{onlyenv} - \begin{onlyenv}<2> - \item - Was die Funktion bewirkt - \begin{picture}(0,0) - \color{red} - \put(-4.00,-0.05){\tikz{\draw[thick](0,0.25)--(3.75,-0.05);% - \draw[thick](-0.1,-0.05)--(3.75,0.3);}} - \end{picture}% - Welche Funktion aufgerufen wird,\\ - hängt vom Typ des Objekts ab: \newterm{virtuelle Methode} - \item - Realisierung über endlose \lstinline{if}-Ketten% - \begin{picture}(0,0) - \color{red} - \put(-2.75,-0.05){\tikz{\draw[thick](0,0.25)--(2.5,-0.05);% - \draw[thick](-0.1,-0.05)--(2.5,0.3);}} - \put(1.5,-1.1){\begin{rotate}{7}\large\bf\textarrow\ - kommt gleich -% nächste Woche - \end{rotate}} - \end{picture} - Zeiger, die im Objekt gespeichert sind\\ - (Genaugenommen: Tabelle von Zeigern) - \end{onlyenv} - \end{itemize} - -\end{frame} - -\begin{frame} - - \showsection - \showsubsection - - \begin{itemize} - \item - Problem: Elemente unterschiedlichen Typs - \item - Lösung: den Typ des Elements zusätzlich speichern \textarrow\ \newterm{Objekt} - \item - \newterm{Methoden\/} und \newterm{virtuelle Methoden} - \end{itemize} - - \begin{itemize} - \item - Zeiger auf verschiedene Strukturen\\ - mit einem gemeinsamen Anteil von Datenfeldern\\ - \textarrow\ "`verwandte"' \newterm{Objekte}, \newterm{Klassenhierarchie} von Objekten - \item - Struktur, die \emph{nur\/} den gemeinsamen Anteil enthält\\ - \textarrow\ "`Vorfahr"', \newterm{Basisklasse}, \newterm{Vererbung} - \item -% Explizite Typumwandlung eines Zeigers auf die Basisklasse\\ -% in einen Zeiger auf die \newterm{abgeleitete Klasse}\\ -% \textarrow\ Man kann ein Array unterschiedlicher Objekte\\ -% \strut\phantom{\textarrow} in einer Schleife abarbeiten.\\ - Zeiger auf die Basisklasse dürfen auf Objekte\\ - der \newterm{abgeleiteten Klasse} zeigen\\ - \textarrow\ \newterm{Polymorphie} - \end{itemize} - -\end{frame} - -\subsection{Beispiel: Zahlen und Buchstaben} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - } t_base;¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\begin{frame}[fragile] - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - } t_base;¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - int type; - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage}\\[0.7cm] - \begin{onlyenv}<1> - \begin{minipage}{8cm} - \begin{lstlisting}[gobble=10] - ¡t_integer i = { 1, 42 }; - t_string s = { 2, "Hello, world!" }; - - t_base *object[] = { (t_base *) &i, (t_base *) &s };¿ - \end{lstlisting} - \end{minipage}% - \begin{picture}(0,0) - \color{red} - \put(-5.4,-0.8){\mbox{$\underbrace{\rule{1.45cm}{0pt}}_{\shortstack{\strut explizite\\Typumwandlung}}$}} - \end{picture} - \end{onlyenv} -% \begin{onlyenv}<2> -% \begin{minipage}{5cm} -% \begin{lstlisting}[gobble=10] -% ¡typedef union -% { -% t_base base; -% t_integer integer; -% t_string string; -% } t_object;¿ -% \end{lstlisting} -% \end{minipage} -% \end{onlyenv} - \end{center} - -\end{frame} - -\subsection{Unions} - -\begin{frame}[fragile] - - \showsubsection - - Variable teilen sich denselben Speicherplatz. - - \medskip - - \begin{minipage}[t]{3.7cm} - \begin{lstlisting}[gobble=6] - ¡typedef union - { - int8_t i; - uint8_t u; - } num8_t;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{4.5cm} - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - num8_t test; - test.i = -1; - printf ("%d\n", test.u); - return 0; - }¿ - \end{lstlisting} - \end{minipage} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Variable teilen sich denselben Speicherplatz. - - \medskip - - \begin{minipage}[t]{3.7cm} - \begin{lstlisting}[gobble=6] - ¡typedef union - { - char s[8]; - uint64_t x; - } num_char_t;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{4.5cm} - \begin{lstlisting}[gobble=6] - ¡int main (void) - { - num_char_t test = { "Hello!" }; - printf ("%lx\n", test.x); - return 0; - }¿ - \end{lstlisting} - \end{minipage} - -\end{frame} - -\begin{frame}[fragile] - - \showsubsection - - Variable teilen sich denselben Speicherplatz. - - \medskip - - \begin{minipage}[t]{3.7cm} - \begin{lstlisting}[gobble=6] - ¡typedef union - { - t_base base; - t_integer integer; - t_string string; - } t_object;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{3.0cm} - \begin{lstlisting}[gobble=6] - - ¡typedef struct - { - int type; - } t_base;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{3.0cm} - \begin{lstlisting}[gobble=6] - - ¡typedef struct - { - int type; - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage}% - \begin{minipage}[t]{3.0cm} - \begin{lstlisting}[gobble=6] - - ¡typedef struct - { - int type; - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage} - - \bigskip - - \begin{center} - \begin{minipage}{8.5cm} - \begin{lstlisting}[gobble=8] - ¡if (this->base.type == T_INTEGER) - printf ("Integer: %d\n", this->integer.content); - else if (this->base.type == T_STRING) - printf ("String: \"%s\"\n", this->string.content);¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\subsection{Virtuelle Methoden} - -\begin{frame}[fragile] - \showsubsection - - \begin{lstlisting} - void print_object (t_object *this) - { - if (this->base.type == T_INTEGER) - printf ("Integer: %d\n", this->integer.content); - else if (this->base.type == T_STRING) - printf ("String: \"%s\"\n", this->string.content); - } - \end{lstlisting} - - \begin{picture}(0,0) - \color{red} - \put(9,1.7){\shortstack[l]{if-Kette:\\\strut wird unübersichtlich}} - \put(1,-2){\mbox{\textarrow}} - \put(0,-3){\mbox{Zeiger auf Funktionen}} - \end{picture} - - \begin{lstlisting}[xleftmargin=4cm] - void print_integer (t_object *this) - { - printf ("Integer: %d\n", this->integer.content); - } - - void print_string (t_object *this) - { - printf ("String: \"%s\"\n", this->string.content); - } - \end{lstlisting} - -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - Zeiger auf Funktionen - - \medskip - - \begin{lstlisting} - void (*print) (t_object *this); - \end{lstlisting} - \begin{picture}(0,1.2)(0,-0.9) - \color{red} - \put(0.95,0.3){\mbox{$\underbrace{\rule{1cm}{0pt}}$}} - \put(0.2,-0.7){\shortstack{das, worauf print zeigt,\\ist eine Funktion}} - \end{picture} - - \begin{itemize} - \item - Objekt enthält Zeiger auf Funktion - \begin{onlyenv}<1> - \medskip - \begin{lstlisting}[gobble=10] - typedef struct - { - void (*print) (union t_object *this); - int content; - } t_integer; - \end{lstlisting} - \vspace*{-2cm} - \end{onlyenv} - \begin{onlyenv}<2-> - \vspace*{-3.5cm} % Why doesn't a picture environment work here??? :-( - \begin{lstlisting}[gobble=10,xleftmargin=5.5cm] - typedef struct - { - void (*print) (union t_object *this); - int content; - } t_integer; - \end{lstlisting} - \vspace*{0.85cm} - \bigskip - \smallskip - \end{onlyenv} - \pause - \item - Konstruktor initialisiert diesen Zeiger - \begin{onlyenv}<2> - \medskip - \begin{lstlisting}[gobble=10] - t_object *new_integer (int i) - { - t_object *p = malloc (sizeof (t_integer)); - p->integer.print = print_integer; - p->integer.content = i; - return p; - } - \end{lstlisting} - \vspace*{-2cm} - \end{onlyenv} - \pause - \item - Aufruf: "`automatisch"' die richtige Funktion - \begin{onlyenv}<3> - \medskip - \begin{lstlisting}[gobble=10] - for (int i = 0; object[i]; i++) - object[i]->base.print (object[i]); - \end{lstlisting} - \end{onlyenv} - \pause - \medskip - \item - in größeren Projekten:\\ - Objekt enthält Zeiger auf Tabelle von Funktionen - \end{itemize} -\end{frame} - -\subsection{Beispiel: Graphische Benutzeroberfläche (GUI)} - -\begin{frame}[fragile] - - \showsubsection - - \scriptsize - \begin{lstlisting} - #include <gtk/gtk.h> - - int main (int argc, char **argv) - { - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); - GtkWidget *label = gtk_label_new ("Hello, world!"); - gtk_container_add (GTK_CONTAINER (vbox), label); - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - gtk_widget_show (button); - gtk_widget_show (label); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; - } - \end{lstlisting} - - \vspace*{-6cm}\strut\hfill - \includegraphics[scale=0.85]{hello-gtk.png}\\[2cm] - \begin{flushright} - \normalsize\bf Praktikumsversuch:\\ - Objektorientiertes Zeichenprogramm - \end{flushright} - -\end{frame} - -\subsection{Ausblick: C++} - -\begin{frame}[fragile] - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (*print) (union t_object *this); - } t_base;¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5.5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (*print) (...); - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (*print) (union t_object *this); - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡struct TBase - { - virtual void print (void); - };¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5.5cm} - \begin{lstlisting}[gobble=8] - ¡struct TInteger: public TBase - { - virtual void print (void); - int content; - };¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡struct TString: public TBase - { - virtual void print (void); - char *content; - };¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \begin{itemize} - \vspace*{-\smallskipamount} - \item[\dots] - \item[6.3] Unions - \color{medgreen} - \item[6.4] Virtuelle Methoden - \item[6.5] Beispiel: Graphische Benutzeroberfläche (GUI) - \item[6.6] Ausblick: C++ - \end{itemize} - \item[\textbf{7}] \textbf{Datenstrukturen} - \begin{itemize} - \color{red} - \item[7.1] Stack und FIFO - \item[7.2] Verkettete Listen - \item[7.3] Bäume - \end{itemize} - \vspace*{-1cm} - \end{itemize} - -\end{frame} - -\section{Datenstrukturen} -\subsection{Stack und FIFO} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \begin{minipage}{0.48\textwidth} - Im letzten Praktikumsversuch: - \begin{itemize} - \item - Array nur zum Teil benutzt - \item - Variable speichert genutzte Länge - \item - Elemente hinten anfügen\\ - oder entfernen - \arrowitem - Stack\\ - \strut - \end{itemize} - \bigskip - \begin{itemize} - \item - hinten anfügen/entfernen: $\mathcal{O}(1)$\hspace*{-1cm} - \item - vorne oder in der Mitte einfügen/entfernen: $\mathcal{O}(n)$ - \end{itemize} - \end{minipage}\hfill - \begin{minipage}{0.52\textwidth} - Auch möglich: - \begin{itemize} - \item - Array nur zum Teil benutzt - \item - 2 Variable speichern\\genutzte Länge (ringförmig) - \item - Elemente hinten anfügen\\ - oder vorne entfernen - \arrowitem - FIFO - \end{itemize} - \bigskip - \begin{itemize} - \item - vorne oder hinten\\ - anfügen oder entfernen: $\mathcal{O}(1)$ - \item - in der Mitte einfügen/entfernen: $\mathcal{O}(n)$ - \end{itemize} - \end{minipage}\hspace*{-1.5mm} - -\end{frame} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \bigskip - - \begin{minipage}[b]{6cm} - \begin{center} - "`First In -- First Out"' - - \bigskip - - \begin{picture}(6,4) - \thicklines - \color{structure} - \put(0.5,0){\line(1,0){5}} - - \put(3.5,0){\only<1-5>{\line(0,1){1}}} - \put(4.5,0){\only<1-4>{\line(0,1){1}}} - \put(3.5,1){\only<1-4>{\line(1,0){1}}} - \put(4.0,0.5){\only<1-4>{\makebox(0,0){\lstinline{3}}}} - \put(3.0,1.5){\only<1>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(3.0,1.5){\only<1>{\makebox(0,0)[b]{\lstinline{push (3)}}}} - - \put(2.5,0){\only<2-6>{\line(0,1){1}}} - \put(2.5,1){\only<2-5>{\line(1,0){1}}} - \put(3.0,0.5){\only<2-5>{\makebox(0,0){\lstinline{7}}}} - \put(2.0,1.5){\only<2>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(2.0,1.5){\only<2>{\makebox(0,0)[b]{\lstinline{push (7)}}}} - - \put(1.5,0){\only<3-6>{\line(0,1){1}}} - \put(1.5,1){\only<3-6>{\line(1,0){1}}} - \put(2.0,0.5){\only<3-6>{\makebox(0,0){\lstinline{137}}}} - \put(1.0,1.5){\only<3>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(1.0,1.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}} - - \put(4.55,1.05){\only<4>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(5.00,1.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 3}}} - - \put(3.55,1.05){\only<5>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(4.00,1.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}} - - \put(2.55,1.05){\only<6>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(3.00,1.60){\only<6>{\makebox(0,0)[b]{\lstinline{pop ()}: 137}}} - \end{picture} - - \bigskip - - FIFO = Queue = Reihe - \end{center} - \end{minipage}\hfill - \begin{minipage}[b]{6cm} - \begin{center} - "`Last In -- First Out"' - - \bigskip - - \begin{picture}(6,4) - \thicklines - \color{structure} - \put(1.5,0){\line(1,0){3}} - - \put(2.5,0){\line(0,1){1}} - \put(3.5,0){\line(0,1){1}} - \put(2.5,1){\line(1,0){1}} - \put(3.0,0.5){\makebox(0,0){\lstinline{3}}} - \put(2.0,1.5){\only<1>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(2.0,1.5){\only<1>{\makebox(0,0)[b]{\lstinline{push (3)}}}} - - \put(2.5,1){\only<2-5>{\line(0,1){1}}} - \put(3.5,1){\only<2-5>{\line(0,1){1}}} - \put(2.5,2){\only<2-5>{\line(1,0){1}}} - \put(3.0,1.5){\only<2-5>{\makebox(0,0){\lstinline{7}}}} - \put(2.0,2.5){\only<2>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(2.0,2.5){\only<2>{\makebox(0,0)[b]{\lstinline{push (7)}}}} - - \put(2.5,2){\only<3-4>{\line(0,1){1}}} - \put(3.5,2){\only<3-4>{\line(0,1){1}}} - \put(2.5,3){\only<3-4>{\line(1,0){1}}} - \put(3.0,2.5){\only<3-4>{\makebox(0,0){\lstinline{137}}}} - \put(2.0,3.5){\only<3>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(2.0,3.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}} - - \put(3.55,3.05){\only<4>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(4.00,3.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 137}}} - - \put(3.55,2.05){\only<5>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(4.00,2.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}} - - \put(3.55,1.05){\only<6>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(4.00,1.60){\only<6>{\makebox(0,0)[b]{\lstinline{pop ()}: 3}}} - \end{picture} - - \bigskip - - LIFO = Stack = Stapel - \end{center} - \end{minipage} - -% -% \dots - -\end{frame} - -\iffalse - -\begin{frame} - - \showsection - \showsubsection - - \bigskip - - \begin{minipage}[t]{6cm} - Array (Stack, FIFO):\\ - in der Mitte einfügen - \begin{center} - \begin{picture}(6,3.8) - \thicklines - \color{structure} - \put(1.5,0){\line(1,0){3}} - - \put(2.5,0){\line(0,1){3}} - \put(3.5,0){\line(0,1){3}} - \put(2.5,1){\line(1,0){1}} - \put(3.0,0.5){\makebox(0,0){\lstinline{3}}} - \put(2.5,1){\line(1,0){1}} - \put(3.0,1.5){\makebox(0,0){\lstinline{7}}} - \put(2.5,2){\line(1,0){1}} - \put(3.0,2.5){\makebox(0,0){\lstinline{137}}} - \put(2.5,3){\line(1,0){1}} - - \put(1.5,1.5){\makebox(0,0)[b]{\lstinline{push (5)}}} - \put(1.5,1.45){\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.95,-0.45);}}} - - \put(3.55,2.5){\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)..controls(0.5,0.45)..(0,0.9);}}} - \put(3.55,1.5){\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)..controls(0.5,0.45)..(0,0.9);}}} - - \pause - \color{red} - \put(4.1,3.0){\makebox(0,0)[l]{\textbf{1.}}} - \put(4.1,2.0){\makebox(0,0)[l]{\textbf{2.}}} - \put(1.5,1.9){\makebox(0,0)[b]{\textbf{3.}}} - - \pause - \put(6.0,1.5){\makebox(0,0)[tl]{$\mathcal{O}(n)$}} - \put(5.95,1.45){\makebox(0,0)[br]{\tikz{\draw[-latex](0,0)--(-1.3,0.4);}}} - \put(5.95,1.49){\makebox(0,0)[br]{\tikz{\draw[-latex](0,0)--(-1.3,1.1);}}} - \end{picture} - \end{center} - \end{minipage}\pause\hfill - \begin{minipage}[t]{5cm} - In Array (Stack, FIFO) \dots - \begin{itemize} - \item - einfügen: $\mathcal{O}(n)$ - \item - suchen: $\mathcal{O}(n)$ - \item - geschickt suchen: $\mathcal{O}(\log n)$ - \item - beim Einfügen sortieren:\\ - $\mathcal{O}(n \log n)$ \hspace*{-1.8cm}\tikz{\draw[red](-1.8,0)--(0,0.2);\draw[red](-1.8,0.2)--(0,0);} - $\mathcal{O}(n^2)$ - \end{itemize} - \end{minipage} - -\end{frame} - -\subsection{Verkettete Listen} - -\begin{frame} - - \showsection - \showsubsection - - \begin{tikzpicture} - \color{structure} - \node(first) at (0,0.5) {first}; - \node[shape=rectangle,draw,line width=1pt](3) at (1,2) {3}; - \node[shape=rectangle,draw,line width=1pt](5) at (2,1) {5}; - \node[shape=rectangle,draw,line width=1pt](7) at (3,2) {7}; - \node[shape=rectangle,draw,line width=1pt](137) at (5,2) {137}; - \node(NULL) at (7,2) {NULL}; - \draw[-latex](first)--(3); - \only<1>{\draw[-latex](3)--(7);} - \only<2>{\draw[-latex](3) to[out=0] (5);} - \only<2>{\draw[-latex](5) to[in=180] (7);} - \draw[-latex](7)--(137); - \draw[-latex](137)--(NULL); - \end{tikzpicture} - \begin{itemize} - \item - Jeder Datensatz enthält einen Zeiger auf das nächste Element. - \item - Beim letzten Element zeigt der Zeiger auf \lstinline{NULL}. - \item - Eine Variable zeigt auf das erste Element. - \item - Wenn die Liste leer ist, zeigt die Variable auf \lstinline{NULL}. - \arrowitem - (einfach) \textbf{verkettete Liste} - \end{itemize} - -\end{frame} - -\begin{frame} - - \showsection - \showsubsection - - \begin{minipage}[t]{5cm} - In Array (Stack, FIFO) \dots - \begin{itemize} - \item - in der Mitte einfügen: $\mathcal{O}(n)$ - \item - wahlfreier Zugriff: $\mathcal{O}(1)$ - \item - suchen: $\mathcal{O}(n)$ - \item - geschickt suchen: $\mathcal{O}(\log n)$ - \item - beim Einfügen sortieren:\\ - $\mathcal{O}(n \log n)$ \hspace*{-1.8cm}\tikz{\draw[red](-1.8,0)--(0,0.2);\draw[red](-1.8,0.2)--(0,0);} - $\mathcal{O}(n^2)$ - \end{itemize} - \end{minipage}\hfill - \begin{minipage}[t]{6cm} - In (einfach) verkettete/r Liste \dots - \begin{itemize} - \item - in der Mitte einfügen: $\mathcal{O}(1)$ - \item - wahlfreier Zugriff: $\mathcal{O}(n)$ - \item - suchen: $\mathcal{O}(n)$ - \item - geschickt \hspace*{-1.7cm}\tikz{\draw[red](-1.7,0)--(0,0.2);\draw[red](-1.7,0.2)--(0,0);} - suchen: {\color{red}$\mathcal{O}(n)$} - \item - beim Einfügen sortieren: - $\mathcal{O}(n \log n)$ \hspace*{-1.8cm}\tikz{\draw[red](-1.8,0)--(0,0.2);\draw[red](-1.8,0.2)--(0,0);} - $\mathcal{O}(n^2)$ - \end{itemize} - \end{minipage} - \pause - \medskip - \begin{center} - \begin{minipage}[t]{6cm} - In (ausbalancierten) Bäumen \dots - \begin{itemize} - \item - in der Mitte einfügen: $\mathcal{O}(\log n)$ - \item - wahlfreier Zugriff: $\mathcal{O}(\log n)$ - \item - suchen: $\mathcal{O}(\log n)$ - \item - beim Einfügen sortieren: - $\mathcal{O}(n \log n)$ - \end{itemize} - \end{minipage} - \end{center} - \vspace*{-1cm} - -\end{frame} - -\subsection{Bäume} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \begin{minipage}[t]{5cm} - \vspace*{-6cm} - \begin{lstlisting}[gobble=6] - ¡typedef struct node - { - int content; - struct node *left, *right; - } node;¿ - \end{lstlisting} -% \bigskip - \bigskip - \begin{onlyenv}<6-> - \begin{itemize} - \item - Einfügen: rekursiv, $\mathcal{O}(\log n)$ - \item - Suchen: rekursiv, $\mathcal{O}(\log n)$ - \item - beim Einfügen sortieren:\\ - rekursiv, $\mathcal{O}(n\log n)$ - \begin{onlyenv}<7-> - \smallskip - \item - {\color{red} - \emph{Worst Case\/}: $\mathcal{O}(n^2)$\\ - vorher bereits sortiert}\\ - \textarrow\ balancierte Bäume\\ - \hspace*{2.15em}Anwendung: Datenbanken\hspace*{-2cm} - \end{onlyenv} - \end{itemize} - \vspace*{-1cm} - \end{onlyenv} - \end{minipage}\hfill - \begin{minipage}[t]{7cm} - \begin{center} - \begin{tikzpicture} - \color{structure} - \node(root) at (0,0) {\lstinline{node *root;}}; - \begin{onlyenv}<2> - \node(3) at (-2,-3) {\lstinline{NULL}}; - \node(137) at (2,-3) {\lstinline{NULL}}; - \end{onlyenv} - \begin{onlyenv}<2-> - \node[shape=rectangle,draw,line width=1pt](7) at (0,-1.5) {7}; - \draw[-latex](root)--(7); - \draw[-latex](7)--(3); - \draw[-latex](7)--(137); - \end{onlyenv} - \begin{onlyenv}<3> - \node(3) at (-2,-3) {\lstinline{NULL}}; - \end{onlyenv} - \begin{onlyenv}<3-> - \node[shape=rectangle,draw,line width=1pt](137) at (2,-3) {137}; - \node(137_left) at (1,-4.5) {\lstinline{NULL}}; - \node(137_right) at (3,-4.5) {\lstinline{NULL}}; - \draw[-latex](137)--(137_left); - \draw[-latex](137)--(137_right); - \end{onlyenv} - \begin{onlyenv}<4> - \node(5) at (-1,-4.5) {\lstinline{NULL}}; - \end{onlyenv} - \begin{onlyenv}<4-> - \node[shape=rectangle,draw,line width=1pt](3) at (-2,-3) {3}; - \node(3_left) at (-3,-4.5) {\lstinline{NULL}}; - \draw[-latex](3)--(3_left); - \draw[-latex](3)--(5); - \end{onlyenv} - \begin{onlyenv}<5-> - \node[shape=rectangle,draw,line width=1pt](5) at (-1,-4.5) {5}; - \node(5_left) at (-2,-6) {\lstinline{NULL}}; - \node(5_right) at (0,-6) {\lstinline{NULL}}; - \draw[-latex](5)--(5_left); - \draw[-latex](5)--(5_right); - \end{onlyenv} - \end{tikzpicture} - \end{center} - \end{minipage} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \item[\textbf{7}] \textbf{Datenstrukturen} - \begin{itemize} - \color{medgreen} - \item[7.1] Stack und FIFO - \item[7.2] Verkettete Listen - \item[7.3] Bäume - \end{itemize} - \end{itemize} - -\end{frame} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \item[\textbf{7}] \textbf{Datenstrukturen} - \begin{itemize} - \item[7.1] Stack und FIFO - \item[7.2] Verkettete Listen - \item[7.3] Bäume - \end{itemize} - \end{itemize} - - \begin{flushright} - \large\bf\em\color{medgreen}Vielen Dank für Ihre Aufmerksamkeit\\ - und viel Erfolg bei den Prüfungen! - \end{flushright} - -\end{frame} - -\fi - -\end{document} diff --git a/20221205/hp-2022ws-p4.pdf b/20221205/hp-2022ws-p4.pdf deleted file mode 100644 index 4e3f925f9b82012b27bbcd75e66036063d25902b..0000000000000000000000000000000000000000 Binary files a/20221205/hp-2022ws-p4.pdf and /dev/null differ diff --git a/20221205/hp-2022ws-p4.tex b/20221205/hp-2022ws-p4.tex deleted file mode 100644 index 1e6a343b0f1fa6b7c8a3601fc81af5dcbb5c17d5..0000000000000000000000000000000000000000 --- a/20221205/hp-2022ws-p4.tex +++ /dev/null @@ -1,224 +0,0 @@ -% hp-2022ws-p4.pdf - Labor Notes on Low-Level Programming -% Copyright (C) 2014, 2015, 2016, 2018, 2019, 2020, 2021, 2022 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: Versuch 4: Objektorientiertes Grafik-Programm - -\documentclass[a4paper]{article} - -\usepackage{pgscript} -\usepackage{multicol} -\usepackage{amsmath} -\usepackage{sfmath} - -\sloppy -%\pagestyle{empty} -\newcommand{\sep}{~$\cdot$~} -\newcommand{\mylicense}{CC-by-sa (Version 3.0) oder GNU GPL (Version 3 oder höher)} - -\begin{document} - - \makebox(0,0.005)[tl]{\includegraphics[scale=0.72]{logo-hochschule-bochum-cvh-text-v2.pdf}}\hfill - \makebox(0,0)[tr]{\includegraphics[scale=0.5]{logo-hochschule-bochum.pdf}} - \par\bigskip\bigskip - \begin{center} - \Large\textbf{Praktikumsversuch 4: Objektorientiertes Grafik-Programm} - \par\medskip - \normalsize Hardwarenahe Programmierung\sep - Wintersemester 2022/23\sep - Prof.~Dr.~Peter Gerwinski - \end{center} - - Aufgabe: Schreiben Sie ein GTK-Programm, - mit dem man verschiedene Objekte (z.\,B.\ Rechtecke, Kreise, Dreiecke) - in eine Grafik einfügen und nachträglich verändern kann - (z.\,B.\ Position, Größe, Farbe). - - (Beispiel: Ich füge zunächst zwei Rechtecke und einen Kreis in eine Grafik ein, - wähle anschließend das erste Rechteck aus und ändere dessen Farbe.) - - \bigskip - - Hinweise: - \vspace*{-\medskipamount} - - \begin{itemize} - \item - Das Beispielprogramm \gitfile{hp}{2022ws/20221128}{objects-08.c} - und seine Nachfolger zeigen, - wie man in C verschiedenartige Objekte - in einem Array von Zeigern verwaltet. - \item - Das Beispielprogramm \gitfile{hp}{2022ws/20221031}{gtk-06.c} zeigt, - wie man mit Hilfe der GUI-Bibliothek GTK - verschiedene Objekte in ein Fenster zeichnet. - \item - Das Beispielprogramm \gitfile{hp}{2022ws/20221031}{gtk-07.c} zeigt, - wie man in der GUI-Bibliothek GTK - Tastatur- und Maus-Eingaben entgegennimmt und verarbeitet. - \item - Das Auswählen eines bereits vorhandenen Objekts geht am einfachsten - mittels Tastatur-Eingaben (z.\,B.\ Ziffer 1 für das erste Objekt usw.). - Auswahl mit der Maus ist auch möglich, aber schwieriger. - \item - Mit Hilfe der Funktion \lstinline{gtk_widget_queue_draw()} - teilen Sie GTK mit, daß Sie ein \lstinline{GtkWidget} - neu zeichnen lassen möchten. - \item - Das Compilieren eines GTK-Programms - (z.\,B.\ \gitfile{hp}{2022ws/20221031}{gtk-07.c}) geschieht wie folgt: - \begin{lstlisting}[style=cmd,gobble=8] - gcc $(pkg-config --cflags gtk+-3.0) -Wall -O gtk-07.c \ - $(pkg-config --libs gtk+-3.0) -o gtk-07 - \end{lstlisting} - (Den Backslash am Ende der ersten Zeile entfällt, - wenn Sie den ganzen Befehl in eine einzige Zeile schreiben.) -% \item -% \textbf{Online-Abgabe:} -% Ihre Quelltexte mit den Lösungen der Praktikumsaufgabe schicken Sie bitte -% per E-Mail an \file{peter.gerwinski@hs-bochum.de} -% mit dem \textbf{Betreff:} \lstinline[style=terminal]{Eelei7ri} -% unter Angabe von Name, Matrikel-Nummer, -% Studiengang (MI/MP/TI) und Studienmodell (KIA/KIS/GS). - \end{itemize} - - \bigskip - \textbf{GTK unter GNU/Linux} - \begin{itemize} - \item - Installieren Sie das Entwickler-Paket für GTK-3,\\ - z.\,B.\ unter Debian GNU/Linux und darauf basierenden Systemen: - \begin{lstlisting}[style=cmd,gobble=8] - apt-get install libgtk-3-dev - \end{lstlisting} - \end{itemize} - - \bigskip - \goodbreak - \textbf{GTK unter MacOS X} - \begin{itemize} - \item - Zuerst den Paketmanager "`Homebrew"' installieren: - \begin{lstlisting}[style=cmd,gobble=8] - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/ - Homebrew/install/HEAD/install.sh)" - \end{lstlisting} - (Die URL nicht trennen, sondern in einer Zeile schreiben.) - \item - Danach mit Hilfe von \lstinline[style=cmd]{brew} GTK installieren: - \begin{lstlisting}[style=cmd,gobble=8] - brew install gtk+3 - \end{lstlisting} - \end{itemize} - - \bigskip - \goodbreak - \textbf{GTK unter Microsoft Windows: Cygwin} - \begin{itemize} - \item - Im Cygwin-Setup-Programm die Pakete \file{libgtk3-devel}, - \file{xorg-server} und \file{dbus-x11} installieren. - \item - Bevor Sie GTK-Programme starten können, - müssen Sie einmalig den X-Server starten: - \begin{lstlisting}[style=cmd,gobble=8] - XWin -multiwindow & - \end{lstlisting} - \item - Bevor Sie GTK-Programme starten können, - müssen Sie einmalig pro Shell-Sitzung\\ - die \lstinline[style=cmd]{DISPLAY}-Variable setzen: - \begin{lstlisting}[style=cmd,gobble=8] - export DISPLAY=:0.0 - \end{lstlisting} - \end{itemize} - - \bigskip - \goodbreak - \textbf{GTK unter Microsoft Windows: MinGW} - \begin{itemize} - \item - Installieren Sie \file{MSYS2} (Installer). - \item - Installieren Sie von der MinGW-Shell aus GTK - und weitere Entwicklungswerkzeuge: - \begin{lstlisting}[style=cmd,gobble=8] - pacman -S mingw-w64-x86_64-gcc - pacman -S mingw-w64-x86_64-gtk3 - pacman -S mingw-w64-x86_64-pkg-config - \end{lstlisting} - \item - Falls nötig, ergänzen Sie in der MinGW-Shell - den Pfad zu den neu installierten Programmen: - \begin{lstlisting}[style=cmd,gobble=8] - export PATH=$PATH:/mingw64/bin - \end{lstlisting} - \end{itemize} - - \bigskip - \goodbreak - \textbf{GTK unter Microsoft Windows: WSL} - \begin{itemize} - \item - Installieren Sie die GTK-Entwicklungswerkzeuge in ihrer Linux-Umgebung (siehe oben). - \item - Installieren Sie einen X-Server für Ihr MS-Windows-System, z.\,B.\ \file{Xming}. - \item - Starten Sie Ihren X-Server mit \file{XLaunch} - und wählen Sie \emph{no access control} aus. - \item - Bevor Sie GTK-Programme starten können, - müssen Sie einmalig pro Shell-Sitzung\\ - die \lstinline[style=cmd]{DISPLAY}-Variable setzen: - \begin{lstlisting}[style=cmd,gobble=8] - export DISPLAY=$(cat /etc/resolv.conf \ - | grep nameserver | awk '{print $2}'):0 - \end{lstlisting} - (Der Backslash ist ein Zeilen-Verlängerungszeichen. Wenn Sie den gesamten\\ - Befehl in einer Zeile eingeben, entfällt der Backslash.) - \end{itemize} - - \bigskip - - \strut\hfill\emph{Viel Erfolg!} - - \vfill - - \begingroup - - \small - - \setlength{\leftskip}{3cm} - - Stand: 8.\ Dezember 2022 - -% Soweit nicht anders angegeben:\\ - Copyright \copyright\ 2014, 2015, 2016, 2018, 2019, 2020, 2021, 2022\quad Peter Gerwinski\\ - Lizenz: \mylicense - - Sie können diese Praktikumsunterlagen einschließlich \LaTeX-Quelltext -% und Beispielprogramme\\ - herunterladen unter:\\ - \url{https://gitlab.cvh-server.de/pgerwinski/hp} - - \endgroup - -\end{document} diff --git a/20221205/hp-musterloesung-20221205.pdf b/20221205/hp-musterloesung-20221205.pdf deleted file mode 100644 index a1baa1c8ee79891261b0d4c1611ea1ae83295d62..0000000000000000000000000000000000000000 Binary files a/20221205/hp-musterloesung-20221205.pdf and /dev/null differ diff --git a/20221205/hp-musterloesung-20221205.tex b/20221205/hp-musterloesung-20221205.tex deleted file mode 100644 index 9de50dc82f9e98ca9c45637187963379b654c6c0..0000000000000000000000000000000000000000 --- a/20221205/hp-musterloesung-20221205.tex +++ /dev/null @@ -1,499 +0,0 @@ -% hp-musterloesung-20221205.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Objektorientierte Tier-Datenbank (Ergänzung), Iterationsfunktionen, Stack-Operationen - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 5.\ Dezember 2022} - - \exercise{Objektorientierte Tier-Datenbank (Ergänzung)} - - Diese Aufgabe ist eine Neuauflage - der Übungsaufgabe 3 vom 28.\ November 2022, - ergänzt um die Teilaufgaben (e) bis (g). - - \medskip - - Das auf der nächsten Seite dargestellte Programm - (Datei: \gitfile{hp}{2022ws/20221205}{aufgabe-1a.c}) - soll Daten von Tieren verwalten. - - Beim Compilieren erscheinen die folgende Fehlermeldungen: - \begin{lstlisting}[style=terminal] - $ ¡gcc -std=c99 -Wall -O aufgabe-1a.c -o aufgabe-1a¿ - aufgabe-1a.c: In function 'main': - aufgabe-1a.c:31: error: 'animal' has no member named 'wings' - aufgabe-1a.c:37: error: 'animal' has no member named 'legs' - \end{lstlisting} - - Der Programmierer nimmt die auf der nächsten Seite in Rot dargestellten Ersetzungen vor\\ - (Datei: \gitfile{hp}{2022ws/20221205}{aufgabe-1b.c}). - Daraufhin gelingt das Compilieren, und die Ausgabe des Programms lautet: - \begin{lstlisting}[style=terminal] - $ ¡gcc -std=c99 -Wall -O aufgabe-1b.c -o aufgabe-1b¿ - $ ¡./aufgabe-1b¿ - A duck has 2 legs. - Error in animal: cow - \end{lstlisting} - - \begin{itemize} - \color{gray} - \item[(a)] - Erklären Sie die o.\,a.\ Compiler-Fehlermeldungen. - % \points{2} - \item[(b)] - Wieso verschwinden die Fehlermeldungen nach den o.\,a.\ Ersetzungen? - % \points{3} - \item[(c)] - Erklären Sie die Ausgabe des Programms. - % \points{5} - \item[(d)] - Beschreiben Sie -- in Worten und/oder als C-Quelltext -- einen Weg, - das Programm so zu berichtigen, daß es die Eingabedaten - (``A duck has 2 wings. A cow has 4 legs.'') korrekt speichert und ausgibt. %\\ - % \points{4} - \color{black} - \item[(e)] - Schreiben Sie das Programm so um, - daß es keine expliziten Typumwandlungen mehr benötigt.\par - Hinweis: Verwenden Sie \lstinline{union}. - \points{4} - \item[(f)] - Schreiben Sie das Programm weiter um, - so daß es die Objektinstanzen \lstinline{duck} und \lstinline{cow} - dynamisch erzeugt.\par - Hinweis: Verwenden Sie \lstinline{malloc()} und schreiben Sie Konstruktoren. - \points{4} - \item[(g)] - Schreiben Sie das Programm weiter um, - so daß die Ausgabe nicht mehr direkt im Hauptprogramm erfolgt, - sondern stattdessen eine virtuelle Methode \lstinline{print()} - aufgerufen wird.\par - Hinweis: Verwenden Sie in den Objekten Zeiger auf Funktionen, - und initialisieren Sie diese in den Konstruktoren. - \points{4} - \end{itemize} - - \begin{minipage}[t]{0.34\textwidth} - \begin{lstlisting}[gobble=6,xleftmargin=0pt] - #include <stdio.h> - - #define ANIMAL 0 - #define WITH_WINGS 1 - #define WITH_LEGS 2 - - typedef struct animal - { - int type; - char *name; - } animal; - - typedef struct with_wings - { - int wings; - } with_wings; - - typedef struct with_legs - { - int legs; - } with_legs; - \end{lstlisting} - \end{minipage}\hfill - \begin{minipage}[t]{0.65\textwidth} - \begin{lstlisting}[gobble=6,xleftmargin=0pt] - int main (void) - { - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - a[0]->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - a[1]->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; - } - \end{lstlisting} - \begin{picture}(0,0) - \color{red} - \put(3.7,6.207){\vector(-1,0){0.7}} - \put(3.8,6.207){\makebox(0,0)[l]{\lstinline[basicstyle=\color{red}]{((with_legs *) a[1])->legs = 4;}}} - \put(4.0,8.735){\vector(-1,0){0.7}} - \put(4.1,8.735){\makebox(0,0)[l]{\lstinline[basicstyle=\color{red}]{((with_wings *) a[0])->wings = 2;}}} - \end{picture} - \end{minipage} - - \solution - - \begin{itemize} - \item[(e)] - \textbf{Schreiben Sie das Programm so um, - daß es keine expliziten Typumwandlungen mehr benötigt.}\par - \textbf{Hinweis: Verwenden Sie \lstinline{union}.} - - Siehe \gitfile{hp}{2022ws/20221205}{loesung-1e.c}. - - Diese Lösung basiert auf \gitfile{hp}{2022ws/20221128}{loesung-3d-2.c}, - da diese bereits weniger explizite Typumwandlungen enthält - als \gitfile{hp}{2022ws/20221128}{loesung-3d-1.c}. - - Arbeitsschritte: - \begin{itemize} - \item - Umbenennen des Basistyps \lstinline{animal} in \lstinline{base}, - damit wir den Bezeichner \lstinline{animal} - für die \lstinline{union} verwenden können - \item - Schreiben einer \lstinline{union animal}, - die die drei Klassen \lstinline{base}, - \lstinline{with_wings} und \lstinline{with_legs} - als Datenfelder enthält - \item - Umschreiben der Initialisierungen: - Zugriff auf Datenfelder erfolgt nun durch - z.\,B.\ \lstinline{a[0]->b.name}. - Hierbei ist \lstinline{b} der Name des \lstinline{base}-Datenfelds - innerhalb der \lstinline{union animal}. - \item - Auf gleiche Weise schreiben wir die \lstinline{if}-Bedingungen - innerhalb der \lstinline{for}-Schleife - sowie die Parameter der \lstinline{printf()}-Aufrufe um. - \end{itemize} - Explizite Typumwandlungen sind nun nicht mehr nötig. - - Nachteil dieser Lösung: - Jede Objekt-Variable belegt nun Speicherplatz - für die gesamte \lstinline{union animal}, - anstatt nur für die benötigte Variable vom Typ - \lstinline{with_wings} oder \lstinline{with_legs}. - Dies kann zu einer Verschwendung von Speicherplatz führen, - auch wenn dies in diesem Beispielprogramm tatsächlich nicht der Fall ist. - - \item[(f)] - \textbf{Schreiben Sie das Programm weiter um, - so daß es die Objektinstanzen \lstinline{duck} und \lstinline{cow} - dynamisch erzeugt.}\par - \textbf{Hinweis: Verwenden Sie \lstinline{malloc()} und schreiben Sie Konstruktoren.} - - Siehe \gitfile{hp}{2022ws/20221205}{loesung-1f.c}. - - \item[(g)] - \textbf{Schreiben Sie das Programm weiter um, - so daß die Ausgabe nicht mehr direkt im Hauptprogramm erfolgt, - sondern stattdessen eine virtuelle Methode \lstinline{print()} - aufgerufen wird.}\par - \textbf{Hinweis: Verwenden Sie in den Objekten Zeiger auf Funktionen, - und initialisieren Sie diese in den Konstruktoren.} - - Siehe \gitfile{hp}{2022ws/20221205}{loesung-1g.c}. - - \end{itemize} - - \exercise{Iterationsfunktionen} - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221205}{aufgabe-2.c}): - - \begin{minipage}[t]{0.4\textwidth} - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - void foreach (int *a, void (*fun) (int x)) - { - for (int *p = a; *p >= 0; p++) - fun (*p); - } - - void even_or_odd (int x) - { - if (x % 2) - printf ("%d ist ungerade.\n", x); - else - printf ("%d ist gerade.\n", x); - } - \end{lstlisting} - \end{minipage}\hfill - \begin{minipage}[t]{0.52\textwidth} - \begin{lstlisting}[gobble=6] - int main (void) - { - int numbers[] = { 12, 17, 32, 1, 3, 16, 19, 18, -1 }; - foreach (numbers, even_or_odd); - return 0; - } - \end{lstlisting} - \begin{enumerate}[\quad(a)] - \item - Was bedeutet \lstinline{void (*fun) (int x)}, - und welchen Sinn hat seine Verwendung in der Funktion \lstinline{foreach()}? - \points{2} - \item - Schreiben Sie das Hauptprogramm \lstinline{main()} so um, - daß es unter Verwendung der Funktion \lstinline{foreach()} - die Summe aller positiven Zahlen in dem Array berechnet. - Sie dürfen dabei weitere Funktionen sowie globale Variable einführen. - \points{4} - \end{enumerate} - \end{minipage} - - \begin{enumerate}[\quad(a)] - \item - \textbf{Was bedeutet \lstinline{void (*fun) (int x)}, - und welchen Sinn hat seine Verwendung in der Funktion \lstinline{foreach()}?} - - \lstinline{void (*fun) (int x)} deklariert einen Zeiger \lstinline{fun}, - der auf Funktionen zeigen kann, die einen Parameter \lstinline{x} - vom Typ \lstinline{int} erwarten und keinen Wert zurückgeben (\lstinline{void}). - - Durch die Übergabe eines derartigen Parameters an die Funktion \lstinline{foreach()} - lassen wir dem Aufrufer die Wahl, - welche Aktion für alle Elemente des Arrays aufgerufen werden soll. - - \item - \textbf{Schreiben Sie das Hauptprogramm \lstinline{main()} so um, - daß es unter Verwendung der Funktion \lstinline{foreach()} - die Summe aller positiven Zahlen in dem Array berechnet. - Sie dürfen dabei weitere Funktionen sowie globale Variable einführen.} - - Siehe: \gitfile{hp}{2022ws/20221205}{loesung-2.c} - - Damit die Funktion \lstinline{add_up()} Zugriff auf die Variable \lstinline{sum} hat, - muß diese global sein - und vor der Funktion \lstinline{add_up()} deklariert werden. - - Die Bedingung, daß nur positive Zahlen summiert werden sollen, - ist durch die Arbeitsweise der Funktion \lstinline{foreach()} - bereits gewährleistet, da negative Zahlen als Ende-Markierungen dienen. - - Wichtig ist, daß die Variable \lstinline{sum} - vor dem Aufruf der Funktion \lstinline{foreach()} - auf den Wert \lstinline{0} gesetzt wird. - In \gitfile{hp}{2022ws/20221205}{loesung-2.c} geschieht dies - durch die Initialisierung von \lstinline{sum}. - Wenn mehrere Summen berechnet werden sollen, - muß dies durch explizite Zuweisungen \lstinline{sum = 0} - vor den Aufrufen von \lstinline{foreach()} erfolgen. - \end{enumerate} - - \exercise{Stack-Operationen} - - Das folgende Programm (\gitfile{hp}{2022ws/20221205}{aufgabe-3.c}) - implementiert einen Stapelspeicher (Stack). - Dies ist ein Array, das nur bis zu einer variablen Obergrenze (Stack-Pointer) - tatsächlich genutzt wird. - An dieser Obergrenze kann man Elemente hinzufügen (push). - - In dieser Aufgabe sollen zusätzlich Elemente - in der Mitte eingefügt werden (insert). - Die dafür bereits existierenden Funktionen \lstinline{insert()} - und \lstinline{insert_sorted()} sind jedoch fehlerhaft. - - \begin{minipage}[t]{0.5\textwidth} - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - #define STACK_SIZE 10 - - int stack[STACK_SIZE]; - int stack_pointer = 0; - - void push (int x) - { - stack[stack_pointer++] = x; - } - - void show (void) - { - printf ("stack content:"); - for (int i = 0; i < stack_pointer; i++) - printf (" %d", stack[i]); - if (stack_pointer) - printf ("\n"); - else - printf (" (empty)\n"); - } - \end{lstlisting} - \end{minipage}\hfill - \begin{minipage}[t]{0.5\textwidth} - \begin{lstlisting}[gobble=6] - void insert (int x, int pos) - { - for (int i = pos; i < stack_pointer; i++) - stack[i + 1] = stack[i]; - stack[pos] = x; - stack_pointer++; - } - - void insert_sorted (int x) - { - int i = 0; - while (i < stack_pointer && x < stack[i]) - i++; - insert (x, i); - } - - int main (void) - { - push (3); - push (7); - push (137); - show (); - insert (5, 1); - show (); - insert_sorted (42); - show (); - insert_sorted (2); - show (); - return 0; - } - \end{lstlisting} - \end{minipage} - - \begin{enumerate}[\quad(a)] - \item - Korrigieren Sie das Programm so, - daß die Funktion \lstinline{insert()} ihren Parameter \lstinline{x} - an der Stelle \lstinline{pos} in den Stack einfügt - und den sonstigen Inhalt des Stacks verschiebt, aber nicht zerstört. - \points{3} - \item - Korrigieren Sie das Programm so, - daß die Funktion \lstinline{insert_sorted()} ihren Parameter \lstinline{x} - an derjenigen Stelle einfügt, an die er von der Sortierung her gehört. - (Der Stack wird hierbei vor dem Funktionsaufruf als sortiert vorausgesetzt.) - \points{2} - \item - Schreiben Sie eine zusätzliche Funktion \lstinline{int search (int x)}, - die die Position (Index) des Elements \lstinline{x} - innerhalb des Stack zurückgibt -- oder die Zahl - \lstinline{-1}, wenn \lstinline{x} nicht im Stack enthalten ist. - Der Rechenaufwand darf höchstens $\mathcal{O}(n)$ betragen. - \points{3} - \item - Wie (c), aber der Rechenaufwand darf höchstens $\mathcal{O}(\log n)$ betragen. - \points{4} - \end{enumerate} - - \solution - - \begin{enumerate}[\quad(a)] - \item - \textbf{Korrigieren Sie das Programm so, - daß die Funktion \lstinline{insert()} ihren Parameter \lstinline{x} - an der Stelle \lstinline{pos} in den Stack einfügt, - und den sonstigen Inhalt des Stacks verschiebt, aber nicht zerstört.} - - Die \lstinline{for}-Schleife in der Funktion \lstinline{insert()} - durchläuft das Array von unten nach oben. - Um den Inhalt des Arrays von unten nach oben zu verschieben, - muß man die Schleife jedoch von oben nach unten durchlaufen. - - \goodbreak - Um die Funktion zu reparieren, ersetze man also - \begin{lstlisting}[gobble=8] - for (int i = pos; i < stack_pointer; i++) - \end{lstlisting} - durch: - \begin{lstlisting}[gobble=8] - for (int i = stack_pointer - 1; i >= pos; i--) - \end{lstlisting} - (Siehe auch: \gitfile{hp}{2022ws/20221205}{loesung-3.c}) - - \item - \textbf{Korrigieren Sie das Programm so, - daß die Funktion \lstinline{insert_sorted()} ihren Parameter \lstinline{x} - an derjenigen Stelle einfügt, an die er von der Sortierung her gehört. - (Der Stack wird hierbei vor dem Funktionsaufruf als sortiert vorausgesetzt.)} - - Der Vergleich \lstinline{x < stack[i]} - als Bestandteil der \lstinline{while}-Bedingung - paßt nicht zur Durchlaufrichtung der Schleife (von unten nach oben). - - Um die Funktion zu reparieren, kann man daher entweder - das Kleinerzeichen durch ein Größerzeichen ersetzen - (\lstinline{x > stack[i]} -- siehe \gitfile{hp}{2022ws/20221205}{loesung-3b-1.c}) - oder die Schleife von oben nach unten durchlaufen - (siehe \gitfile{hp}{2022ws/20221205}{loesung-3b-2.c}). - - Eine weitere Möglichkeit besteht darin, - das Suchen nach der Einfügeposition - mit dem Verschieben des Arrays zu kombinieren - (siehe \gitfile{hp}{2022ws/20221205}{loesung-3.c}). - Hierdurch spart man sich eine Schleife; das Programm wird schneller. - (Es bleibt allerdings bei $\mathcal{O}(n)$.) - - \item - \textbf{Schreiben Sie eine zusätzliche Funktion \lstinline{int search (int x)}, - die die Position (Index) des Elements \lstinline{x} - innerhalb des Stack zurückgibt - -- oder \lstinline{-1}, wenn \lstinline{x} nicht im Stack enthalten ist. - Der Rechenaufwand darf höchstens $\mathcal{O}(n)$ betragen.} - - Man geht in einer Schleife den Stack (= den genutzten Teil des Arrays) durch. - Bei Gleichheit gibt man direkt mit \lstinline{return} den Index zurück. - Nach dem Schleifendurchlauf steht fest, - daß \lstinline{x} nicht im Stack vorhanden ist; - man kann dann direkt \lstinline{-1} zurückgeben - (siehe \gitfile{hp}{2022ws/20221205}{loesung-3c.c}). - - Da es sich um eine einzelne Schleife handelt, - ist die Ordnung $\mathcal{O}(n)$. - - \item - \textbf{Wie (c), aber der Rechenaufwand darf höchstens $\mathcal{O}(\log n)$ betragen.} - - Um $\mathcal{O}(\log n)$ zu erreichen, - halbiert man fortwährend das Intervall von (einschließlich) \lstinline{0} - bis (ausschließlich) \lstinline{stack_pointer} - (siehe \gitfile{hp}{2022ws/20221205}{loesung-3d.c}). % -- -% wie in der Funktion \lstinline{push_sorted()} -% im Beispiel-Programm \gitfile{hp}{2022ws/20221205}{stack-11.c}. - -% Ein wichtiger Unterschied besteht darin, - Wichtig ist, - daß man nach dem Durchlauf der Schleife noch auf die Gleichheit - \lstinline{x == stack[left]} (insbesondere nicht: \lstinline{stack[right]}) - prüfen und ggf.\ \lstinline{left} bzw.\ \lstinline{-1} zurückgeben muß. - \end{enumerate} - -\end{document} diff --git a/20221205/hp-uebung-20221205.pdf b/20221205/hp-uebung-20221205.pdf deleted file mode 100644 index 4ccdeb9c1be1c4bc31b2f8964702467bd9d70dc6..0000000000000000000000000000000000000000 Binary files a/20221205/hp-uebung-20221205.pdf and /dev/null differ diff --git a/20221205/hp-uebung-20221205.tex b/20221205/hp-uebung-20221205.tex deleted file mode 100644 index bda4e34b525d06ef9a2b7b5320b3ab39c31f8951..0000000000000000000000000000000000000000 --- a/20221205/hp-uebung-20221205.tex +++ /dev/null @@ -1,329 +0,0 @@ -% hp-uebung-20221205.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Objektorientierte Tier-Datenbank (Ergänzung), Iterationsfunktionen, Stack-Operationen - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 5.\ Dezember 2022} - - Diese Übung enthält Punkteangaben wie in einer Klausur. - Um zu "`bestehen"', müssen Sie innerhalb von 85 Minuten - unter Verwendung ausschließlich zugelassener Hilfsmittel - 15 Punkte (von insgesamt \totalpoints) erreichen. - - \exercise{Objektorientierte Tier-Datenbank (Ergänzung)} - - Diese Aufgabe ist eine Neuauflage - der Übungsaufgabe 3 vom 28.\ November 2022, - ergänzt um die Teilaufgaben (e) bis (g). - - \medskip - - Das auf der nächsten Seite dargestellte Programm - (Datei: \gitfile{hp}{2022ws/20221205}{aufgabe-1a.c}) - soll Daten von Tieren verwalten. - - Beim Compilieren erscheinen die folgende Fehlermeldungen: - \begin{lstlisting}[style=terminal] - $ ¡gcc -std=c99 -Wall -O aufgabe-1a.c -o aufgabe-1a¿ - aufgabe-1a.c: In function 'main': - aufgabe-1a.c:31: error: 'animal' has no member named 'wings' - aufgabe-1a.c:37: error: 'animal' has no member named 'legs' - \end{lstlisting} - - Der Programmierer nimmt die auf der nächsten Seite in Rot dargestellten Ersetzungen vor\\ - (Datei: \gitfile{hp}{2022ws/20221205}{aufgabe-1b.c}). - Daraufhin gelingt das Compilieren, und die Ausgabe des Programms lautet: - \begin{lstlisting}[style=terminal] - $ ¡gcc -std=c99 -Wall -O aufgabe-1b.c -o aufgabe-1b¿ - $ ¡./aufgabe-1b¿ - A duck has 2 legs. - Error in animal: cow - \end{lstlisting} - - \begin{itemize} - \color{gray} - \item[(a)] - Erklären Sie die o.\,a.\ Compiler-Fehlermeldungen. - % \points{2} - \item[(b)] - Wieso verschwinden die Fehlermeldungen nach den o.\,a.\ Ersetzungen? - % \points{3} - \item[(c)] - Erklären Sie die Ausgabe des Programms. - % \points{5} - \item[(d)] - Beschreiben Sie -- in Worten und/oder als C-Quelltext -- einen Weg, - das Programm so zu berichtigen, daß es die Eingabedaten - (``A duck has 2 wings. A cow has 4 legs.'') korrekt speichert und ausgibt. %\\ - % \points{4} - \color{black} - \item[(e)] - Schreiben Sie das Programm so um, - daß es keine expliziten Typumwandlungen mehr benötigt.\par - Hinweis: Verwenden Sie \lstinline{union}. - \points{4} - \item[(f)] - Schreiben Sie das Programm weiter um, - so daß es die Objektinstanzen \lstinline{duck} und \lstinline{cow} - dynamisch erzeugt.\par - Hinweis: Verwenden Sie \lstinline{malloc()} und schreiben Sie Konstruktoren. - \points{4} - \item[(g)] - Schreiben Sie das Programm weiter um, - so daß die Ausgabe nicht mehr direkt im Hauptprogramm erfolgt, - sondern stattdessen eine virtuelle Methode \lstinline{print()} - aufgerufen wird.\par - Hinweis: Verwenden Sie in den Objekten Zeiger auf Funktionen, - und initialisieren Sie diese in den Konstruktoren. - \points{4} - \end{itemize} - - \begin{minipage}[t]{0.34\textwidth} - \begin{lstlisting}[gobble=6,xleftmargin=0pt] - #include <stdio.h> - - #define ANIMAL 0 - #define WITH_WINGS 1 - #define WITH_LEGS 2 - - typedef struct animal - { - int type; - char *name; - } animal; - - typedef struct with_wings - { - int wings; - } with_wings; - - typedef struct with_legs - { - int legs; - } with_legs; - \end{lstlisting} - \end{minipage}\hfill - \begin{minipage}[t]{0.65\textwidth} - \begin{lstlisting}[gobble=6,xleftmargin=0pt] - int main (void) - { - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - a[0]->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - a[1]->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, - ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, - ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; - } - \end{lstlisting} - \begin{picture}(0,0) - \color{red} - \put(3.7,6.207){\vector(-1,0){0.7}} - \put(3.8,6.207){\makebox(0,0)[l]{\lstinline[basicstyle=\color{red}]{((with_legs *) a[1])->legs = 4;}}} - \put(4.0,8.735){\vector(-1,0){0.7}} - \put(4.1,8.735){\makebox(0,0)[l]{\lstinline[basicstyle=\color{red}]{((with_wings *) a[0])->wings = 2;}}} - \end{picture} - \end{minipage} - - \vfil - - \exercise{Iterationsfunktionen} - - Wir betrachten das folgende Programm (\gitfile{hp}{2022ws/20221205}{aufgabe-2.c}): - - \begin{minipage}[t]{0.4\textwidth} - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - void foreach (int *a, void (*fun) (int x)) - { - for (int *p = a; *p >= 0; p++) - fun (*p); - } - - void even_or_odd (int x) - { - if (x % 2) - printf ("%d ist ungerade.\n", x); - else - printf ("%d ist gerade.\n", x); - } - \end{lstlisting} - \end{minipage}\hfill - \begin{minipage}[t]{0.52\textwidth} - \begin{lstlisting}[gobble=6] - int main (void) - { - int numbers[] = { 12, 17, 32, 1, 3, 16, 19, 18, -1 }; - foreach (numbers, even_or_odd); - return 0; - } - \end{lstlisting} - \begin{enumerate}[\quad(a)] - \item - Was bedeutet \lstinline{void (*fun) (int x)}, - und welchen Sinn hat seine Verwendung in der Funktion \lstinline{foreach()}? - \points{2} - \item - Schreiben Sie das Hauptprogramm \lstinline{main()} so um, - daß es unter Verwendung der Funktion \lstinline{foreach()} - die Summe aller positiven Zahlen in dem Array berechnet. - Sie dürfen dabei weitere Funktionen sowie globale Variable einführen. - \points{4} - \end{enumerate} - \end{minipage} - - \clearpage - - \exercise{Stack-Operationen} - - Das folgende Programm (\gitfile{hp}{2022ws/20221205}{aufgabe-3.c}) - implementiert einen Stapelspeicher (Stack). - Dies ist ein Array, das nur bis zu einer variablen Obergrenze (Stack-Pointer) - tatsächlich genutzt wird. - An dieser Obergrenze kann man Elemente hinzufügen (push). - - In dieser Aufgabe sollen zusätzlich Elemente - in der Mitte eingefügt werden (insert). - Die dafür bereits existierenden Funktionen \lstinline{insert()} - und \lstinline{insert_sorted()} sind jedoch fehlerhaft. - - \begin{minipage}[t]{0.5\textwidth} - \begin{lstlisting}[gobble=6] - #include <stdio.h> - - #define STACK_SIZE 10 - - int stack[STACK_SIZE]; - int stack_pointer = 0; - - void push (int x) - { - stack[stack_pointer++] = x; - } - - void show (void) - { - printf ("stack content:"); - for (int i = 0; i < stack_pointer; i++) - printf (" %d", stack[i]); - if (stack_pointer) - printf ("\n"); - else - printf (" (empty)\n"); - } - \end{lstlisting} - \end{minipage}\hfill - \begin{minipage}[t]{0.5\textwidth} - \begin{lstlisting}[gobble=6] - void insert (int x, int pos) - { - for (int i = pos; i < stack_pointer; i++) - stack[i + 1] = stack[i]; - stack[pos] = x; - stack_pointer++; - } - - void insert_sorted (int x) - { - int i = 0; - while (i < stack_pointer && x < stack[i]) - i++; - insert (x, i); - } - - int main (void) - { - push (3); - push (7); - push (137); - show (); - insert (5, 1); - show (); - insert_sorted (42); - show (); - insert_sorted (2); - show (); - return 0; - } - \end{lstlisting} - \end{minipage} - - \begin{enumerate}[\quad(a)] - \item - Korrigieren Sie das Programm so, - daß die Funktion \lstinline{insert()} ihren Parameter \lstinline{x} - an der Stelle \lstinline{pos} in den Stack einfügt - und den sonstigen Inhalt des Stacks verschiebt, aber nicht zerstört. - \points{3} - \item - Korrigieren Sie das Programm so, - daß die Funktion \lstinline{insert_sorted()} ihren Parameter \lstinline{x} - an derjenigen Stelle einfügt, an die er von der Sortierung her gehört. - (Der Stack wird hierbei vor dem Funktionsaufruf als sortiert vorausgesetzt.) - \points{2} - \item - Schreiben Sie eine zusätzliche Funktion \lstinline{int search (int x)}, - die die Position (Index) des Elements \lstinline{x} - innerhalb des Stack zurückgibt -- oder die Zahl - \lstinline{-1}, wenn \lstinline{x} nicht im Stack enthalten ist. - Der Rechenaufwand darf höchstens $\mathcal{O}(n)$ betragen. - \points{3} - \item - Wie (c), aber der Rechenaufwand darf höchstens $\mathcal{O}(\log n)$ betragen. - \points{4} - \end{enumerate} - - \begin{flushright} - \textit{Viel Erfolg!} - \end{flushright} - - \makeatletter - \immediate\write\@mainaux{\string\gdef\string\totalpoints{\arabic{points}}} - \makeatother - -\end{document} diff --git a/20221205/loesung-1e.c b/20221205/loesung-1e.c deleted file mode 100644 index b984d9253b9c379a88f0fc0ca130c88c3103f8f3..0000000000000000000000000000000000000000 --- a/20221205/loesung-1e.c +++ /dev/null @@ -1,61 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct -{ - int type; - char *name; -} base; - -typedef struct -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct -{ - int type; - char *name; - int legs; -} with_legs; - -typedef union -{ - base b; - with_wings w; - with_legs l; -} animal; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - duck.b.type = WITH_WINGS; - duck.b.name = "duck"; - duck.w.wings = 2; - - animal cow; - a[1] = &cow; - cow.b.type = WITH_LEGS; - cow.b.name = "cow"; - cow.l.legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->b.type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->b.name, - a[i]->l.legs); - else if (a[i]->b.type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->b.name, - a[i]->w.wings); - else - printf ("Error in animal: %s\n", a[i]->b.name); - - return 0; -} diff --git a/20221205/loesung-1f.c b/20221205/loesung-1f.c deleted file mode 100644 index 7b949e6365fc3839e6adc7661e0f8b4dd0c059df..0000000000000000000000000000000000000000 --- a/20221205/loesung-1f.c +++ /dev/null @@ -1,69 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct -{ - int type; - char *name; -} base; - -typedef struct -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct -{ - int type; - char *name; - int legs; -} with_legs; - -typedef union -{ - base b; - with_wings w; - with_legs l; -} animal; - -animal *new_with_wings (char *name, int wings) -{ - animal *a = malloc (sizeof (with_wings)); - a->b.type = WITH_WINGS; - a->b.name = name; - a->w.wings = wings; - return a; -} - -animal *new_with_legs (char *name, int legs) -{ - animal *a = malloc (sizeof (with_legs)); - a->b.type = WITH_LEGS; - a->b.name = name; - a->l.legs = legs; - return a; -} - -int main (void) -{ - animal *a[2] = { new_with_wings ("duck", 2), - new_with_legs ("cow", 4) }; - - for (int i = 0; i < 2; i++) - if (a[i]->b.type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->b.name, - a[i]->l.legs); - else if (a[i]->b.type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->b.name, - a[i]->w.wings); - else - printf ("Error in animal: %s\n", a[i]->b.name); - - return 0; -} diff --git a/20221205/loesung-1g.c b/20221205/loesung-1g.c deleted file mode 100644 index b453a52dbe0ef27399255819808b3f6e562ba3ef..0000000000000000000000000000000000000000 --- a/20221205/loesung-1g.c +++ /dev/null @@ -1,77 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -union animal; - -typedef struct -{ - int type; - char *name; - void (*print) (union animal *this); -} base; - -typedef struct -{ - int type; - char *name; - void (*print) (union animal *this); - int wings; -} with_wings; - -typedef struct -{ - int type; - char *name; - void (*print) (union animal *this); - int legs; -} with_legs; - -typedef union animal -{ - base b; - with_wings w; - with_legs l; -} animal; - -void print_with_wings (animal *this) -{ - printf ("A %s has %d wings.\n", this->b.name, this->w.wings); -} - -void print_with_legs (animal *this) -{ - printf ("A %s has %d legs.\n", this->b.name, this->l.legs); -} - -animal *new_with_wings (char *name, int wings) -{ - animal *a = malloc (sizeof (with_wings)); - a->b.type = WITH_WINGS; - a->b.name = name; - a->b.print = print_with_wings; - a->w.wings = wings; - return a; -} - -animal *new_with_legs (char *name, int legs) -{ - animal *a = malloc (sizeof (with_legs)); - a->b.type = WITH_LEGS; - a->b.name = name; - a->b.print = print_with_legs; - a->l.legs = legs; - return a; -} - -int main (void) -{ - animal *a[2] = { new_with_wings ("duck", 2), - new_with_legs ("cow", 4) }; - for (int i = 0; i < 2; i++) - a[i]->b.print (a[i]); - return 0; -} diff --git a/20221205/loesung-3.c b/20221205/loesung-3.c deleted file mode 100644 index 9b87d6c2f977af2843bcc2b75896fb5f00d8fc35..0000000000000000000000000000000000000000 --- a/20221205/loesung-3.c +++ /dev/null @@ -1,62 +0,0 @@ -#include <stdio.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - stack[stack_pointer++] = x; -} - -int pop (void) -{ - return stack[--stack_pointer]; -} - -void show (void) -{ - printf ("stack content:"); - for (int i = 0; i < stack_pointer; i++) - printf (" %d", stack[i]); - if (stack_pointer) - printf ("\n"); - else - printf (" (empty)\n"); -} - -void insert (int x, int pos) -{ - for (int i = stack_pointer - 1; i >= pos; i--) - stack[i + 1] = stack[i]; - stack[pos] = x; - stack_pointer++; -} - -void insert_sorted (int x) -{ - int i = stack_pointer - 1; - while (i >= 0 && x < stack[i]) - { - stack[i + 1] = stack[i]; - i--; - } - stack[i + 1] = x; - stack_pointer++; -} - -int main (void) -{ - push (3); - push (7); - push (137); - show (); - insert (5, 1); - show (); - insert_sorted (42); - show (); - insert_sorted (2); - show (); - return 0; -} diff --git a/20221205/loesung-3b-1.c b/20221205/loesung-3b-1.c deleted file mode 100644 index cbbe37055109d203105a7ad4acb63d5bef61f4c0..0000000000000000000000000000000000000000 --- a/20221205/loesung-3b-1.c +++ /dev/null @@ -1,58 +0,0 @@ -#include <stdio.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - stack[stack_pointer++] = x; -} - -int pop (void) -{ - return stack[--stack_pointer]; -} - -void show (void) -{ - printf ("stack content:"); - for (int i = 0; i < stack_pointer; i++) - printf (" %d", stack[i]); - if (stack_pointer) - printf ("\n"); - else - printf (" (empty)\n"); -} - -void insert (int x, int pos) -{ - for (int i = stack_pointer - 1; i >= pos; i--) - stack[i + 1] = stack[i]; - stack[pos] = x; - stack_pointer++; -} - -void insert_sorted (int x) -{ - int i = 0; - while (i < stack_pointer && x > stack[i]) - i++; - insert (x, i); -} - -int main (void) -{ - push (3); - push (7); - push (137); - show (); - insert (5, 1); - show (); - insert_sorted (42); - show (); - insert_sorted (2); - show (); - return 0; -} diff --git a/20221205/loesung-3b-2.c b/20221205/loesung-3b-2.c deleted file mode 100644 index b1e1ae846f15a29e9cd53a8d1d689e3ccbefacce..0000000000000000000000000000000000000000 --- a/20221205/loesung-3b-2.c +++ /dev/null @@ -1,58 +0,0 @@ -#include <stdio.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - stack[stack_pointer++] = x; -} - -int pop (void) -{ - return stack[--stack_pointer]; -} - -void show (void) -{ - printf ("stack content:"); - for (int i = 0; i < stack_pointer; i++) - printf (" %d", stack[i]); - if (stack_pointer) - printf ("\n"); - else - printf (" (empty)\n"); -} - -void insert (int x, int pos) -{ - for (int i = stack_pointer - 1; i >= pos; i--) - stack[i + 1] = stack[i]; - stack[pos] = x; - stack_pointer++; -} - -void insert_sorted (int x) -{ - int i = stack_pointer - 1; - while (i >= 0 && x < stack[i]) - i--; - insert (x, i + 1); -} - -int main (void) -{ - push (3); - push (7); - push (137); - show (); - insert (5, 1); - show (); - insert_sorted (42); - show (); - insert_sorted (2); - show (); - return 0; -} diff --git a/20221205/loesung-3c.c b/20221205/loesung-3c.c deleted file mode 100644 index 79d061e3d7b78a2bec05b632e74b083a16d5a326..0000000000000000000000000000000000000000 --- a/20221205/loesung-3c.c +++ /dev/null @@ -1,72 +0,0 @@ -#include <stdio.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - stack[stack_pointer++] = x; -} - -int pop (void) -{ - return stack[--stack_pointer]; -} - -void show (void) -{ - printf ("stack content:"); - for (int i = 0; i < stack_pointer; i++) - printf (" %d", stack[i]); - if (stack_pointer) - printf ("\n"); - else - printf (" (empty)\n"); -} - -void insert (int x, int pos) -{ - for (int i = stack_pointer - 1; i >= pos; i--) - stack[i + 1] = stack[i]; - stack[pos] = x; - stack_pointer++; -} - -void insert_sorted (int x) -{ - int i = stack_pointer - 1; - while (i >= 0 && x < stack[i]) - { - stack[i + 1] = stack[i]; - i--; - } - stack[i + 1] = x; - stack_pointer++; -} - -int search (int x) -{ - for (int i = 0; i < stack_pointer; i++) - if (stack[i] == x) - return i; - return -1; -} - -int main (void) -{ - push (3); - push (7); - push (137); - show (); - insert (5, 1); - show (); - insert_sorted (42); - show (); - insert_sorted (2); - show (); - printf ("%d\n", search (42)); - printf ("%d\n", search (1117)); - return 0; -} diff --git a/20221205/loesung-3d.c b/20221205/loesung-3d.c deleted file mode 100644 index 9079d8d3be7a500498aede2cf8e89a7d7db48a35..0000000000000000000000000000000000000000 --- a/20221205/loesung-3d.c +++ /dev/null @@ -1,86 +0,0 @@ -#include <stdio.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - stack[stack_pointer++] = x; -} - -int pop (void) -{ - return stack[--stack_pointer]; -} - -void show (void) -{ - printf ("stack content:"); - for (int i = 0; i < stack_pointer; i++) - printf (" %d", stack[i]); - if (stack_pointer) - printf ("\n"); - else - printf (" (empty)\n"); -} - -void insert (int x, int pos) -{ - for (int i = stack_pointer - 1; i >= pos; i--) - stack[i + 1] = stack[i]; - stack[pos] = x; - stack_pointer++; -} - -void insert_sorted (int x) -{ - int i = stack_pointer - 1; - while (i >= 0 && x < stack[i]) - { - stack[i + 1] = stack[i]; - i--; - } - stack[i + 1] = x; - stack_pointer++; -} - -int search (int x) -{ - int left = 0; - int right = stack_pointer; - while (left < right - 1) - { - int middle = (left + right) / 2; - if (x < stack[middle]) - right = middle; - else - left = middle; - } - if (x == stack[left]) - return left; - else - return -1; -} - -int main (void) -{ - push (3); - push (7); - push (137); - show (); - insert (5, 1); - show (); - insert_sorted (42); - show (); - insert_sorted (2); - show (); - printf ("%d\n", search (2)); - printf ("%d\n", search (4)); - printf ("%d\n", search (42)); - printf ("%d\n", search (67)); - printf ("%d\n", search (137)); - printf ("%d\n", search (1117)); - return 0; -} diff --git a/20221205/logo-hochschule-bochum-cvh-text-v2.pdf b/20221205/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221205/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221205/logo-hochschule-bochum.pdf b/20221205/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221205/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221205/objects-05a.c b/20221205/objects-05a.c deleted file mode 100644 index d7a3d1e679f6d659812f1578af946708171539e9..0000000000000000000000000000000000000000 --- a/20221205/objects-05a.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int i = 42; - char *s = "Hello, world!"; - - void *object[] = { &i, &s }; - - for (int i = 0; i < 2; i++) - if (typeof (object[i]) == int) /* funktioniert nicht */ - printf ("Integer: %d\n", *object[i]); - else if (typeof (object[i] == char *)) - printf ("String: \"%s\"\n", object[i]); - - return 0; -} diff --git a/20221205/objects-05b.c b/20221205/objects-05b.c deleted file mode 100644 index d36aff93853be2b7466e28396729aea995c366f1..0000000000000000000000000000000000000000 --- a/20221205/objects-05b.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int i = 42; - char *s = "Hello, world!"; - - int *object[] = { &i, (int *) &s }; - - for (int i = 0; i < 2; i++) - if (sizeof (object[i]) == sizeof (int *)) /* funktioniert nicht */ - printf ("Integer: %d\n", *object[i]); - else if (sizeof (object[i]) == sizeof (char *)) - printf ("String: \"%s\"\n", *((char **) object[i])); - - return 0; -} diff --git a/20221205/objects-05c.c b/20221205/objects-05c.c deleted file mode 100644 index e2906e5a62e03db3fbe84b7b6ef7f37da259602f..0000000000000000000000000000000000000000 --- a/20221205/objects-05c.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int i = 42; - char *s = "Hello, world!"; - - int *object[] = { &i, (int *) &s }; - - for (int i = 0; i < 2; i++) - if (*object[i] > -1000 && *object[i] < 1000) - printf ("Integer: %d\n", *object[i]); - else - printf ("String: \"%s\"\n", *((char **) object[i])); - - return 0; -} diff --git a/20221205/objects-05d.c b/20221205/objects-05d.c deleted file mode 100644 index d58a7addfcb7d158e04704f73a057c1f3eb2fe10..0000000000000000000000000000000000000000 --- a/20221205/objects-05d.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> -#include <signal.h> - -void segv_handler (int s) -{ - printf ("Hello, world!\n"); - signal (SIGSEGV, NULL); -} - -int main (void) -{ - signal (SIGSEGV, segv_handler); - printf (42); - - return 0; -} diff --git a/20221205/objects-05e.c b/20221205/objects-05e.c deleted file mode 100644 index 892632b726ff235acdf59459ce6462c9f537b417..0000000000000000000000000000000000000000 --- a/20221205/objects-05e.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdio.h> -#include <signal.h> - -char *s = "Hello, world!"; -int i = 42; - -int *object[] = { (int *) &s, &i }; - -volatile int j; - -void segv_handler (int s) -{ - printf ("Integer: %d\n", *object[j]); - signal (SIGSEGV, NULL); -} - -int main (void) -{ - signal (SIGSEGV, segv_handler); - - for (j = 0; j < 2; j++) - printf ("String: \"%s\"\n", *((char **) object[j])); - - return 0; -} diff --git a/20221205/objects-05f.c b/20221205/objects-05f.c deleted file mode 100644 index 880d7c04ec4b18b2ef93f5e3d7878077bb0efdf6..0000000000000000000000000000000000000000 --- a/20221205/objects-05f.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <stdio.h> -#include <signal.h> - -char *s = "Hello, world!"; -int i = 42; - -int *object[] = { (int *) &s, &i }; - -volatile int j; - -void segv_handler (int s) -{ - printf ("Integer: %d\n", *object[j]); - signal (SIGSEGV, NULL); -} - -int main (void) -{ - signal (SIGSEGV, segv_handler); - - for (j = 0; j < 2; j++) - { - volatile char UAAAH = *(*(char **) object[j]); - printf ("String: \"%s\"\n", *((char **) object[j])); - } - - return 0; -} diff --git a/20221205/objects-05g.c b/20221205/objects-05g.c deleted file mode 100644 index 1722051b8dc0709a43013c89825d4930cfb59ed7..0000000000000000000000000000000000000000 --- a/20221205/objects-05g.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <stdio.h> -#include <signal.h> - -#define UAAAH uaaah - -char *s = "Hello, world!"; -int i = 42; - -int *object[] = { (int *) &s, &i }; - -volatile int j; - -void segv_handler (int s) -{ - printf ("Integer: %d\n", *object[j]); - signal (SIGSEGV, NULL); -} - -int main (void) -{ - signal (SIGSEGV, segv_handler); - - for (j = 0; j < 2; j++) - { - volatile char UAAAH = *(*(char **) object[j]); - printf ("String: \"%s\"\n", *((char **) object[j])); - } - - return 0; -} diff --git a/20221205/objects-05h.c b/20221205/objects-05h.c deleted file mode 100644 index 820c4712e72e6e1ff89b4e0318b033a9608c27cf..0000000000000000000000000000000000000000 --- a/20221205/objects-05h.c +++ /dev/null @@ -1,32 +0,0 @@ -#include <stdio.h> -#include <signal.h> - -#define UAAAH uaaah - -char *s = "Hello, world!"; -int i = 42; - -int *object[] = { (int *) &s, &i }; - -volatile int j; - -void segv_handler (int s) -{ - printf ("Integer: %d\e[01;30m", *object[j]); - fflush (stdout); - signal (SIGSEGV, NULL); -} - -int main (void) -{ - signal (SIGSEGV, segv_handler); - - for (j = 0; j < 2; j++) - { - volatile char UAAAH = *(*(char **) object[j]); - (void) UAAAH; - printf ("String: \"%s\"\n", *((char **) object[j])); - } - - return 0; -} diff --git a/20221205/objects-06a.c b/20221205/objects-06a.c deleted file mode 100644 index 8a1294bea03009beb408e87494047c3de35eaf69..0000000000000000000000000000000000000000 --- a/20221205/objects-06a.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int type; -} t_base; - -typedef struct -{ - int content; - int type; -} t_integer; - -typedef struct -{ - char *content; - int type; -} t_string; - -void print_object (t_base *this) -{ - if (this->type == 1) - printf ("Integer: %d\n", ((t_integer *) this)->content); - else if (this->type == 2) - printf ("String: \"%s\"\n", ((t_string *) this)->content); -} - -int main (void) -{ - t_integer i = { 42, 1 }; - t_string s = { "Hello, world!", 2 }; - - t_base *object[] = { (t_base *) &i, (t_base *) &s }; - - for (int i = 0; i < 2; i++) - print_object (object[i]); - - return 0; -} diff --git a/20221205/objects-13.c b/20221205/objects-13.c deleted file mode 100644 index 1ed5887177bc6809a2a110bb360a847ad004bf85..0000000000000000000000000000000000000000 --- a/20221205/objects-13.c +++ /dev/null @@ -1,78 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -union t_object; -struct t_vmt; - -typedef struct -{ - struct t_vmt *vmt; -} t_base; - -typedef struct -{ - struct t_vmt *vmt; - int content; -} t_integer; - -typedef struct -{ - struct t_vmt *vmt; - char *content; -} t_string; - -typedef union t_object -{ - t_base base; - t_integer integer; - t_string string; -} t_object; - -typedef struct t_vmt -{ - void (*print) (union t_object *this); -} t_vmt; - -void print_integer (t_object *this) -{ - printf ("Integer: %d\n", this->integer.content); -} - -void print_string (t_object *this) -{ - printf ("String: \"%s\"\n", this->string.content); -} - -t_vmt vmt_integer = { print_integer }; -t_vmt vmt_string = { print_string }; - -t_object *new_integer (int i) -{ - t_object *p = malloc (sizeof (t_integer)); - p->integer.vmt = &vmt_integer; - p->integer.content = i; - return p; -} - -t_object *new_string (char *s) -{ - t_object *p = malloc (sizeof (t_string)); - p->integer.vmt = &vmt_string; - p->string.content = s; - return p; -} - -int main (void) -{ - t_object *object[] = { new_integer (42), - new_string ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - object[i]->base.vmt->print (object[i]); - - for (int i = 0; object[i]; i++) - free (object[i]); - - return 0; -} diff --git a/20221205/objects-13a.c b/20221205/objects-13a.c deleted file mode 100644 index 1bf74a5769da98f518718d8b0e8ae952df849a71..0000000000000000000000000000000000000000 --- a/20221205/objects-13a.c +++ /dev/null @@ -1,83 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -union t_object; -struct t_vmt; - -typedef struct -{ - struct t_vmt *vmt; -} t_base; - -typedef struct -{ - struct t_vmt *vmt; - int content; -} t_integer; - -typedef struct -{ - struct t_vmt *vmt; - char *content; -} t_string; - -typedef union t_object -{ - t_base base; - t_integer integer; - t_string string; -} t_object; - -typedef struct t_vmt -{ - ssize_t size; - ssize_t neg_size; - void (*print) (union t_object *this); -} t_vmt; - -void print_integer (t_object *this) -{ - printf ("Integer: %d\n", this->integer.content); -} - -void print_string (t_object *this) -{ - printf ("String: \"%s\"\n", this->string.content); -} - -t_vmt vmt_integer = { sizeof (t_integer), -sizeof (t_integer), print_integer }; -t_vmt vmt_string = { sizeof (t_string), -sizeof (t_string), print_string }; - -t_object *new_integer (int i) -{ - t_object *p = malloc (sizeof (t_integer)); - p->integer.vmt = &vmt_integer; - p->integer.content = i; - return p; -} - -t_object *new_string (char *s) -{ - t_object *p = malloc (sizeof (t_string)); - p->integer.vmt = &vmt_string; - p->string.content = s; - return p; -} - -int main (void) -{ - t_object *object[] = { new_integer (42), - new_string ("Hello, world!"), - NULL }; - - for (int i = 0; object[i]; i++) - if (object[i]->base.vmt - && object[i]->base.vmt->size > 0 - && object[i]->base.vmt->neg_size == - object[i]->base.vmt->size) - object[i]->base.vmt->print (object[i]); - - for (int i = 0; object[i]; i++) - free (object[i]); - - return 0; -} diff --git a/20221205/pgscript.sty b/20221205/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221205/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221205/pgslides.sty b/20221205/pgslides.sty deleted file mode 120000 index 5be1416f4216f076aa268901f52a15d775e43f64..0000000000000000000000000000000000000000 --- a/20221205/pgslides.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgslides.sty \ No newline at end of file diff --git a/20221205/stack-00.c b/20221205/stack-00.c deleted file mode 100644 index 97a17ac787768b1f5ef7597579a4eadf41509607..0000000000000000000000000000000000000000 --- a/20221205/stack-00.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <stdio.h> - -void push (int x) -{ - /* FIXME */ -} - -int pop (void) -{ - return 42; /* FIXME */ -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/stack-01.c b/20221205/stack-01.c deleted file mode 100644 index 154331c13743b852e859ca06aee9077af6854b33..0000000000000000000000000000000000000000 --- a/20221205/stack-01.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <stdio.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - stack[stack_pointer] = x; - stack_pointer++; -} - -int pop (void) -{ - return 42; /* FIXME */ -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/stack-02.c b/20221205/stack-02.c deleted file mode 100644 index 1eee46152c3d651d09cdeb34d24915bb48f3466a..0000000000000000000000000000000000000000 --- a/20221205/stack-02.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <stdio.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - stack[stack_pointer++] = x; -} - -int pop (void) -{ - return 42; /* FIXME */ -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/stack-03.c b/20221205/stack-03.c deleted file mode 100644 index b20a444d628a88101416097c79b34e0669b24d21..0000000000000000000000000000000000000000 --- a/20221205/stack-03.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <stdio.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - stack[stack_pointer++] = x; -} - -int pop (void) -{ - stack_pointer--; - return stack[stack_pointer]; -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/stack-04.c b/20221205/stack-04.c deleted file mode 100644 index 0d738f95ff81ce1701b4aa8a12df30094b723851..0000000000000000000000000000000000000000 --- a/20221205/stack-04.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <stdio.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - stack[stack_pointer++] = x; -} - -int pop (void) -{ - return stack[--stack_pointer]; -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/stack-05.c b/20221205/stack-05.c deleted file mode 100644 index 38a187208208488bdb8e988d93442d57730e421e..0000000000000000000000000000000000000000 --- a/20221205/stack-05.c +++ /dev/null @@ -1,40 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - if (stack_pointer < STACK_SIZE) - stack[stack_pointer++] = x; - else - { - fprintf (stderr, "stack overflow\n"); - exit (1); - } -} - -int pop (void) -{ - if (stack_pointer > 0) - return stack[--stack_pointer]; - else - { - fprintf (stderr, "stack underflow\n"); - exit (1); - } -} - -int main (void) -{ - push (3); - push (7); - push (137); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/stack-06.c b/20221205/stack-06.c deleted file mode 100644 index be00e160384be5e4af05831547ed74b636c3bdf0..0000000000000000000000000000000000000000 --- a/20221205/stack-06.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - if (stack_pointer < STACK_SIZE) - stack[stack_pointer++] = x; - else - { - fprintf (stderr, "stack overflow\n"); - exit (1); - } -} - -int pop (void) -{ - if (stack_pointer > 0) - return stack[--stack_pointer]; - else - { - fprintf (stderr, "stack underflow\n"); - exit (1); - } -} - -int main (void) -{ - for (int i = 0; i < 42; i++) - push (i); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/stack-07.c b/20221205/stack-07.c deleted file mode 100644 index b583bc281f9ae3acd673ec9ea4de75720084fb50..0000000000000000000000000000000000000000 --- a/20221205/stack-07.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define STACK_SIZE 10 - -int stack[STACK_SIZE]; -int stack_pointer = 0; - -void push (int x) -{ - if (stack_pointer < STACK_SIZE) - stack[stack_pointer++] = x; - else - { - fprintf (stderr, "stack overflow\n"); - exit (1); - } -} - -int pop (void) -{ - if (stack_pointer > 0) - return stack[--stack_pointer]; - else - { - fprintf (stderr, "stack underflow\n"); - exit (1); - } -} - -int main (void) -{ - push (3); - push (7); - push (137); - for (int i = 0; i < 42; i++) - printf ("%d\n", pop ()); - return 0; -} diff --git a/20221205/stack-07.out b/20221205/stack-07.out deleted file mode 100644 index 2344cb9a2fd2e0950ddd40193267ea4b208032cb..0000000000000000000000000000000000000000 --- a/20221205/stack-07.out +++ /dev/null @@ -1,3 +0,0 @@ -137 -7 -3 diff --git a/20221212/aufgabe-1.c b/20221212/aufgabe-1.c deleted file mode 100644 index 5b0cb23fdd5ee15a4403808c18d2104ed49caf3f..0000000000000000000000000000000000000000 --- a/20221212/aufgabe-1.c +++ /dev/null @@ -1,62 +0,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; -} diff --git a/20221212/aufgabe-2.c b/20221212/aufgabe-2.c deleted file mode 100644 index d0b065941fbc0082bf867d872527299dca97b98f..0000000000000000000000000000000000000000 --- a/20221212/aufgabe-2.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <string.h> - -int fun_1 (char *s) -{ - int x = 0; - for (int i = 0; i < strlen (s); i++) - x += s[i]; - return x; -} - -int fun_2 (char *s) -{ - int i = 0, x = 0; - int len = strlen (s); - while (i < len) - x += s[i++]; - return x; -} diff --git a/20221212/aufgabe-3.c b/20221212/aufgabe-3.c deleted file mode 100644 index ac63ca250c79fd76c26f4045ece703407024a4ce..0000000000000000000000000000000000000000 --- a/20221212/aufgabe-3.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <stdio.h> - -/* ... */ - -int main (void) -{ - pbm_open (14, 14, "test.pbm"); - pbm_line (" "); - pbm_line (" XXXXXX "); - pbm_line (" X X "); - pbm_line (" X X "); - pbm_line (" X X "); - pbm_line (" X XX XX X "); - pbm_line (" X X X X "); - pbm_line (" X X "); - pbm_line (" X X X X "); - pbm_line (" X X X X "); - pbm_line (" X XXXX X "); - pbm_line (" X X "); - pbm_line (" XXXXXX "); - pbm_line (" "); - pbm_close (); - return 0; -} diff --git a/20221212/aufgabe-3.pbm b/20221212/aufgabe-3.pbm deleted file mode 100644 index bc5b70b1ad6f7236ec9469afac311f05fb056946..0000000000000000000000000000000000000000 Binary files a/20221212/aufgabe-3.pbm and /dev/null differ diff --git a/20221212/aufgabe-3.png b/20221212/aufgabe-3.png deleted file mode 100644 index e655af0096cc6e50da81c8f820395dfaed27277f..0000000000000000000000000000000000000000 Binary files a/20221212/aufgabe-3.png and /dev/null differ diff --git a/20221212/hello-gtk.png b/20221212/hello-gtk.png deleted file mode 120000 index cca99209d86683a9a3b0f70bbc149780bae10ba6..0000000000000000000000000000000000000000 --- a/20221212/hello-gtk.png +++ /dev/null @@ -1 +0,0 @@ -../common/hello-gtk.png \ No newline at end of file diff --git a/20221212/hp-musterloesung-20221212.pdf b/20221212/hp-musterloesung-20221212.pdf deleted file mode 100644 index b39527cbb9349c44637186c4bb66c4e1edb7d414..0000000000000000000000000000000000000000 Binary files a/20221212/hp-musterloesung-20221212.pdf and /dev/null differ diff --git a/20221212/hp-musterloesung-20221212.tex b/20221212/hp-musterloesung-20221212.tex deleted file mode 100644 index a640276da85b3f56302d18c560a78fa07d577160..0000000000000000000000000000000000000000 --- a/20221212/hp-musterloesung-20221212.tex +++ /dev/null @@ -1,378 +0,0 @@ -% hp-musterloesung-20221212.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Länge von Strings (Neuauflage), Text-Grafik-Bibliothek, PBM-Grafik - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 12.\ Dezember 2022} - - \exercise{Länge von Strings} - - Diese Aufgabe ist eine Neuauflage von Aufgabe 2 der - Übung vom 7.\ November 2022,\\ - ergänzt um die Teilaufgaben (f) und (g). - - \medskip - - Strings werden in der Programmiersprache C durch Zeiger auf \lstinline{char}-Variable realisiert. - - Beispiel: \lstinline{char *hello_world = "Hello, world!\n"} - - Die Systembibliothek stellt eine Funktion \lstinline{strlen()} zur Ermittlung der Länge von Strings\\ - zur Verfügung (\lstinline{#include <string.h>}). - - \begin{enumerate}[\quad(a)] - \item - Auf welche Weise ist die Länge eines Strings gekennzeichnet? - \points{1} - \item - Wie lang ist die Beispiel-String-Konstante \lstinline{"Hello, world!\n"}, - und wieviel Speicherplatz belegt sie?\\ - \points{2} - \item - Schreiben Sie eine eigene Funktion \lstinline{int strlen (char *s)}, - die die Länge eines Strings zurückgibt.\\ - \points{3} - \end{enumerate} - - \goodbreak - - Wir betrachten nun die folgenden Funktionen (Datei: \gitfile{hp}{2022ws/20221212}{aufgabe-2.c}): - \begin{center} - \begin{minipage}{8cm} - \begin{lstlisting}[gobble=8] - int fun_1 (char *s) - { - int x = 0; - for (int i = 0; i < strlen (s); i++) - x += s[i]; - return x; - } - \end{lstlisting} - \end{minipage}% - \begin{minipage}{6cm} - \vspace*{-1cm} - \begin{lstlisting}[gobble=8] - int fun_2 (char *s) - { - int i = 0, x = 0; - int len = strlen (s); - while (i < len) - x += s[i++]; - return x; - } - \end{lstlisting} - \vspace*{-1cm} - \end{minipage} - \end{center} - \begin{enumerate}[\quad(a)]\setcounter{enumi}{3} - \item - Was bewirken die beiden Funktionen? - \points{2} - \item - Schreiben Sie eine eigene Funktion, - die dieselbe Aufgabe erledigt wie \lstinline{fun_2()},\\ - nur effizienter. - \points{4} - \item - Von welcher Ordnung (Landau-Symbol) sind die beiden Funktionen - hinsichtlich der Anzahl ihrer Zugriffe auf die Zeichen im String? - Begründen Sie Ihre Antwort. - Sie dürfen für \lstinline{strlen()} Ihre eigene Version der Funktion voraussetzen. - \points{3} - \item - Von welcher Ordnung (Landau-Symbol) ist Ihre effizientere Funktion?\\ - Begründen Sie Ihre Antwort. - \points{1} - \end{enumerate} - - \solution - - \begin{itemize} - \item[(a)] - \textbf{Auf welche Weise ist die Länge eines Strings gekennzeichnet?} - - Ein String ist ein Array von \lstinline{char}s. - Nach den eigentlichen Zeichen des Strings enthält das Array - \textbf{ein Null-Symbol} (Zeichen mit Zahlenwert 0, - nicht zu verwechseln mit der Ziffer \lstinline{'0'}) als Ende-Markierung. - Die Länge eines Strings ist die Anzahl der Zeichen - \emph{vor\/} diesem Symbol. - - \item[(b)] - {\bf Wie lang ist die Beispiel-String-Konstante \lstinline{"Hello, world!\n"}, - und wieviel Speicherplatz belegt sie?} - - Sie ist 14 Zeichen lang (\lstinline{'\n'} ist nur 1 Zeichen; - das Null-Symbol, das das Ende markiert, zählt hier nicht mit) - und belegt Speicherplatz für 15 Zeichen - (15 Bytes -- einschließlich Null-Symbol / Ende-Markierung). - - \item[(c)] - \textbf{Schreiben Sie eine eigene Funktion \lstinline{int strlen (char *s)}, - die die Länge eines Strings zurückgibt.} - - Siehe die Dateien \gitfile{hp}{2022ws/20221212}{loesung-2c-1.c} (mit Array-Index) - und \gitfile{hp}{2022ws/20221212}{loesung-2c-2.c} (mit Zeiger-Arithmetik). - Beide Lösungen sind korrekt und arbeiten gleich schnell. - - Die Warnung \lstinline[style=terminal]{conflicting types for built-in function "strlen"} - kann normalerweise ignoriert werden; - auf manchen Systemen (z.\,B.\ MinGW) hat jedoch die eingebaute Funktion \lstinline{strlen()} - beim Linken Vorrang vor der selbstgeschriebenen, - so daß die selbstgeschriebene Funktion nie aufgerufen wird. - In solchen Fällen ist es zulässig, die selbstgeschriebene Funktion - anders zu nennen (z.\,B.\ \lstinline{my_strlen()}). - - \item[(d)] - \textbf{Was bewirken die beiden Funktionen?} - - Beide addieren die Zahlenwerte der im String enthaltenen Zeichen - und geben die Summe als Funktionsergebnis zurück. - - Im Falle des Test-Strings \lstinline{"Hello, world!\n"} - lautet der Rückgabewert 1171 (siehe \gitfile{hp}{2022ws/20221212}{loesung-2d-1.c} und \gitfile{hp}{2022ws/20221212}{loesung-2d-2.c}). - - \item[(e)] - \textbf{Schreiben Sie eine eigene Funktion, - die dieselbe Aufgabe erledigt wie \lstinline{fun_2()}, - nur effizienter.} - - Die Funktion wird effizienter, - wenn man auf den Aufruf von \lstinline{strlen()} verzichtet - und stattdessen die Ende-Prüfung in derselben Schleife vornimmt, - in der man auch die Zahlenwerte der Zeichen des Strings aufsummiert. - - Die Funktion \lstinline{fun_3()} in der Datei \gitfile{hp}{2022ws/20221212}{loesung-2e-1.c} - realisiert dies mit einem Array-Index, - Die Funktion \lstinline{fun_4()} in der Datei \gitfile{hp}{2022ws/20221212}{loesung-2e-2.c} - mit Zeiger-Arithmetik. - Beide Lösungen sind korrekt und arbeiten gleich schnell. - - \textbf{Bemerkung:} Die effizientere Version der Funktion - arbeitet doppelt so schnell wie die ursprüngliche, - hat aber ebenfalls die Ordnung $\mathcal{O}(n)$ -- siehe unten. - - \item[(f)] - \textbf{Von welcher Ordnung (Landau-Symbol) sind die beiden Funktionen - hinsichtlich der Anzahl ihrer Zugriffe auf die Zeichen im String? - Begründen Sie Ihre Antwort. - Sie dürfen für \lstinline{strlen()} Ihre eigene Version der Funktion voraussetzen.} - - Vorüberlegung: \lstinline{strlen()} greift in einer Schleife - auf alle Zeichen des Strings der Länge $n$ zu, - hat also $\mathcal{O}(n)$. - - \lstinline{fun_1()} ruft in jedem Schleifendurchlauf - (zum Prüfen der \lstinline{while}-Bedingung) einmal \lstinline{strlen()} auf - und greift anschließend auf ein Zeichen des Strings zu, - hat also $\mathcal{O}\bigl(n\cdot(n+1)\bigr) = \mathcal{O}(n^2)$. - - \lstinline{fun_2()} ruft einmalig \lstinline{strlen()} auf - und greift anschließend in einer Schleife auf alle Zeichen des Strings zu, - hat also $\mathcal{O}(n+n) = \mathcal{O}(n)$. - - \item[(g)] - \textbf{Von welcher Ordnung (Landau-Symbol) ist Ihre effizientere Funktion?\\ - Begründen Sie Ihre Antwort.} - - In beiden o.\,a.\ Lösungsvarianten - -- \gitfile{hp}{2022ws/20221212}{loesung-2e-1.c} - und \gitfile{hp}{2022ws/20221212}{loesung-2e-2.c} -- - arbeitet die Funktion mit einer einzigen Schleife, - die gleichzeitig die Zahlenwerte addiert und das Ende des Strings sucht. - - Mit jeweils einer einzigen Schleife - haben beide Funktionen die Ordnung $\mathcal{O}(n)$. - - \end{itemize} - - \exercise{Text-Grafik-Bibliothek} - - Schreiben Sie eine Bibliothek für "`Text-Grafik"' mit folgenden Funktionen:\vspace*{-\medskipamount} - \begin{itemize} - \item - \lstinline|void clear (char c)|\\ - Bildschirm auf Zeichen \lstinline|c| löschen,\\ - also komplett mit diesem Zeichen (z.\,B.: Leerzeichen) füllen - \item - \lstinline|void put_point (int x, int y, char c)|\\ - Punkt setzen (z.\,B.\ einen Stern (\lstinline{*}) an die Stelle $(x,y)$ "`malen"') - \item - \lstinline|char get_point (int x, int y)|\\ - Punkt lesen -% \item -% \lstinline|void fill (int x, int y, char c, char o)|\\ -% Fläche in der "`Farbe"' \lstinline|o|, -% die den Punkt \lstinline|(x, y)| enthält, -% mit der "`Farbe"' \lstinline|c| ausmalen - \item - \lstinline|void display (void)|\\ - das Gezeichnete auf dem Bildschirm ausgeben - \end{itemize} - - \goodbreak - - Hinweise:\vspace*{-\medskipamount} - \begin{itemize} - \item - Eine C-Bibliothek besteht aus (mindestens) - einer \file{.h}-Datei und einer \file{.c}-Datei. - \item - Verwenden Sie ein Array als "`Bildschirm"'. - - Vor dem Aufruf der Funktion \lstinline|display()| ist nichts zu sehen;\\ - alle Grafikoperationen erfolgen auf dem Array. - \item - Verwenden Sie Präprozessor-Konstante, - z.\,B.\ \lstinline{WIDTH} und \lstinline{HEIGHT},\\ - um Höhe und Breite des "`Bildschirms"' festzulegen: - \begin{lstlisting}[gobble=8] - #define WIDTH 72 - #define HEIGHT 24 - \end{lstlisting} - \item - Schreiben Sie zusätzlich ein Test-Programm, - das alle Funktionen der Bibliothek benutzt,\\ - um ein hübsches Bild (z.\,B.\ ein stilisiertes Gesicht -- "`Smiley"') - auszugeben. - \end{itemize} - \points{8} - - \solution - - Siehe die Dateien \gitfile{hp}{2022ws/20221212}{textgraph.c} und \gitfile{hp}{2022ws/20221212}{textgraph.h} (Bibliothek) - sowie \gitfile{hp}{2022ws/20221212}{test-textgraph.c} (Test-Programm). - - Diese Lösung erfüllt zusätzlich die Aufgabe, - bei fehlerhafter Benutzung (Koordinaten außerhalb des Zeichenbereichs) - eine sinnvolle Fehlermeldung auszugeben, - anstatt unkontrolliert Speicher zu überschreiben und abzustürzen. - - Das Schlüsselwort \lstinline{static} - bei der Deklaration der Funktion \lstinline{check_coordinates()} - bedeutet, daß diese Funktion nur lokal (d.\,h.\ innerhalb der Bibliothek) - verwendet und insbesondere nicht nach außen - (d.\,h.\ für die Benutzung durch das Hauptprogramm) exportiert wird. - Dies dient dazu, nicht unnötig Bezeichner zu reservieren - (Vermeidung von "`Namensraumverschmutzung"'). - - Man beachte die Verwendung einfacher Anführungszeichen (Apostrophe) - bei der Angabe von \lstinline{char}-Kon"-stanten (\lstinline{'*'}) - im Gegensatz zur Verwendung doppelter Anführungszeichen - bei der Angabe von String-Konstanten - (String = Array von \lstinline{char}s, abgeschlossen mit Null-Symbol). - Um das einfache Anführungszeichen selbst als \lstinline{char}-Konstante anzugeben, - ist ein vorangestellter Backslash erforderlich: \lstinline{'\''} ("`Escape-Sequenz"'). - Entsprechendes gilt für die Verwendung doppelter Anführungszeichen - innerhalb von String-Konstanten: - \lstinline{printf ("Your name is: \"%s\"", name);} - - \exercise{PBM-Grafik} - - Bei einer PBM-Grafikdatei handelt es sich - um ein abgespeichertes C-Array von Bytes (\lstinline{uint8_t}), - das die Bildinformationen enthält: - \begin{itemize}\itemsep0pt - \item Die Datei beginnt mit der Kennung \lstinline{P4}, - danach folgen Breite und Höhe in Pixel als ASCII-Zahlen, - danach ein Trennzeichen und die eigentlichen Bilddaten. - \item Jedes Bit entspricht einem Pixel. - \item Nullen stehen für Weiß, Einsen für Schwarz. - \item MSB first. - \item Jede Zeile des Bildes wird auf ganze Bytes aufgefüllt. - \end{itemize} - Viele Grafikprogramme können PBM-Dateien öffnen und bearbeiten. - Der Anfang der Datei (Kennung, Breite und Höhe) - ist auch in einem Texteditor lesbar. - - Beispiel (\gitfile{hp}{2022ws/20221212}{aufgabe-3.pbm}):\hfill - \makebox(0,0)[tr]{\framebox{\includegraphics[scale=3]{aufgabe-3.png}}} - \begin{lstlisting} - P4 - 14 14 - <Bilddaten> - \end{lstlisting} - - In dem untenstehenden Programmfragment (\gitfile{hp}{2022ws/20221212}{aufgabe-3.c}) - wird eine Grafik aus Textzeilen zusammengesetzt, - so daß man mit einem Texteditor "`malen"' kann: - \begin{lstlisting} - #include <stdio.h> - - /* ... */ - - int main (void) - { - pbm_open (14, 14, "test.pbm"); - pbm_line (" "); - pbm_line (" XXXXXX "); - pbm_line (" X X "); - pbm_line (" X X "); - pbm_line (" X X "); - pbm_line (" X XX XX X "); - pbm_line (" X X X X "); - pbm_line (" X X "); - pbm_line (" X X X X "); - pbm_line (" X X X X "); - pbm_line (" X XXXX X "); - pbm_line (" X X "); - pbm_line (" XXXXXX "); - pbm_line (" "); - pbm_close (); - return 0; - } - \end{lstlisting} - Ergänzen Sie das Programmfragment so, - daß es eine Datei \file{test.pbm} erzeugt, die die Grafik enthält. - - Das Programm soll typische Benutzerfehler abfangen - (z.\,B.\ weniger Zeilen als in \lstinline{pbm_open} angegeben), - keine fehlerhaften Ausgaben produzieren oder abstürzen, - sondern stattdessen sinnvolle Fehlermeldungen ausgeben. - - Zum Vergleich liegt eine Datei \gitfile{hp}{2022ws/20221212}{aufgabe-3.pbm} - mit dem gewünschten Ergebnis bei,\\ - und die Datei \gitfile{hp}{2022ws/20221212}{aufgabe-3.png} enthält dasselbe Bild. - - \points{10} - - \solution - - Die Datei \gitfile{hp}{2022ws/20221212}{loesung-3.c} enthält eine richtige Lösung. - Man beachte die Aufrufe der Funktion \lstinline{error()} im Falle von - falscher Benutzung der Bibliotheksfunktionen. - Weitere Erklärungen finden Sie als Kommentare im Quelltext. - - Die Datei \gitfile{hp}{2022ws/20221212}{loesung-3f.c} enthält eine falsche Lösung. - (Beide Dateien unterscheiden sich nur in Zeile 46.) - Dieses Programm speichert die Bits in den Bytes von rechts nach links (LSB first). - Richtig wäre von links nach rechts (MBS first). - Das erzeugte Bild ist dementsprechend fehlerhaft. - -\end{document} diff --git a/20221212/hp-uebung-20221212.pdf b/20221212/hp-uebung-20221212.pdf deleted file mode 100644 index 5c7ca52036ce2787b35c2eab0a31b7da68961bce..0000000000000000000000000000000000000000 Binary files a/20221212/hp-uebung-20221212.pdf and /dev/null differ diff --git a/20221212/hp-uebung-20221212.tex b/20221212/hp-uebung-20221212.tex deleted file mode 100644 index 874be4742ac818823b17913de97f2f0524734059..0000000000000000000000000000000000000000 --- a/20221212/hp-uebung-20221212.tex +++ /dev/null @@ -1,255 +0,0 @@ -% hp-uebung-20221212.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Länge von Strings (Neuauflage), Text-Grafik-Bibliothek, PBM-Grafik - -% ? Hüpfender Ball (20211206-3) -% ! Text-Grafik-Bibliothek (20211213-2) -% ! PBM-Grafik (20211213-3) -% ! Länge von Strings (Neuauflage) (20211220-2) -% ? Hexdumps (20220110-3) -% ? einfach und doppelt verkettete Listen (20220117-2) -% ? ternärer Baum (20220117-3) - -\documentclass[a4paper]{article} - -\usepackage{pgscript} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 12.\ Dezember 2022} - - Diese Übung enthält Punkteangaben wie in einer Klausur. - Um zu "`bestehen"', müssen Sie innerhalb von 100 Minuten - unter Verwendung ausschließlich zugelassener Hilfsmittel - 17 Punkte (von insgesamt \totalpoints) erreichen. - - \exercise{Länge von Strings} - - Diese Aufgabe ist eine Neuauflage von Aufgabe 2 der - Übung vom 7.\ November 2022,\\ - ergänzt um die Teilaufgaben (f) und (g). - - \medskip - - Strings werden in der Programmiersprache C durch Zeiger auf \lstinline{char}-Variable realisiert. - - Beispiel: \lstinline{char *hello_world = "Hello, world!\n"} - - Die Systembibliothek stellt eine Funktion \lstinline{strlen()} zur Ermittlung der Länge von Strings\\ - zur Verfügung (\lstinline{#include <string.h>}). - - \begin{enumerate}[\quad(a)] - \item - Auf welche Weise ist die Länge eines Strings gekennzeichnet? - \points{1} - \item - Wie lang ist die Beispiel-String-Konstante \lstinline{"Hello, world!\n"}, - und wieviel Speicherplatz belegt sie?\\ - \points{2} - \item - Schreiben Sie eine eigene Funktion \lstinline{int strlen (char *s)}, - die die Länge eines Strings zurückgibt.\\ - \points{3} - \end{enumerate} - - \goodbreak - - Wir betrachten nun die folgenden Funktionen (Datei: \gitfile{hp}{2022ws/20221212}{aufgabe-2.c}): - \begin{center} - \begin{minipage}{8cm} - \begin{lstlisting}[gobble=8] - int fun_1 (char *s) - { - int x = 0; - for (int i = 0; i < strlen (s); i++) - x += s[i]; - return x; - } - \end{lstlisting} - \end{minipage}% - \begin{minipage}{6cm} - \vspace*{-1cm} - \begin{lstlisting}[gobble=8] - int fun_2 (char *s) - { - int i = 0, x = 0; - int len = strlen (s); - while (i < len) - x += s[i++]; - return x; - } - \end{lstlisting} - \vspace*{-1cm} - \end{minipage} - \end{center} - \begin{enumerate}[\quad(a)]\setcounter{enumi}{3} - \item - Was bewirken die beiden Funktionen? - \points{2} - \item - Schreiben Sie eine eigene Funktion, - die dieselbe Aufgabe erledigt wie \lstinline{fun_2()},\\ - nur effizienter. - \points{4} - \item - Von welcher Ordnung (Landau-Symbol) sind die beiden Funktionen - hinsichtlich der Anzahl ihrer Zugriffe auf die Zeichen im String? - Begründen Sie Ihre Antwort. - Sie dürfen für \lstinline{strlen()} Ihre eigene Version der Funktion voraussetzen. - \points{3} - \item - Von welcher Ordnung (Landau-Symbol) ist Ihre effizientere Funktion?\\ - Begründen Sie Ihre Antwort. - \points{1} - \end{enumerate} - - \clearpage - \exercise{Text-Grafik-Bibliothek} - - Schreiben Sie eine Bibliothek für "`Text-Grafik"' mit folgenden Funktionen:\vspace*{-\medskipamount} - \begin{itemize} - \item - \lstinline|void clear (char c)|\\ - Bildschirm auf Zeichen \lstinline|c| löschen,\\ - also komplett mit diesem Zeichen (z.\,B.: Leerzeichen) füllen - \item - \lstinline|void put_point (int x, int y, char c)|\\ - Punkt setzen (z.\,B.\ einen Stern (\lstinline{*}) an die Stelle $(x,y)$ "`malen"') - \item - \lstinline|char get_point (int x, int y)|\\ - Punkt lesen -% \item -% \lstinline|void fill (int x, int y, char c, char o)|\\ -% Fläche in der "`Farbe"' \lstinline|o|, -% die den Punkt \lstinline|(x, y)| enthält, -% mit der "`Farbe"' \lstinline|c| ausmalen - \item - \lstinline|void display (void)|\\ - das Gezeichnete auf dem Bildschirm ausgeben - \end{itemize} - - Hinweise:\vspace*{-\medskipamount} - \begin{itemize} - \item - Eine C-Bibliothek besteht aus (mindestens) - einer \file{.h}-Datei und einer \file{.c}-Datei. - \item - Verwenden Sie ein Array als "`Bildschirm"'. - - Vor dem Aufruf der Funktion \lstinline|display()| ist nichts zu sehen;\\ - alle Grafikoperationen erfolgen auf dem Array. - \item - Verwenden Sie Präprozessor-Konstante, - z.\,B.\ \lstinline{WIDTH} und \lstinline{HEIGHT},\\ - um Höhe und Breite des "`Bildschirms"' festzulegen: - \begin{lstlisting}[gobble=8] - #define WIDTH 72 - #define HEIGHT 24 - \end{lstlisting} - \item - Schreiben Sie zusätzlich ein Test-Programm, - das alle Funktionen der Bibliothek benutzt,\\ - um ein hübsches Bild (z.\,B.\ ein stilisiertes Gesicht -- "`Smiley"') - auszugeben. - \end{itemize} - \points{8} - - \exercise{PBM-Grafik} - - Bei einer PBM-Grafikdatei handelt es sich - um ein abgespeichertes C-Array von Bytes (\lstinline{uint8_t}), - das die Bildinformationen enthält: - \begin{itemize}\itemsep0pt - \item Die Datei beginnt mit der Kennung \lstinline{P4}, - danach folgen Breite und Höhe in Pixel als ASCII-Zahlen, - danach ein Trennzeichen und die eigentlichen Bilddaten. - \item Jedes Bit entspricht einem Pixel. - \item Nullen stehen für Weiß, Einsen für Schwarz. - \item MSB first. - \item Jede Zeile des Bildes wird auf ganze Bytes aufgefüllt. - \end{itemize} - Viele Grafikprogramme können PBM-Dateien öffnen und bearbeiten. - Der Anfang der Datei (Kennung, Breite und Höhe) - ist auch in einem Texteditor lesbar. - - Beispiel (\gitfile{hp}{2022ws/20221212}{aufgabe-3.pbm}):\hfill - \makebox(0,0)[tr]{\framebox{\includegraphics[scale=3]{aufgabe-3.png}}} - \begin{lstlisting} - P4 - 14 14 - <Bilddaten> - \end{lstlisting} - - In dem untenstehenden Programmfragment (\gitfile{hp}{2022ws/20221212}{aufgabe-3.c}) - wird eine Grafik aus Textzeilen zusammengesetzt, - so daß man mit einem Texteditor "`malen"' kann: - \begin{lstlisting} - #include <stdio.h> - - /* ... */ - - int main (void) - { - pbm_open (14, 14, "test.pbm"); - pbm_line (" "); - pbm_line (" XXXXXX "); - pbm_line (" X X "); - pbm_line (" X X "); - pbm_line (" X X "); - pbm_line (" X XX XX X "); - pbm_line (" X X X X "); - pbm_line (" X X "); - pbm_line (" X X X X "); - pbm_line (" X X X X "); - pbm_line (" X XXXX X "); - pbm_line (" X X "); - pbm_line (" XXXXXX "); - pbm_line (" "); - pbm_close (); - return 0; - } - \end{lstlisting} - Ergänzen Sie das Programmfragment so, - daß es eine Datei \file{test.pbm} erzeugt, die die Grafik enthält. - - Das Programm soll typische Benutzerfehler abfangen - (z.\,B.\ weniger Zeilen als in \lstinline{pbm_open} angegeben), - keine fehlerhaften Ausgaben produzieren oder abstürzen, - sondern stattdessen sinnvolle Fehlermeldungen ausgeben. - - Zum Vergleich liegt eine Datei \gitfile{hp}{2022ws/20221212}{aufgabe-3.pbm} - mit dem gewünschten Ergebnis bei,\\ - und die Datei \gitfile{hp}{2022ws/20221212}{aufgabe-3.png} enthält dasselbe Bild. - - \points{10} - - \begin{flushright} - \textit{Viel Erfolg!} - \end{flushright} - - \makeatletter - \immediate\write\@mainaux{\string\gdef\string\totalpoints{\arabic{points}}} - \makeatother - -\end{document} diff --git a/20221212/loesung-2c-1.c b/20221212/loesung-2c-1.c deleted file mode 100644 index 69ddd0e4e749f6ca31bfa3d4f929c333648ef6ea..0000000000000000000000000000000000000000 --- a/20221212/loesung-2c-1.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int strlen (char *s) -{ - int l = 0; - while (s[l]) - l++; - return l; -} - -int main (void) -{ - printf ("%d\n", strlen ("Hello, world!\n")); - return 0; -} diff --git a/20221212/loesung-2c-2.c b/20221212/loesung-2c-2.c deleted file mode 100644 index e783c474e485e80d08a6e86f8ae6e179f5a294f4..0000000000000000000000000000000000000000 --- a/20221212/loesung-2c-2.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int strlen (char *s) -{ - char *s0 = s; - while (*s) - s++; - return s - s0; -} - -int main (void) -{ - printf ("%d\n", strlen ("Hello, world!\n")); - return 0; -} diff --git a/20221212/loesung-2d-1.c b/20221212/loesung-2d-1.c deleted file mode 100644 index 57521382c21fb743c6f5f5c65320bc4ac9360b1a..0000000000000000000000000000000000000000 --- a/20221212/loesung-2d-1.c +++ /dev/null @@ -1,34 +0,0 @@ - -#include <stdio.h> - -int strlen (char *s) -{ - int l = 0; - while (s[l]) - l++; - return l; -} - -int fun_1 (char *s) -{ - int x = 0; - for (int i = 0; i < strlen (s); i++) - x += s[i]; - return x; -} - -int fun_2 (char *s) -{ - int i = 0, x = 0; - int len = strlen (s); - while (i < len) - x += s[i++]; - return x; -} - -int main (void) -{ - printf ("%d\n", fun_1 ("Hello, world!\n")); - printf ("%d\n", fun_2 ("Hello, world!\n")); - return 0; -} diff --git a/20221212/loesung-2d-2.c b/20221212/loesung-2d-2.c deleted file mode 100644 index 5f3f0961129aa16fc9c4510ae21bb77b69913b12..0000000000000000000000000000000000000000 --- a/20221212/loesung-2d-2.c +++ /dev/null @@ -1,34 +0,0 @@ - -#include <stdio.h> - -int strlen (char *s) -{ - char *s0 = s; - while (*s) - s++; - return s - s0; -} - -int fun_1 (char *s) -{ - int x = 0; - for (int i = 0; i < strlen (s); i++) - x += s[i]; - return x; -} - -int fun_2 (char *s) -{ - int i = 0, x = 0; - int len = strlen (s); - while (i < len) - x += s[i++]; - return x; -} - -int main (void) -{ - printf ("%d\n", fun_1 ("Hello, world!\n")); - printf ("%d\n", fun_2 ("Hello, world!\n")); - return 0; -} diff --git a/20221212/loesung-2e-1.c b/20221212/loesung-2e-1.c deleted file mode 100644 index 74f5add0c5f62cccb8f817d40f860893f496db11..0000000000000000000000000000000000000000 --- a/20221212/loesung-2e-1.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int fun_3 (char *s) -{ - int i = 0, x = 0; - while (s[i]) - x += s[i++]; - return x; -} - -int main (void) -{ - printf ("%d\n", fun_3 ("Hello, world!\n")); - return 0; -} diff --git a/20221212/loesung-2e-2.c b/20221212/loesung-2e-2.c deleted file mode 100644 index b223d2d17c261d7cf1373a8379def8911a45ccb7..0000000000000000000000000000000000000000 --- a/20221212/loesung-2e-2.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int fun_4 (char *s) -{ - int x = 0; - while (*s) - x += *s++; - return x; -} - -int main (void) -{ - printf ("%d\n", fun_4 ("Hello, world!\n")); - return 0; -} diff --git a/20221212/loesung-3.c b/20221212/loesung-3.c deleted file mode 100644 index 8d5733e92e6a1c2d28419adc60321c50f5c18129..0000000000000000000000000000000000000000 --- a/20221212/loesung-3.c +++ /dev/null @@ -1,80 +0,0 @@ -#include <stdio.h> -#include <stdint.h> -#include <string.h> -#include <errno.h> -#include <error.h> - -/* Die Aufgabe besteht darin, die Funktionen pbm_open(), - * pbm_line() und pbm_close() zu schreiben. - */ - -int pbm_width = 0; -int pbm_height = 0; -int line_no = 0; -FILE *pbm_file = NULL; /* globale Variable für die PBM-Datei */ - -void pbm_open (int width, int height, char *filename) -{ - pbm_file = fopen (filename, "w"); - if (!pbm_file) - error (errno, errno, "pbm_open(): cannot open file %s for writing", filename); - pbm_width = width; - pbm_height = height; - fprintf (pbm_file, "P4\n%d %d\n", pbm_width, pbm_height); -} - -void pbm_line (char *line) -{ - if (!pbm_file) - error (1, 0, "pbm_line(): PBM file not open"); - if (!line) - error (1, 0, "pbm_line(): line is NULL"); - if (strlen (line) != pbm_width) - error (1, 0, "pbm_line(): line length does not match width"); - if (line_no >= pbm_height) - error (1, 0, "pbm_line(): too many lines"); - int pbm_bytes = (pbm_width + 7) / 8; /* benötigte Bytes pro Zeile (immer aufrunden) */ - uint8_t buffer[pbm_bytes]; - for (int i = 0; i < pbm_bytes; i++) /* Puffer auf 0 initialisieren */ - buffer[i] = 0; - line_no++; - for (int x = 0; line[x]; x++) - { - int i = x / 8; /* In welches Byte des Puffers gehört dieses Pixel? */ - int b = x % 8; /* Welches Bit innerhalb des Bytes ist dieses Pixel? */ - if (line[x] != ' ') /* Kein Leerzeichen --> Bit auf 1 setzen */ - buffer[i] |= 0x80 >> b; /* MSB first. LSB first wäre 1 << b. */ - } - for (int i = 0; i < pbm_bytes; i++) /* Puffer in Datei ausgeben */ - fprintf (pbm_file, "%c", buffer[i]); -} - -void pbm_close (void) -{ - if (!pbm_file) - error (1, 0, "pbm_close(): PBM file not open"); - if (line_no < pbm_height) - error (1, 0, "pbm_close(): too few lines"); - fclose (pbm_file); -} - -int main (void) -{ - pbm_open (14, 14, "test.pbm"); - pbm_line (" "); - pbm_line (" XXXXXX "); - pbm_line (" X X "); - pbm_line (" X X "); - pbm_line (" X X "); - pbm_line (" X XX XX X "); - pbm_line (" X X X X "); - pbm_line (" X X "); - pbm_line (" X X X X "); - pbm_line (" X X X X "); - pbm_line (" X XXXX X "); - pbm_line (" X X "); - pbm_line (" XXXXXX "); - pbm_line (" "); - pbm_close (); - return 0; -} diff --git a/20221212/loesung-3f.c b/20221212/loesung-3f.c deleted file mode 100644 index d358fa1de54ad08a770dc733d089d3d40342bdde..0000000000000000000000000000000000000000 --- a/20221212/loesung-3f.c +++ /dev/null @@ -1,80 +0,0 @@ -#include <stdio.h> -#include <stdint.h> -#include <string.h> -#include <errno.h> -#include <error.h> - -/* Die Aufgabe besteht darin, die Funktionen pbm_open(), - * pbm_line() und pbm_close() zu schreiben. - */ - -int pbm_width = 0; -int pbm_height = 0; -int line_no = 0; -FILE *pbm_file = NULL; /* globale Variable für die PBM-Datei */ - -void pbm_open (int width, int height, char *filename) -{ - pbm_file = fopen (filename, "w"); - if (!pbm_file) - error (errno, errno, "pbm_open(): cannot open file %s for writing", filename); - pbm_width = width; - pbm_height = height; - fprintf (pbm_file, "P4\n%d %d\n", pbm_width, pbm_height); -} - -void pbm_line (char *line) -{ - if (!pbm_file) - error (1, 0, "pbm_line(): PBM file not open"); - if (!line) - error (1, 0, "pbm_line(): line is NULL"); - if (strlen (line) != pbm_width) - error (1, 0, "pbm_line(): line length does not match width"); - if (line_no >= pbm_height) - error (1, 0, "pbm_line(): too many lines"); - int pbm_bytes = (pbm_width + 7) / 8; /* benötigte Bytes pro Zeile (immer aufrunden) */ - uint8_t buffer[pbm_bytes]; - for (int i = 0; i < pbm_bytes; i++) /* Puffer auf 0 initialisieren */ - buffer[i] = 0; - line_no++; - for (int x = 0; line[x]; x++) - { - int i = x / 8; /* In welches Byte des Puffers gehört dieses Pixel? */ - int b = x % 8; /* Welches Bit innerhalb des Bytes ist dieses Pixel? */ - if (line[x] != ' ') /* Kein Leerzeichen --> Bit auf 1 setzen */ - buffer[i] |= 1 << b; - } - for (int i = 0; i < pbm_bytes; i++) /* Puffer in Datei ausgeben */ - fprintf (pbm_file, "%c", buffer[i]); -} - -void pbm_close (void) -{ - if (!pbm_file) - error (1, 0, "pbm_close(): PBM file not open"); - if (line_no < pbm_height) - error (1, 0, "pbm_close(): too few lines"); - fclose (pbm_file); -} - -int main (void) -{ - pbm_open (14, 14, "test.pbm"); - pbm_line (" "); - pbm_line (" XXXXXX "); - pbm_line (" X X "); - pbm_line (" X X "); - pbm_line (" X X "); - pbm_line (" X XX XX X "); - pbm_line (" X X X X "); - pbm_line (" X X "); - pbm_line (" X X X X "); - pbm_line (" X X X X "); - pbm_line (" X XXXX X "); - pbm_line (" X X "); - pbm_line (" XXXXXX "); - pbm_line (" "); - pbm_close (); - return 0; -} diff --git a/20221212/logo-hochschule-bochum-cvh-text-v2.pdf b/20221212/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221212/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221212/logo-hochschule-bochum.pdf b/20221212/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221212/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221212/pgscript.sty b/20221212/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20221212/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20221212/test-textgraph.c b/20221212/test-textgraph.c deleted file mode 100644 index 4033f61ba55d794afbb5b6c03a0bb55dcc5d3e4e..0000000000000000000000000000000000000000 --- a/20221212/test-textgraph.c +++ /dev/null @@ -1,36 +0,0 @@ -#include <stdio.h> -#include "textgraph.h" - -int main (void) -{ - clear (' '); - put_point (-5, 10, 'X'); - for (int i = 17; i < 23; i++) - put_point (i, 5, '*'); - put_point (15, 6, '*'); - put_point (14, 7, '*'); - put_point (13, 8, '*'); - put_point (13, 9, '*'); - put_point (14, 10, '*'); - put_point (15, 11, '*'); - for (int i = 17; i < 23; i++) - put_point (i, 12, '*'); - put_point (24, 11, '*'); - put_point (25, 10, '*'); - put_point (26, 9, '*'); - put_point (26, 8, '*'); - put_point (25, 7, '*'); - put_point (24, 6, '*'); - put_point (18, 8, 'O'); - put_point (21, 8, 'O'); - put_point (17, 10, '`'); - for (int i = 18; i < 22; i++) - put_point (i, 10, '-'); - put_point (22, 10, '\''); - put_point (13, 42, 'Y'); - printf ("get_point (%d, %d): '%c'\n", 13, 9, get_point (13, 9)); - printf ("get_point (%d, %d): '%c'\n", 14, 9, get_point (14, 9)); - printf ("get_point (%d, %d): '%c'\n", 94, 9, get_point (94, 9)); - display (); - return 0; -} diff --git a/20221212/textgraph.c b/20221212/textgraph.c deleted file mode 100644 index a17f9a91173f9fe871967f5aef509798c0efbb64..0000000000000000000000000000000000000000 --- a/20221212/textgraph.c +++ /dev/null @@ -1,46 +0,0 @@ -#include <stdio.h> -#include "textgraph.h" - -char buffer[HEIGHT][WIDTH]; - -void clear (char c) -{ - for (int y = 0; y < HEIGHT; y++) - for (int x = 0; x < WIDTH; x++) - buffer[y][x] = c; -} - -static int check_coordinates (int x, int y, char *function) -{ - if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT) - return 1; - else - { - fprintf (stderr, "coordinates (%d,%d) out of range in %s\n", x, y, function); - return 0; - } -} - -void put_point (int x, int y, char c) -{ - if (check_coordinates (x, y, "put_point")) - buffer[y][x] = c; -} - -char get_point (int x, int y) -{ - if (check_coordinates (x, y, "get_point")) - return buffer[y][x]; - else - return 0; -} - -void display (void) -{ - for (int y = 0; y < HEIGHT; y++) - { - for (int x = 0; x < WIDTH; x++) - printf ("%c", buffer[y][x]); - printf ("\n"); - } -} diff --git a/20221212/textgraph.h b/20221212/textgraph.h deleted file mode 100644 index 419e0fbd04f3b5d07d42509ab1980513d434eb07..0000000000000000000000000000000000000000 --- a/20221212/textgraph.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef TEXTGRAPH_H -#define TEXTGRAPH_H - -#define WIDTH 40 -#define HEIGHT 20 - -extern void clear (char c); -extern void put_point (int x, int y, char c); -extern char get_point (int x, int y); -extern void display (void); - -#endif diff --git a/20221212/tier-datenbank-01.c b/20221212/tier-datenbank-01.c deleted file mode 100644 index d03f97b80c06c305ab08b491c768165c543afb14..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-01.c +++ /dev/null @@ -1,48 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int wings; -} with_wings; - -typedef struct with_legs -{ - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - ((with_wings *) a[0])->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - - return 0; -} diff --git a/20221212/tier-datenbank-02.c b/20221212/tier-datenbank-02.c deleted file mode 100644 index bd3b8afc70b40889bdfb5d8a92c56155c082db2b..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-02.c +++ /dev/null @@ -1,51 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int wings; -} with_wings; - -typedef struct with_legs -{ - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - ((with_wings *) a[0])->wings = 2; - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - { - printf ("a[i]->type = %d\n", a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-03.c b/20221212/tier-datenbank-03.c deleted file mode 100644 index 31029a4a159cf1c93f8cc8238acd54c8f4cca23b..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-03.c +++ /dev/null @@ -1,51 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int wings; -} with_wings; - -typedef struct with_legs -{ - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - ((with_wings *) a[0])->wings = 2; - - animal cow; - a[1] = &cow; -// a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - { - printf ("a[i]->type = %d\n", a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-04.c b/20221212/tier-datenbank-04.c deleted file mode 100644 index c41051f7d1c037b9dd05a9d93b542b4871e59775..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-04.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int wings; -} with_wings; - -typedef struct with_legs -{ - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - printf ("1: a[0]->type = %d\n", a[0]->type); - a[0]->type = WITH_WINGS; - printf ("2: a[0]->type = %d\n", a[0]->type); - a[0]->name = "duck"; - printf ("3: a[0]->type = %d\n", a[0]->type); - ((with_wings *) a[0])->wings = 2; - printf ("4: a[0]->type = %d\n", a[0]->type); - - animal cow; - printf ("5: a[0]->type = %d\n", a[0]->type); - a[1] = &cow; - printf ("6: a[0]->type = %d\n", a[0]->type); - a[1]->type = WITH_LEGS; - printf ("7: a[0]->type = %d\n", a[0]->type); - a[1]->name = "cow"; - printf ("8: a[0]->type = %d\n", a[0]->type); - ((with_legs *) a[1])->legs = 4; - printf ("9: a[0]->type = %d\n", a[0]->type); - - for (int i = 0; i < 2; i++) - { - printf ("a[i]->type = %d\n", a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-05.c b/20221212/tier-datenbank-05.c deleted file mode 100644 index fcd9745e2ac3a5b270e3ff50b3d873ac458c1575..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-05.c +++ /dev/null @@ -1,60 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int wings; -} with_wings; - -typedef struct with_legs -{ - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->type = WITH_WINGS; - printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->name = "duck"; - printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - ((with_wings *) a[0])->wings = 2; - printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - - animal cow; - printf ("5: a[0]->type = %d\n", a[0]->type); - a[1] = &cow; - printf ("6: a[0]->type = %d\n", a[0]->type); - a[1]->type = WITH_LEGS; - printf ("7: a[0]->type = %d\n", a[0]->type); - a[1]->name = "cow"; - printf ("8: a[0]->type = %d\n", a[0]->type); - ((with_legs *) a[1])->legs = 4; - printf ("9: a[0]->type = %d\n", a[0]->type); - - for (int i = 0; i < 2; i++) - { - printf ("a[i]->type = %d\n", a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-06.c b/20221212/tier-datenbank-06.c deleted file mode 100644 index 57f45244067cc1ad3d61ed68f4db427af0099fad..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-06.c +++ /dev/null @@ -1,55 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int wings; -} with_wings; - -typedef struct with_legs -{ - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->type = WITH_WINGS; - printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->name = "duck"; - printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - ((with_wings *) a[0])->wings = 2; - printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - { - printf ("a[%d]->type = %d\n", i, a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-07.c b/20221212/tier-datenbank-07.c deleted file mode 100644 index 9472095fb2da3066970d5414f0445c4e43572641..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-07.c +++ /dev/null @@ -1,57 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->type = WITH_WINGS; - printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->name = "duck"; - printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - ((with_wings *) a[0])->wings = 2; - printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - { - printf ("a[%d]->type = %d\n", i, a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-08.c b/20221212/tier-datenbank-08.c deleted file mode 100644 index 99c3d0826b41eb076af6cccf88c313a68e5a5d13..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-08.c +++ /dev/null @@ -1,58 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - int dummy; /* 64-Bit-Alignment */ - char *name; -} animal; - -typedef struct with_wings -{ - int type; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->type = WITH_WINGS; - printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->name = "duck"; - printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - ((with_wings *) a[0])->wings = 2; - printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - { - printf ("a[%d]->type = %d\n", i, a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-09.c b/20221212/tier-datenbank-09.c deleted file mode 100644 index 8393ec2786708930bf270d8c4ac1b56d9471f215..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-09.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - char *name; - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - animal duck; - a[0] = &duck; - printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->type = WITH_WINGS; - printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->name = "duck"; - printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - ((with_wings *) a[0])->wings = 2; - printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - - animal cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - { - printf ("a[%d]->type = %d\n", i, a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-10.c b/20221212/tier-datenbank-10.c deleted file mode 100644 index b146d5cc3b1b24ad3d90012150c43a71ae2ba9f9..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-10.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - char *name; - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - with_wings duck; - a[0] = &duck; - printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->type = WITH_WINGS; - printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->name = "duck"; - printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - ((with_wings *) a[0])->wings = 2; - printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - - with_legs cow; - a[1] = &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - { - printf ("a[%d]->type = %d\n", i, a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-11.c b/20221212/tier-datenbank-11.c deleted file mode 100644 index b5399a5914b750b5b34c6ec297ab3ab3fc6ba749..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-11.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - char *name; - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - with_wings duck; - a[0] = (with_wings *) &duck; - printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->type = WITH_WINGS; - printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->name = "duck"; - printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - ((with_wings *) a[0])->wings = 2; - printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - - with_legs cow; - a[1] = (with_legs *) &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - { - printf ("a[%d]->type = %d\n", i, a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-12.c b/20221212/tier-datenbank-12.c deleted file mode 100644 index 83bfb8d6254c3e60ea9530dc61da76ced143dae3..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-12.c +++ /dev/null @@ -1,66 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef union object -{ - animal a; - with_wings w; - with_legs l; -} object; - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - char *name; - int legs; -} with_legs; - -int main (void) -{ - animal *a[2]; - - with_wings duck; - a[0] = (with_wings *) &duck; - printf ("1: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->type = WITH_WINGS; - printf ("2: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - a[0]->name = "duck"; - printf ("3: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - ((with_wings *) a[0])->wings = 2; - printf ("4: a[0]->type = %d, a[0]->wings = %d\n", a[0]->type, ((with_wings *) a[0])->wings); - - with_legs cow; - a[1] = (with_legs *) &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - { - printf ("a[%d]->type = %d\n", i, a[i]->type); - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-13.c b/20221212/tier-datenbank-13.c deleted file mode 100644 index e556244ecddc251493d779ad9b743df32c61d853..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-13.c +++ /dev/null @@ -1,61 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - char *name; - int legs; -} with_legs; - -typedef union object -{ - animal a; - with_wings w; - with_legs l; -} object; - -int main (void) -{ - animal *a[2]; - - with_wings duck; - a[0] = (animal *) &duck; - a[0]->type = WITH_WINGS; - a[0]->name = "duck"; - ((with_wings *) a[0])->wings = 2; - - with_legs cow; - a[1] = (animal *) &cow; - a[1]->type = WITH_LEGS; - a[1]->name = "cow"; - ((with_legs *) a[1])->legs = 4; - - for (int i = 0; i < 2; i++) - { - if (a[i]->type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->name, ((with_legs *) a[i])-> legs); - else if (a[i]->type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->name, ((with_wings *) a[i])-> wings); - else - printf ("Error in animal: %s\n", a[i]->name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-14.c b/20221212/tier-datenbank-14.c deleted file mode 100644 index 74eeb74db0f3369b98b30406dbc535cb79b45ca2..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-14.c +++ /dev/null @@ -1,61 +0,0 @@ -#include <stdio.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - char *name; - int legs; -} with_legs; - -typedef union object -{ - animal a; - with_wings w; - with_legs l; -} object; - -int main (void) -{ - object *a[2]; - - object duck; - a[0] = &duck; - a[0]->a.type = WITH_WINGS; - a[0]->a.name = "duck"; - a[0]->w.wings = 2; - - object cow; - a[1] = &cow; - a[1]->a.type = WITH_LEGS; - a[1]->a.name = "cow"; - a[1]->l.legs = 4; - - for (int i = 0; i < 2; i++) - { - if (a[i]->a.type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->a.name, a[i]->l.legs); - else if (a[i]->a.type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->a.name, a[i]->w.wings); - else - printf ("Error in animal: %s\n", a[i]->a.name); - } - - return 0; -} diff --git a/20221212/tier-datenbank-15.c b/20221212/tier-datenbank-15.c deleted file mode 100644 index 1fee6ab7722c1d05eb68a22d909a4bcf6175b4d6..0000000000000000000000000000000000000000 --- a/20221212/tier-datenbank-15.c +++ /dev/null @@ -1,68 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#define ANIMAL 0 -#define WITH_WINGS 1 -#define WITH_LEGS 2 - -typedef struct animal -{ - int type; - char *name; -} animal; - -typedef struct with_wings -{ - int type; - char *name; - int wings; -} with_wings; - -typedef struct with_legs -{ - int type; - char *name; - int legs; -} with_legs; - -typedef union object -{ - animal a; - with_wings w; - with_legs l; -} object; - -object *new_wings (char *pname, int pwings) -{ - object *o = malloc (sizeof (with_wings)); - o->a.type = WITH_WINGS; - o->a.name = pname; - o->l.legs = pwings; - return o; -} - -object *new_legs (char *pname, int plegs) -{ - object *o = malloc (sizeof (with_legs)); - o->a.type = WITH_LEGS; - o->a.name = pname; - o->l.legs = plegs; - return o; -} - -int main (void) -{ - object *a[2] = { new_wings ("duck", 2), new_legs ("cow", 4) }; - - for (int i = 0; i < 2; i++) - { - if (a[i]->a.type == WITH_LEGS) - printf ("A %s has %d legs.\n", a[i]->a.name, a[i]->l.legs); - else if (a[i]->a.type == WITH_WINGS) - printf ("A %s has %d wings.\n", a[i]->a.name, a[i]->w.wings); - else - printf ("Error in animal: %s\n", a[i]->a.name); - } - - return 0; -} diff --git a/20221219/hp-20221219.pdf b/20221219/hp-20221219.pdf deleted file mode 100644 index 92ee79e58267f1a17c4e8148b5c659d57a12ffaa..0000000000000000000000000000000000000000 Binary files a/20221219/hp-20221219.pdf and /dev/null differ diff --git a/20221219/hp-20221219.tex b/20221219/hp-20221219.tex deleted file mode 100644 index b8192292385110d8e8c3e66f9c20d84e87bab5ff..0000000000000000000000000000000000000000 --- a/20221219/hp-20221219.tex +++ /dev/null @@ -1,786 +0,0 @@ -% hp-20221212.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 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: Objektorientierte Programmierung, Datenstrukturen - -\documentclass[10pt,t]{beamer} - -\usepackage{pgslides} -\usepackage{pdftricks} -\usepackage{tikz} -\usepackage{rotating} - -\begin{psinputs} - \usepackage[utf8]{inputenc} - \usepackage[german]{babel} - \usepackage[T1]{fontenc} - \usepackage{helvet} - \renewcommand*\familydefault{\sfdefault} - \usepackage{pstricks,pst-grad} -\end{psinputs} - -\newcommand{\redurl}[1]{\href{#1}{\color{red}\nolinkurl{#1}}} - -\title{Hardwarenahe Programmierung} -\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{12.\ Dezember 2022} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \begin{itemize} - \vspace*{-\smallskipamount} - \item[\dots] - \item[6.3] Unions - \color{medgreen} - \item[6.4] Virtuelle Methoden - \item[6.5] Beispiel: Graphische Benutzeroberfläche (GUI) - \item[6.6] Ausblick: C++ - \end{itemize} - \item[\textbf{7}] \textbf{Datenstrukturen} - \begin{itemize} - \color{medgreen} - \item[7.1] Stack und FIFO - \color{red} - \item[7.2] Verkettete Listen - \item[7.3] Bäume - \end{itemize} - \vspace*{-1cm} - \end{itemize} - \vspace*{-1cm} - -\end{frame} - -\setcounter{section}{5} -\section{Objektorientierte Programmierung} -\setcounter{subsection}{3} -\subsection{Virtuelle Methoden} - -\begin{frame}[fragile] - \showsubsection - - \begin{lstlisting} - void print_object (t_object *this) - { - if (this->base.type == T_INTEGER) - printf ("Integer: %d\n", this->integer.content); - else if (this->base.type == T_STRING) - printf ("String: \"%s\"\n", this->string.content); - } - \end{lstlisting} - - \begin{picture}(0,0) - \color{red} - \put(9,1.7){\shortstack[l]{if-Kette:\\\strut wird unübersichtlich}} - \put(1,-2){\mbox{\textarrow}} - \put(0,-3){\mbox{Zeiger auf Funktionen}} - \end{picture} - - \begin{lstlisting}[xleftmargin=4cm] - void print_integer (t_object *this) - { - printf ("Integer: %d\n", this->integer.content); - } - - void print_string (t_object *this) - { - printf ("String: \"%s\"\n", this->string.content); - } - \end{lstlisting} - -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - Zeiger auf Funktionen - - \medskip - - \begin{lstlisting} - void (*print) (t_object *this); - \end{lstlisting} - \begin{picture}(0,1.2)(0,-0.9) - \color{red} - \put(0.95,0.3){\mbox{$\underbrace{\rule{1cm}{0pt}}$}} - \put(0.2,-0.7){\shortstack{das, worauf print zeigt,\\ist eine Funktion}} - \end{picture} - - \begin{itemize} - \item - Objekt enthält Zeiger auf Funktion - \begin{onlyenv}<1> - \medskip - \begin{lstlisting}[gobble=10] - typedef struct - { - void (*print) (union t_object *this); - int content; - } t_integer; - \end{lstlisting} - \vspace*{-2cm} - \end{onlyenv} - \begin{onlyenv}<2-> - \vspace*{-3.5cm} % Why doesn't a picture environment work here??? :-( - \begin{lstlisting}[gobble=10,xleftmargin=5.5cm] - typedef struct - { - void (*print) (union t_object *this); - int content; - } t_integer; - \end{lstlisting} - \vspace*{0.85cm} - \bigskip - \smallskip - \end{onlyenv} - \pause - \item - Konstruktor initialisiert diesen Zeiger - \begin{onlyenv}<2> - \medskip - \begin{lstlisting}[gobble=10] - t_object *new_integer (int i) - { - t_object *p = malloc (sizeof (t_integer)); - p->integer.print = print_integer; - p->integer.content = i; - return p; - } - \end{lstlisting} - \vspace*{-2cm} - \end{onlyenv} - \pause - \item - Aufruf: "`automatisch"' die richtige Funktion - \begin{onlyenv}<3> - \medskip - \begin{lstlisting}[gobble=10] - for (int i = 0; object[i]; i++) - object[i]->base.print (object[i]); - \end{lstlisting} - \end{onlyenv} - \pause - \medskip - \item - in größeren Projekten:\\ - Objekt enthält Zeiger auf Tabelle von Funktionen - \end{itemize} -\end{frame} - -\subsection{Beispiel: Graphische Benutzeroberfläche (GUI)} - -\begin{frame}[fragile] - - \showsubsection - - \scriptsize - \begin{lstlisting} - #include <gtk/gtk.h> - - int main (int argc, char **argv) - { - gtk_init (&argc, &argv); - GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "Hello"); - g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); - GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); - GtkWidget *label = gtk_label_new ("Hello, world!"); - gtk_container_add (GTK_CONTAINER (vbox), label); - GtkWidget *button = gtk_button_new_with_label ("Quit"); - g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL); - gtk_container_add (GTK_CONTAINER (vbox), button); - gtk_widget_show (button); - gtk_widget_show (label); - gtk_widget_show (vbox); - gtk_widget_show (window); - gtk_main (); - return 0; - } - \end{lstlisting} - - \vspace*{-6cm}\strut\hfill - \includegraphics[scale=0.85]{hello-gtk.png}\\[2cm] - \begin{flushright} - \normalsize\bf Praktikumsversuch:\\ - Objektorientiertes Zeichenprogramm - \end{flushright} - -\end{frame} - -\subsection{Ausblick: C++} - -\begin{frame}[fragile] - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (*print) (union t_object *this); - } t_base;¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5.5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (*print) (...); - int content; - } t_integer;¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡typedef struct - { - void (*print) (union t_object *this); - char *content; - } t_string;¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\end{frame} - -\begin{frame}[fragile] - \showsubsection - - \begin{center} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡struct TBase - { - virtual void print (void); - };¿ - \end{lstlisting} - \end{minipage}\\[0.5cm] - \begin{minipage}{5.5cm} - \begin{lstlisting}[gobble=8] - ¡struct TInteger: public TBase - { - virtual void print (void); - int content; - };¿ - \end{lstlisting} - \end{minipage} - \begin{minipage}{5cm} - \begin{lstlisting}[gobble=8] - ¡struct TString: public TBase - { - virtual void print (void); - char *content; - };¿ - \end{lstlisting} - \end{minipage} - \end{center} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \begin{itemize} - \vspace*{-\smallskipamount} - \item[\dots] - \item[6.3] Unions - \color{medgreen} - \item[6.4] Virtuelle Methoden - \item[6.5] Beispiel: Graphische Benutzeroberfläche (GUI) - \item[6.6] Ausblick: C++ - \end{itemize} - \item[\textbf{7}] \textbf{Datenstrukturen} - \begin{itemize} - \color{medgreen} - \item[7.1] Stack und FIFO - \color{red} - \item[7.2] Verkettete Listen - \item[7.3] Bäume - \end{itemize} - \vspace*{-1cm} - \end{itemize} - -\end{frame} - -\section{Datenstrukturen} -\subsection{Stack und FIFO} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \begin{minipage}{0.48\textwidth} - Im letzten Praktikumsversuch: - \begin{itemize} - \item - Array nur zum Teil benutzt - \item - Variable speichert genutzte Länge - \item - Elemente hinten anfügen\\ - oder entfernen - \arrowitem - Stack\\ - \strut - \end{itemize} - \bigskip - \begin{itemize} - \item - hinten anfügen/entfernen: $\mathcal{O}(1)$\hspace*{-1cm} - \item - vorne oder in der Mitte einfügen/entfernen: $\mathcal{O}(n)$ - \end{itemize} - \end{minipage}\hfill - \begin{minipage}{0.52\textwidth} - Auch möglich: - \begin{itemize} - \item - Array nur zum Teil benutzt - \item - 2 Variable speichern\\genutzte Länge (ringförmig) - \item - Elemente hinten anfügen\\ - oder vorne entfernen - \arrowitem - FIFO - \end{itemize} - \bigskip - \begin{itemize} - \item - vorne oder hinten\\ - anfügen oder entfernen: $\mathcal{O}(1)$ - \item - in der Mitte einfügen/entfernen: $\mathcal{O}(n)$ - \end{itemize} - \end{minipage}\hspace*{-1.5mm} - -\end{frame} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \bigskip - - \begin{minipage}[b]{6cm} - \begin{center} - "`First In -- First Out"' - - \bigskip - - \begin{picture}(6,4) - \thicklines - \color{structure} - \put(0.5,0){\line(1,0){5}} - - \put(3.5,0){\only<1-5>{\line(0,1){1}}} - \put(4.5,0){\only<1-4>{\line(0,1){1}}} - \put(3.5,1){\only<1-4>{\line(1,0){1}}} - \put(4.0,0.5){\only<1-4>{\makebox(0,0){\lstinline{3}}}} - \put(3.0,1.5){\only<1>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(3.0,1.5){\only<1>{\makebox(0,0)[b]{\lstinline{push (3)}}}} - - \put(2.5,0){\only<2-6>{\line(0,1){1}}} - \put(2.5,1){\only<2-5>{\line(1,0){1}}} - \put(3.0,0.5){\only<2-5>{\makebox(0,0){\lstinline{7}}}} - \put(2.0,1.5){\only<2>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(2.0,1.5){\only<2>{\makebox(0,0)[b]{\lstinline{push (7)}}}} - - \put(1.5,0){\only<3-6>{\line(0,1){1}}} - \put(1.5,1){\only<3-6>{\line(1,0){1}}} - \put(2.0,0.5){\only<3-6>{\makebox(0,0){\lstinline{137}}}} - \put(1.0,1.5){\only<3>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(1.0,1.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}} - - \put(4.55,1.05){\only<4>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(5.00,1.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 3}}} - - \put(3.55,1.05){\only<5>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(4.00,1.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}} - - \put(2.55,1.05){\only<6>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(3.00,1.60){\only<6>{\makebox(0,0)[b]{\lstinline{pop ()}: 137}}} - \end{picture} - - \bigskip - - FIFO = Queue = Reihe - \end{center} - \end{minipage}\hfill - \begin{minipage}[b]{6cm} - \begin{center} - "`Last In -- First Out"' - - \bigskip - - \begin{picture}(6,4) - \thicklines - \color{structure} - \put(1.5,0){\line(1,0){3}} - - \put(2.5,0){\line(0,1){1}} - \put(3.5,0){\line(0,1){1}} - \put(2.5,1){\line(1,0){1}} - \put(3.0,0.5){\makebox(0,0){\lstinline{3}}} - \put(2.0,1.5){\only<1>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(2.0,1.5){\only<1>{\makebox(0,0)[b]{\lstinline{push (3)}}}} - - \put(2.5,1){\only<2-5>{\line(0,1){1}}} - \put(3.5,1){\only<2-5>{\line(0,1){1}}} - \put(2.5,2){\only<2-5>{\line(1,0){1}}} - \put(3.0,1.5){\only<2-5>{\makebox(0,0){\lstinline{7}}}} - \put(2.0,2.5){\only<2>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(2.0,2.5){\only<2>{\makebox(0,0)[b]{\lstinline{push (7)}}}} - - \put(2.5,2){\only<3-4>{\line(0,1){1}}} - \put(3.5,2){\only<3-4>{\line(0,1){1}}} - \put(2.5,3){\only<3-4>{\line(1,0){1}}} - \put(3.0,2.5){\only<3-4>{\makebox(0,0){\lstinline{137}}}} - \put(2.0,3.5){\only<3>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} - \put(2.0,3.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}} - - \put(3.55,3.05){\only<4>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(4.00,3.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 137}}} - - \put(3.55,2.05){\only<5>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(4.00,2.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}} - - \put(3.55,1.05){\only<6>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} - \put(4.00,1.60){\only<6>{\makebox(0,0)[b]{\lstinline{pop ()}: 3}}} - \end{picture} - - \bigskip - - LIFO = Stack = Stapel - \end{center} - \end{minipage} - -% -% \dots - -\end{frame} - -\begin{frame} - - \showsection - \showsubsection - - \bigskip - - \begin{minipage}[t]{6cm} - Array (Stack, FIFO):\\ - in der Mitte einfügen - \begin{center} - \begin{picture}(6,3.8) - \thicklines - \color{structure} - \put(1.5,0){\line(1,0){3}} - - \put(2.5,0){\line(0,1){3}} - \put(3.5,0){\line(0,1){3}} - \put(2.5,1){\line(1,0){1}} - \put(3.0,0.5){\makebox(0,0){\lstinline{3}}} - \put(2.5,1){\line(1,0){1}} - \put(3.0,1.5){\makebox(0,0){\lstinline{7}}} - \put(2.5,2){\line(1,0){1}} - \put(3.0,2.5){\makebox(0,0){\lstinline{137}}} - \put(2.5,3){\line(1,0){1}} - - \put(1.5,1.5){\makebox(0,0)[b]{\lstinline{push (5)}}} - \put(1.5,1.45){\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.95,-0.45);}}} - - \put(3.55,2.5){\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)..controls(0.5,0.45)..(0,0.9);}}} - \put(3.55,1.5){\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)..controls(0.5,0.45)..(0,0.9);}}} - - \pause - \color{red} - \put(4.1,3.0){\makebox(0,0)[l]{\textbf{1.}}} - \put(4.1,2.0){\makebox(0,0)[l]{\textbf{2.}}} - \put(1.5,1.9){\makebox(0,0)[b]{\textbf{3.}}} - - \pause - \put(6.0,1.5){\makebox(0,0)[tl]{$\mathcal{O}(n)$}} - \put(5.95,1.45){\makebox(0,0)[br]{\tikz{\draw[-latex](0,0)--(-1.3,0.4);}}} - \put(5.95,1.49){\makebox(0,0)[br]{\tikz{\draw[-latex](0,0)--(-1.3,1.1);}}} - \end{picture} - \end{center} - \end{minipage}\pause\hfill - \begin{minipage}[t]{5cm} - In Array (Stack, FIFO) \dots - \begin{itemize} - \item - einfügen: $\mathcal{O}(n)$ - \item - suchen: $\mathcal{O}(n)$ - \item - geschickt suchen: $\mathcal{O}(\log n)$ - \item - beim Einfügen sortieren:\\ - $\mathcal{O}(n \log n)$ \hspace*{-1.8cm}\tikz{\draw[red](-1.8,0)--(0,0.2);\draw[red](-1.8,0.2)--(0,0);} - $\mathcal{O}(n^2)$ - \end{itemize} - \end{minipage} - -\end{frame} - -\subsection{Verkettete Listen} - -\begin{frame} - - \showsection - \showsubsection - - \begin{tikzpicture} - \color{structure} - \node(first) at (0,0.5) {first}; - \node[shape=rectangle,draw,line width=1pt](3) at (1,2) {3}; - \node[shape=rectangle,draw,line width=1pt](5) at (2,1) {5}; - \node[shape=rectangle,draw,line width=1pt](7) at (3,2) {7}; - \node[shape=rectangle,draw,line width=1pt](137) at (5,2) {137}; - \node(NULL) at (7,2) {NULL}; - \draw[-latex](first)--(3); - \only<1>{\draw[-latex](3)--(7);} - \only<2>{\draw[-latex](3) to[out=0] (5);} - \only<2>{\draw[-latex](5) to[in=180] (7);} - \draw[-latex](7)--(137); - \draw[-latex](137)--(NULL); - \end{tikzpicture} - \begin{itemize} - \item - Jeder Datensatz enthält einen Zeiger auf das nächste Element. - \item - Beim letzten Element zeigt der Zeiger auf \lstinline{NULL}. - \item - Eine Variable zeigt auf das erste Element. - \item - Wenn die Liste leer ist, zeigt die Variable auf \lstinline{NULL}. - \arrowitem - (einfach) \textbf{verkettete Liste} - \end{itemize} - -\end{frame} - -\begin{frame} - - \showsection - \showsubsection - - \begin{minipage}[t]{5cm} - In Array (Stack, FIFO) \dots - \begin{itemize} - \item - in der Mitte einfügen: $\mathcal{O}(n)$ - \item - wahlfreier Zugriff: $\mathcal{O}(1)$ - \item - suchen: $\mathcal{O}(n)$ - \item - geschickt suchen: $\mathcal{O}(\log n)$ - \item - beim Einfügen sortieren:\\ - $\mathcal{O}(n \log n)$ \hspace*{-1.8cm}\tikz{\draw[red](-1.8,0)--(0,0.2);\draw[red](-1.8,0.2)--(0,0);} - $\mathcal{O}(n^2)$ - \end{itemize} - \end{minipage}\hfill - \begin{minipage}[t]{6cm} - In (einfach) verkettete/r Liste \dots - \begin{itemize} - \item - in der Mitte einfügen: $\mathcal{O}(1)$ - \item - wahlfreier Zugriff: $\mathcal{O}(n)$ - \item - suchen: $\mathcal{O}(n)$ - \item - geschickt \hspace*{-1.7cm}\tikz{\draw[red](-1.7,0)--(0,0.2);\draw[red](-1.7,0.2)--(0,0);} - suchen: {\color{red}$\mathcal{O}(n)$} - \item - beim Einfügen sortieren: - $\mathcal{O}(n \log n)$ \hspace*{-1.8cm}\tikz{\draw[red](-1.8,0)--(0,0.2);\draw[red](-1.8,0.2)--(0,0);} - $\mathcal{O}(n^2)$ - \end{itemize} - \end{minipage} - \pause - \medskip - \begin{center} - \begin{minipage}[t]{6cm} - In (ausbalancierten) Bäumen \dots - \begin{itemize} - \item - in der Mitte einfügen: $\mathcal{O}(\log n)$ - \item - wahlfreier Zugriff: $\mathcal{O}(\log n)$ - \item - suchen: $\mathcal{O}(\log n)$ - \item - beim Einfügen sortieren: - $\mathcal{O}(n \log n)$ - \end{itemize} - \end{minipage} - \end{center} - \vspace*{-1cm} - -\end{frame} - -\subsection{Bäume} - -\begin{frame}[fragile] - - \showsection - \showsubsection - - \begin{minipage}[t]{5cm} - \vspace*{-6cm} - \begin{lstlisting}[gobble=6] - ¡typedef struct node - { - int content; - struct node *left, *right; - } node;¿ - \end{lstlisting} -% \bigskip - \bigskip - \begin{onlyenv}<6-> - \begin{itemize} - \item - Einfügen: rekursiv, $\mathcal{O}(\log n)$ - \item - Suchen: rekursiv, $\mathcal{O}(\log n)$ - \item - beim Einfügen sortieren:\\ - rekursiv, $\mathcal{O}(n\log n)$ - \begin{onlyenv}<7-> - \smallskip - \item - {\color{red} - \emph{Worst Case\/}: $\mathcal{O}(n^2)$\\ - vorher bereits sortiert}\\ - \textarrow\ balancierte Bäume\\ - \hspace*{2.15em}Anwendung: Datenbanken\hspace*{-2cm} - \end{onlyenv} - \end{itemize} - \vspace*{-1cm} - \end{onlyenv} - \end{minipage}\hfill - \begin{minipage}[t]{7cm} - \begin{center} - \begin{tikzpicture} - \color{structure} - \node(root) at (0,0) {\lstinline{node *root;}}; - \begin{onlyenv}<2> - \node(3) at (-2,-3) {\lstinline{NULL}}; - \node(137) at (2,-3) {\lstinline{NULL}}; - \end{onlyenv} - \begin{onlyenv}<2-> - \node[shape=rectangle,draw,line width=1pt](7) at (0,-1.5) {7}; - \draw[-latex](root)--(7); - \draw[-latex](7)--(3); - \draw[-latex](7)--(137); - \end{onlyenv} - \begin{onlyenv}<3> - \node(3) at (-2,-3) {\lstinline{NULL}}; - \end{onlyenv} - \begin{onlyenv}<3-> - \node[shape=rectangle,draw,line width=1pt](137) at (2,-3) {137}; - \node(137_left) at (1,-4.5) {\lstinline{NULL}}; - \node(137_right) at (3,-4.5) {\lstinline{NULL}}; - \draw[-latex](137)--(137_left); - \draw[-latex](137)--(137_right); - \end{onlyenv} - \begin{onlyenv}<4> - \node(5) at (-1,-4.5) {\lstinline{NULL}}; - \end{onlyenv} - \begin{onlyenv}<4-> - \node[shape=rectangle,draw,line width=1pt](3) at (-2,-3) {3}; - \node(3_left) at (-3,-4.5) {\lstinline{NULL}}; - \draw[-latex](3)--(3_left); - \draw[-latex](3)--(5); - \end{onlyenv} - \begin{onlyenv}<5-> - \node[shape=rectangle,draw,line width=1pt](5) at (-1,-4.5) {5}; - \node(5_left) at (-2,-6) {\lstinline{NULL}}; - \node(5_right) at (0,-6) {\lstinline{NULL}}; - \draw[-latex](5)--(5_left); - \draw[-latex](5)--(5_right); - \end{onlyenv} - \end{tikzpicture} - \end{center} - \end{minipage} - -\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}}} - \item[\textbf{2}] \textbf{Einführung in C} - \item[\textbf{3}] \textbf{Bibliotheken} - \item[\textbf{4}] \textbf{Hardwarenahe Programmierung} - \item[\textbf{5}] \textbf{Algorithmen} - \item[\textbf{6}] \textbf{Objektorientierte Programmierung} - \item[\textbf{7}] \textbf{Datenstrukturen} - \begin{itemize} - \color{medgreen} - \item[7.1] Stack und FIFO - \item[7.2] Verkettete Listen - \item[7.3] Bäume - \end{itemize} - \end{itemize} - -\end{frame} - -\end{document} diff --git a/20221219/lists-1.c b/20221219/lists-1.c deleted file mode 100644 index a04067e1403601ef56dd706d6148c1d386884e82..0000000000000000000000000000000000000000 --- a/20221219/lists-1.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int content; - node *next; -} node; - -int main (void) -{ - return 0; -} diff --git a/20221219/lists-2.c b/20221219/lists-2.c deleted file mode 100644 index f27d1d5af7c0c237f0d0286155380ef9452a497a..0000000000000000000000000000000000000000 --- a/20221219/lists-2.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -typedef struct node -{ - int content; - struct node *next; -} node; - -int main (void) -{ - return 0; -} diff --git a/20221219/lists-3.c b/20221219/lists-3.c deleted file mode 100644 index 9c9029724efff25263813c5491add92504779d17..0000000000000000000000000000000000000000 --- a/20221219/lists-3.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <stdio.h> - -typedef struct node -{ - int content; - struct node *next; -} node; - -int main (void) -{ - node node3 = { 3, NULL }; - node node7 = { 7, NULL }; - node node137 = { 137, NULL }; - - node *first = &node3; - - for (node *p = first; p; p = p->next) - printf ("%d\n", p->content); - - return 0; -} diff --git a/20221219/lists-4.c b/20221219/lists-4.c deleted file mode 100644 index e048736b85cc228c35f31644d003e00cdefc5496..0000000000000000000000000000000000000000 --- a/20221219/lists-4.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdio.h> - -typedef struct node -{ - int content; - struct node *next; -} node; - -int main (void) -{ - node node3 = { 3, NULL }; - node node7 = { 7, NULL }; - node node137 = { 137, NULL }; - - node3.next = &node7; - node7.next = &node137; - node137.next = NULL; - - node *first = &node3; - - for (node *p = first; p; p = p->next) - printf ("%d\n", p->content); - - return 0; -} diff --git a/20221219/lists-5.c b/20221219/lists-5.c deleted file mode 100644 index a0cc620a884c133dd89582de726139091bc9c5d0..0000000000000000000000000000000000000000 --- a/20221219/lists-5.c +++ /dev/null @@ -1,29 +0,0 @@ -#include <stdio.h> - -typedef struct node -{ - int content; - struct node *next; -} node; - -int main (void) -{ - node node3 = { 3, NULL }; - node node7 = { 7, NULL }; - node node137 = { 137, NULL }; - - node3.next = &node7; - node7.next = &node137; - node137.next = NULL; - - node node5 = { 5, NULL }; - node5.next = node3.next; - node3.next = &node5; - - node *first = &node3; - - for (node *p = first; p; p = p->next) - printf ("%d\n", p->content); - - return 0; -} diff --git a/20221219/logo-hochschule-bochum-cvh-text-v2.pdf b/20221219/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20221219/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20221219/logo-hochschule-bochum.pdf b/20221219/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20221219/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20221219/pgslides.sty b/20221219/pgslides.sty deleted file mode 120000 index 5be1416f4216f076aa268901f52a15d775e43f64..0000000000000000000000000000000000000000 --- a/20221219/pgslides.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgslides.sty \ No newline at end of file diff --git a/20221219/tree-01.c b/20221219/tree-01.c deleted file mode 100644 index d347186a019709e416529c1b73c32f268e0fce57..0000000000000000000000000000000000000000 --- a/20221219/tree-01.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int content; - node *left, *right; -} node; - -int main (void) -{ - node *root = NULL; - return 0; -} diff --git a/20221219/tree-02.c b/20221219/tree-02.c deleted file mode 100644 index 7e591c3282329f0211c479dfa1b8c82f3dc755a3..0000000000000000000000000000000000000000 --- a/20221219/tree-02.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <stdio.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -int main (void) -{ - node *root = NULL; - return 0; -} diff --git a/20221219/tree-03.c b/20221219/tree-03.c deleted file mode 100644 index b88b8671bbda9efe1031d09e3caa60ebeea8ccea..0000000000000000000000000000000000000000 --- a/20221219/tree-03.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -void insert (node *root, int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - root = p; -} - -void output (node *root) -{ - if (root) - printf ("%d\n", root->content); -} - -int main (void) -{ - node *root = NULL; - insert (root, 7); - output (root); - return 0; -} diff --git a/20221219/tree-04.c b/20221219/tree-04.c deleted file mode 100644 index db3b53dde184a82e1f85aa46e1f7e76b38e6b775..0000000000000000000000000000000000000000 --- a/20221219/tree-04.c +++ /dev/null @@ -1,37 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -void insert (int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - root = p; -} - -void output (void) -{ - if (root) - printf ("%d\n", root->content); - else - printf ("root is NULL\n"); -} - -int main (void) -{ - insert (7); - insert (137); - insert (3); - output (); - return 0; -} diff --git a/20221219/tree-05.c b/20221219/tree-05.c deleted file mode 100644 index 628d8803131ca8ff163a085ee8ff4cb6ede0bc88..0000000000000000000000000000000000000000 --- a/20221219/tree-05.c +++ /dev/null @@ -1,44 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -void insert (int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - root = p; - else - { - if (content > root->content) - root->right = p; - else - root->left = p; - } -} - -void output (void) -{ - if (root) - printf ("%d\n", root->content); - else - printf ("root is NULL\n"); -} - -int main (void) -{ - insert (7); - insert (137); - insert (3); - output (); - return 0; -} diff --git a/20221219/tree-06.c b/20221219/tree-06.c deleted file mode 100644 index f38634d004a020104e65e04cf437c87085dd0d18..0000000000000000000000000000000000000000 --- a/20221219/tree-06.c +++ /dev/null @@ -1,50 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -void insert (int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - root = p; - else - { - if (content > root->content) - root->right = p; - else - root->left = p; - } -} - -void output (void) -{ - if (root) - { - if (root->left) - printf ("%d\n", root->left->content); - printf ("%d\n", root->content); - if (root->right) - printf ("%d\n", root->right->content); - } - else - printf ("root is NULL\n"); -} - -int main (void) -{ - insert (7); - insert (137); - insert (3); - output (); - return 0; -} diff --git a/20221219/tree-07.c b/20221219/tree-07.c deleted file mode 100644 index df1dd66b3e1a5892235bcaa894888f8becb4de85..0000000000000000000000000000000000000000 --- a/20221219/tree-07.c +++ /dev/null @@ -1,71 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -void insert (int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - root = p; - else - { - node *save_root = root; - if (content > root->content) - { - root = root->left; - insert (content); - } - else - { - root = root->right; - insert (content); - } - root = save_root; - } -} - -void output (void) -{ - if (root) - { - if (root->left) - { - node *save_root = root; - root = root->left; - output (); - root = save_root; - } - printf ("%d\n", root->content); - if (root->right) - { - node *save_root = root; - root = root->right; - output (); - root = save_root; - } - } - else - printf ("root is NULL\n"); -} - -int main (void) -{ - insert (7); - insert (137); - insert (3); - insert (1117); - insert (42); - insert (13); - output (); - return 0; -} diff --git a/20221219/tree-08.c b/20221219/tree-08.c deleted file mode 100644 index fd3cafcad82fb4b9bbc6d7c905c1005d7c202f6e..0000000000000000000000000000000000000000 --- a/20221219/tree-08.c +++ /dev/null @@ -1,73 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -void insert (int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - root = p; - else - { - node *save_root = root; - if (content > root->content) - { - root = root->left; - insert (content); - save_root->left = root; - } - else - { - root = root->right; - insert (content); - save_root->right = root; - } - root = save_root; - } -} - -void output (void) -{ - if (root) - { - if (root->left) - { - node *save_root = root; - root = root->left; - output (); - root = save_root; - } - printf ("%d\n", root->content); - if (root->right) - { - node *save_root = root; - root = root->right; - output (); - root = save_root; - } - } - else - printf ("root is NULL\n"); -} - -int main (void) -{ - insert (7); - insert (137); - insert (3); - insert (1117); - insert (42); - insert (13); - output (); - return 0; -} diff --git a/20221219/tree-09.c b/20221219/tree-09.c deleted file mode 100644 index 6b44c1108c747f4e6021ddf92d771d77288af18d..0000000000000000000000000000000000000000 --- a/20221219/tree-09.c +++ /dev/null @@ -1,73 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -void insert (int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - root = p; - else - { - node *save_root = root; - if (content < root->content) - { - root = root->left; - insert (content); - save_root->left = root; - } - else - { - root = root->right; - insert (content); - save_root->right = root; - } - root = save_root; - } -} - -void output (void) -{ - if (root) - { - if (root->left) - { - node *save_root = root; - root = root->left; - output (); - root = save_root; - } - printf ("%d\n", root->content); - if (root->right) - { - node *save_root = root; - root = root->right; - output (); - root = save_root; - } - } - else - printf ("root is NULL\n"); -} - -int main (void) -{ - insert (7); - insert (137); - insert (3); - insert (1117); - insert (42); - insert (13); - output (); - return 0; -} diff --git a/20221219/tree-10.c b/20221219/tree-10.c deleted file mode 100644 index 26a5575d8c0dbd139b08ca9365ad0a667223841b..0000000000000000000000000000000000000000 --- a/20221219/tree-10.c +++ /dev/null @@ -1,63 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -void insert (int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - root = p; - else - { - node *save_root = root; - if (content < root->content) - { - root = root->left; - insert (content); - save_root->left = root; - } - else - { - root = root->right; - insert (content); - save_root->right = root; - } - root = save_root; - } -} - -void output (node *root) -{ - if (root) - { - if (root->left) - output (root->left); - printf ("%d\n", root->content); - if (root->right) - output (root->right); - } - else - printf ("root is NULL\n"); -} - -int main (void) -{ - insert (7); - insert (137); - insert (3); - insert (1117); - insert (42); - insert (13); - output (root); - return 0; -} diff --git a/20221219/tree-11.c b/20221219/tree-11.c deleted file mode 100644 index 508b24316bf6696abc9225fac3fe7ef398a7e094..0000000000000000000000000000000000000000 --- a/20221219/tree-11.c +++ /dev/null @@ -1,61 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -void insert (int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - root = p; - else - { - node *save_root = root; - if (content < root->content) - { - root = root->left; - insert (content); - save_root->left = root; - } - else - { - root = root->right; - insert (content); - save_root->right = root; - } - root = save_root; - } -} - -void output (node *root) -{ - if (root) - { - output (root->left); - printf ("%d\n", root->content); - output (root->right); - } - else - printf ("root is NULL\n"); -} - -int main (void) -{ - insert (7); - insert (137); - insert (3); - insert (1117); - insert (42); - insert (13); - output (root); - return 0; -} diff --git a/20221219/tree-12.c b/20221219/tree-12.c deleted file mode 100644 index ff07e64e6dceb10266dc6d376d68fd15bc59e68b..0000000000000000000000000000000000000000 --- a/20221219/tree-12.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -void insert (int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - root = p; - else - { - node *save_root = root; - if (content < root->content) - { - root = root->left; - insert (content); - save_root->left = root; - } - else - { - root = root->right; - insert (content); - save_root->right = root; - } - root = save_root; - } -} - -void output (node *root) -{ - if (root) - { - output (root->left); - printf ("%d\n", root->content); - output (root->right); - } -} - -int main (void) -{ - insert (7); - insert (137); - insert (3); - insert (1117); - insert (42); - insert (13); - output (root); - return 0; -} diff --git a/20221219/tree-13.c b/20221219/tree-13.c deleted file mode 100644 index 236930ed75a80984bfe343a582320470180db3ad..0000000000000000000000000000000000000000 --- a/20221219/tree-13.c +++ /dev/null @@ -1,55 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -node *insert (node *root, int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - return p; - else - { - if (content < root->content) - { - root->left = insert (root->left, content); - return root; - } - else - { - root->right = insert (root->right, content); - return root; - } - } -} - -void output (node *root) -{ - if (root) - { - output (root->left); - printf ("%d\n", root->content); - output (root->right); - } -} - -int main (void) -{ - root = insert (root, 7); - root = insert (root, 137); - root = insert (root, 3); - root = insert (root, 1117); - root = insert (root, 42); - root = insert (root, 13); - output (root); - return 0; -} diff --git a/20221219/tree-14.c b/20221219/tree-14.c deleted file mode 100644 index a95a1fc5acec20d7fa0fcf714af2d5d746899c1c..0000000000000000000000000000000000000000 --- a/20221219/tree-14.c +++ /dev/null @@ -1,55 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -node *insert (node *root, int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - return p; - else - { - if (content < root->content) - { - root->left = insert (root->left, content); - return root; - } - else - { - root->right = insert (root->right, content); - return root; - } - } -} - -void output (node *root) -{ - if (root) - { - output (root->left); - printf ("%d\n", root->content); - output (root->right); - } -} - -int main (void) -{ - insert (root, 7); - insert (root, 137); - insert (root, 3); - insert (root, 1117); - insert (root, 42); - insert (root, 13); - output (root); - return 0; -} diff --git a/20221219/tree-15.c b/20221219/tree-15.c deleted file mode 100644 index 929d253f77de0cc15a6707dd499420965eb9daca..0000000000000000000000000000000000000000 --- a/20221219/tree-15.c +++ /dev/null @@ -1,48 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -void insert (node **root, int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (*root == NULL) - *root = p; - else - { - if (content < root->content) - insert (&root->left, content); - else - insert (&root->right, content); - } -} - -void output (node *root) -{ - if (root) - { - output (root->left); - printf ("%d\n", root->content); - output (root->right); - } -} - -int main (void) -{ - node *root = NULL; - insert (&root, 7); - insert (&root, 137); - insert (&root, 3); - insert (&root, 1117); - insert (&root, 42); - insert (&root, 13); - output (root); - return 0; -} diff --git a/20221219/tree-16.c b/20221219/tree-16.c deleted file mode 100644 index be7163d4fdf57b897887bb861418e342e5061961..0000000000000000000000000000000000000000 --- a/20221219/tree-16.c +++ /dev/null @@ -1,48 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -void insert (node **root, int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (*root == NULL) - *root = p; - else - { - if (content < (*root)->content) - insert (&(*root)->left, content); - else - insert (&(*root)->right, content); - } -} - -void output (node *root) -{ - if (root) - { - output (root->left); - printf ("%d\n", root->content); - output (root->right); - } -} - -int main (void) -{ - node *root = NULL; - insert (&root, 7); - insert (&root, 137); - insert (&root, 3); - insert (&root, 1117); - insert (&root, 42); - insert (&root, 13); - output (root); - return 0; -} diff --git a/20221219/tree-16a.cpp b/20221219/tree-16a.cpp deleted file mode 100644 index e11b48316a1ecae2c3263f85ee7e2c3616b3e912..0000000000000000000000000000000000000000 --- a/20221219/tree-16a.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -void insert (node *&root, int content) -{ - node *p = (node *) malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - if (root == NULL) - root = p; - else - { - if (content < root->content) - insert (root->left, content); - else - insert (root->right, content); - } -} - -void output (node *root) -{ - if (root) - { - output (root->left); - printf ("%d\n", root->content); - output (root->right); - } -} - -int main (void) -{ - node *root = NULL; - insert (root, 7); - insert (root, 137); - insert (root, 3); - insert (root, 1117); - insert (root, 42); - insert (root, 13); - output (root); - return 0; -} diff --git a/20221219/tree-3a.c b/20221219/tree-3a.c deleted file mode 100644 index 8031ec72af9bcb97b83c46b296ab5f2464832fcd..0000000000000000000000000000000000000000 --- a/20221219/tree-3a.c +++ /dev/null @@ -1,33 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -void insert (node *root, int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - root = p; -} - -void output (node *root) -{ - if (root) - printf ("%d\n", root->content); - else - printf ("root is NULL\n"); -} - -int main (void) -{ - node *root = NULL; - insert (root, 7); - output (root); - return 0; -} diff --git a/20221219/tree-3b.c b/20221219/tree-3b.c deleted file mode 100644 index 5b47c41b61d5a76380bccefc98f2fd3057ad645b..0000000000000000000000000000000000000000 --- a/20221219/tree-3b.c +++ /dev/null @@ -1,34 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *root = NULL; - -void insert (int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - root = p; -} - -void output (void) -{ - if (root) - printf ("%d\n", root->content); - else - printf ("root is NULL\n"); -} - -int main (void) -{ - insert (7); - output (); - return 0; -} diff --git a/20221219/tree-3c.c b/20221219/tree-3c.c deleted file mode 100644 index 63ffbaa792e5bc4d122f96e5cfd32e7579c2077c..0000000000000000000000000000000000000000 --- a/20221219/tree-3c.c +++ /dev/null @@ -1,33 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *left, *right; -} node; - -node *insert (node *root, int content) -{ - node *p = malloc (sizeof (node)); - p->content = content; - p->left = NULL; - p->right = NULL; - return p; -} - -void output (node *root) -{ - if (root) - printf ("%d\n", root->content); - else - printf ("root is NULL\n"); -} - -int main (void) -{ - node *root = NULL; - root = insert (root, 7); - output (root); - return 0; -} diff --git a/20230109/aufgabe-1.c b/20230109/aufgabe-1.c deleted file mode 100644 index f26ce5d665012e2cdbaac8b0f43f01d40f338254..0000000000000000000000000000000000000000 --- a/20230109/aufgabe-1.c +++ /dev/null @@ -1,47 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *next; -} node; - -void output_list (node *first) -{ - for (node *p = first; p; p = p->next) - printf ("%d ", p->content); - printf ("\n"); -} - -void insert_into_list (node *what, node *where) -{ - what->next = where->next; - where->next = what; -} - -int main (void) -{ - node *element3 = malloc (sizeof (node)); - node *element7 = malloc (sizeof (node)); - node *element137 = malloc (sizeof (node)); - - element3->content = 3; - element7->content = 7; - element137->content = 137; - - node *first = element3; - element3->next = element7; - element7->next = element137; - element137->next = NULL; - - output_list (first); - - node *element5 = malloc (sizeof (node)); - element5->content = 5; - insert_into_list (element5, element3); - - output_list (first); - - return 0; -} diff --git a/20230109/aufgabe-1b-gpt.c b/20230109/aufgabe-1b-gpt.c deleted file mode 100644 index 3b75051963b0f8f325725a2b71305c88f9a6b8e6..0000000000000000000000000000000000000000 --- a/20230109/aufgabe-1b-gpt.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void insert_into_string (char src, char *target, int pos) { - // Bestimme die Länge des Strings target - int len = strlen(target); - - // Verschiebe alle Zeichen des Strings ab der Stelle pos um eine Stelle nach rechts - for (int i = len; i > pos; i--) { - target[i] = target[i-1]; - } - - // Füge das Zeichen src an der Stelle pos ein - target[pos] = src; -} - -int main (void) -{ - char test[] = "Hochshule Bochum"; - insert_into_string ('c', test, 5); - printf ("%s\n", test); - return 0; -} diff --git a/20230109/aufgabe-1e-gpt.c b/20230109/aufgabe-1e-gpt.c deleted file mode 100644 index 7e010cb2b66d3dd447b0aa9e64c9d591fc9cb0d3..0000000000000000000000000000000000000000 --- a/20230109/aufgabe-1e-gpt.c +++ /dev/null @@ -1,42 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void insert_into_string (char src, char *target, int pos) { - // Bestimme die Länge des Strings target - int len = strlen(target); - - // Verschiebe alle Zeichen des Strings ab der Stelle pos um eine Stelle nach rechts - for (int i = len; i > pos; i--) { - target[i] = target[i-1]; - } - - // Füge das Zeichen src an der Stelle pos ein - target[pos] = src; -} - -void insert_into_string_sorted (char src, char *target) { - // Bestimme die Länge des Strings target - int len = strlen(target); - - // Iteriere über alle Zeichen des Strings target - for (int i = 0; i < len; i++) { // Wenn das aktuelle Zeichen alphabetisch hinter src liegt, füge src an dieser Stelle ein - if (target[i] > src) { - insert_into_string(src, target, i); - return; - } - } - - // Wenn src das letzte Zeichen im String ist, füge es am Ende des Strings ein - insert_into_string(src, target, len); -} - -int main (void) -{ - char test[100] = ""; - insert_into_string_sorted ('c', test); - insert_into_string_sorted ('a', test); - insert_into_string_sorted ('d', test); - insert_into_string_sorted ('b', test); - printf ("%s\n", test); - return 0; -} diff --git a/20230109/aufgabe-1g-gpt.c b/20230109/aufgabe-1g-gpt.c deleted file mode 100644 index 047fa6f565913323f715d8b9a7ce413e70a2b07a..0000000000000000000000000000000000000000 --- a/20230109/aufgabe-1g-gpt.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <stdio.h> -#include <string.h> - -void insert_into_string (char src, char *target, int pos) { - // Bestimme die Länge des Strings target - int len = strlen(target); - - // Verschiebe alle Zeichen des Strings ab der Stelle pos um eine Stelle nach rechts - for (int i = len; i > pos; i--) { - target[i] = target[i-1]; - } - - // Füge das Zeichen src an der Stelle pos ein - target[pos] = src; -} - -void insert_into_string_sorted (char src, char *target) { - // Bestimme die Länge des Strings target - int len = strlen(target); - - // Setze die Grenzen für die binäre Suche auf das erste und letzte Zeichen des Strings - int left = 0; - int right = len - 1; - - // Führe die binäre Suche durch, bis left und right auf dasselbe Zeichen zeigen - while (left < right) { // Bestimme die Mitte des aktuellen Suchbereichs - int mid = (left + right) / 2; - - // Wenn src alphabetisch vor dem aktuellen Zeichen liegt, suche im linken Teilbereich weiter - if (src < target[mid]) { - right = mid; - } - // Wenn src alphabetisch hinter dem aktuellen Zeichen liegt, suche im rechten Teilbereich weiter - else { - left = mid + 1; - } - } - - // Füge src an der Stelle left in den String ein - insert_into_string(src, target, left); -} - -int main (void) -{ - char test[100] = ""; - insert_into_string_sorted ('c', test); - insert_into_string_sorted ('a', test); - insert_into_string_sorted ('d', test); - insert_into_string_sorted ('b', test); - printf ("%s\n", test); - return 0; -} diff --git a/20230109/aufgabe-3.c b/20230109/aufgabe-3.c deleted file mode 100644 index 5b0cb23fdd5ee15a4403808c18d2104ed49caf3f..0000000000000000000000000000000000000000 --- a/20230109/aufgabe-3.c +++ /dev/null @@ -1,62 +0,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; -} diff --git a/20230109/aufgabe-4.c b/20230109/aufgabe-4.c deleted file mode 100644 index 2bcd5e63a71f212b7243d1f7d9c92406d1e41e77..0000000000000000000000000000000000000000 --- a/20230109/aufgabe-4.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - char buffer[100]; - fgets (buffer, 100, stdin); - for (char *p = buffer; *p; p++) - printf ("%02x", *p); - printf ("\n"); -} diff --git a/20230109/hp-20230109.txt b/20230109/hp-20230109.txt deleted file mode 100644 index 7f2127e54ae3a8e7a9046a1bb1c082c0dec0ad97..0000000000000000000000000000000000000000 --- a/20230109/hp-20230109.txt +++ /dev/null @@ -1,430 +0,0 @@ -Klausur vom 13.2.2018, gelöst von ChatGPT - -Aufgabe 1 - -(a) Das Programm fügt das Zeichen 'c' an der Stelle 5 in die Zeichenkette 'test' - ein. Allerdings wird das Programm nicht korrekt implementiert, da der Inhalt - der Zeichenkette nach der Stelle 5 nicht korrekt verschoben wird. Die Schleife - 'for (int i = pos; i < len; i++)' sollte stattdessen 'for (int i = len; i > - pos; i--)' lauten, um die Zeichen ab der Stelle 'pos' nach rechts zu - verschieben. - - Da das Programm so implementiert ist, werden alle Zeichen ab der Stelle 5 mit - dem Wert 'h' überschrieben. Da der Inhalt der Zeichenkette nach der Stelle 5 - nicht verschoben wird, wird das Zeichen 'c' an der Stelle 5 eingefügt, während - der Rest der Zeichenkette unverändert bleibt. Deshalb lautet die Ausgabe - "Hochschhhhhhhhhhh". - ---> Viel Geschwafel, aber korrekt. Volle Punktzahl. - -(b) void insert_into_string (char src, char *target, int pos) { - // Bestimme die Länge des Strings target - int len = strlen(target); - - // Verschiebe alle Zeichen des Strings ab der Stelle pos um eine Stelle nach rechts - for (int i = len; i > pos; i--) { - target[i] = target[i-1]; - } - - // Füge das Zeichen src an der Stelle pos ein - target[pos] = src; - } - ---> Funktioniert, aber Null-Symbol am Ende nicht berücksichtigt. 1 Punkt Abzug. - -(c) Wenn man char test[] = "Hochshule Bochum"; anstelle von char test[100] = - "Hochshule Bochum"; schreibt, wird der Compiler den Array test automatisch - auf die notwendige Größe anpassen, um den String "Hochshule Bochum" - aufnehmen zu können. Wenn man die Funktion insert_into_string aufruft und - versucht, ein Zeichen an eine Stelle jenseits des Endes des Strings - einzufügen, könnte dies zu einem Speicherzugriffsfehler führen, da der - Array test nicht ausreichend groß ist, um das Zeichen aufzunehmen - ---> Richtig. Volle Punktzahl. - -(d) Wenn man char *test = "Hochshule Bochum"; anstelle von char test[100] = - "Hochshule Bochum"; schreibt, deklariert man test als Zeiger auf einen - char, der auf den ersten Buchstaben des Strings "Hochshule Bochum" zeigt. - In diesem Fall kann man nicht mehr auf die einzelnen Zeichen des Strings - test zugreifen, da der String "Hochshule Bochum" im ROM-Speicher - gespeichert ist und nicht verändert werden darf. Wenn man versucht, in der - Funktion insert_into_string das Zeichen an einer bestimmten Stelle im - String test zu ändern, wird dies zu einem Fehler führen - ---> Richtig, auch wenn die Formulierung eher in Richtung "ändern" als "einfügen" geht. - Volle Punktzahl. - -(e) void insert_into_string_sorted (char src, char *target) { - // Bestimme die Länge des Strings target - int len = strlen(target); - - // Iteriere über alle Zeichen des Strings target - for (int i = 0; i < len; i++) { // Wenn das aktuelle Zeichen alphabetisch hinter src liegt, füge src an dieser Stelle ein - if (target[i] > src) { - insert_into_string(src, target, i); - return; - } - } - - // Wenn src das letzte Zeichen im String ist, füge es am Ende des Strings ein - insert_into_string(src, target, len); - } - ---> Scheint zu funktionieren. Könnte volle Punktzahl geben. - -(f) Die Funktion void insert_into_string_sorted (char src, char *target) - arbeitet in O(n)-Zeit, da sie die Länge des Strings target durchläuft - und in jedem Durchlauf das Zeichen src in den String einfügt. - ---> Korrekt. - -(g) void insert_into_string_sorted (char src, char *target) { - // Bestimme die Länge des Strings target - int len = strlen(target); - - // Setze die Grenzen für die binäre Suche auf das erste und letzte Zeichen des Strings - int left = 0; - int right = len - 1; - - // Führe die binäre Suche durch, bis left und right auf dasselbe Zeichen zeigen - while (left < right) { // Bestimme die Mitte des aktuellen Suchbereichs - int mid = (left + right) / 2; - - // Wenn src alphabetisch vor dem aktuellen Zeichen liegt, suche im linken Teilbereich weiter - if (src < target[mid]) { - right = mid; - } - // Wenn src alphabetisch hinter dem aktuellen Zeichen liegt, suche im rechten Teilbereich weiter - else { - left = mid + 1; - } - } - - // Füge src an der Stelle left in den String ein - insert_into_string(src, target, left); - } - ---> Nicht ganz ausgereift, aber i.w. korrekt. Spontan 2 von 3 Punkten. - -Aufgabe 2 - -(a) Die beim Compilieren auftretende Warnung wird angezeigt, weil in der - printf-Anweisung in Zeile 14 der Typ des zweiten Arguments ("&xyz") als - "three_numbers * {aka struct *}" angegeben ist, aber der Format-String "%s" - erwartet, dass das zweite Argument ein Zeiger auf einen char-Wert (also - einen String) ist. Die Formatierungsanweisung "%s" gibt an, dass das - Argument, auf das der Zeiger verweist, als String interpretiert werden - soll. Da das zweite Argument aber ein Zeiger auf ein three_numbers-Struct - ist, kann es nicht als String interpretiert werden und es wird daher eine - Warnung angezeigt. - ---> Sehr lang formuliert, trotzdem volle Punktzahl. - -(a) Die beim Compilieren auftretende Warnung wird angezeigt, weil in der - printf-Anweisung der Typ des zweiten Arguments ("&xyz", ein Zeiger auf - ein three_numbers-Struct) und der Format-String "%s" (erwartet einen - String) inkonsistent sind. Das bedeutet, dass das Programm versucht, - ein three_numbers-Struct als String auszugeben, was nicht möglich ist - und daher eine Warnung ausgelöst wird. - ---> Besser formuliert. Volle Punktzahl. (Ein Komma fehlt.;-) - -(b) Das Programm enthält einen Fehler in der Verwendung von printf auf Zeile - 14. Der "%s" Formatstring erwartet einen "char *" als Argument, aber &xyz - wurde übergeben, was ein "three_numbers *" (also ein Zeiger auf eine - Struktur) ist. Dies führt zu unerwartetem Verhalten und einer Warnung bei - der Compilierung. - ---> Bis hierin: Geschwafel. - - In diesem Fall gibt printf jedoch "Hallo, Welt!" aus, da es den Inhalt - der Speicheradresse als Zeichenkette interpretiert. - ---> Das ist sogar richtig. - - Es ist jedoch unwahrscheinlich, dass dieser Speicherbereich tatsächlich - eine gültige Zeichenkette enthält, daher sollte dieser Code vermieden - werden. - ---> Daraus kann ich entnehmen, daß ChatGPT die Aufgabe nicht wirklich verstanden hat. - Es felht eine Analyse, weshalb die Ausgabe genau "Hallo, Welt!" sein muß. - ---> Großzügig: 2 von 4 Punkten. - ---> Richtige Lösung: Zahlen nach Hexadezimal umwandeln. - In der ersten Zahl steht dann ganz rechts "48" für "H", - links davon "61" für "a", danach zweimal "6c" für "l". - --> Der Rechner ist Little-Endian (schon mal für (c)). - - Was liegt im Speicher? - - l l a H ! t l e W _ , o \0 - 6c6c6148 21746c6557202C6f 00 - `------' `--------------' `' - a b c <-- direkt hintereinander, weil gemeinsam im Struct - (Dies dazuzuschreiben, könnte einen Extra-Punkt bringen.) - (Achtung: auch hier kann Alignment eine Rolle spielen!) - - Reihenfolge im Speicher: für jede Zahl andersherum, da Little Endian - - H a l l o , _ W e l t ! \0 - 48 61 6c 6c 6f 2C 20 57 65 6c 74 21 00 <-- String im Speicher - `---------' `----------------------' `' - a b c - - Wenn man die Inhalte der Speicherzellen visualisiert, aus denen das Struct - xyz besteht, erkennt man, daß bei Little Endian die Speicherzellen gemäß - ASCII-Zeichensatz den String "Hallo, Welt!" einschließlich Null-Symbol am - Ende ergeben. - -(c) Es ist nicht möglich, die Endianness des verwendeten Rechners anhand des - obigen Programms zu bestimmen. Die Endianness beschreibt die Reihenfolge, - in der Bytes in einem Wort gespeichert werden, und hat keine Auswirkungen - auf die Ausgabe von printf. - ---> Leider falsch. - - Die Ausgabe des Programms hängt davon ab, welche Daten sich in dem - Speicherbereich befinden, der an printf übergeben wird. In diesem Fall - wurde &xyz, also die Adresse der Struktur "three_numbers", übergeben. Wenn - der Speicherbereich an dieser Adresse tatsächlich eine gültige Zeichenkette - enthält, würde die Ausgabe auf jedem Rechner gleich sein, unabhängig von - der Endianness. Wenn der Speicherbereich jedoch zufällige Daten enthält, - würde die Ausgabe auf jedem Rechner unterschiedlich sein. - ---> Das klingt erstaunlich überzeugend, ist aber eigentlich ziemlich falsch. - - Es ist wichtig zu beachten, dass der Code in der obigen Frage fehlerhaft - ist und nicht wie erwartet funktionieren wird. Es wird empfohlen, diesen - Code zu überarbeiten, um korrektes Verhalten zu gewährleisten. - ---> Daß man so nicht programmieren sollte, ist klar. Leider hat dies nichts - mit der Aufgabenstellung zu tun. - ---> 0 Punkte. - ---> Richtige Lösung: Little Endian (Begründung: siehe oben) - - Rechner nit entgegengesetzter Endianness: - Wir behalten die Reihenfolge von a, b und c bei und drehen nur innerhalb - jeder Variable die Reihenfolge der Speicherzellen um: - - l l a H ! t l e W _ , o \0 - 6c 6c 61 48 21 74 6c 65 57 20 2C 6f 00 <-- String im Speicher - `---------' `----------------------' `' - a b c - - Aufgabe auf einem Big-Endian-Rechner: "llaH!tleW ,o" - -(d) Die Ausgabe des Programms hängt davon ab, welche Daten sich in dem - Speicherbereich befinden, der an printf übergeben wird. In diesem Fall - wurde &xyz, also die Adresse der Struktur "three_numbers", übergeben. Wenn - der Speicherbereich an dieser Adresse tatsächlich eine gültige Zeichenkette - enthält, würde die Ausgabe auf jedem Rechner gleich sein, unabhängig von - der Architektur des Rechners. Wenn der Speicherbereich jedoch zufällige - Daten enthält, würde die Ausgabe auf jedem Rechner unterschiedlich sein. - ---> Geschwafel. Wiederholung von (a). - - Es ist wichtig zu beachten, dass der Code in der obigen Frage fehlerhaft - ist und nicht wie erwartet funktionieren wird. Es wird empfohlen, diesen - Code zu überarbeiten, um korrektes Verhalten zu gewährleisten. Die - Tatsache, dass die Ausgabe des Programms auf einem 64-Bit-Rechner anders - aussieht als auf einem 32-Bit-Rechner, ist wahrscheinlich auf die - unterschiedliche Speicherstruktur zurückzuführen und hat nichts mit der - Endianness zu tun. - ---> Geschwafel, aber enthält auch etwas Korrektes: Es hat tatsächlich nicht - mit der Endianness zu tun, sondern mit dem Alignment. - - Möchten Sie noch etwas wissen oder haben Sie weitere Fragen zum obigen - Programm? - ---> *in die Tischkante beiß* - ---> 0 Punkte. - ---> Richtige Lösung: 64-Bit-Rechner - - Ausgabe: Hall5V - - typedef struct - { - uint32_t a; - uint64_t b; - uint8_t c; - } three_numbers; - - l l a H 5 V \0 \? ! t l e W _ , o \0 - 6c 6c 61 48 35 56 00 ?? 21 74 6c 65 57 20 2C 6f 00 <-- String im Speicher - `---------' `---------' `----------------------' `' - a dummy b c - wegen 64-Bit-Alignment - - -==> Korrektur, 16.3.2023: ?? 00 56 35 statt 35 56 00 ?? - - - Um das 64-Bit-Alignment der Variablen b einzuhalten, hat der Compiler zwischen - a und b 32 Bits, also 4 Speicherzellen, freigelassen und mit zufälligen Werten - gefüllt. Gemäß der Ausgabe sind diese zufälligen Werte die Ziffer 5, Der Buchstabe V, - ein Null-Symbol und ein für uns unbekannter Wert. - - $ gcc -Wall -m64 -O aufgabe-2.c -o aufgabe-2 - aufgabe-2.c: In function ‘main’: - aufgabe-2.c:14:13: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘three_numbers *’ {aka ‘struct <anonymous> *’} [-Wformat=] - printf ("%s\n", &xyz); - ~^ ~~~~ - $ ./aufgabe-2 - Vall - $ ./aufgabe-2 - Hall V - $ ./aufgabe-2 - HallfU - $ ./aufgabe-2 - Hall\U - $ ./aufgabe-2 - HallV - $ - - Das "Vall" ist in Wirklichkeit: "Hall\rV" - ("\r" bedeutet: zurückgehen an den Zeilenanfang) - - $ echo -e "Hall\rV" - Vall - -Aufgabe 3 - -(a) void (*fun)(int x) bedeutet, dass "fun" ein Zeiger auf eine Funktion ist, - die einen int-Wert als Argument nimmt und keinen Rückgabewert hat. - ---> Korrekt. Schon mal 1 Punkt. - - Die Verwendung von fun in der Funktion foreach() ermöglicht es, jedes - Element im Array "a" der Funktion "fun" zu übergeben, sodass diese auf - jedes Element angewendet werden kann. - ---> Etwas merkwürdig, aber trotzdem korrekt beantwortet. - Noch ein Punkt. Volle Punktzahl. 8-) - - (Ich vermisse das Stichwort "Callback-Funktion" oder von mir aus auch - "virtuelle Methode". Aber die Beschreibung dessen, was foreach() mit - der übergebenen Funktion macht, ist korrekt.) - -(b) #include <stdio.h> - - int sum; // globale Variable für die Summe - - void add_to_sum (int x) - { - if (x > 0) - { - sum += x; - } - } - - void foreach (int *a, void (*fun) (int x)) - { - for (int *p = a; *p >= 0; p++) - { - fun (*p); - } - } - - int main (void) - { - int numbers[] = { 12, 17, 32, 1, 3, 16, 19, 18, -1 }; - foreach (numbers, add_to_sum); - printf ("Summe der positiven Zahlen: %d\n", sum); - return 0; - } - ---> Ich vermisse ein explizites "sum = 0"; ansonsten ist alles korrekt. Volle Punktzahl. - (Die Initialisierung auf 0 erfolgt bei globalen Variablen automatisch. Das ist für - ChatGPT anscheinend so selbstverständlich, daß es das nicht erwähnt.) - -Aufgabe 4 - - Es scheint, dass du eine Aufgabe aus einem Computer Science Kurs hast, bei - der du ein Programm schreiben sollst, das eine XBM-Grafikdatei liest und - in eine PBM-Grafikdatei umwandelt. XBM-Grafikdateien sind als C-Quelltext - abgespeicherte Arrays, die Bildinformationen enthalten. PBM-Grafikdateien sind - binär abgespeicherte C-Arrays von Bytes, die auch Bildinformationen enthalten. - - Um diese Aufgabe zu lösen, musst du das XBM-Array lesen und die Bilddaten - in das PBM-Format umwandeln. Du musst die Breite und Höhe des Bildes aus den - Konstantendefinitionen in der XBM-Datei extrahieren und diese Informationen in - der PBM-Datei speichern. Du musst auch sicherstellen, dass du die Bilddaten im - PBM-Format speicherst, indem du jedes Bit des XBM-Arrays liest und es im MSB - first Format in das PBM-Array schreibst. - - Eine Möglichkeit, dies zu erreichen, wäre die Verwendung von - Bit-Shift-Operationen, um die Bits des XBM-Arrays zu lesen und sie im - PBM-Format zu speichern. Du könntest auch Funktionen wie fprintf verwenden, um - die Breite und Höhe des Bildes und die Bilddaten in die PBM-Datei zu schreiben - - Hier ist ein Beispiel für ein Programm, das die Aufgabe löst, eine - XBM-Grafikdatei in eine PBM-Grafikdatei umzuwandeln. Beachte, dass dieses - Beispiel nur als Anregung dient und dass es möglicherweise Anpassungen oder - Erweiterungen benötigt, um es für deine spezifischen Bedürfnisse zu optimieren: - - #include <stdio.h> - #include <stdint.h> - - #define XBM_WIDTH 14 - #define XBM_HEIGHT 14 - - static unsigned char xbm_bits[] = { - 0x00, 0x00, 0xf0, 0x03, 0x08, 0x04, 0x04, 0x08, 0x02, 0x10, 0x32, 0x13, - 0x22, 0x12, 0x02, 0x10, 0x0a, 0x14, 0x12, 0x12, 0xe4, 0x09, 0x08, 0x04, - 0xf0, 0x03, 0x00, 0x00 - }; - - int main(int argc, char **argv) - { - // Öffne die Ausgabedatei - FILE *output_file = fopen("test.pbm", "w"); - if (output_file == NULL) { - printf("Fehler beim Öffnen der Ausgabedatei\n"); - return 1; - } - - // Schreibe die PBM-Dateikennung, Breite und Höhe in die Ausgabedatei - fprintf(output_file, "P4\n%d %d\n", XBM_WIDTH, XBM_HEIGHT); - - // Iteriere über jedes Byte im XBM-Array - for (int i = 0; i < XBM_HEIGHT * XBM_WIDTH / 8; i++) { // Iteriere über jedes Bit im aktuellen Byte - for (int j = 7; j >= 0; j--) { - // Lies das aktuelle Bit des XBM-Arrays und schreibe es in die Ausgabedatei - uint8_t xbm_bit = (xbm_bits[i] >> j) & 1; - fprintf(output_file, "%c", xbm_bit ? '1' : '0'); - } - } - - // Schließe die Ausgabedatei - fclose(output_file); - - return 0; - } - ---> Mehrere Fehler, aber durchaus sinnvolle Ansätze. - Großzügig: 4 von 8 Punkten (möglicherweise weniger) - -Zusammenfassung: - -Aufgabe 1 (a) 3 / 3 - (b) 1 / 2 - (c) 2 / 2 - (d) 2 / 2 - (e) 4 / 4 - (f) 1 / 1 - (g) 2 / 3 -Aufgabe 2 (a) 2 / 2 - (b) 2 / 4 - (c) 0 / 2 - (d) 0 / 3 -Aufgabe 3 (a) 2 / 2 - (b) 4 / 4 -Aufgabe 4 4 / 8 - -- --- - 29 / 42 --> 2.7. Immerhin. diff --git a/20230109/hp-musterloesung-20230109.pdf b/20230109/hp-musterloesung-20230109.pdf deleted file mode 100644 index fecb1322d2d38ae43542bdc5fe222115f6503eba..0000000000000000000000000000000000000000 Binary files a/20230109/hp-musterloesung-20230109.pdf and /dev/null differ diff --git a/20230109/hp-musterloesung-20230109.tex b/20230109/hp-musterloesung-20230109.tex deleted file mode 100644 index a10d64ce3bff36aae2a0a9c59bc18a3beacd64c3..0000000000000000000000000000000000000000 --- a/20230109/hp-musterloesung-20230109.tex +++ /dev/null @@ -1,636 +0,0 @@ -% hp-musterloesung-20230109.pdf - Solutions to the Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 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: Einfach und doppelt verkettete Listen, ternärer Baum, hüpfender Ball, Hexdumps - -% ! Hüpfender Ball (20211206-3) -% ! Hexdumps (20220110-3) -% ! einfach und doppelt verkettete Listen (20220117-2) -% ! ternärer Baum (20220117-3) - -\documentclass[a4paper]{article} - -\usepackage{pgscript} -\usepackage{tikz} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Musterlösung zu den Übungsaufgaben -- 9.\ Januar 2023} - - \exercise{Einfach und doppelt verkettete Listen} - - Das Beispiel-Programm \gitfile{hp}{2022ws/20230109}{aufgabe-1.c} - demonstriert zwei Funktionen zur Verwaltung einfach verketteter Listen: - \lstinline{output_list()} zum Ausgeben der Liste auf den Bildschirm und - \lstinline{insert_into_list()} zum Einfügen in die Liste. - - \begin{enumerate}[\quad(a)] - \item - Ergänzen Sie eine Funktion \lstinline{delete_from_list()} - zum Löschen eines Elements aus der Liste - mit Freigabe des Speicherplatzes. - \points{5} - \item - Ergänzen Sie eine Funktion \lstinline{reverse_list()} - die die Reihenfolge der Elemente in der Liste umdreht.\\ - \points{3} - \end{enumerate} - - Eine doppelt verkettete Liste hat in jedem Knotenpunkt (\lstinline{node}) - \emph{zwei\/} Zeiger -- einen auf das nächste Element (\lstinline{next}) - und einen auf das vorherige Element (z.\,B.\ \lstinline{prev} für "`previous"'). - Dadurch ist es leichter als bei einer einfach verketteten Liste, - die Liste in umgekehrter Reihenfolge durchzugehen. - - \begin{quote} - \begin{tikzpicture} - \color{blendedblue} - \node(first) at (0,3.5) {first}; - \node(NULL1) at (-1,1.25) {NULL}; - \node[shape=rectangle,draw,line width=1pt](3) at (1,2) {3}; - \node[shape=rectangle,draw,line width=1pt](7) at (3,2) {7}; - \node[shape=rectangle,draw,line width=1pt](137) at (5,2) {137}; - \node(NULL2) at (7,2.75) {NULL}; - \draw[-latex](first)--(3); - \draw[-latex](3) to[out=45,in=135] (7); - \draw[-latex](3) to[out=-135,in=0] (NULL1); - \draw[-latex](7) to[out=-135,in=-45] (3); - \draw[-latex](7) to[out=45,in=135] (137); - \draw[-latex](137) to[out=-135,in=-45] (7); - \draw[-latex](137) to[out=45,in=180] (NULL2); - \end{tikzpicture} - \end{quote} - - Der Rückwärts-Zeiger (\lstinline{prev}) des ersten Elements zeigt, - genau wie der Vorwärts-Zeiger (\lstinline{next}) des letzten Elements, - auf \emph{nichts}, hat also den Wert \lstinline{NULL}. - - \begin{enumerate}[\quad(a)]\setcounter{enumi}{2} - \item - Schreiben Sie das Programm um für doppelt verkettete Listen. - \points{5} - \end{enumerate} - - \solution - - \begin{enumerate}[\quad(a)] - \item - \textbf{Ergänzen Sie eine Funktion \lstinline{delete_from_list()} - zum Löschen eines Elements aus der Liste - mit Freigabe des Speicherplatzes.} - - Siehe: \gitfile{hp}{2022ws/20230109}{loesung-1a.c} - - Um ein Element aus einer verketteten Liste zu löschen, - müssen zuerst die Zeiger umgestellt werden, - um das Element von der Liste auszuschließen. - Erst danach darf der Speicherplatz für das Element freigegeben werden. - -% Da das Beispielprogramm (\gitfile{hp}{2021ws/20220117}{lists-5.c}) -% nicht mit dynamischem Speicher arbeitet, -% stellen wir dieses zunächst auf dynamischen Speicher um, z.\,B.: -% \begin{lstlisting}[gobble=8] -% node *element5 = malloc (sizeof (node)); -% \end{lstlisting} -% Danach bezeichnet \lstinline{element5} -% die Adresse der \lstinline{struct}-Variablen; -% es wird also \lstinline{element5} an die Funktionen übergeben -% und nicht \lstinline{&element5} (die Adresse des Zeigers). - -% Um nun ein Element aus der Liste zu entfernen, -% benötigt man - Man benötigt also - \emph{das vorherige Element}, - dessen \lstinline{next}-Zeiger man dann auf - das übernächste Element \lstinline{next->next} weitersetzt. - - Bei jedem Zeiger muß man vor dem Zugriff prüfen, - daß dieser nicht auf \lstinline{NULL} zeigt. - (Die Musterlösung ist in dieser Hinsicht nicht konsequent. - Für den Produktiveinsatz müßte z.\,B.\ \lstinline{delete_from_list()} - auch den übergebenen Zeiger \lstinline{what} auf \lstinline{NULL} prüfen.) - - Ein Spezialfall tritt ein, wenn das erste Element einer Liste - entfernt werden soll. In diesem Fall tritt \lstinline{first} - an die Stelle des \lstinline{next}-Zeigers - des (nicht vorhandenen) vorherigen Elements. - Da \lstinline{delete_from_list()} \emph{schreibend\/} auf \lstinline{first} - zugreift, muß \lstinline{first} \emph{als Zeiger\/} übergeben werden - (\lstinline{node **first}). - - Um alle Spezialfälle zu testen (am Anfang, am Ende und in der Mitte der Liste), - wurden die Testfälle im Hauptprogramm erweitert. - - \item - \textbf{Schreiben Sie das Programm um für doppelt verkettete Listen.} - - Siehe: \gitfile{hp}{2022ws/20230109}{loesung-1b.c} - - Bei allen Einfüge- und Löschaktionen müssen \emph{jeweils zwei\/} - \lstinline{next}- und \lstinline{prev}-Zeiger neu gesetzt werden. - - Zum Debuggen empfiehlt es sich sehr, - eine Funktion zu schreiben, die die Liste auf Konsistenz prüft - (hier: \lstinline{check_list()}). - - Das Testprogramm macht von der Eigenschaft der doppelt verketteten Liste, - daß man sie auch rückwärts effizient durchgehen kann, keinen Gebrauch. - Um diese Eigenschaft als Vorteil nutzen zu können, empfiehlt es sich, - zusätzlich zu \lstinline{first} - auch einen Zeiger auf das letzte Element (z.\,B.\ \lstinline{last}) - einzuführen. Dieser muß dann natürlich bei allen Operationen - (Einfügen, Löschen, \dots) auf dem aktuellen Stand gehalten werden. - - \end{enumerate} - - \exercise{Ternärer Baum} - - Der in der Vorlesung vorgestellte \newterm{binäre Baum\/} - ist nur ein Spezialfall; - im allgemeinen können Bäume auch mehr als zwei Verzweigungen - pro Knotenpunkt haben. - Dies ist nützlich bei der Konstruktion \emph{balancierter Bäume}, - also solcher, die auch im \emph{Worst Case\/} - nicht zu einer linearen Liste entarten, - sondern stets eine -- möglichst flache -- Baumstruktur behalten. - - Wir betrachten einen Baum mit bis zu drei Verzweigungen pro Knotenpunkt, - einen sog.\ \newterm{ternären Baum}. - Jeder Knoten enthält dann nicht nur einen, - sondern \emph{zwei\/} Werte als Inhalt: - \begin{lstlisting} - typedef struct node - { - int content_left, content_right; - struct node *left, *middle, *right; - } node; - \end{lstlisting} - - Wir konstruieren nun einen Baum nach folgenden Regeln: - \vspace{-\medskipamount} - \begin{itemize}\itemsep0pt - \item - Innerhalb eines Knotens sind die Werte sortiert: - \lstinline{content_left} muß stets kleiner sein als \lstinline{content_right}. - \item - Der Zeiger \lstinline{left} zeigt auf Knoten, - deren enthaltene Werte durchweg kleiner sind als \lstinline{content_left}. - \item - Der Zeiger \lstinline{right} zeigt auf Knoten, - deren enthaltene Werte durchweg größer sind als \lstinline{content_right}. - \item - Der Zeiger \lstinline{middle} zeigt auf Knoten, - deren enthaltene Werte durchweg größer sind als \lstinline{content_left}, - aber kleiner als \lstinline{content_right}. - \item - Ein Knoten muß nicht immer mit zwei Werten voll besetzt sein; - er darf auch \emph{nur einen\/} gültigen Wert enthalten. - - Der Einfachheit halber lassen wir in diesem Beispiel - nur positive Zahlen als Werte zu. - Wenn ein Knoten nur einen Wert enthält, - setzen wir \lstinline{content_right = -1}, - und der Zeiger \lstinline{middle} wird nicht verwendet. - \item - Wenn wir neue Werte in den Baum einfügen, - werden \emph{zuerst\/} die nicht voll besetzten Knoten aufgefüllt - und \emph{danach erst\/} neue Knoten angelegt und Zeiger gesetzt. - \item - Beim Auffüllen eines Knotens darf nötigenfalls \lstinline{content_left} - nach \lstinline{content_right} verschoben werden. - Ansonsten werden einmal angelegte Knoten nicht mehr verändert. - \end{itemize} - \vspace*{-\medskipamount} - (In der Praxis dürfen Knoten gemäß speziellen Regeln - nachträglich verändert werden, - um Entartungen gar nicht erst entstehen zu lassen -- - siehe z.\,B.\ \url{https://en.wikipedia.org/wiki/2-3_tree}.) - \begin{enumerate}[\quad(a)] - \item - Zeichnen Sie ein Schaubild, das veranschaulicht, - wie die Zahlen 7, 137, 3, 5, 6, 42, 1, 2 und 12 - nacheinander und in dieser Reihenfolge - in den oben beschriebenen Baum eingefügt werden - -- analog zu den Vortragsfolien (\gitfile{hp}{2022ws/20221219}{hp-20221219.pdf}), - Seite 33. - \points{3} - % - % Lösung: - % - % 7 137 - % / | - % 3 5 12 42 - % / \ - % 1 2 6 - % - % (NULL-Zeiger sind hier nicht dargestellt, - % gehören aber dazu.) - % - \item - Dasselbe, aber in der Reihenfolge - 2, 7, 42, 12, 1, 137, 5, 6, 3. - \points{3} - % - % Lösung: - % - % 2 7 - % / | \ - % 1 5 6 12 42 - % / \ - % 3 137 - % - % (NULL-Zeiger sind hier wieder nicht dargestellt, - % gehören aber dazu.) - % - \item - Beschreiben Sie in Worten und/oder als C-Quelltext-Fragment, - wie eine Funktion aussehen müßte, um den auf diese Weise entstandenen Baum - sortiert auszugeben. - \points{4} - \end{enumerate} - - \solution - - \begin{enumerate}[\quad(a)] - \item - \textbf{Zeichnen Sie ein Schaubild, das veranschaulicht, - wie die Zahlen 7, 137, 3, 5, 6, 42, 1, 2 und 12 - nacheinander und in dieser Reihenfolge - in den oben beschriebenen Baum eingefügt werden - -- analog zu den Vortragsfolien (\gitfile{hp}{2022ws/20221219}{hp-20221219.pdf}), - Seite 21.} - % - % Lösung: - % - % 7 137 - % / | - % 3 5 12 42 - % / \ - % 1 2 6 - % - % (NULL-Zeiger sind hier nicht dargestellt, - % gehören aber dazu.) - % - \begin{center} - \newcommand{\x}{~\makebox(0,0){\raisebox{0.7em}{\rule{1pt}{1.4em}}}~} - \begin{tikzpicture} - \color{blendedblue} - \node(root) at (0,0) {\lstinline{node *root;}}; - \node[shape=rectangle,draw,line width=1pt](7-137) at (0,-1.5) {7\x 137}; - \draw[-latex](root)--(7-137); - \node[shape=rectangle,draw,line width=1pt](3-5) at (-2,-3) {3\x 5}; - \draw[-latex](7-137)--(3-5); - \node[shape=rectangle,draw,line width=1pt](12-42) at (0,-3) {12\x 42}; - \draw[-latex](7-137)--(12-42); - \node[shape=rectangle,draw,line width=1pt](1-2) at (-4,-4.5) {1\x 2}; - \draw[-latex](3-5)--(1-2); - \node[shape=rectangle,draw,line width=1pt](6) at (0,-4.5) {6}; - \draw[-latex](3-5)--(6); - \end{tikzpicture} - \end{center} - Bemerkungen: - \begin{itemize} - \item - Zeiger mit dem Wert \lstinline{NULL} sind nicht dargestellt: - \lstinline{right}-Zeiger von 7/137, - \lstinline{middle}-Zeiger von 3/5, - sämtliche Zeiger von 1/2, 12/42 und 6. - \item - Beim Einfügen der 12 wird die sich bereits vorher in diesem - \lstinline{node} befindliche 42 zu \lstinline{content_right}, - und die 12 wird das neue \lstinline{content_left}. - \item - Dieser Baum hat sehr einfache Regeln und ist daher \emph{nicht\/} - balanciert. Insbesondere unsere Regel, daß einmal angelegte Knoten - nicht mehr verändert werden dürfen, steht dem im Wege. - Ein einfaches Beispiel für einen \emph{balancierten\/} ternären - Baum ist der 2-3-Baum -- siehe z.\,B.\ \url{https://en.wikipedia.org/wiki/2-3_tree}. - \end{itemize} - \goodbreak - \item - \textbf{Dasselbe, aber in der Reihenfolge - 2, 7, 42, 12, 1, 137, 5, 6, 3.} - % - % Lösung: - % - % 2 7 - % / | \ - % 1 5 6 12 42 - % / \ - % 3 137 - % - % (NULL-Zeiger sind hier wieder nicht dargestellt, - % gehören aber dazu.) - % - \begin{center} - \newcommand{\x}{~\makebox(0,0){\raisebox{0.7em}{\rule{1pt}{1.4em}}}~} - \begin{tikzpicture} - \color{blendedblue} - \node(root) at (0,0) {\lstinline{node *root;}}; - \node[shape=rectangle,draw,line width=1pt](2-7) at (0,-1.5) {2\x 7}; - \draw[-latex](root)--(7-137); - \node[shape=rectangle,draw,line width=1pt](1) at (-2,-3) {1}; - \draw[-latex](2-7)--(1); - \node[shape=rectangle,draw,line width=1pt](5-6) at (0,-3) {5\x 6}; - \draw[-latex](2-7)--(5-6); - \node[shape=rectangle,draw,line width=1pt](3) at (-2,-4.5) {3}; - \draw[-latex](5-6)--(3); - \node[shape=rectangle,draw,line width=1pt](12-42) at (2,-3) {12\x 42}; - \draw[-latex](2-7)--(12-42); - \node[shape=rectangle,draw,line width=1pt](137) at (4,-4.5) {137}; - \draw[-latex](12-42)--(137); - \end{tikzpicture} - \end{center} - Bemerkungen: - \begin{itemize} - \item - Wieder sind Zeiger mit dem Wert \lstinline{NULL} nicht dargestellt: - \lstinline{middle}- und \lstinline{right}-Zeiger von 5/6, - \lstinline{left}- und \lstinline{middle}-Zeiger von 12/42, - sämtliche Zeiger von 1, 3 und 137. - \item - Beim Einfügen der 12 wird wieder die sich bereits vorher in diesem - \lstinline{node} befindliche 42 zu \lstinline{content_right}, - und die 12 wird das neue \lstinline{content_left}. - \end{itemize} - \item - \textbf{Beschreiben Sie in Worten und/oder als C-Quelltext-Fragment, - wie eine Funktion aussehen müßte, um den auf diese Weise entstandenen Baum - sortiert auszugeben.} - - Die entscheidende Idee ist \textbf{Rekursion}. - - Eine Funktion, die den gesamten Baum ausgibt, - müßte einmalig für den Zeiger \lstinline{root} aufgerufen werden - und folgendes tun: - \begin{enumerate}[\quad 1.] - \item - falls der übergebene Zeiger den Wert \lstinline{NULL} hat, - nichts ausgeben, sondern die Funktion direkt beenden, - \item - sich selbst für den \lstinline{left}-Zeiger aufrufen, - \item - den Wert von \lstinline{content_left} ausgeben, - \item - sich selbst für den \lstinline{middle}-Zeiger aufrufen, - \item - sofern vorhanden (also ungleich \lstinline{-1}), - den Wert von \lstinline{content_right} ausgeben, - \item - sich selbst für den \lstinline{right}-Zeiger aufrufen. - \end{enumerate} - Als C-Fragment: - \begin{lstlisting}[gobble=8] - void output_tree (node *root) - { - if (root) - { - output_tree (root->left); - printf ("%d\n", root->content_left); - output_tree (root->middle); - if (root->content_right >= 0) - printf ("%d\n", root->content_right); - output_tree (root->right); - } - } - \end{lstlisting} - Die Datei \gitfile{hp}{2022ws/20230109}{loesung-2c.c} erweitert dieses Fragment - zu einem vollständigen C-Programm zum Erstellen und sortierten Ausgeben - eines ternären Baums mit den Zahlenwerten von Aufgabenteil (a). - \end{enumerate} - - \exercise{Fehlerhaftes Programm: Hüpfender Ball} - - Das auf der nächsten Seite abgedruckte GTK+-Programm - (Datei: \gitfile{hp}{2022ws/20230109}{aufgabe-3.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. - - \solution - - \begin{enumerate}[\quad(a)] - \item - \textbf{Warum sieht man lediglich ein leeres Fenster? - Welchen Befehl muß man ergänzen, um diesen Fehler zu beheben?} - - Die für das Zeichnen zuständige Callback-Funktion wurde zwar geschrieben, - aber nicht installiert. - Um dies zu beheben, ergänze man den folgenden Befehl im Hauptprogramm: - - \lstinline{g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL);} - - Dies erkennt man sehr schnell durch Vergleich mit dem Beispiel-Programm - \gitfile{hp}{2022ws/20221114}{gtk-13.c}. - - \item - \textbf{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?} - - Die Timer-Callback-Funktion wurde zwar geschrieben, aber nicht installiert. - Um dies zu beheben, ergänze man den folgenden Befehl im Hauptprogramm: - - \lstinline{g_timeout_add (50, (GSourceFunc) timer, drawing_area);} - - Auch dies erkennt man sehr schnell durch Vergleich mit dem Beispiel-Programm - \gitfile{hp}{2022ws/20221114}{gtk-13.c}. - - \item - \textbf{Erklären Sie das merkwürdige Hüpfverhalten des Balls. - Wie kommt es zustande? - Was an diesem Verhalten ist korrekt, und was ist fehlerhaft?} - - Die Geschwindigkeit in $y$-Richtung wächst immer weiter. - Der Grund dafür ist, daß die $y$-Komponente der Geschwindigkeit - nicht auf physikalisch sinnvolle Weise berechnet wird. - In der dafür zuständigen Zeile - \lstinline{vy = 0.5 * g * (t * t);} - wird stattdessen der Weg in $y$-Richtung bei einer gleichmäßig - beschleunigten Bewegung berechnet und als Geschwindigkeit verwendet. - - \item - \textbf{Welche Befehle muß man in welcher Weise ändern, - um ein realistischeres Hüpf-Verhalten zu bekommen?} - - Da der Ball am Boden abprallen soll, ist es \emph{nicht\/} sinnvoll, - die $y$-Komponente der Geschwindigkeit über die bekannte physikalische - Formel $v_y = -g\cdot t$ für die Geschwindigkeit in einer - gleichmäßig beschleunigten Bewegung zu berechnen. - - Stattdessen ist es sinnvoll, die \emph{Geschwindigkeitsänderung\/} - innerhalb des Zeitintervalls \lstinline{dt} - zur Geschwindigkeitskomponente zu addieren: - \lstinline{vy += g * dt;} - - Auch dies erkennt man sehr schnell durch Vergleich mit dem Beispiel-Programm - \gitfile{hp}{2022ws/20221114}{gtk-13.c}. - \end{enumerate} - - \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); - - gtk_main (); - return 0; - } - \end{lstlisting}\vss} - - \clearpage - - \exercise{Hexdumps} - - Das folgende Programm (\gitfile{hp}{2022ws/20230109}{aufgabe-4.c}) liest - einen String ein und gibt die ASCII-Werte der Buchstaben hexadezimal aus. - (Anders als z.\,B.\ \lstinline{scanf()} - akzeptiert die Funktion \lstinline{fgets()} zum Lesen von Strings auch Leerzeichen, - und sie vermeidet Pufferüberläufe.) - \begin{lstlisting}[style=numbered] - #include <stdio.h> - - int main (void) - { - char buffer[100]; - fgets (buffer, 100, stdin); - for (char *p = buffer; *p; p++) - printf ("%02x", *p); - printf ("\n"); - } - \end{lstlisting} - Beispiel: Bei der Eingabe von \lstinline[style=cmd]{Dies ist ein Test.} - erscheint die Ausgabe\\ - \lstinline[style=terminal]{44696573206973742065696e20546573742e0a}. - - Schreiben Sie ein Programm, das diese Umwandlung in umgekehrter Richtung vornimmt, - also z.\,B.\ bei Eingabe von \lstinline[style=cmd]{44696573206973742065696e20546573742e0a} - wieder \lstinline[style=terminal]{Dies ist ein Test.} ausgibt. - - \points{6} - - Hinweis für die Klausur: - Abgabe in digitaler Form ist erwünscht, aber nicht zwingend. - - \solution - - Siehe \gitfile{hp}{2022ws/20230109}{loesung-4.c}. - - Das Programm macht mehrfach davon Gebrauch, - daß in C Zeichen und Zahlen äquivalent sind. - Wenn z.\,B.\ die \lstinline{char}-Variable \lstinline{c} - den Wert \lstinline{'3'} (Ziffer 3) enthält, - dann hat der Ausdruck \lstinline{c - '0'} den Wert \lstinline{3} (Zahlenwert 3). - Hierfür ist es insbesondere nicht nötig, vorauszusetzen, - daß wir den ASCII-Zeichensatz verwenden und \lstinline{'0'} - den Wert \lstinline{48} hat. - - Bei Eingabe von \lstinline[style=cmd]{44696573206973742065696e20546573742e0a} - gibt das Programm zusätzlich eine Leerzeile aus. - Die liegt daran, daß das \lstinline[style=cmd]{0a} am Ende - bereits eine Zeilenschaltung enthält und das Programm mit - \lstinline{printf ("\n")} eine zusätzliche Zeilenschaltung ausgibt. - -\end{document} diff --git a/20230109/hp-uebung-20230109.pdf b/20230109/hp-uebung-20230109.pdf deleted file mode 100644 index fa3d56e5adb15c9eca45f503587d85415b4cd073..0000000000000000000000000000000000000000 Binary files a/20230109/hp-uebung-20230109.pdf and /dev/null differ diff --git a/20230109/hp-uebung-20230109.tex b/20230109/hp-uebung-20230109.tex deleted file mode 100644 index e74dbe9a04de7ba9eb0de465392b0d840323d5cd..0000000000000000000000000000000000000000 --- a/20230109/hp-uebung-20230109.tex +++ /dev/null @@ -1,350 +0,0 @@ -% hp-uebung-20230109.pdf - Exercises on Low-Level Programming / Applied Computer Sciences -% Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 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: Einfach und doppelt verkettete Listen, ternärer Baum, hüpfender Ball, Hexdumps - -% ! Hüpfender Ball (20211206-3) -% ! Hexdumps (20220110-3) -% ! einfach und doppelt verkettete Listen (20220117-2) -% ! ternärer Baum (20220117-3) - -\documentclass[a4paper]{article} - -\usepackage{pgscript} -\usepackage{tikz} - -\begin{document} - - \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 9.\ Januar 2023} - - Diese Übung enthält Punkteangaben wie in einer Klausur. - Um zu "`bestehen"', müssen Sie innerhalb von 120 Minuten - unter Verwendung ausschließlich zugelassener Hilfsmittel - 20 Punkte (von insgesamt \totalpoints) erreichen. - - \exercise{Einfach und doppelt verkettete Listen} - - Das Beispiel-Programm \gitfile{hp}{2022ws/20230109}{aufgabe-1.c} - demonstriert zwei Funktionen zur Verwaltung einfach verketteter Listen: - \lstinline{output_list()} zum Ausgeben der Liste auf den Bildschirm und - \lstinline{insert_into_list()} zum Einfügen in die Liste. - - \begin{enumerate}[\quad(a)] - \item - Ergänzen Sie eine Funktion \lstinline{delete_from_list()} - zum Löschen eines Elements aus der Liste - mit Freigabe des Speicherplatzes. - \points{5} - \item - Ergänzen Sie eine Funktion \lstinline{reverse_list()} - die die Reihenfolge der Elemente in der Liste umdreht.\\ - \points{3} - \end{enumerate} - - Eine doppelt verkettete Liste hat in jedem Knotenpunkt (\lstinline{node}) - \emph{zwei\/} Zeiger -- einen auf das nächste Element (\lstinline{next}) - und einen auf das vorherige Element (z.\,B.\ \lstinline{prev} für "`previous"'). - Dadurch ist es leichter als bei einer einfach verketteten Liste, - die Liste in umgekehrter Reihenfolge durchzugehen. - - \begin{quote} - \begin{tikzpicture} - \color{blendedblue} - \node(first) at (0,3.5) {first}; - \node(NULL1) at (-1,1.25) {NULL}; - \node[shape=rectangle,draw,line width=1pt](3) at (1,2) {3}; - \node[shape=rectangle,draw,line width=1pt](7) at (3,2) {7}; - \node[shape=rectangle,draw,line width=1pt](137) at (5,2) {137}; - \node(NULL2) at (7,2.75) {NULL}; - \draw[-latex](first)--(3); - \draw[-latex](3) to[out=45,in=135] (7); - \draw[-latex](3) to[out=-135,in=0] (NULL1); - \draw[-latex](7) to[out=-135,in=-45] (3); - \draw[-latex](7) to[out=45,in=135] (137); - \draw[-latex](137) to[out=-135,in=-45] (7); - \draw[-latex](137) to[out=45,in=180] (NULL2); - \end{tikzpicture} - \end{quote} - - Der Rückwärts-Zeiger (\lstinline{prev}) des ersten Elements zeigt, - genau wie der Vorwärts-Zeiger (\lstinline{next}) des letzten Elements, - auf \emph{nichts}, hat also den Wert \lstinline{NULL}. - - \begin{enumerate}[\quad(a)]\setcounter{enumi}{2} - \item - Schreiben Sie das Programm um für doppelt verkettete Listen. - \points{5} - \end{enumerate} - - \vspace{3cm} - - \exercise{Ternärer Baum} - - Der in der Vorlesung vorgestellte \newterm{binäre Baum\/} - ist nur ein Spezialfall; - im allgemeinen können Bäume auch mehr als zwei Verzweigungen - pro Knotenpunkt haben. - Dies ist nützlich bei der Konstruktion \emph{balancierter Bäume}, - also solcher, die auch im \emph{Worst Case\/} - nicht zu einer linearen Liste entarten, - sondern stets eine -- möglichst flache -- Baumstruktur behalten. - - Wir betrachten einen Baum mit bis zu drei Verzweigungen pro Knotenpunkt, - einen sog.\ \newterm{ternären Baum}. - Jeder Knoten enthält dann nicht nur einen, - sondern \emph{zwei\/} Werte als Inhalt: - \begin{lstlisting} - typedef struct node - { - int content_left, content_right; - struct node *left, *middle, *right; - } node; - \end{lstlisting} - - Wir konstruieren nun einen Baum nach folgenden Regeln: - \vspace{-\medskipamount} - \begin{itemize}\itemsep0pt - \item - Innerhalb eines Knotens sind die Werte sortiert: - \lstinline{content_left} muß stets kleiner sein als \lstinline{content_right}. - \item - Der Zeiger \lstinline{left} zeigt auf Knoten, - deren enthaltene Werte durchweg kleiner sind als \lstinline{content_left}. - \item - Der Zeiger \lstinline{right} zeigt auf Knoten, - deren enthaltene Werte durchweg größer sind als \lstinline{content_right}. - \item - Der Zeiger \lstinline{middle} zeigt auf Knoten, - deren enthaltene Werte durchweg größer sind als \lstinline{content_left}, - aber kleiner als \lstinline{content_right}. - \item - Ein Knoten muß nicht immer mit zwei Werten voll besetzt sein; - er darf auch \emph{nur einen\/} gültigen Wert enthalten. - - Der Einfachheit halber lassen wir in diesem Beispiel - nur positive Zahlen als Werte zu. - Wenn ein Knoten nur einen Wert enthält, - setzen wir \lstinline{content_right = -1}, - und der Zeiger \lstinline{middle} wird nicht verwendet. - \item - Wenn wir neue Werte in den Baum einfügen, - werden \emph{zuerst\/} die nicht voll besetzten Knoten aufgefüllt - und \emph{danach erst\/} neue Knoten angelegt und Zeiger gesetzt. - \item - Beim Auffüllen eines Knotens darf nötigenfalls \lstinline{content_left} - nach \lstinline{content_right} verschoben werden. - Ansonsten werden einmal angelegte Knoten nicht mehr verändert. - \end{itemize} - \vspace*{-\medskipamount} - (In der Praxis dürfen Knoten gemäß speziellen Regeln - nachträglich verändert werden, - um Entartungen gar nicht erst entstehen zu lassen -- - siehe z.\,B.\ \url{https://en.wikipedia.org/wiki/2-3_tree}.) - \begin{enumerate}[\quad(a)] - \item - Zeichnen Sie ein Schaubild, das veranschaulicht, - wie die Zahlen 7, 137, 3, 5, 6, 42, 1, 2 und 12 - nacheinander und in dieser Reihenfolge - in den oben beschriebenen Baum eingefügt werden - -- analog zu den Vortragsfolien (\gitfile{hp}{2022ws/20221219}{hp-20221219.pdf}), - Seite 33. - \points{3} - % - % Lösung: - % - % 7 137 - % / | - % 3 5 12 42 - % / \ - % 1 2 6 - % - % (NULL-Zeiger sind hier nicht dargestellt, - % gehören aber dazu.) - % - \item - Dasselbe, aber in der Reihenfolge - 2, 7, 42, 12, 1, 137, 5, 6, 3. - \points{3} - % - % Lösung: - % - % 2 7 - % / | \ - % 1 5 6 12 42 - % / \ - % 3 137 - % - % (NULL-Zeiger sind hier wieder nicht dargestellt, - % gehören aber dazu.) - % - \item - Beschreiben Sie in Worten und/oder als C-Quelltext-Fragment, - wie eine Funktion aussehen müßte, um den auf diese Weise entstandenen Baum - sortiert auszugeben. - \points{4} - \end{enumerate} - - \vspace{3cm} - - \exercise{Fehlerhaftes Programm: Hüpfender Ball} - - Das auf der nächsten Seite abgedruckte GTK+-Programm - (Datei: \gitfile{hp}{2022ws/20230109}{aufgabe-3.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. - - \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); - - gtk_main (); - return 0; - } - \end{lstlisting}\vss} - - \exercise{Hexdumps} - - Das folgende Programm (\gitfile{hp}{2022ws/20230109}{aufgabe-4.c}) liest - einen String ein und gibt die ASCII-Werte der Buchstaben hexadezimal aus. - (Anders als z.\,B.\ \lstinline{scanf()} - akzeptiert die Funktion \lstinline{fgets()} zum Lesen von Strings auch Leerzeichen, - und sie vermeidet Pufferüberläufe.) - \begin{lstlisting}[style=numbered] - #include <stdio.h> - - int main (void) - { - char buffer[100]; - fgets (buffer, 100, stdin); - for (char *p = buffer; *p; p++) - printf ("%02x", *p); - printf ("\n"); - } - \end{lstlisting} - Beispiel: Bei der Eingabe von \lstinline[style=cmd]{Dies ist ein Test.} - erscheint die Ausgabe\\ - \lstinline[style=terminal]{44696573206973742065696e20546573742e0a}. - - Schreiben Sie ein Programm, das diese Umwandlung in umgekehrter Richtung vornimmt, - also z.\,B.\ bei Eingabe von \lstinline[style=cmd]{44696573206973742065696e20546573742e0a} - wieder \lstinline[style=terminal]{Dies ist ein Test.} ausgibt. - - \points{6} - - Hinweis für die Klausur: - Abgabe in digitaler Form ist erwünscht, aber nicht zwingend. - - \begin{flushright} - \textit{Viel Erfolg -- auch in den Prüfungen!} - \end{flushright} - - \makeatletter - \immediate\write\@mainaux{\string\gdef\string\totalpoints{\arabic{points}}} - \makeatother - -\end{document} diff --git a/20230109/loesung-1a.c b/20230109/loesung-1a.c deleted file mode 100644 index 93f5e5629a98d13d6292c56d1a3f855b4f5bd8fd..0000000000000000000000000000000000000000 --- a/20230109/loesung-1a.c +++ /dev/null @@ -1,69 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *next; -} node; - -void output_list (node *first) -{ - for (node *p = first; p; p = p->next) - printf ("%d ", p->content); - printf ("\n"); -} - -void insert_into_list (node *what, node *where) -{ - what->next = where->next; - where->next = what; -} - -void delete_from_list (node *what, node **first) -{ - if (what == *first) - *first = what->next; - else - { - node *p = *first; - while (p && p->next != what) - p = p->next; - if (p) - p->next = what->next; - } - free (what); -} - -int main (void) -{ - node *element3 = malloc (sizeof (node)); - node *element7 = malloc (sizeof (node)); - node *element137 = malloc (sizeof (node)); - - element3->content = 3; - element7->content = 7; - element137->content = 137; - - node *first = element3; - element3->next = element7; - element7->next = element137; - element137->next = NULL; - - output_list (first); - - node *element5 = malloc (sizeof (node)); - element5->content = 5; - insert_into_list (element5, element3); - - output_list (first); - - delete_from_list (element5, &first); - output_list (first); - delete_from_list (element3, &first); - output_list (first); - delete_from_list (element137, &first); - output_list (first); - - return 0; -} diff --git a/20230109/loesung-1b.c b/20230109/loesung-1b.c deleted file mode 100644 index 811b99b1fc9697ca0302eea8950c9bc6e7ab6042..0000000000000000000000000000000000000000 --- a/20230109/loesung-1b.c +++ /dev/null @@ -1,97 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content; - struct node *next, *prev; -} node; - -void check_list (node *first) -{ - for (node *p = first; p; p = p->next) - { - if (p->next && p->next->prev != p) - fprintf (stderr, "List inconsistency!\n"); - if (p->prev && p->prev->next != p) - fprintf (stderr, "List inconsistency!\n"); - } -} - -void output_list (node *first) -{ - for (node *p = first; p; p = p->next) - printf ("%d ", p->content); - printf ("\n"); -} - -void insert_into_list (node *what, node *where) -{ - what->next = where->next; - if (where->next) - where->next->prev = what; - what->prev = where; - where->next = what; -} - -void delete_from_list (node *what, node **first) -{ - if (what == *first) - { - *first = what->next; - if (*first) - (*first)->prev = NULL; - } - else - { - node *p = *first; - while (p && p->next != what) - p = p->next; - if (p) - p->next = what->next; - if (what->next) - what->next->prev = p; - } - free (what); -} - -int main (void) -{ - node *element3 = malloc (sizeof (node)); - node *element7 = malloc (sizeof (node)); - node *element137 = malloc (sizeof (node)); - - element3->content = 3; - element7->content = 7; - element137->content = 137; - - node *first = element3; - element3->prev = NULL; - element3->next = element7; - element7->prev = element3; - element7->next = element137; - element137->prev = element7; - element137->next = NULL; - - output_list (first); - check_list (first); - - node *element5 = malloc (sizeof (node)); - element5->content = 5; - insert_into_list (element5, element3); - - output_list (first); - check_list (first); - - delete_from_list (element5, &first); - output_list (first); - check_list (first); - delete_from_list (element3, &first); - output_list (first); - check_list (first); - delete_from_list (element137, &first); - output_list (first); - check_list (first); - - return 0; -} diff --git a/20230109/loesung-2c.c b/20230109/loesung-2c.c deleted file mode 100644 index a6dea990b25895475e343f07895c6a946426d2d8..0000000000000000000000000000000000000000 --- a/20230109/loesung-2c.c +++ /dev/null @@ -1,68 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct node -{ - int content_left, content_right; - struct node *left, *middle, *right; -} node; - -void insert_into_tree (node **root, int value) -{ - if (*root) - { - if ((*root)->content_right >= 0) - if (value < (*root)->content_left) - insert_into_tree (&(*root)->left, value); - else if (value < (*root)->content_right) - insert_into_tree (&(*root)->middle, value); - else - insert_into_tree (&(*root)->right, value); - else - if (value < (*root)->content_left) - { - (*root)->content_right = (*root)->content_left; - (*root)->content_left = value; - } - else - (*root)->content_right = value; - } - else - { - *root = malloc (sizeof (node)); - (*root)->left = NULL; - (*root)->content_left = value; - (*root)->middle = NULL; - (*root)->content_right = -1; - (*root)->right = NULL; - } -} - -void output_tree (node *root) -{ - if (root) - { - output_tree (root->left); - printf ("%d\n", root->content_left); - output_tree (root->middle); - if (root->content_right >= 0) - printf ("%d\n", root->content_right); - output_tree (root->right); - } -} - -int main (void) -{ - node *root = NULL; - insert_into_tree (&root, 7); - insert_into_tree (&root, 137); - insert_into_tree (&root, 3); - insert_into_tree (&root, 5); - insert_into_tree (&root, 6); - insert_into_tree (&root, 42); - insert_into_tree (&root, 1); - insert_into_tree (&root, 2); - insert_into_tree (&root, 12); - output_tree (root); - return 0; -} diff --git a/20230109/loesung-3b-gpt.c b/20230109/loesung-3b-gpt.c deleted file mode 100644 index 467813bbaf0bb0ca60e6e983769bfbb98e74b96a..0000000000000000000000000000000000000000 --- a/20230109/loesung-3b-gpt.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <stdio.h> - -int sum; // globale Variable für die Summe - -void add_to_sum (int x) -{ - if (x > 0) - { - sum += x; - } -} - -void foreach (int *a, void (*fun) (int x)) -{ - for (int *p = a; *p >= 0; p++) - { - fun (*p); - } -} - -int main (void) -{ - int numbers[] = { 12, 17, 32, 1, 3, 16, 19, 18, -1 }; - foreach (numbers, add_to_sum); - printf ("Summe der positiven Zahlen: %d\n", sum); - return 0; -} diff --git a/20230109/loesung-4-gpt-pg.c b/20230109/loesung-4-gpt-pg.c deleted file mode 100644 index 50270f858e7de49ea99cb6e125b4775b652ada81..0000000000000000000000000000000000000000 --- a/20230109/loesung-4-gpt-pg.c +++ /dev/null @@ -1,42 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -/* eigentlich: #include "aufgabe-4.xbm" */ - -#define XBM_WIDTH 14 -#define XBM_HEIGHT 14 - -static unsigned char xbm_bits[] = { - 0x00, 0x00, 0xf0, 0x03, 0x08, 0x04, 0x04, 0x08, 0x02, 0x10, 0x32, 0x13, - 0x22, 0x12, 0x02, 0x10, 0x0a, 0x14, 0x12, 0x12, 0xe4, 0x09, 0x08, 0x04, - 0xf0, 0x03, 0x00, 0x00 -}; - -int main(int argc, char **argv) -{ - // Öffne die Ausgabedatei - FILE *output_file = fopen("test.pbm", "w"); - if (output_file == NULL) { - printf("Fehler beim Öffnen der Ausgabedatei\n"); - return 1; - } - - // Schreibe die PBM-Dateikennung, Breite und Höhe in die Ausgabedatei - fprintf(output_file, "P4\n%d %d\n", XBM_WIDTH, XBM_HEIGHT); - - // Iteriere über jedes Byte im XBM-Array - for (int i = 0; i < XBM_HEIGHT * XBM_WIDTH / 8; i++) { // Iteriere über jedes Bit im aktuellen Byte - for (int j = 7; j >= 0; j--) { - // Lies das aktuelle Bit des XBM-Arrays und schreibe es in die Ausgabedatei - // PG: nicht berücksichtigt: umgekehrte Bit-Reihenfolge (MSB/LSB first) - uint8_t xbm_bit = (xbm_bits[i] >> j) & 1; - fprintf(output_file, "%c", xbm_bit ? '1' : '0'); - } - } - - // Schließe die Ausgabedatei - fclose(output_file); - - return 0; -} - diff --git a/20230109/loesung-4-gpt.c b/20230109/loesung-4-gpt.c deleted file mode 100644 index 8a47e33344c510eb059c7e876ae5300aca3c35ed..0000000000000000000000000000000000000000 --- a/20230109/loesung-4-gpt.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <stdio.h> -#include <stdint.h> - -#define XBM_WIDTH 14 -#define XBM_HEIGHT 14 - -static unsigned char xbm_bits[] = { - 0x00, 0x00, 0xf0, 0x03, 0x08, 0x04, 0x04, 0x08, 0x02, 0x10, 0x32, 0x13, - 0x22, 0x12, 0x02, 0x10, 0x0a, 0x14, 0x12, 0x12, 0xe4, 0x09, 0x08, 0x04, - 0xf0, 0x03, 0x00, 0x00 -}; - -int main(int argc, char **argv) -{ - // Öffne die Ausgabedatei - FILE *output_file = fopen("test.pbm", "w"); - if (output_file == NULL) { - printf("Fehler beim Öffnen der Ausgabedatei\n"); - return 1; - } - - // Schreibe die PBM-Dateikennung, Breite und Höhe in die Ausgabedatei - fprintf(output_file, "P4\n%d %d\n", XBM_WIDTH, XBM_HEIGHT); - - // Iteriere über jedes Byte im XBM-Array - for (int i = 0; i < XBM_HEIGHT * XBM_WIDTH / 8; i++) { // Iteriere über jedes Bit im aktuellen Byte - for (int j = 7; j >= 0; j--) { - // Lies das aktuelle Bit des XBM-Arrays und schreibe es in die Ausgabedatei - uint8_t xbm_bit = (xbm_bits[i] >> j) & 1; - fprintf(output_file, "%c", xbm_bit ? '1' : '0'); - } - } - - // Schließe die Ausgabedatei - fclose(output_file); - - return 0; -} - diff --git a/20230109/loesung-4.c b/20230109/loesung-4.c deleted file mode 100644 index 872058ac9fecdcb59ac1104ca67841cb3dc974a9..0000000000000000000000000000000000000000 --- a/20230109/loesung-4.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <stdio.h> - -int read_hex (char c) -{ - if (c >= '0' && c <= '9') - return c - '0'; - else if (c >= 'A' && c <= 'F') - return c - 'A' + 10; - else if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - else - { - fprintf (stderr, "invalid hex digit '%c'\n", c); - return 0; - } -} - -int main (void) -{ - char buffer[100]; - fgets (buffer, 100, stdin); - for (char *p = buffer; p[0] && p[1]; p += 2) - { - char c = 16 * read_hex (p[0]) + read_hex (p[1]); - printf ("%c", c); - } - printf ("\n"); -} diff --git a/20230109/logo-hochschule-bochum-cvh-text-v2.pdf b/20230109/logo-hochschule-bochum-cvh-text-v2.pdf deleted file mode 120000 index 4aa99b8f81061aca6dcaf43eed2d9efef40555f8..0000000000000000000000000000000000000000 --- a/20230109/logo-hochschule-bochum-cvh-text-v2.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum-cvh-text-v2.pdf \ No newline at end of file diff --git a/20230109/logo-hochschule-bochum.pdf b/20230109/logo-hochschule-bochum.pdf deleted file mode 120000 index b6b9491e370e499c9276918182cdb82cb311bcd1..0000000000000000000000000000000000000000 --- a/20230109/logo-hochschule-bochum.pdf +++ /dev/null @@ -1 +0,0 @@ -../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20230109/output-01.c b/20230109/output-01.c deleted file mode 100644 index d4f8b191d6d4491df2661046ce99c21ec2045a60..0000000000000000000000000000000000000000 --- a/20230109/output-01.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - printf (42); - return 0; -} diff --git a/20230109/pgscript.sty b/20230109/pgscript.sty deleted file mode 120000 index 95c888478c99ea7fda0fd11ccf669ae91be7178b..0000000000000000000000000000000000000000 --- a/20230109/pgscript.sty +++ /dev/null @@ -1 +0,0 @@ -../common/pgscript.sty \ No newline at end of file diff --git a/20230109/test-gpt-pg.pbm b/20230109/test-gpt-pg.pbm deleted file mode 100644 index f0e9e7e193831ff0a079359d6808c7bcaad78670..0000000000000000000000000000000000000000 --- a/20230109/test-gpt-pg.pbm +++ /dev/null @@ -1,3 +0,0 @@ -P1 -16 14 -000000000000000011110000000000110000100000000100000001000000100000000010000100000011001000010011001000100001001000000010000100000000101000010100000100100001001011100100000010010000100000000100 diff --git a/20230109/test-gpt.pbm b/20230109/test-gpt.pbm deleted file mode 100644 index 485ad2684c82d10da9d600467ddd1e89f7682080..0000000000000000000000000000000000000000 --- a/20230109/test-gpt.pbm +++ /dev/null @@ -1,3 +0,0 @@ -P4 -14 14 -000000000000000011110000000000110000100000000100000001000000100000000010000100000011001000010011001000100001001000000010000100000000101000010100000100100001001011100100000010010000100000000100 \ No newline at end of file diff --git a/20230116/func-pointers-01.c b/20230116/func-pointers-01.c deleted file mode 100644 index b2db5145e720b39de50d37e98365b02f1bb25ca2..0000000000000000000000000000000000000000 --- a/20230116/func-pointers-01.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -void hello (void) -{ - printf ("Hello, world!\n"); -} - -int main (void) -{ - hello (); - return 0; -} diff --git a/20230116/func-pointers-02.c b/20230116/func-pointers-02.c deleted file mode 100644 index 7c9d60ea9da2416b2f27b944dc500479825dd363..0000000000000000000000000000000000000000 --- a/20230116/func-pointers-02.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> - -void hello (void) -{ - printf ("Hello, world!\n"); -} - -int main (void) -{ - /* h ist ein Zeiger auf eine Funktion; - h soll auf die Funktion hello() zeigen; */ - /* Merken: "*h ist eine Funktion." */ - /* void *h (void) wäre eine Funktion, die keine Parameter bekommt - und einen Zeiger auf void zurückgibt. */ - void (*h) (void) = hello; - h (); - return 0; -} diff --git a/20230116/func-pointers-03.c b/20230116/func-pointers-03.c deleted file mode 100644 index 003591a933eb6123e6b92ac20c14454de17c2ac3..0000000000000000000000000000000000000000 --- a/20230116/func-pointers-03.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> - -void hello (void) -{ - printf ("Hello, world!\n"); -} - -int main (void) -{ - typedef void (*funcptr) (void); - funcptr h = hello; - h (); - return 0; -} diff --git a/20230116/func-pointers-04.c b/20230116/func-pointers-04.c deleted file mode 100644 index 403cb68fa3490e93301ad6ffe574a273ff39bc88..0000000000000000000000000000000000000000 --- a/20230116/func-pointers-04.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - void (*greeting) (void); // Zeiger auf Funktion, nicht initialisiert -} -object; - -void hello (void) -{ - printf ("Hello, world!\n"); -} - -int main (void) -{ - object o; - - o.greeting = hello; // "Konstruktor" - Initiallisieren des Funktions-Zeigers - //Ohne Klammerpaar: Adresse der Funktion - o.greeting (); // mit Klammerpaar: Funktion aufrufen - - return 0; -} diff --git a/20230116/func-pointers-05.c b/20230116/func-pointers-05.c deleted file mode 100644 index 8870230b80a2d0e78017133ab339590d1ed33e4b..0000000000000000000000000000000000000000 --- a/20230116/func-pointers-05.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - void (*greeting) (void); // Zeiger auf Funktion, nicht initialisiert -} -object; - -void hello (void) -{ - printf ("Hello, world!\n"); -} - -int main (void) -{ - object *o; - // FEHLER: Verwendung von "o" ohne daß "o" auf etwas Sinnvolles zeigt! - o->greeting = hello; // "Konstruktor" - Initiallisieren des Funktions-Zeigers - // Ohne Klammerpaar: Adresse der Funktion - o->greeting (); // mit Klammerpaar: Funktion aufrufen - - return 0; -} diff --git a/20230116/func-pointers-06.c b/20230116/func-pointers-06.c deleted file mode 100644 index 995bc6ea0b673144b57f0e2a587a60df6b676228..0000000000000000000000000000000000000000 --- a/20230116/func-pointers-06.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct -{ - void (*greeting) (void); // Zeiger auf Funktion, nicht initialisiert -} -object; - -void hello (void) -{ - printf ("Hello, world!\n"); -} - -int main (void) -{ - object *o; - - o = malloc (sizeof (object)); // Speicherplatz dynamisch erzeugen - - o->greeting = hello; // "Konstruktor" - Initiallisieren des Funktions-Zeigers - // Ohne Klammerpaar: Adresse der Funktion - o->greeting (); // mit Klammerpaar: Funktion aufrufen - - return 0; -} diff --git a/20230116/func-pointers-07.c b/20230116/func-pointers-07.c deleted file mode 100644 index a47689d0c3bd5c8d23594e90c31415df8c221c47..0000000000000000000000000000000000000000 --- a/20230116/func-pointers-07.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - void (*greeting) (void); // Zeiger auf Funktion, nicht initialisiert -} -object; - -void hello (void) -{ - printf ("Hello, world!\n"); -} - -int main (void) -{ - object *o; - - object apfel; // Speicherplatz innerhalb von main() reservieren - o = &apfel; // Zeiger darauf zeigen lassen - - o->greeting = hello; // "Konstruktor" - Initiallisieren des Funktions-Zeigers - // Ohne Klammerpaar: Adresse der Funktion - o->greeting (); // mit Klammerpaar: Funktion aufrufen - - return 0; -} diff --git a/20230116/func-pointers-08.c b/20230116/func-pointers-08.c deleted file mode 100644 index 0b28bed135607997794ef02d3ddc3c823cbe3515..0000000000000000000000000000000000000000 --- a/20230116/func-pointers-08.c +++ /dev/null @@ -1,36 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - void (*greeting) (void); // Zeiger auf Funktion, nicht initialisiert -} -object; - -void hello_apple (void) -{ - printf ("Hello, apple!\n"); -} - -void hello_pear (void) -{ - printf ("Hello, pear!\n"); -} - -int main (void) -{ - object *a; - object *b; - - object apfel; // Speicherplatz innerhalb von main() reservieren - a = &apfel; // Zeiger darauf zeigen lassen - a->greeting = hello_apple; // "Konstruktor": virtuelle Methode initialisieren - - object birne; // Speicherplatz innerhalb von main() reservieren - b = &birne; // Zeiger darauf zeigen lassen - b->greeting = hello_pear; // "Konstruktor": virtuelle Methode initialisieren - - a->greeting (); - b->greeting (); - - return 0; -} diff --git a/20230116/func-pointers-09.c b/20230116/func-pointers-09.c deleted file mode 100644 index 25ca1bba9b9d775134383d0078611ed5dd890911..0000000000000000000000000000000000000000 --- a/20230116/func-pointers-09.c +++ /dev/null @@ -1,35 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - void (*greeting) (void); // Zeiger auf Funktion, nicht initialisiert -} -object; - -void hello_apple (void) -{ - printf ("Hello, apple!\n"); -} - -void hello_pear (void) -{ - printf ("Hello, pear!\n"); -} - -int main (void) -{ - object *o[2]; // Array mit 2 Zeigern auf Objekte - - object apfel; // Speicherplatz innerhalb von main() reservieren - o[0] = &apfel; // Zeiger darauf zeigen lassen - o[0]->greeting = hello_apple; // "Konstruktor": virtuelle Methode initialisieren - - object birne; // Speicherplatz innerhalb von main() reservieren - o[1] = &birne; // Zeiger darauf zeigen lassen - o[1]->greeting = hello_pear; // "Konstruktor": virtuelle Methode initialisieren - - for (int i = 0; i < 2; i++) - o[i]->greeting (); - - return 0; -} diff --git a/20230116/func-pointers-10.c b/20230116/func-pointers-10.c deleted file mode 100644 index 10ad166342d4cf47c9df9e06e8f78211e5776be9..0000000000000000000000000000000000000000 --- a/20230116/func-pointers-10.c +++ /dev/null @@ -1,34 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -typedef struct -{ - void (*greeting) (void); // Zeiger auf Funktion, nicht initialisiert -} -object; - -void hello_apple (void) -{ - printf ("Hello, apple!\n"); -} - -void hello_pear (void) -{ - printf ("Hello, pear!\n"); -} - -int main (void) -{ - object *o[2]; // Array mit 2 Zeigern auf Objekte - - o[0] = malloc (sizeof (object)); // "Konstrutor": Speicherplatz dynamisch reservieren - o[0]->greeting = hello_apple; // "Konstruktor": virtuelle Methode initialisieren - - o[1] = malloc (sizeof (object)); // "Konstrutor": Speicherplatz dynamisch reservieren - o[1]->greeting = hello_pear; // "Konstruktor": virtuelle Methode initialisieren - - for (int i = 0; i < 2; i++) - o[i]->greeting (); - - return 0; -} diff --git a/20230116/hp-20230116.txt b/20230116/hp-20230116.txt deleted file mode 100644 index d53358e95adc81494c9b3d1a4291614c119008a9..0000000000000000000000000000000000000000 --- a/20230116/hp-20230116.txt +++ /dev/null @@ -1,19 +0,0 @@ -Klausur-Themen, 16.01.2023, 13:57:20 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Seiteneffekte - - Arrays, Zeiger, Strings - - Speicherzellen - - Bit-Manipulation - - Endianness - - Alignment - - Algorithmen, Landau-Symbol - - Objekte, Zeiger auf Funktionen - ---> Es ist mal wieder Zeit für: - - Seiteneffekte - - Mikrocontroller - -Zeiger, 16.01.2023, 11:30:23 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - auf Funktionen - - auf Structs und Unions diff --git a/20230116/pointers-01.c b/20230116/pointers-01.c deleted file mode 100644 index 230e8ed7d6dc91e2104c08028e2c58d8f654afa3..0000000000000000000000000000000000000000 --- a/20230116/pointers-01.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 7; - int b = 13; - int *p = &a; - printf ("*p = %d\n", *p); - p = &b; - printf ("*p = %d\n", *p); - return 0; -} diff --git a/20230116/pointers-01.pas b/20230116/pointers-01.pas deleted file mode 100644 index 1fe7afcbee05de4cd407d232b019e0906931fe2e..0000000000000000000000000000000000000000 --- a/20230116/pointers-01.pas +++ /dev/null @@ -1,12 +0,0 @@ -program Pointers; - -var - a: Integer = 7; - b: Integer = 13; - p: ^Integer = @a; - -begin - WriteLn ('p^ = ', p^); - p := @b; - WriteLn ('p^ = ', p^) -end. diff --git a/20230116/pointers-02.c b/20230116/pointers-02.c deleted file mode 100644 index b551c9c9911df26b7076ab833306b9715ea985b6..0000000000000000000000000000000000000000 --- a/20230116/pointers-02.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 7; - int b = 13; - int *p = &a; - printf ("*p = %d\n", *p); - *p = &b; /* falsch */ - printf ("*p = %d\n", *p); - return 0; -} diff --git a/20230116/pointers-03.c b/20230116/pointers-03.c deleted file mode 100644 index b330a5f6f3eafaed6cbdc608f98aee7652ecc13d..0000000000000000000000000000000000000000 --- a/20230116/pointers-03.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdio.h> - -int main (void) -{ - int a = 7; - int b = 13; - int *p; - p = &a; - printf ("*p = %d\n", *p); - *p = &b; /* falsch: Zuweisung der Speicheradresse von b an die Zahl a, - weil p zu diesem Zeitpunkt auf a zeigt */ - printf ("*p = %d\n", *p); - printf ("a = %d\n", a); - return 0; -} diff --git a/20230116/struct-pointers-01.c b/20230116/struct-pointers-01.c deleted file mode 100644 index 9837cbfbaa89bbab67cc31948927e637d6c3d84b..0000000000000000000000000000000000000000 --- a/20230116/struct-pointers-01.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int a; - int b; -} -data; - -int main (void) -{ - data d; - d.a = 7; - d.b = 13; - data *p = &d; - printf ("*p = { %d, %d }\n", *p.a, *p.b); - return 0; -} diff --git a/20230116/struct-pointers-02.c b/20230116/struct-pointers-02.c deleted file mode 100644 index d6527ad8983e8db8f3b2a0f86416d577fd8dd85a..0000000000000000000000000000000000000000 --- a/20230116/struct-pointers-02.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int a; - int b; -} -data; - -int main (void) -{ - data d; - d.a = 7; - d.b = 13; - data *p = &d; - printf ("*p = { %d, %d }\n", (*p).a, (*p).b); - return 0; -} diff --git a/20230116/struct-pointers-03.c b/20230116/struct-pointers-03.c deleted file mode 100644 index 2aebb0624adead6acfb2d0017587239faeee343d..0000000000000000000000000000000000000000 --- a/20230116/struct-pointers-03.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int a; - int b; -} -data; - -int main (void) -{ - data d; - d.a = 7; - d.b = 13; - data *p = &d; - printf ("*p = { %d, %d }\n", p->a, p->b); - return 0; -} diff --git a/20230116/struct-pointers-03.pas b/20230116/struct-pointers-03.pas deleted file mode 100644 index 2c998ff1410a786ab03eaa39757971d4f5b14e05..0000000000000000000000000000000000000000 --- a/20230116/struct-pointers-03.pas +++ /dev/null @@ -1,17 +0,0 @@ -program StructPointers; - -type - data = record - a, b: Integer - end; - -var - d: data; - p: ^data; - -begin - d.a := 7; - d.b := 13; - p := @d; - WriteLn ('p^ = { ', p^.a, ', ', p^.b, ' }') -end. diff --git a/20230116/struct-pointers-04.c b/20230116/struct-pointers-04.c deleted file mode 100644 index ca2c30cffd0bac3a004d74d0cbf46ffe8e152674..0000000000000000000000000000000000000000 --- a/20230116/struct-pointers-04.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int a; - int b; -} -data; - -int main (void) -{ - data d; - d.a = 7; - d.b = 13; - printf ("d = { %d, %d }\n", d->a, d->b); - return 0; -} diff --git a/20230116/struct-pointers-05.c b/20230116/struct-pointers-05.c deleted file mode 100644 index d98b8f23fc7b88fc1570c32f336e6377d08f0340..0000000000000000000000000000000000000000 --- a/20230116/struct-pointers-05.c +++ /dev/null @@ -1,17 +0,0 @@ -#include <stdio.h> - -typedef struct -{ - int a; - int b; -} -data; - -int main (void) -{ - data d; - d.a = 7; - d.b = 13; - printf ("d = { %d, %d }\n", d.a, d.b); - return 0; -} diff --git a/20220926/gitlab.png b/20231005/gitlab.png similarity index 100% rename from 20220926/gitlab.png rename to 20231005/gitlab.png diff --git a/20220926/hp-20220926-fig1.pdf b/20231005/hp-20231005-fig1.pdf similarity index 100% rename from 20220926/hp-20220926-fig1.pdf rename to 20231005/hp-20231005-fig1.pdf diff --git a/20220926/hp-20220926-fig1.tex b/20231005/hp-20231005-fig1.tex similarity index 100% rename from 20220926/hp-20220926-fig1.tex rename to 20231005/hp-20231005-fig1.tex diff --git a/20220926/hp-20220926.pdf b/20231005/hp-20231005.pdf similarity index 97% rename from 20220926/hp-20220926.pdf rename to 20231005/hp-20231005.pdf index 32fdcc7a48089797b5e787a4ce85c04f7127b265..bed537dad3781150e86ba681a4326a4d77eaba40 100644 Binary files a/20220926/hp-20220926.pdf and b/20231005/hp-20231005.pdf differ diff --git a/20220926/hp-20220926.tex b/20231005/hp-20231005.tex similarity index 97% rename from 20220926/hp-20220926.tex rename to 20231005/hp-20231005.tex index a45414e946e0f83a58d9ad68cf20626a4c35a64e..bb6663dcc01b228d3261d87ee54c23a3b22c81d0 100644 --- a/20220926/hp-20220926.tex +++ b/20231005/hp-20231005.tex @@ -1,5 +1,5 @@ -% hp-20220926.pdf - Lecture Slides on Low-Level Programming -% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Peter Gerwinski +% hp-20231005.pdf - Lecture Slides on Low-Level Programming +% Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Peter Gerwinski % % This document is free software: you can redistribute it and/or % modify it either under the terms of the Creative Commons @@ -41,7 +41,7 @@ \title{Hardwarenahe Programmierung} \author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{26.\ September 2022} +\date{5.\ Oktober 2023} \begin{document} @@ -49,11 +49,11 @@ \date{\begin{picture}(0,0) \color{red} - \put(0.87,1.05){\makebox(0,0)[t]{$\underbrace{\rule{1.45cm}{0pt}}_{% + \put(0.55,1.05){\makebox(0,0)[t]{$\underbrace{\rule{1.45cm}{0pt}}_{% \mbox{\emph{rerum naturalium\/} = der natürlichen Dinge (lat.)}}$}} - \put(1.8,-3){\makebox(0,0)[bl]{\redurl{https://www.peter.gerwinski.de/physik/}}} + \put(1.55,-3){\makebox(0,0)[bl]{\redurl{https://www.peter.gerwinski.de/physik/}}} \end{picture}% - 26.\ September 2022} + 5.\ Oktober 2023} \maketitleframe @@ -86,13 +86,13 @@ \item Notfall-Schnellzugang: \url{https://www.cvh-server.de/virtuelle-raeume/}\\ Seminarraum 2, VNC-Passwort: \lstinline[style=cmd]{testcvh} - \smallskip - \item - Bei Problemen: bitte notieren:\\ - Art des Problems, genaue Uhrzeit, eigener Internet-Zugang +% \smallskip +% \item +% Bei Problemen: bitte notieren:\\ +% Art des Problems, genaue Uhrzeit, eigener Internet-Zugang \bigskip \item - GitLab: \url{https://gitlab.cvh-server.de/pgerwinski/hp} + \textbf{Lehrmaterialien:} \url{https://gitlab.cvh-server.de/pgerwinski/hp} \end{itemize} \end{frame} @@ -319,7 +319,7 @@ \item \textbf{Klausur:} - Zeit: 150 Minuten + Zeit: 120 Minuten Zulässige Hilfsmittel: \begin{itemize} @@ -330,12 +330,13 @@ \end{itemize} \item \textbf{Übungen}\\ - sind mit der Vorlesung integriert. + sind mit der Vorlesung und dem Praktikum integriert. \item Das \textbf{Praktikum}\\ findet jede Woche statt.\\ Diese Woche: vorbereitende Maßnahmen,\\ - Kennenlernen der verwendeten Werkzeuge + Kennenlernen der verwendeten Werkzeuge.\\ + Im Laufe des Semesters: \textbf{4 Praktikumsversuche} \end{itemize} \end{frame} diff --git a/20220926/logo-hochschule-bochum-cvh-text-v2.pdf b/20231005/logo-hochschule-bochum-cvh-text-v2.pdf similarity index 100% rename from 20220926/logo-hochschule-bochum-cvh-text-v2.pdf rename to 20231005/logo-hochschule-bochum-cvh-text-v2.pdf diff --git a/20220926/logo-hochschule-bochum.pdf b/20231005/logo-hochschule-bochum.pdf similarity index 100% rename from 20220926/logo-hochschule-bochum.pdf rename to 20231005/logo-hochschule-bochum.pdf diff --git a/20220926/pgscript.sty b/20231005/pgscript.sty similarity index 100% rename from 20220926/pgscript.sty rename to 20231005/pgscript.sty diff --git a/20220926/pgslides.sty b/20231005/pgslides.sty similarity index 100% rename from 20220926/pgslides.sty rename to 20231005/pgslides.sty diff --git a/README.md b/README.md index 583ac081047ac170412f57d62da3988669520b2c..b1eee3dbc2a731dea96f2a312c6e91912b9d32e1 100644 --- a/README.md +++ b/README.md @@ -1,108 +1,74 @@ Hardwarenahe Programmierung =========================== -Lehrveranstaltung im Wintersemester 2022/23 +Lehrveranstaltung im Wintersemester 2023/24 Hochschule Bochum, Campus Velbert/Heiligenhaus Prof. Dr. rer. nat. Peter Gerwinski -Copyright © 2012–2022 Peter Gerwinski +Copyright © 2012–2023 Peter Gerwinski **Diese Lehrmaterialien sind freie Software.** Sie dürfen diese gemäß den jeweils angegebenen Lizenzen -([CC-BY-SA 3.0](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/common/CC-BY-SA-3.0), -[GNU GPL 3+](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/common/GNU-GPL-3), -[modified BSD License](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/common/BSD-MODIFIED)) +([CC-BY-SA 3.0](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/common/CC-BY-SA-3.0), +[GNU GPL 3+](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/common/GNU-GPL-3), +[modified BSD License](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/common/BSD-MODIFIED)) studieren, kopieren, modifizieren und/oder weitergeben. -Für Details siehe [common/README](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/common/README). +Für Details siehe [common/README](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/common/README). Vortragsfolien und Beispiele: ----------------------------- - * [26.09.2022: Einführung, Einführung in C (bis Seiteneffekte)](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20220926/hp-20220926.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20220926/) - * [10.10.2022: Funktionen, Zeiger, Arrays und Strings](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221010/hp-20221010.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221010/) - * [17.10.2022: Strukturen, Dateien und Fehlerbehandlung, Parameter des Hauptprogramms, String-Operationen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221017/hp-20221017.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221017/) - * [24.10.2022: Bibliotheken](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221024/hp-20221024.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221024/) - * [31.10.2022: Callback-Funktionen, make, Bit-Operationen, I/O-Ports](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221031/hp-20221031.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221031/) - * [07.11.2022: Interrupts, volatile-Variable, Endianness](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221107/hp-20221107.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221107/) - * [14.11.2022: Binärdarstellung negativer Zahlen, Alignment, Differentialgleichungen, Rekursion](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221114/hp-20221114.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221114/) - * [21.11.2022: Aufwandsabschätzungen, Objektorientierte Programmierung](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221121/hp-20221121.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221121/) - * [28.11.2022: Objektorientierte Programmierung](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221128/hp-20221128.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221128/) - * [05.12.2022: Objektorientierte Programmierung, Datenstrukturen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221205/hp-20221205.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221205/) - * [19.12.2022: Objektorientierte Programmierung, Datenstrukturen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221219/hp-20221219.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/20221219/) - * [alle in 1 Datei](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/hp-slides-2022ws.pdf) + * [05.10.2023: Einführung, Einführung in C (bis Seiteneffekte)](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/20231005/hp-20231005.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws/20231005/) + * [alle in 1 Datei](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/hp-slides-2023ws.pdf) Übungsaufgaben: --------------- - * [26.09.2022: Hello-World-Programme, Schaltjahr ermitteln, Maximum berechnen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20220926/hp-uebung-20220926.pdf) - * [10.10.2022: Schaltjahr ermitteln, Multiplikationstabelle, Fibonacci-Zahlen, fehlerhaftes Programm](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221010/hp-uebung-20221010.pdf) - * [17.10.2022: Seltsame Programme, Kalender-Berechnung, Strings, Programm analysieren](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221017/hp-uebung-20221017.pdf) - * [24.10.2022: Arrays mit Zahlen, Datum-Bibliothek, fehlerhaftes Primzahl-Programm](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221024/hp-uebung-20221024.pdf) - * [31.10.2022: Zahlensysteme, Mikrocontroller, Einfügen in Strings](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221031/hp-uebung-20221031.pdf) - * [07.11.2022: Ausgabe von Hexadezimalzahlen, Länge von Strings, LED-Blinkmuster](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221107/hp-uebung-20221107.pdf) - * [14.11.2022: Trickprogrammierung, Thermometer-Baustein an I²C-Bus, Speicherformate von Zahlen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221114/hp-uebung-20221114.pdf) - * [21.11.2022: Kondensator, Personen-Datenbank, Fakultät](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221121/hp-uebung-20221121.pdf) - * [28.11.2022: Einfügen in Strings (Ergänzung), dynamisches Bit-Array, objektorientierte Tier-Datenbank](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221128/hp-uebung-20221128.pdf) - * [05.12.2022: Objektorientierte Tier-Datenbank (Ergänzung), Iterationsfunktionen, Stack-Operationen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221205/hp-uebung-20221205.pdf) - * [12.12.2022: Länge von Strings (Neuauflage), Text-Grafik-Bibliothek, PBM-Grafik](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221212/hp-uebung-20221212.pdf) - * [09.01.2023: Einfach und doppelt verkettete Listen, ternärer Baum, hüpfender Ball, Hexdumps](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20230109/hp-uebung-20230109.pdf) +(kommen noch) Musterlösungen: --------------- - * [10.10.2022: Schaltjahr ermitteln, Multiplikationstabelle, Fibonacci-Zahlen, fehlerhaftes Programm](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221010/hp-musterloesung-20221010.pdf) - * [17.10.2022: Seltsame Programme, Kalender-Berechnung, Strings, Programm analysieren](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221017/hp-musterloesung-20221017.pdf) - * [24.10.2022: Arrays mit Zahlen, Datum-Bibliothek, fehlerhaftes Primzahl-Programm](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221024/hp-musterloesung-20221024.pdf) - * [31.10.2022: Zahlensysteme, Mikrocontroller, Einfügen in Strings](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221031/hp-musterloesung-20221031.pdf) - * [07.11.2022: Ausgabe von Hexadezimalzahlen, Länge von Strings, LED-Blinkmuster](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221107/hp-musterloesung-20221107.pdf) - * [14.11.2022: Trickprogrammierung, Thermometer-Baustein an I²C-Bus, Speicherformate von Zahlen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221114/hp-musterloesung-20221114.pdf) - * [21.11.2022: Kondensator, Personen-Datenbank, Fakultät](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221121/hp-musterloesung-20221121.pdf) - * [28.11.2022: Einfügen in Strings (Ergänzung), dynamisches Bit-Array, objektorientierte Tier-Datenbank](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221128/hp-musterloesung-20221128.pdf) - * [05.12.2022: Objektorientierte Tier-Datenbank (Ergänzung), Iterationsfunktionen, Stack-Operationen](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221205/hp-musterloesung-20221205.pdf) - * [12.12.2022: Länge von Strings (Neuauflage), Text-Grafik-Bibliothek, PBM-Grafik](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221212/hp-musterloesung-20221212.pdf) - * [09.01.2023: Einfach und doppelt verkettete Listen, ternärer Baum, hüpfender Ball, Hexdumps](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20230109/hp-musterloesung-20230109.pdf) +(kommen noch) Praktikumsunterlagen: --------------------- - * [Versuch 1: RSA-Verschlüsselung](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221006/hp-2022ws-p1.pdf) - * [Versuch 2: Druckknopfampel](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221031/hp-2022ws-p2.pdf) - * [Versuch 3: Weltraum-Simulation](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221114/hp-2022ws-p3.pdf) - * [Versuch 4: Objektorientiertes Grafik-Programm](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/20221205/hp-2022ws-p4.pdf) +(kommen noch) Alte Klausuren: --------------- - * [Wintersemester 2015/16](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/exams/20160129/ainf-klausur-20160129.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/exams/20160129/) - * [Wintersemester 2016/17](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/exams/20170206/hp-klausur-20170206.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/exams/20170206/) - * [Wintersemester 2017/18](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/exams/20180213/hp-klausur-20180213.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/exams/20180213/) + * [Wintersemester 2015/16](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/exams/20160129/ainf-klausur-20160129.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws/exams/20160129/) + * [Wintersemester 2016/17](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/exams/20170206/hp-klausur-20170206.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws/exams/20170206/) + * [Wintersemester 2017/18](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/exams/20180213/hp-klausur-20180213.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws/exams/20180213/) Skript: ------- - * [Hardwarenahe Programmierung](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/script/hp-2022ws.pdf) + * [Hardwarenahe Programmierung](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/script/hp-2023ws.pdf) Original-Materialien einschließlich Beispiel-Programme und LaTeX-Quelltexte: ---------------------------------------------------------------------------- - * [common – gemeinsame Dateien für Skript und Vortragsfolien](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/common) - * [script – Skript zur Lehrveranstaltung](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/script) - * [202????? – Vortragsfolien und Beispiele](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws) - * [branch 2021ws – vollständige Lehrmaterialien vom Wintersemester 2021/22](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2021ws) + * [common – gemeinsame Dateien für Skript und Vortragsfolien](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws/common) + * [script – Skript zur Lehrveranstaltung](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws/script) + * [202????? – Vortragsfolien und Beispiele](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws) + * [branch 2022ws – vollständige Lehrmaterialien vom Wintersemester 2022/23](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws) Low-Level Programming ===================== -Course in winter semester 2022-23 +Course in winter semester 2023-24 Bochum University of Applied Sciences, Campus Velbert/Heiligenhaus Prof. Dr. rer. nat. Peter Gerwinski -Copyright © 2012–2022 Peter Gerwinski +Copyright © 2012–2023 Peter Gerwinski **These teaching materials are Free Software.** You may study, copy, modify, and/or distribute them according to their respective licences -([CC-BY-SA 3.0](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/common/CC-BY-SA-3.0), -[GNU GPL 3+](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/common/GNU-GPL-3), -[modified BSD License](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/common/BSD-MODIFIED)). -See the file [common/README](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/common/README) for details. - - * [common – common files for lecture notes and slides](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/common) - * [script – lecture notes](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws/script) - * [202????? – slides and examples](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws) - * [hp-slides-2022ws.pdf – all slides in 1 file](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2022ws/hp-slides-2022ws.pdf) - * [branch 2021ws – complete teaching materials from winter semester 2021-22](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2021ws) +([CC-BY-SA 3.0](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/common/CC-BY-SA-3.0), +[GNU GPL 3+](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/common/GNU-GPL-3), +[modified BSD License](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/common/BSD-MODIFIED)). +See the file [common/README](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/common/README) for details. + + * [common – common files for lecture notes and slides](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws/common) + * [script – lecture notes](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws/script) + * [202????? – slides and examples](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws) + * [hp-slides-2023ws.pdf – all slides in 1 file](https://gitlab.cvh-server.de/pgerwinski/hp/raw/2023ws/hp-slides-2023ws.pdf) + * [branch 2022ws – complete teaching materials from winter semester 2022-23](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws) diff --git a/hp-slides-2022ws.pdf b/hp-slides-2022ws.pdf deleted file mode 100644 index 0cb2dca473c2d72ab105466ba6de05d0a9ff66d0..0000000000000000000000000000000000000000 Binary files a/hp-slides-2022ws.pdf and /dev/null differ diff --git a/hp-slides-2022ws.tex b/hp-slides-2022ws.tex deleted file mode 100644 index 75e83d9d1c5254640c356c866c1f9ce0a78aa303..0000000000000000000000000000000000000000 --- a/hp-slides-2022ws.tex +++ /dev/null @@ -1,36 +0,0 @@ -\documentclass{article} - -\usepackage[final]{pdfpages} -\usepackage[paperwidth=363pt,paperheight=272pt]{geometry} -\usepackage{hyperref} -\usepackage[utf8]{luainputenc} % Without this, umlauts are broken. Weird. - -\pagestyle{empty} - -\begin{document} - \includepdf[pages=1]{script/hp-slides-title-2022ws.pdf} - \pdfbookmark[1]{Wichtiger Hinweis}{Hinweis} - \includepdf[pages=2-]{script/hp-slides-title-2022ws.pdf} - \pdfbookmark[1]{26.09.2022: Einführung, Einführung in C (bis Seiteneffekte)}{20220926} - \includepdf[pages=-]{20220926/hp-20220926.pdf} - \pdfbookmark[1]{10.10.2022: Funktionen, Zeiger, Arrays und Strings}{20221010} - \includepdf[pages=-]{20221010/hp-20221010.pdf} - \pdfbookmark[1]{17.10.2022: Strukturen, Dateien und Fehlerbehandlung, Parameter des Hauptprogramms, String-Operationen}{20221017} - \includepdf[pages=-]{20221017/hp-20221017.pdf} - \pdfbookmark[1]{24.10.2022: Bibliotheken}{20221024} - \includepdf[pages=-]{20221024/hp-20221024.pdf} - \pdfbookmark[1]{31.10.2022: Callback-Funktionen, make, Bit-Operationen, I/O-Ports}{20221031} - \includepdf[pages=-]{20221031/hp-20221031.pdf} - \pdfbookmark[1]{07.11.2022: Interrupts, volatile-Variable, Endianness}{20221107} - \includepdf[pages=-]{20221107/hp-20221107.pdf} - \pdfbookmark[1]{14.11.2022: Binärdarstellung negativer Zahlen, Alignment, Differentialgleichungen, Rekursion}{20221114} - \includepdf[pages=-]{20221114/hp-20221114.pdf} - \pdfbookmark[1]{21.11.2022: Aufwandsabschätzungen, Objektorientierte Programmierung}{20221121} - \includepdf[pages=-]{20221121/hp-20221121.pdf} - \pdfbookmark[1]{28.11.2022: Objektorientierte Programmierung}{20221128} - \includepdf[pages=-]{20221128/hp-20221128.pdf} - \pdfbookmark[1]{05.12.2022: Objektorientierte Programmierung, Datenstrukturen}{20221205} - \includepdf[pages=-]{20221205/hp-20221205.pdf} - \pdfbookmark[1]{12.12.2022: Objektorientierte Programmierung, Datenstrukturen}{20221212} - \includepdf[pages=-]{20221212/hp-20221212.pdf} -\end{document} diff --git a/hp-slides-2023ws.pdf b/hp-slides-2023ws.pdf new file mode 100644 index 0000000000000000000000000000000000000000..8f8a0d808345b3f03d9fe6505e28bde6ec3eb42c Binary files /dev/null and b/hp-slides-2023ws.pdf differ diff --git a/hp-slides-2023ws.tex b/hp-slides-2023ws.tex new file mode 100644 index 0000000000000000000000000000000000000000..bb92eb9cc664dbbfdf1fb0bf85789c086062882e --- /dev/null +++ b/hp-slides-2023ws.tex @@ -0,0 +1,16 @@ +\documentclass{article} + +\usepackage[final]{pdfpages} +\usepackage[paperwidth=363pt,paperheight=272pt]{geometry} +\usepackage{hyperref} +\usepackage[utf8]{luainputenc} % Without this, umlauts are broken. Weird. + +\pagestyle{empty} + +\begin{document} + \includepdf[pages=1]{script/hp-slides-title-2023ws.pdf} + \pdfbookmark[1]{Wichtiger Hinweis}{Hinweis} + \includepdf[pages=2-]{script/hp-slides-title-2023ws.pdf} + \pdfbookmark[1]{05.10.2023: Einführung, Einführung in C (bis Seiteneffekte)}{20231005} + \includepdf[pages=-]{20231005/hp-20231005.pdf} +\end{document} diff --git a/script/hp-2022ws.pdf b/script/hp-2023ws.pdf similarity index 100% rename from script/hp-2022ws.pdf rename to script/hp-2023ws.pdf diff --git a/script/hp-2022ws.tex b/script/hp-2023ws.tex similarity index 100% rename from script/hp-2022ws.tex rename to script/hp-2023ws.tex diff --git a/script/hp-slides-title-2022ws.pdf b/script/hp-slides-title-2023ws.pdf similarity index 79% rename from script/hp-slides-title-2022ws.pdf rename to script/hp-slides-title-2023ws.pdf index fd5eb1d8f940986e7f3260f63ebe5e9fa8f47e36..ad596dbac825aad38baca39f0b0355b2fe841eb9 100644 Binary files a/script/hp-slides-title-2022ws.pdf and b/script/hp-slides-title-2023ws.pdf differ diff --git a/script/hp-slides-title-2022ws.tex b/script/hp-slides-title-2023ws.tex similarity index 89% rename from script/hp-slides-title-2022ws.tex rename to script/hp-slides-title-2023ws.tex index 73b501a12ae87034e70b5a30eb4d2ec646c7e769..a74a2acca28e52b0e2834f34442c6601c0a58ef4 100644 --- a/script/hp-slides-title-2022ws.tex +++ b/script/hp-slides-title-2023ws.tex @@ -1,5 +1,5 @@ -% hp-slides-title-2022ws.pdf - Title Page for Lecture Slides on Low-Level Programming -% Copyright (C) 2018, 2019, 2020, 2021, 2022 Peter Gerwinski +% hp-slides-title-2023ws.pdf - Title Page for Lecture Slides on Low-Level Programming +% Copyright (C) 2018, 2019, 2020, 2021, 2022, 2023 Peter Gerwinski % % This document is free software: you can redistribute it and/or % modify it either under the terms of the Creative Commons @@ -28,7 +28,7 @@ \title{Hardwarenahe Programmierung} \author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{Wintersemester 2022/23} +\date{Wintersemester 2023/24} \begin{document} @@ -59,8 +59,8 @@ (\url{https://gitlab.cvh-server.de/pgerwinski/hp.git}) mit allen Zwischenschritten enthalten und befinden sich in den zu den jeweiligen Kalenderdaten gehörenden Verzeichnissen - (z.\,B.\ für den 4.\,10.\,2021 unter - \url{https://gitlab.cvh-server.de/pgerwinski/hp/tree/2021ws/20211004/}\kern1pt). + (z.\,B.\ für den 5.\,10.\,2023 unter + \url{https://gitlab.cvh-server.de/pgerwinski/hp/tree/2023ws/20231005/}\kern1pt). Wenn Sie die Übungsaufgaben bearbeiten, nutzen Sie die Gelegenheit, Ihre Lösungen in den Übungen überprüfen zu lassen. diff --git a/update b/update index 1aee5f72410e13a8c1d5e573a138bc7e1978fdc7..18e0bcf58df13248d230af6c54a519745b1dc371 100755 --- a/update +++ b/update @@ -1,6 +1,6 @@ #!/bin/bash -sem=2022ws +sem=2023ws course=hp date_mask="20[12][0-9][01][0-9][0-3][0-9]" @@ -52,7 +52,7 @@ EOF exit 1 } - rm -f hp-slides-2022ws.{aux,log,out} + rm -f hp-slides-2023ws.{aux,log,out} echo fi @@ -118,11 +118,11 @@ cat > $readme << EOF Hardwarenahe Programmierung =========================== -Lehrveranstaltung im Wintersemester 2022/23 +Lehrveranstaltung im Wintersemester 2023/24 Hochschule Bochum, Campus Velbert/Heiligenhaus Prof. Dr. rer. nat. Peter Gerwinski -Copyright © 2012–2022 Peter Gerwinski +Copyright © 2012–2023 Peter Gerwinski **Diese Lehrmaterialien sind freie Software.** Sie dürfen diese gemäß den jeweils angegebenen Lizenzen @@ -156,17 +156,17 @@ Original-Materialien einschließlich Beispiel-Programme und LaTeX-Quelltexte: * [common – gemeinsame Dateien für Skript und Vortragsfolien](https://gitlab.cvh-server.de/pgerwinski/hp/tree/$sem/common) * [script – Skript zur Lehrveranstaltung](https://gitlab.cvh-server.de/pgerwinski/hp/tree/$sem/script) * [202????? – Vortragsfolien und Beispiele](https://gitlab.cvh-server.de/pgerwinski/hp/tree/$sem) - * [branch 2021ws – vollständige Lehrmaterialien vom Wintersemester 2021/22](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2021ws) + * [branch 2022ws – vollständige Lehrmaterialien vom Wintersemester 2022/23](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws) Low-Level Programming ===================== -Course in winter semester 2022-23 +Course in winter semester 2023-24 Bochum University of Applied Sciences, Campus Velbert/Heiligenhaus Prof. Dr. rer. nat. Peter Gerwinski -Copyright © 2012–2022 Peter Gerwinski +Copyright © 2012–2023 Peter Gerwinski **These teaching materials are Free Software.** You may study, copy, modify, and/or distribute them @@ -179,8 +179,8 @@ See the file [common/README](https://gitlab.cvh-server.de/pgerwinski/hp/raw/$sem * [common – common files for lecture notes and slides](https://gitlab.cvh-server.de/pgerwinski/hp/tree/$sem/common) * [script – lecture notes](https://gitlab.cvh-server.de/pgerwinski/hp/tree/$sem/script) * [202????? – slides and examples](https://gitlab.cvh-server.de/pgerwinski/hp/tree/$sem) - * [hp-slides-2022ws.pdf – all slides in 1 file](https://gitlab.cvh-server.de/pgerwinski/hp/raw/$sem/hp-slides-2022ws.pdf) - * [branch 2021ws – complete teaching materials from winter semester 2021-22](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2021ws) + * [hp-slides-2023ws.pdf – all slides in 1 file](https://gitlab.cvh-server.de/pgerwinski/hp/raw/$sem/hp-slides-2023ws.pdf) + * [branch 2022ws – complete teaching materials from winter semester 2022-23](https://gitlab.cvh-server.de/pgerwinski/hp/tree/2022ws) EOF if diff -wu $readme_old $readme; then