Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
No results found
Select Git revision
  • master
1 result
Show changes

Commits on Source 39

266 files
+ 13228
28
Compare changes
  • Side-by-side
  • Inline

Files

Original line number Diff line number Diff line
@@ -104,7 +104,7 @@
    \item
      \textbf{Doppelte Pufferung}\\
      2 "`Bildschirme"': einer zum Zeichnen; einer wird angezeigt\\
      \file{opengl-magic.double.c}, \lstinline{gluSwapBuffers()}
      \file{opengl-magic-double.c}, \lstinline{gluSwapBuffers()}
    \pause
    \item
      \textbf{Im Display-Handler} (\lstinline{draw()}) \textbf{wirklich nur zeichnen!}\\
+179 −0
Original line number Diff line number Diff line
% ainf-uebung-20151119.pdf - Exercises on Applied Computer Sciences
% Copyright (C) 2013, 2015  Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document.  If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document.  If not, see <http://creativecommons.org/licenses/>.

\documentclass[a4paper]{article}

\usepackage{pgscript}
\usepackage{pdftricks}
\usepackage{fleqn}

\begin{psinputs}
  \usepackage{pgscript}
  \definecolor{PracticallyWhite}{rgb}{0.99 0.99 0.99}
\end{psinputs}

\newcounter{exercise}
\newcommand{\exercise}[1]{\addtocounter{exercise}{1}\subsection*{Aufgabe \arabic{exercise}: #1}}

\newcounter{points}
\newcommand{\onepoint}{(1 Punkt)\addtocounter{points}{1}}
\newcommand{\points}[1]{(#1 Punkte)\addtocounter{points}{#1}}

\begin{document}

%  \thispagestyle{empty}

  \section*{Angewandte Informatik\\Übungsaufgaben -- 19.\ November 2015}

  \exercise{Fakultät}

  Die Fakultät $n!$ einer natürlichen Zahl $n$ ist definiert als:
  \begin{eqnarray*}
    0 & \mbox{für} & n \le 1, \\
    n \cdot (n-1)! & \mbox{für} & n > 1.
  \end{eqnarray*}

  Mit anderen Worten: $n! = 1\cdot2\cdot3\cdot\dots\cdot n$.

  Die folgende Funktion \lstinline{fak()} berechnet die Fakultät \emph{rekursiv}:

  \begin{lstlisting}
    #include <stdio.h>

    int fak (int n)
    {
      if (n <= 1)
        return 1;
      else
        return n * fak (n - 1);
    }

    int main (void)
    {
      for (int n = 1; n <= 5; n++)
        printf ("%d\n", fak (n));
      return 0;
    }
  \end{lstlisting}

  \begin{itemize}
    \item[(a)]
      Schreiben Sie eine Funktion, die die Fakultät \emph{iterativ} berechnet,\\
      d.\,h.\ mit Hilfe einer Schleife anstelle von Rekursion.
    \item[(b)]
      Wie viele Multiplikationen erfordern beide Versionen der Fakultätsfunktion?
    \item[(c)]
      Wieviel Speicherplatz erfordern beide Versionen der Fakultätsfunktion?
  \end{itemize}

%  \exercise{Koordinaten-FIFO}
%
%  Implementieren Sie einen FIFO für Koordinaten-Paare.\\
%  Koordinatenpaare sollen "`hintereinander eingereiht"' werden.
%
%  \begin{itemize}
%    \item
%      Eine Funktion \lstinline{push (int x, int y)}
%      schiebt sie in den FIFO.
%    \item
%      Eine Funktion \lstinline{pop (int &x, int &y)}
%      liest und entfernt sie wieder aus dem FIFO.
%    \item
%      Eine Funktion \lstinline{dump ()}
%      gibt den Inhalt des FIFO auf dem Bildschirm aus.
%  \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, 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 weist mehrere Code-Verdopplungen auf:
  \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,
  die sich -- z.\,B.\ durch eine Funktion \lstinline{DaysInYear()} -- leicht hätte vermeiden lassen.

  Gut hingegen ist die Verwendung einer Präprozessor-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}

%  \bigskip
%
%  Anleitung:
%  \begin{itemize}
%    \item
%      1 Array
%    \item
%      2 Index-Variablen (eine zum Schreiben, eine zum Lesen)
%    \item
%      ansonsten wie Stack
%  \end{itemize}

\end{document}

20151119/bla/hex-1.c

0 → 100644
+19 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdint.h>

void print_hex (uint32_t x)
{
  print_hex (x / 16);
  int e = x % 16;
  if (e < 10)
    printf ("%d", e);
  else
    printf ("%c", 'a' + e - 10);
}

int main (void)
{
  print_hex (16777226);
  printf ("\n");
  return 0;
}
+9 −0
Original line number Diff line number Diff line
#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;
}

20151119/blubb

0 → 100644
+9 −0
Original line number Diff line number Diff line

         ************************
         *                      *
         *     ++     ++        *
         *     ++     ++        *
         *  -             -    *
         *   -------------    *
         *                   *
         ********************

20151119/fak-1.c

0 → 100644
+16 −0
Original line number Diff line number Diff line
#include <stdio.h>

int fak (int n)
{
  if (n <= 1)
    return 1;
  else
    return n * fak (n - 1);
}

int main (void)
{
  for (int n = 1; n <= 5; n++)
    printf ("%d\n", fak (n));
  return 0;
}

20151119/hanoi-0.c

0 → 100644
+25 −0
Original line number Diff line number Diff line
#include <stdio.h>

#define DISKS 4

int n[3], tower[3][DISKS];

void display (void)
{
  for (int i = 0; i < 3; i++)
    {
      printf ("tower %d: ", i);
      for (int j = 0; j < n[i]; j++)
        printf ("%2d", tower[i][j]);
      printf ("\n");
    }
  printf ("\n");
}

int main (void)
{
  n[0] = 0;
  n[1] = 0;
  n[2] = 0;
  display ();
}

20151119/hanoi-1.c

0 → 100644
+29 −0
Original line number Diff line number Diff line
#include <stdio.h>

#define DISKS 4

int n[3], tower[3][DISKS];

void display (void)
{
  for (int i = 0; i < 3; i++)
    {
      printf ("tower %d: ", i);
      for (int j = 0; j < n[i]; j++)
        printf ("%2d", tower[i][j]);
      printf ("\n");
    }
  printf ("\n");
}

int main (void)
{
  n[0] = 4;
  tower[0][0] = 3;
  tower[0][1] = 2;
  tower[0][2] = 1;
  tower[0][3] = 0;
  n[1] = 0;
  n[2] = 0;
  display ();
}

20151119/hanoi-2.c

0 → 100644
+51 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define DISKS 4

int n[3], tower[3][DISKS];
char *program_name;

void display (void)
{
  for (int i = 0; i < 3; i++)
    {
      printf ("tower %d: ", i);
      for (int j = 0; j < n[i]; j++)
        printf ("%2d", tower[i][j]);
      printf ("\n");
    }
  printf ("\n");
}

void fatal_error (char *msg)
{
  fprintf (stderr, "%s: %s\n", program_name, msg);
  exit (1);
}

void move (int from, int to, int disks)
{
  if (disks == 1)
    {
      if (n[from] <= 0)
        fatal_error ("trying to move disk from empty tower");
      tower[to][n[to]] = tower[from][n[from] - 1];
      n[to]++;
      n[from]--;
    }
}

int main (int argc, char **argv)
{
  program_name = argv[0];
  n[0] = 4;
  tower[0][0] = 3;
  tower[0][1] = 2;
  tower[0][2] = 1;
  tower[0][3] = 0;
  n[1] = 0;
  n[2] = 0;
  move (2, 0, 1);
  display ();
}

20151119/hanoi-3.c

0 → 100644
+51 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define DISKS 4

int n[3], tower[3][DISKS];
char *program_name;

void display (void)
{
  for (int i = 0; i < 3; i++)
    {
      printf ("tower %d: ", i);
      for (int j = 0; j < n[i]; j++)
        printf ("%2d", tower[i][j]);
      printf ("\n");
    }
  printf ("\n");
}

void fatal_error (char *msg)
{
  fprintf (stderr, "%s: %s\n", program_name, msg);
  exit (1);
}

void move (int from, int to, int disks)
{
  if (disks == 1)
    {
      if (n[from] <= 0)
        fatal_error ("trying to move disk from empty tower");
      tower[to][n[to]] = tower[from][n[from] - 1];
      n[to]++;
      n[from]--;
    }
}

int main (int argc, char **argv)
{
  program_name = argv[0];
  n[0] = 4;
  tower[0][0] = 3;
  tower[0][1] = 2;
  tower[0][2] = 1;
  tower[0][3] = 0;
  n[1] = 0;
  n[2] = 0;
  move (0, 2, 1);
  display ();
}

20151119/hanoi-4.c

0 → 100644
+52 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define DISKS 4

int n[3], tower[3][DISKS];
char *program_name;

void display (void)
{
  for (int i = 0; i < 3; i++)
    {
      printf ("tower %d: ", i);
      for (int j = 0; j < n[i]; j++)
        printf ("%2d", tower[i][j]);
      printf ("\n");
    }
  printf ("\n");
}

void fatal_error (char *msg)
{
  fprintf (stderr, "%s: %s\n", program_name, msg);
  exit (1);
}

void move (int from, int to, int disks)
{
  if (disks == 1)
    {
      if (n[from] <= 0)
        fatal_error ("trying to move disk from empty tower");
      tower[to][n[to]] = tower[from][n[from] - 1];
      n[to]++;
      n[from]--;
      display ();
    }
}

int main (int argc, char **argv)
{
  program_name = argv[0];
  n[0] = 4;
  tower[0][0] = 3;
  tower[0][1] = 2;
  tower[0][2] = 1;
  tower[0][3] = 0;
  n[1] = 0;
  n[2] = 0;
  display ();
  move (0, 2, 1);
}

20151119/hanoi-5.c

0 → 100644
+59 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define DISKS 4

int n[3], tower[3][DISKS];
char *program_name;

void display (void)
{
  for (int i = 0; i < 3; i++)
    {
      printf ("tower %d: ", i);
      for (int j = 0; j < n[i]; j++)
        printf ("%2d", tower[i][j]);
      printf ("\n");
    }
  printf ("\n");
}

void fatal_error (char *msg)
{
  fprintf (stderr, "%s: %s\n", program_name, msg);
  exit (1);
}

void move (int from, int to, int disks)
{
  if (disks == 1)
    {
      if (n[from] <= 0)
        fatal_error ("trying to move disk from empty tower");
      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, 1);
      move (from, to, disks - 1);
      move (help, to, 1);
    }
}

int main (int argc, char **argv)
{
  program_name = argv[0];
  n[0] = 4;
  tower[0][0] = 3;
  tower[0][1] = 2;
  tower[0][2] = 1;
  tower[0][3] = 0;
  n[1] = 0;
  n[2] = 0;
  display ();
  move (0, 2, DISKS);
}

20151119/hanoi-6.c

0 → 100644
+61 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define DISKS 4

int n[3], tower[3][DISKS];
char *program_name;

void display (void)
{
  for (int i = 0; i < 3; i++)
    {
      printf ("tower %d: ", i);
      for (int j = 0; j < n[i]; j++)
        printf ("%2d", tower[i][j]);
      printf ("\n");
    }
  printf ("\n");
}

void fatal_error (char *msg)
{
  fprintf (stderr, "%s: %s\n", program_name, msg);
  exit (1);
}

void move (int from, int to, int disks)
{
  if (disks == 1)
    {
      if (n[from] <= 0)
        fatal_error ("trying to move disk from empty tower");
      if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1])
        fatal_error ("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, 1);
      move (from, to, disks - 1);
      move (help, to, 1);
    }
}

int main (int argc, char **argv)
{
  program_name = argv[0];
  n[0] = 4;
  tower[0][0] = 3;
  tower[0][1] = 2;
  tower[0][2] = 1;
  tower[0][3] = 0;
  n[1] = 0;
  n[2] = 0;
  display ();
  move (0, 2, DISKS);
}

20151119/hanoi-7.c

0 → 100644
+61 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define DISKS 4

int n[3], tower[3][DISKS];
char *program_name;

void display (void)
{
  for (int i = 0; i < 3; i++)
    {
      printf ("tower %d: ", i);
      for (int j = 0; j < n[i]; j++)
        printf ("%2d", tower[i][j]);
      printf ("\n");
    }
  printf ("\n");
}

void fatal_error (char *msg)
{
  fprintf (stderr, "%s: %s\n", program_name, msg);
  exit (1);
}

void move (int from, int to, int disks)
{
  if (disks == 1)
    {
      if (n[from] <= 0)
        fatal_error ("trying to move disk from empty tower");
      if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1])
        fatal_error ("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 (int argc, char **argv)
{
  program_name = argv[0];
  n[0] = 4;
  tower[0][0] = 3;
  tower[0][1] = 2;
  tower[0][2] = 1;
  tower[0][3] = 0;
  n[1] = 0;
  n[2] = 0;
  display ();
  move (0, 2, DISKS);
}

20151119/hanoi-8.c

0 → 100644
+59 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define DISKS 5

int n[3], tower[3][DISKS];
char *program_name;

void display (void)
{
  for (int i = 0; i < 3; i++)
    {
      printf ("tower %d: ", i);
      for (int j = 0; j < n[i]; j++)
        printf ("%2d", tower[i][j]);
      printf ("\n");
    }
  printf ("\n");
}

void fatal_error (char *msg)
{
  fprintf (stderr, "%s: %s\n", program_name, msg);
  exit (1);
}

void move (int from, int to, int disks)
{
  if (disks == 1)
    {
      if (n[from] <= 0)
        fatal_error ("trying to move disk from empty tower");
      if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1])
        fatal_error ("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 (int argc, char **argv)
{
  program_name = argv[0];
  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);
}

20151119/hanoi-9.c

0 → 100644
+59 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define DISKS 64

int n[3], tower[3][DISKS];
char *program_name;

void display (void)
{
  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");
    }
  printf ("\n");
}

void fatal_error (char *msg)
{
  fprintf (stderr, "%s: %s\n", program_name, msg);
  exit (1);
}

void move (int from, int to, int disks)
{
  if (disks == 1)
    {
      if (n[from] <= 0)
        fatal_error ("trying to move disk from empty tower");
      if (n[to] > 0 && tower[to][n[to] - 1] < tower[from][n[from] - 1])
        fatal_error ("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 (int argc, char **argv)
{
  program_name = argv[0];
  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);
}

20151119/hex-2.c

0 → 100644
+22 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdint.h>

void print_hex (uint32_t x)
{
  if (x > 0)
    {
      print_hex (x / 16);
      int e = x % 16;
      if (e < 10)
        printf ("%d", e);
      else
        printf ("%c", 'a' + e - 10);
    }
}

int main (void)
{
  print_hex (16777226);
  printf ("\n");
  return 0;
}

20151119/hex-3.c

0 → 100644
+22 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdint.h>

void print_hex (uint32_t x)
{
  if (x > 0)
    {
      print_hex (x / 16);
      int e = x % 16;
      if (e < 10)
        printf ("%d", e);
      else
        printf ("%c", 'a' + e - 10);
    }
}

int main (void)
{
  print_hex (0);
  printf ("\n");
  return 0;
}

20151119/hex-4.c

0 → 100644
+24 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdint.h>

void print_hex (uint32_t x)
{
  if (x == 0)
    printf ("0");
  else
    {
      print_hex (x / 16);
      int e = x % 16;
      if (e < 10)
        printf ("%d", e);
      else
        printf ("%c", 'a' + e - 10);
    }
}

int main (void)
{
  print_hex (0);
  printf ("\n");
  return 0;
}

20151119/hex-5.c

0 → 100644
+22 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdint.h>

void print_hex (uint32_t x)
{
  if (x >= 16)
    print_hex (x / 16);
  int e = x % 16;
  if (e < 10)
    printf ("%d", e);
  else
    printf ("%c", 'a' + e - 10);
}

int main (void)
{
  print_hex (16777226);
  printf ("\n");
  print_hex (0);
  printf ("\n");
  return 0;
}

20151119/mainparam-1.c

0 → 100644
+9 −0
Original line number Diff line number Diff line
#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;
}
+347 −0
Original line number Diff line number Diff line
% ainf-20151126.pdf - Lecture Slides on Applied Computer Sciences
% Copyright (C) 2012, 2013, 2015  Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document.  If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document.  If not, see <http://creativecommons.org/licenses/>.

\documentclass[10pt,t]{beamer}

\usepackage{pgslides}
\usepackage{pdftricks}

\newrgbcolor{orange}{0.7 0.2 0.0}

\begin{psinputs}
  \usepackage[latin1]{inputenc}
  \usepackage[german]{babel}
  \usepackage[T1]{fontenc}
  \usepackage{helvet}
  \renewcommand*\familydefault{\sfdefault}
  \usepackage{pstricks,pst-grad,pst-node,pst-plot}
\end{psinputs}

\title{Angewandte Informatik}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{26.\ November 2015}

\begin{document}

\maketitleframe

\sectionnonumber{\inserttitle}

\begin{frame}

  \showsectionnonumber

  \begin{itemize}
    \item[\textbf{1}] \textbf{Einführung}
    \item[\textbf{2}] \textbf{Einführung in C}
    \item[\textbf{3}] \textbf{Bibliotheken}
    \item[\textbf{4}] \textbf{Algorithmen}
      \begin{itemize}
        \item[4.1] Differentialgleichungen
        \color{medgreen}
        \item[4.2] Rekursion
        \color{red}
        \item[4.3] Stack und FIFO
        \item[4.4] Aufwandsabschätzungen
      \end{itemize}
    \color{gray}
    \item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
    \item[\makebox(0,0){\textbf{\raisebox{0.5ex}{\dots}}}]
%    \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke}
  \end{itemize}

\end{frame}

\sectionnonumber{Ergänzungen}
\subsectionnonumber{OpenGL}

\begin{frame}

  \showsectionnonumber
  \showsubsectionnonumber

  \begin{itemize}
    \item
      \textbf{Doppelte Pufferung}\\
      2 "`Bildschirme"': einer zum Zeichnen; einer wird angezeigt\\
      \file{opengl-magic-double.c}, \lstinline{gluSwapBuffers()}
    \item
      \textbf{Im Display-Handler} (\lstinline{draw()}) \textbf{wirklich nur zeichnen!}\\
      Wir haben nicht unter Kontrolle, wann, wie oft oder ob überhaupt\\
      diese Funktion aufgerufen wird.
  \end{itemize}

\end{frame}

\subsectionnonumber{Umgang mit Bibliotheken}

\begin{frame}[fragile]

  \showsectionnonumber
  \showsubsectionnonumber

  \begin{itemize}
    \item
      \textbf{Separates Compilieren}\\
      \begin{lstlisting}[style=terminal,gobble=8]
        $ ¡gcc -c -Wall opengl-magic.c¿
        $ ¡gcc -c -Wall textured-spheres.c¿
        $ ¡gcc -Wall orbit-x.c -lGL -lGLU -lglut \
          opengl-magic.o textured-spheres.o -o orbit-x¿
      \end{lstlisting}
    \item
      Die \textbf{Link-Reihenfolge} kann eine Rolle spielen!\\
      \begin{lstlisting}[style=terminal,gobble=8]
        $ ¡gcc -Wall orbit-x.c \
          opengl-magic.o textured-spheres.o \
          -lGL -lGLU -lglut -o orbit-x¿
      \end{lstlisting}
      Notfalls:
      \begin{lstlisting}[style=terminal,gobble=8]
        $ ¡gcc -Wall orbit-x.c -lGL -lGLU -lglut \
          opengl-magic.o textured-spheres.o \
          -lGL -lGLU -lglut -o orbit-x¿
      \end{lstlisting}
  \end{itemize}

\end{frame}

\subsectionnonumber{Parameter des Hauptprogramms}

\begin{frame}[fragile]
  \showsectionnonumber
  \showsubsectionnonumber

  \medskip

  \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}

\section{Einführung}
\section{Einführung in C}
\section{Bibliotheken}

\section{Algorithmen}
\subsection{Differentialgleichungen}
\subsection{Rekursion}
\subsection{Stack und FIFO}

\begin{frame}[fragile]

  \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>{\vector(1,-1){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>{\vector(1,-1){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>{\vector(1,-1){0.45}}}
        \put(1.0,1.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}}

        \put(4.55,1.05){\only<4>{\vector(1,1){0.45}}}
        \put(5.00,1.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 3}}}

        \put(3.55,1.05){\only<5>{\vector(1,1){0.45}}}
        \put(4.00,1.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}}

        \put(2.55,1.05){\only<6>{\vector(1,1){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>{\vector(1,-1){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>{\vector(1,-1){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>{\vector(1,-1){0.45}}}
        \put(2.0,3.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}}

        \put(3.55,3.05){\only<4>{\vector(1,1){0.45}}}
        \put(4.00,3.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 137}}}

        \put(3.55,2.05){\only<5>{\vector(1,1){0.45}}}
        \put(4.00,2.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}}

        \put(3.55,1.05){\only<6>{\vector(1,1){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}

\subsection{Aufwandsabschätzungen}

\begin{frame}[fragile]

  \showsubsection

  Beispiel: Sortieralgorithmen

  \begin{itemize}
    \item
      Maximum suchen\only<2->{: $\mathcal{O}(n)$}
      \hfill
      \begin{minipage}[t]{5.6cm}
        \vspace*{-1.3cm}
        \begin{pdfpic}
          \psset{unit=0.5pt}
          \begin{pspicture}(-20,-20)(250,200)
            \psline[arrows=->](-10,0)(200,0)
            \psline[arrows=->](0,-10)(0,200)
            \psplot[plotpoints=200]{1}{125}{2 x 0.06 mul exp}
            \put(70,190){\mbox{$g(n) \sim 2^n$}}
            \psplot[plotpoints=200]{0}{190}{x x mul 0.005 mul}
            \put(190,190){\mbox{$g(n) \sim n^2$}}
            \psplot[plotpoints=200]{1}{190}{x ln x mul 0.1 mul}
            \put(195,100){\mbox{$g(n) \sim n \log n$}}
            \psplot[plotpoints=200]{0}{190}{x 0.4 mul}
            \put(195,75){\mbox{$g(n) \sim n$}}
            \psplot[plotpoints=200]{1}{190}{x ln 10 mul}
            \put(195,50){\mbox{$g(n) \sim \log n$}}
            \put(205,0){\makebox(0,0)[l]{$n$}}
            \put(-10,210){\makebox(0,0)[l]{$g(n)$}}
            \psplot[plotpoints=200]{1}{190}{30}
            \put(195,25){\mbox{$g(n) \sim 1$}}
          \end{pspicture}
        \end{pdfpic}
        \small
        \begin{description}\itemsep0pt
          \item[$n$:] Eingabedaten
          \item[$g(n)$:] Rechenzeit
        \end{description}
        \vspace*{-10cm}\strut
      \end{minipage}
    \pause[3]
    \item
      Maximum ans Ende tauschen\\
      \textarrow\ Selectionsort\pause: $\mathcal{O}(n^2)$
    \pause
    \item
      Während Maximumsuche prüfen,\\abbrechen, falls schon sortiert\\
      \textarrow\ Bubblesort\pause: $\mathcal{O}(n)$ bis $\mathcal{O}(n^2)$
    \pause
    \item
      Rekursiv sortieren\\
      \textarrow\ Quicksort\pause: $\mathcal{O}(n\log n)$ bis $\mathcal{O}(n^2)$\hfill
  \end{itemize}

\end{frame}

\sectionnonumber{\inserttitle}

\begin{frame}

  \showsectionnonumber

  \begin{itemize}
    \item[\textbf{1}] \textbf{Einführung}
    \item[\textbf{2}] \textbf{Einführung in C}
    \item[\textbf{3}] \textbf{Bibliotheken}
    \item[\textbf{4}] \textbf{Algorithmen}
      \begin{itemize}
        \item[4.1] Differentialgleichungen
        \item[4.2] Rekursion
        \color{medgreen}
        \item[4.3] Stack und FIFO
        \item[4.4] Aufwandsabschätzungen
      \end{itemize}
    \item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
    \color{gray}
    \item[\makebox(0,0){\textbf{\raisebox{0.5ex}{\dots}}}]
%    \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke}
  \end{itemize}

\end{frame}

\end{document}
+136 −0
Original line number Diff line number Diff line
% ainf-uebung-20151126.pdf - Exercises on Applied Computer Sciences
% Copyright (C) 2013, 2015  Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document.  If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document.  If not, see <http://creativecommons.org/licenses/>.

\documentclass[a4paper]{article}

\usepackage{pgscript}
\usepackage{enumerate}

\newcounter{exercise}
\newcommand{\exercise}[1]{\addtocounter{exercise}{1}\subsection*{Aufgabe \arabic{exercise}: #1}}

\newcounter{points}
\newcommand{\onepoint}{(1 Punkt)\addtocounter{points}{1}}
\newcommand{\points}[1]{(#1 Punkte)\addtocounter{points}{#1}}

\begin{document}

  \thispagestyle{empty}

  \section*{Angewandte Informatik\\Übungsaufgaben -- 26.\ November 2015}

  \subsection*{Koordinaten-FIFO}

  Implementieren Sie einen FIFO für Koordinaten-Paare.\\
  Koordinatenpaare sollen "`hintereinander eingereiht"' werden.

  \begin{itemize}
    \item
      Eine Funktion \lstinline{push (int x, int y)}
      schiebt sie in den FIFO.
    \item
      Eine Funktion \lstinline{pop (int &x, int &y)}
      liest und entfernt sie wieder aus dem FIFO.
    \item
      Eine Funktion \lstinline{dump ()}
      gibt den Inhalt des FIFO auf dem Bildschirm aus.
  \end{itemize}
  \points{10}

\iffalse

  \exercise{Arrays mit Zahlen}

  \begin{minipage}[t]{0.5\textwidth}
    Wir betrachten das folgende Programm:
    \begin{lstlisting}[gobble=6]
      #include <stdio.h>

      void f (int *s0, int *s1)
      {
        while (*s0 >= 0)
        {
          int *s = s1;
          while (*s >= 0)
            if (*s0 == *s++)
              printf ("%d ", *s0);
          s0++;
        }
        printf ("\n");
      }

      int main (void)
      {
        int a[] = { 10, 4, 3, 7, 12, 0, 1, -1 };
        int b[] = { 7, 14, 0, 8, 9, 22, 10, -1 };
        f (a, b);
        return 0;
      }
    \end{lstlisting}
  \end{minipage}\hfill
  \begin{minipage}[t]{0.5\textwidth}
    \vspace*{-\bigskipamount}
    \begin{enumerate}[\quad(a)]
      \item
        Was bewirkt die Funktion \lstinline{f} und warum?\\
        \points{4}
      \item
        Von welcher Ordnung (Landau-Symbol) ist die Funktion und warum?

        Wir beziehen uns hierbei auf die Anzahl der Vergleiche
        in Abhängigkeit von der Länge der Eingabedaten \lstinline{s0} und \lstinline{s1}.
        Für die Rechnung dürfen Sie beide Längen mit $n$ gleichsetzen,
        obwohl sie normalerweise nicht gleich sind.
        \points{2}
      \item
        Was passiert, wenn Sie beim Aufruf der Funktion für einen der
        Parameter den Wert \lstinline{NULL} übergeben und warum?
        \points{2}
      \item
        Was passiert, wenn Sie das Hauptprogramm wie folgt abändern
        (\file{aufgabe-1d.c}) und warum?
        \begin{lstlisting}[gobble=8]
          int main (void)
          {
            int a[] = { 10, 4, 3, 7, 12, 0, 1 };
            int b[] = { 7, 14, 0, 8, 9, 22, 10 };
            f (a, b);
            return 0;
          }
        \end{lstlisting}
        \points{2}
      \item
        Beschreiben Sie -- in Worten und/oder als C-Quelltext --, wie
        sich die Funktion \lstinline{f} effizienter gestalten läßt,
        wenn man die ihr übergebenen Arrays \lstinline{s0} und
        \lstinline{s1} als sortiert voraussetzt.\\
        \points{5}
      \item
        Von welcher
        Ordnung (Landau-Symbol) ist Ihre effizientere Version der Funktion und warum?\\
        \points{2}
    \end{enumerate}
  \end{minipage}

\fi

\end{document}

20151126/aufgabe-2.c

0 → 100644
+42 −0
Original line number Diff line number Diff line
#include <stdio.h>

#define ORIGINYEAR 1980

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 days = (2008 - ORIGINYEAR) * 365 + 8 + 365;  /* 2008-12-31 */

  int year = ORIGINYEAR;

  while (days > 365)
    {
      if (IsLeapYear (year))
        {
          if (days > 366)
            {
              days -= 366;
              year += 1;
            }
        }
      else
        {
          days -= 365;
          year += 1;
        }
    }

  printf ("day #%d in the year %d\n", days, year);
  return 0;
}

20151126/fifo-1.c

0 → 100644
+67 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define FIFO_SIZE 42

int fifo[FIFO_SIZE];
int fifo_pointer = 0;

void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x)
{
  if (fifo_pointer < 0 || fifo_pointer >= FIFO_SIZE)
    fatal_error ("fifo overflow");
  else
    fifo[fifo_pointer++] = x;
}

int pop (void)
{
  if (fifo_pointer < 1 || fifo_pointer > FIFO_SIZE)
    {
      fatal_error ("fifo underflow");
      return 0;
    }
  else
    return fifo[--fifo_pointer];
}

void dump (void)
{
  if (fifo_pointer < 0)
    fatal_error ("fifo underflow");
  else if (fifo_pointer >= FIFO_SIZE)
    fatal_error ("fifo overflow");
  else if (fifo_pointer == 0)
    printf ("fifo is empty\n");
  else
    {
      printf ("fifo:");
      for (int i = 0; i < fifo_pointer; i++)
        printf (" %d", fifo[i]);
      printf ("\n");
    }
}

int main (void)
{
  dump ();
  push (7);
  dump ();
  push (13);
  dump ();
  push (42);
  dump ();
  printf ("%d\n", pop ());  /* 42 */
  dump ();
  printf ("%d\n", pop ());  /* 13 */
  dump ();
  printf ("%d\n", pop ());  /*  7 */
  dump ();
  return 0;
}

20151126/fifo-2.c

0 → 100644
+73 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define FIFO_SIZE 42

int fifo[FIFO_SIZE];
int fifo_pointer = 0;

void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x)
{
  if (fifo_pointer < 0 || fifo_pointer >= FIFO_SIZE)
    fatal_error ("fifo overflow");
  else
    fifo[fifo_pointer++] = x;
}

int pop (void)
{
  if (fifo_pointer < 1 || fifo_pointer > FIFO_SIZE)
    {
      fatal_error ("fifo underflow");
      return 0;
    }
  else
    {
      int value = fifo[0];
      for (int i = 1; i < fifo_pointer; i++)
        fifo[i - 1] = fifo[i];
      fifo_pointer--;
      return value;
    }
}

void dump (void)
{
  if (fifo_pointer < 0)
    fatal_error ("fifo underflow");
  else if (fifo_pointer >= FIFO_SIZE)
    fatal_error ("fifo overflow");
  else if (fifo_pointer == 0)
    printf ("fifo is empty\n");
  else
    {
      printf ("fifo:");
      for (int i = 0; i < fifo_pointer; i++)
        printf (" %d", fifo[i]);
      printf ("\n");
    }
}

int main (void)
{
  dump ();
  push (7);
  dump ();
  push (13);
  dump ();
  push (42);
  dump ();
  printf ("%d\n", pop ());  /* 42 */
  dump ();
  printf ("%d\n", pop ());  /* 13 */
  dump ();
  printf ("%d\n", pop ());  /*  7 */
  dump ();
  return 0;
}

20151126/fifo-3.c

0 → 100644
+70 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define FIFO_SIZE 42

int fifo[FIFO_SIZE];
int fifo_read_pointer = 0;
int fifo_write_pointer = 0;

void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x)
{
  if (fifo_write_pointer < 0 || fifo_write_pointer >= FIFO_SIZE)
    fatal_error ("fifo overflow");
  else
    fifo[fifo_write_pointer++] = x;
}

int pop (void)
{
  if (fifo_read_pointer < 0 || fifo_read_pointer >= fifo_write_pointer)
    {
      fatal_error ("fifo underflow");
      return 0;
    }
  else
    return fifo[fifo_read_pointer++];
}

void dump (void)
{
/*
  if (fifo_pointer < 0)
    fatal_error ("fifo underflow");
  else if (fifo_pointer >= FIFO_SIZE)
    fatal_error ("fifo overflow");
  else if (fifo_pointer == 0)
    printf ("fifo is empty\n");
  else
    {
      printf ("fifo:");
      for (int i = 0; i < fifo_pointer; i++)
        printf (" %d", fifo[i]);
      printf ("\n");
    }
*/
}

int main (void)
{
  dump ();
  push (7);
  dump ();
  push (13);
  dump ();
  push (42);
  dump ();
  printf ("%d\n", pop ());  /* 42 */
  dump ();
  printf ("%d\n", pop ());  /* 13 */
  dump ();
  printf ("%d\n", pop ());  /*  7 */
  dump ();
  return 0;
}

20151126/fifo-4.c

0 → 100644
+62 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define FIFO_SIZE 42

int fifo[FIFO_SIZE];
int fifo_read_pointer = 0;
int fifo_write_pointer = 0;

void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x)
{
  if (fifo_write_pointer < 0 || fifo_write_pointer >= FIFO_SIZE)
    fatal_error ("push: fifo inconsistence");
  else
    {
      fifo[fifo_write_pointer++] = x;
      if (fifo_write_pointer >= FIFO_SIZE)
        fifo_write_pointer = 0;
      if (fifo_write_pointer == fifo_read_pointer)
        fatal_error ("fifo overflow");
    }
}

int pop (void)
{
  if (fifo_read_pointer < 0 || fifo_read_pointer >= FIFO_SIZE)
    {
      fatal_error ("pop: fifo inconsistence");
      return 0;
    }
  else if (fifo_read_pointer == fifo_write_pointer)
    {
      fatal_error ("fifo underflow");
      return 0;
    }
  else
    {
      int value = fifo[fifo_read_pointer++];
      if (fifo_read_pointer >= FIFO_SIZE)
        fifo_read_pointer = 0;
      return value;
    }
}

int main (void)
{
  int value = 42;
  for (int i = 0; i < 7; i++)
    {
      for (int j = 0; j < 10; j++)
        push (value++);
      for (int j = 0; j < 10; j++)
        printf ("%d\n", pop ());
    }
  return 0;
}

20151126/loesung-2-0.c

0 → 100644
+44 −0
Original line number Diff line number Diff line
#include <stdio.h>

#define ORIGINYEAR 1980

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 days = (2008 - ORIGINYEAR) * 365 + 8 + 365;  /* 2008-12-31 */

  int year = ORIGINYEAR;

  while (days > 365)
    {
      if (IsLeapYear (year))
        {
          if (days > 366)
            {
              days -= 366;
              year += 1;
            }
          else
            break;
        }
      else
        {
          days -= 365;
          year += 1;
        }
    }

  printf ("day #%d in the year %d\n", days, year);
  return 0;
}

20151126/loesung-2-1.c

0 → 100644
+39 −0
Original line number Diff line number Diff line
#include <stdio.h>

#define ORIGINYEAR 1980

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 days = (2008 - ORIGINYEAR) * 365 + 8 + 365;  /* 2008-12-31 */

  int year = ORIGINYEAR;

  while (days > DaysInYear (year))
    {
      days -= DaysInYear (year);
      year += 1;
    }

  printf ("day #%d in the year %d\n", days, year);
  return 0;
}

20151126/loesung-2-2.c

0 → 100644
+42 −0
Original line number Diff line number Diff line
#include <stdio.h>

#define ORIGINYEAR 1980

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 days = (2008 - ORIGINYEAR) * 365 + 8 + 365;  /* 2008-12-31 */

  int year = ORIGINYEAR;
  int days_in_year;

  days_in_year = DaysInYear (year);
  while (days > days_in_year)
    {
      days -= days_in_year;
      year += 1;
      days_in_year = DaysInYear (year);
    }

  printf ("day #%d in the year %d\n", days, year);
  return 0;
}

20151126/loesung-2-3.c

0 → 100644
+40 −0
Original line number Diff line number Diff line
#include <stdio.h>

#define ORIGINYEAR 1980

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 days = (2008 - ORIGINYEAR) * 365 + 8 + 365;  /* 2008-12-31 */

  int year = ORIGINYEAR;
  int days_in_year;

  while (days > (days_in_year = DaysInYear (year)))
    {
      days -= days_in_year;
      year += 1;
    }

  printf ("day #%d in the year %d\n", days, year);
  return 0;
}
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>
#include "stack.h"

char screen[WIDTH][HEIGHT];

//Setze alle Einträge in display auf c
void clear (char c)
{
 for (int i=0;i<WIDTH;i++)
  {
   for (int j=0;j<HEIGHT;j++)
    {
     screen[i][j]=c;
    }
  }
}

//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
 screen[x][y]=c;
}

//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
  char c=screen[x][y];
  return c;
}

//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
 if (getPoint(x,y)==o)
  {
   putPoint(x,y,c);
   push(x+1,y);
   push(x-1,y);
   push(x,y+1);
   push(x,y-1);
  }
}

//Gib display aus
void display (void)
{
 for (int i=0;i<HEIGHT;i++)
  {
   for (int j=0;j<WIDTH;j++)
    {
     printf("%c",screen[j][i]);
    }
   printf("\n");
  }
}
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>
#include "stack.h"

char screen[WIDTH][HEIGHT];

//Setze alle Einträge in display auf c
void clear (char c)
{
 for (int i=0;i<WIDTH;i++)
  {
   for (int j=0;j<HEIGHT;j++)
    {
     screen[i][j]=c;
    }
  }
}

//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
 screen[x][y]=c;
}

//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
  char c=screen[x][y];
  return c;
}

//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
  push (x, y);
  while (!stack_empty ())
    {
      pop (&x, &y);
      if (getPoint (x, y) == o)
	{
	  putPoint (x, y, c);
	  push (x + 1, y);
	  push (x - 1, y);
	  push (x, y + 1);
	  push (x, y - 1);
	}
    }
}

//Gib display aus
void display (void)
{
 for (int i=0;i<HEIGHT;i++)
  {
   for (int j=0;j<WIDTH;j++)
    {
     printf("%c",screen[j][i]);
    }
   printf("\n");
  }
}
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>

char screen[WIDTH][HEIGHT];

//Setze alle Einträge in display auf c
void clear (char c)
{
 for (int i=0;i<WIDTH;i++)
  {
   for (int j=0;j<HEIGHT;j++)
    {
     screen[i][j]=c;
    }
  }
}

//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
 screen[x][y]=c;
}

//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
  char c=screen[x][y];
  return c;
}

//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
 if (getPoint(x,y)==o)
  {
   putPoint(x,y,c);
   fill(x+1,y,c,o);
   fill(x-1,y,c,o);
   fill(x,y+1,c,o);
   fill(x,y-1,c,o);
  }
}

//Gib display aus
void display (void)
{
 for (int i=0;i<HEIGHT;i++)
  {
   for (int j=0;j<WIDTH;j++)
    {
     printf("%c",screen[j][i]);
    }
   printf("\n");
  }
}
Original line number Diff line number Diff line
#define HEIGHT 20
#define WIDTH 15

extern void clear(char c);
extern void fill(int x, int y, char c, char o);
extern void putPoint(int x, int y, char c);
extern char getPoint(int x, int y);
extern void display(void);
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>
#include "stack.h"

char screen[WIDTH][HEIGHT];

//Setze alle Einträge in display auf c
void clear (char c)
{
 for (int i=0;i<WIDTH;i++)
  {
   for (int j=0;j<HEIGHT;j++)
    {
     screen[i][j]=c;
    }
  }
}

//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
 screen[x][y]=c;
}

//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
  char c=screen[x][y];
  return c;
}

//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
  push (x, y);
  while (!stack_empty ())
    {
      pop (&x, &y);
      if (getPoint (x, y) == o)
	{
	  putPoint (x, y, c++);
	  push (x + 1, y);
	  push (x - 1, y);
	  push (x, y + 1);
	  push (x, y - 1);
	}
    }
}

//Gib display aus
void display (void)
{
 for (int i=0;i<HEIGHT;i++)
  {
   for (int j=0;j<WIDTH;j++)
    {
     printf("%c",screen[j][i]);
    }
   printf("\n");
  }
}
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>

char screen[WIDTH][HEIGHT];

//Setze alle Einträge in display auf c
void clear (char c)
{
 for (int i=0;i<WIDTH;i++)
  {
   for (int j=0;j<HEIGHT;j++)
    {
     screen[i][j]=c;
    }
  }
}

//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
 screen[x][y]=c;
}

//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
  char c=screen[x][y];
  return c;
}

//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
 if (getPoint(x,y)==o)
  {
   putPoint(x,y,c);
   fill(x+1,y,c,o);
   fill(x-1,y,c,o);
   fill(x,y+1,c,o);
   fill(x,y-1,c,o);
  }
}

//Gib display aus
void display (void)
{
 for (int i=0;i<HEIGHT;i++)
  {
   for (int j=0;j<WIDTH;j++)
    {
     printf("%c",screen[j][i]);
    }
   printf("\n");
  }
}
+56 −0
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>

char screen[WIDTH][HEIGHT];

//Setze alle Einträge in display auf c
void clear (char c)
{
 for (int i=0;i<WIDTH;i++)
  {
   for (int j=0;j<HEIGHT;j++)
    {
     screen[i][j]=c;
    }
  }
}

//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
 screen[x][y]=c;
}

//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
  char c=screen[x][y];
  return c;
}

//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
 if (getPoint(x,y)==o)
  {
   putPoint(x,y,c);
   fill(x+1,y,c,o);
   fill(x-1,y,c,o);
   fill(x,y+1,c,o);
   fill(x,y-1,c,o);
  }
}

//Gib display aus
void display (void)
{
 for (int i=0;i<HEIGHT;i++)
  {
   for (int j=0;j<WIDTH;j++)
    {
     printf("%c",screen[i][j]);
    }
   printf("\n");
  }
}
Original line number Diff line number Diff line
#define HEIGHT 5
#define WIDTH 10

extern void clear(char c);
extern void fill(int x, int y, char c, char o);
extern void putPoint(int x, int y, char c);
extern char getPoint(int x, int y);
extern void display(void);
+1 −0
Original line number Diff line number Diff line
while true; do clear; ./test; sleep 1; clear; ./test-pg; sleep 1; done

20151126/orzol/stack.c

0 → 100644
+62 −0
Original line number Diff line number Diff line
#include "stack.h"

typedef struct
{
  int x, y;
}
coordinate;

coordinate stack[STACK_SIZE];
int stack_pointer = 0;

int stack_empty (void)
{
  return !stack_pointer;
}

void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x, int y)
{
  if (stack_pointer < 0 || stack_pointer >= STACK_SIZE)
    fatal_error ("stack overflow");
  else
    {
      stack[stack_pointer].x = x;
      stack[stack_pointer].y = y;
      stack_pointer++;
    }
}

void pop (int *x, int *y)
{
  if (stack_pointer < 1 || stack_pointer > STACK_SIZE)
    fatal_error ("stack underflow");
  else
    {
      --stack_pointer;
      *x = stack[stack_pointer].x;
      *y = stack[stack_pointer].y;
    }
}

void dump (void)
{
  if (stack_pointer < 0)
    fatal_error ("stack underflow");
  else if (stack_pointer >= STACK_SIZE)
    fatal_error ("stack overflow");
  else if (stack_pointer == 0)
    printf ("stack is empty\n");
  else
    {
      printf ("stack:");
      for (int i = 0; i < stack_pointer; i++)
        printf (" (%d,%d)", stack[i].x, stack[i].y);
      printf ("\n");
    }
}

20151126/orzol/stack.h

0 → 100644
+9 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define STACK_SIZE (7 * 42)

extern int stack_empty (void);
extern void push (int x, int y);
extern void pop (int *x, int *y);
extern void dump (void);
+10 −0
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>

int main (void)
{
  clear ('.');
  putPoint (3, 1, '*');
  display ();
  return 0;
}
+10 −0
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>

int main (void)
{
  clear ('.');
  putPoint (10, 1, '*');
  display ();
  return 0;
}
+10 −0
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>

int main (void)
{
  clear ('.');
  putPoint (3, 6, '*');
  display ();
  return 0;
}
+23 −0
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>

int main (void)
{
  clear ('.');
  for (int i = 3; i < 13; i++)
    putPoint (i, 3, '*');
  for (int j = 4; j < 11; j++)
    putPoint (2, j, '*');
  putPoint (13, 4, '*');
  putPoint (12, 5, '*');
  putPoint (12, 6, '*');
  putPoint (13, 7, '*');
  putPoint (14, 8, '*');
  putPoint (14, 9, '*');
  putPoint (13, 10, '*');
  for (int i = 3; i < 13; i++)
    putPoint (i, 11, '*');
  fill (5, 5, '%', '.');
  display ();
  return 0;
}
+23 −0
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>

int main (void)
{
  clear ('.');
  for (int i = 3; i < 13; i++)
    putPoint (i, 3, '*');
  for (int j = 4; j < 11; j++)
    putPoint (2, j, '*');
  putPoint (13, 4, '*');
  putPoint (12, 5, '*');
  putPoint (12, 6, '*');
  putPoint (13, 7, '*');
  putPoint (14, 8, '*');
  putPoint (14, 9, '*');
  putPoint (13, 10, '*');
  for (int i = 3; i < 13; i++)
    putPoint (i, 11, 'A');
  fill (5, 5, '%', '.');
  display ();
  return 0;
}

20151126/orzol/test.c

0 → 100644
+22 −0
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek.h"
#include <stdio.h>

int main(void)
{
clear(' ');
display();
printf("______________\n");
putPoint(1,1,'A');
display();
printf("______________\n");
fill(2,3,'*',' ');
display();
printf("______________\n");
putPoint(3,4,'B');
display();




return 0;
}

20151126/pgscript.sty

0 → 120000
+1 −0
Original line number Diff line number Diff line
../common/pgscript.sty
 No newline at end of file

20151126/pgslides.sty

0 → 120000
+1 −0
Original line number Diff line number Diff line
../common/pgslides.sty
 No newline at end of file

20151126/stack-0.c

0 → 100644
+12 −0
Original line number Diff line number Diff line
#include <stdio.h>

int main (void)
{
  push (7);
  push (13);
  push (42);
  printf ("%d\n", pop ());  /* 42 */
  printf ("%d\n", pop ());  /* 13 */
  printf ("%d\n", pop ());  /*  7 */
  return 0;
}

20151126/stack-1.c

0 → 100644
+21 −0
Original line number Diff line number Diff line
#include <stdio.h>

void push (int x)
{
}

int pop (void)
{
  return 0;
}

int main (void)
{
  push (7);
  push (13);
  push (42);
  printf ("%d\n", pop ());  /* 42 */
  printf ("%d\n", pop ());  /* 13 */
  printf ("%d\n", pop ());  /*  7 */
  return 0;
}

20151126/stack-2.c

0 → 100644
+27 −0
Original line number Diff line number Diff line
#include <stdio.h>

#define STACK_SIZE 42

int stack[STACK_SIZE];
int stack_pointer = 0;

void push (int x)
{
  stack[stack_pointer++] = x;
}

int pop (void)
{
  return 0;
}

int main (void)
{
  push (7);
  push (13);
  push (42);
  printf ("%d\n", pop ());  /* 42 */
  printf ("%d\n", pop ());  /* 13 */
  printf ("%d\n", pop ());  /*  7 */
  return 0;
}

20151126/stack-3.c

0 → 100644
+37 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define STACK_SIZE 42

int stack[STACK_SIZE];
int stack_pointer = 0;

void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x)
{
  if (stack_pointer < 0 || stack_pointer >= STACK_SIZE)
    fatal_error ("stack overflow");
  else
    stack[stack_pointer++] = x;
}

int pop (void)
{
  return 0;
}

int main (void)
{
  push (7);
  push (13);
  push (42);
  printf ("%d\n", pop ());  /* 42 */
  printf ("%d\n", pop ());  /* 13 */
  printf ("%d\n", pop ());  /*  7 */
  return 0;
}

20151126/stack-4.c

0 → 100644
+37 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define STACK_SIZE 42

int stack[STACK_SIZE];
int stack_pointer = 0;

void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x)
{
  if (stack_pointer < 0 || stack_pointer >= STACK_SIZE)
    fatal_error ("stack overflow");
  else
    stack[stack_pointer++] = x;
}

int pop (void)
{
  return 0;
}

int main (void)
{
  push (7);
  push (13);
  push (42);
  printf ("%d\n", pop ());  /* 42 */
  printf ("%d\n", pop ());  /* 13 */
  printf ("%d\n", pop ());  /*  7 */
  return 0;
}

20151126/stack-5.c

0 → 100644
+40 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define STACK_SIZE 42

int stack[STACK_SIZE];
int stack_pointer = 0;

void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x)
{
  if (stack_pointer < 0 || stack_pointer >= STACK_SIZE)
    fatal_error ("stack overflow");
  else
    stack[stack_pointer++] = x;
}

int pop (void)
{
  if (stack_pointer < 1 || stack_pointer > STACK_SIZE)
    fatal_error ("stack underflow");
  else
    return stack[--stack_pointer];
}

int main (void)
{
  push (7);
  push (13);
  push (42);
  printf ("%d\n", pop ());  /* 42 */
  printf ("%d\n", pop ());  /* 13 */
  printf ("%d\n", pop ());  /*  7 */
  return 0;
}

20151126/stack-6.c

0 → 100644
+43 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define STACK_SIZE 42

int stack[STACK_SIZE];
int stack_pointer = 0;

void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x)
{
  if (stack_pointer < 0 || stack_pointer >= STACK_SIZE)
    fatal_error ("stack overflow");
  else
    stack[stack_pointer++] = x;
}

int pop (void)
{
  if (stack_pointer < 1 || stack_pointer > STACK_SIZE)
    {
      fatal_error ("stack underflow");
      return 0;
    }
  else
    return stack[--stack_pointer];
}

int main (void)
{
  push (7);
  push (13);
  push (42);
  printf ("%d\n", pop ());  /* 42 */
  printf ("%d\n", pop ());  /* 13 */
  printf ("%d\n", pop ());  /*  7 */
  return 0;
}

20151126/stack-7.c

0 → 100644
+40 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define STACK_SIZE 42

int stack[STACK_SIZE];
int stack_pointer = 0;

__attribute__ ((noreturn)) void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x)
{
  if (stack_pointer < 0 || stack_pointer >= STACK_SIZE)
    fatal_error ("stack overflow");
  else
    stack[stack_pointer++] = x;
}

int pop (void)
{
  if (stack_pointer < 1 || stack_pointer > STACK_SIZE)
    fatal_error ("stack underflow");
  else
    return stack[--stack_pointer];
}

int main (void)
{
  push (7);
  push (13);
  push (42);
  printf ("%d\n", pop ());  /* 42 */
  printf ("%d\n", pop ());  /* 13 */
  printf ("%d\n", pop ());  /*  7 */
  return 0;
}

20151126/stack-8.c

0 → 100644
+67 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define STACK_SIZE 42

int stack[STACK_SIZE];
int stack_pointer = 0;

void fatal_error (char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

void push (int x)
{
  if (stack_pointer < 0 || stack_pointer >= STACK_SIZE)
    fatal_error ("stack overflow");
  else
    stack[stack_pointer++] = x;
}

int pop (void)
{
  if (stack_pointer < 1 || stack_pointer > STACK_SIZE)
    {
      fatal_error ("stack underflow");
      return 0;
    }
  else
    return stack[--stack_pointer];
}

void dump (void)
{
  if (stack_pointer < 0)
    fatal_error ("stack underflow");
  else if (stack_pointer >= STACK_SIZE)
    fatal_error ("stack overflow");
  else if (stack_pointer == 0)
    printf ("stack is empty\n");
  else
    {
      printf ("stack:");
      for (int i = 0; i < stack_pointer; i++)
        printf (" %d", stack[i]);
      printf ("\n");
    }
}

int main (void)
{
  dump ();
  push (7);
  dump ();
  push (13);
  dump ();
  push (42);
  dump ();
  printf ("%d\n", pop ());  /* 42 */
  dump ();
  printf ("%d\n", pop ());  /* 13 */
  dump ();
  printf ("%d\n", pop ());  /*  7 */
  dump ();
  return 0;
}

20151203/Makefile

0 → 100644
+606 −0
Original line number Diff line number Diff line
# Hey Emacs, this is a -*- makefile -*-
###############################################################################
# RP6 MAKEFILE FOR WinAVR
# Based on WinAVR Sample makefile written by Eric B. Weddington,
# Jörg Wunsch, et al.
#
#
# YOU NEED TO EDIT SOME SMALL THINGS IN THIS FILE IF YOU WANT TO USE
# IT FOR YOUR OWN PROJECTS!
# THESE LINES ARE ALL AT THE TOP OF THIS FILE AND MARKED VERY CLEARLY !
# BETTER DO NOT EDIT ANYTHING ELSE!
#
# To compile everything you can simply type "make all" on a command line in
# this directory or simply use the supplied batch files!
# To remove all the temporary files the compiler has generated you can use
# "make clean"
# See end of this file and "make" user manual for more details!
#
#
# Note: Everything behind a '#' is interpreted as a comment in this file!
#
###############################################################################




###############################################################################
# Target file name (without extension).
# This is the name of your main C source file! Do NOT append the ".c"!
# Example: Let's assume your main source file is "RP6Base_MyProgram.c", then
# you would write: TARGET = RP6Base_MyProgram

TARGET = blink-3

###############################################################################



###############################################################################
# Specify relative path to RP6 library files here.
# This is "../lib" usually.

RP6_LIB_PATH=../RP6Lib
RP6_LIB_PATH_OTHERS= $(RP6_LIB_PATH)/RP6base $(RP6_LIB_PATH)/RP6common

###############################################################################


#------------------------------------------------
# Main Source file is _automatically_ added here:
SRC = $(TARGET).c

###############################################################################
# If there is more than one source file, append them here separated by spaces.
# Usually you have to add the Library files here! (ONLY add c files "*.c" here,
# NO header files "*.h"!)
# Don't forget to add relative paths!

#SRC += $(RP6_LIB_PATH)/RP6base/RP6RobotBaseLib.c
#SRC += $(RP6_LIB_PATH)/RP6common/RP6uart.c
##SRC += $(RP6_LIB_PATH)/RP6common/RP6I2CmasterTWI.c

# You can also wrap lines by appending a backslash to the end of the line
# like this:
#SRC += xyz.c \
#abc.c \
#asdf.c
#
###############################################################################


###############################################################################
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)

OPT = s

###############################################################################











#                                                                             #
#-----------------------------------------------------------------------------#
###############################################################################
######-------------------------------------------------------------------######
###### DO NOT EDIT ANYTHING BELOW IF YOU DO NOT KNOW WHAT YOU ARE DOING! ######
######-------------------------------------------------------------------######
###############################################################################
#-----------------------------------------------------------------------------#
#                                                                             #














# MCU name - atmega32 for RP6 Base and Processor Expansion
MCU = atmega32


# Output format. (can be srec, ihex, binary)
FORMAT = ihex


# List Assembler source files here.
#     Make them always end in a capital .S.  Files ending in a lowercase .s
#     will not be considered source files but generated files (assembler
#     output from the compiler), and will be deleted upon "make clean"!
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
#     it will preserve the spelling of the filenames, and gcc itself does
#     care about how the name is spelled on its command-line.
ASRC =


# Debugging format.
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
#     AVR Studio 4.10 requires dwarf-2.
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
DEBUG = dwarf-2


# List any extra directories to look for include files here.
#     Each directory must be seperated by a space.
#     Use forward slashes for directory separators.
#     For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = $(RP6_LIB_PATH) $(RP6_LIB_PATH_OTHERS)


# Compiler flag to set the C Standard level.
#     c89   = "ANSI" C
#     gnu89 = c89 plus GCC extensions
#     c99   = ISO C99 standard (not yet fully implemented)
#     gnu99 = c99 plus GCC extensions
CSTANDARD = -std=gnu99




# DO NOT USE THIS FOR RP6 PROJECTS!
#
# Processor frequency.
#     This will define a symbol, F_CPU, in all source code files equal to the
#     processor frequency. You can then use this symbol in your source code to
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
#     automatically to create a 32-bit value in your source code.
# F_CPU = 8000000

# Place -D or -U options here
CDEFS = -DDEBUG_MEASURE_DUTY_CYCLE 
# -DF_CPU=$(F_CPU)UL
# uncommented - caused a compile problem.




# Place -I options here
CINCS =



#---------------- Compiler Options ----------------
#  -g*:          generate debugging information
#  -O*:          optimization level
#  -f...:        tuning, see GCC manual and avr-libc documentation
#  -Wall...:     warning level
#  -Wa,...:      tell GCC to pass this to the assembler.
#    -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes -Werror
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)


#---------------- Assembler Options ----------------
#  -Wa,...:   tell GCC to pass this to the assembler.
#  -ahlms:    create listing
#  -gstabs:   have the assembler create line number information; note that
#             for use in COFF files, additional information about filenames
#             and function names needs to be present in the assembler source
#             files -- see avr-libc docs [FIXME: not yet described there]
#  -listing-cont-lines: Sets the maximum number of continuation lines of hex
#       dump that will be displayed for a given single line of source input.
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs,--listing-cont-lines=100


#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min

# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt

# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB =
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)


# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min

# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt

# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB =
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)


MATH_LIB = -lm



#---------------- External Memory Options ----------------

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff

EXTMEMOPTS =



#---------------- Linker Options ----------------
#  -Wl,...:     tell GCC to pass this to linker.
#    -Map:      create map file
#    --cref:    add cross reference to  map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)



#---------------- Programming Options (avrdude) ----------------

# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = stk500

# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = com1    # programmer connected to serial device

AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep


# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y

# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V

# Increase verbosity level.  Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v

AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)



#---------------- Debugging Options ----------------

# For simulavr only - target MCU frequency.
DEBUG_MFREQ = $(F_CPU)

# Set the DEBUG_UI to either gdb or insight.
# DEBUG_UI = gdb
DEBUG_UI = insight

# Set the debugging back-end to either avarice, simulavr.
DEBUG_BACKEND = avarice
#DEBUG_BACKEND = simulavr

# GDB Init Filename.
GDBINIT_FILE = __avr_gdbinit

# When using avarice settings for the JTAG
JTAG_DEV = /dev/com1

# Debugging port used to communicate between GDB / avarice / simulavr.
DEBUG_PORT = 4242

# Debugging host used to communicate between GDB / avarice / simulavr, normally
#     just set to localhost unless doing some sort of crazy debugging when
#     avarice is running on a different computer.
DEBUG_HOST = localhost



#============================================================================


# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
REMOVEDIR = rmdir
COPY = cp
WINSHELL = cmd


# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = --------  end  --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:




# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)

# Define all listing files.
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)


# Compiler flags to generate dependency files.
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d


# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)





# Default target.
all: begin gccversion sizebefore build sizeafter end

build: elf hex eep lss sym

elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym



# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
	@echo
	@echo $(MSG_BEGIN)

end:
	@echo $(MSG_END)
	@echo


# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) --format=avr --mcu=$(MCU) $(TARGET).elf

sizebefore:
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
	2>/dev/null; echo; fi

sizeafter:
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
	2>/dev/null; echo; fi



# Display compiler version information.
gccversion :
	@$(CC) --version



# Program the device.
program: $(TARGET).hex $(TARGET).eep
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)


# Generate avr-gdb config/init file which does the following:
#     define the reset signal, load the target file, connect to target, and set
#     a breakpoint at main().
gdb-config:
	@$(REMOVE) $(GDBINIT_FILE)
	@echo define reset >> $(GDBINIT_FILE)
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
	@echo end >> $(GDBINIT_FILE)
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
ifeq ($(DEBUG_BACKEND),simulavr)
	@echo load  >> $(GDBINIT_FILE)
endif
	@echo break main >> $(GDBINIT_FILE)

debug: gdb-config $(TARGET).elf
ifeq ($(DEBUG_BACKEND), avarice)
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
	@$(WINSHELL) /c pause
else
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
endif
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)



# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000


coff: $(TARGET).elf
	@echo
	@echo $(MSG_COFF) $(TARGET).cof
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof


extcoff: $(TARGET).elf
	@echo
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof



# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
	@echo
	@echo $(MSG_FLASH) $@
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@

%.eep: %.elf
	@echo
	@echo $(MSG_EEPROM) $@
	-$(OBJCOPY) -j .eeprom --set-section-flags .eeprom=alloc,load \
	--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0

# Create extended listing file from ELF output file.
%.lss: %.elf
	@echo
	@echo $(MSG_EXTENDED_LISTING) $@
	$(OBJDUMP) -h -S $< > $@

# Create a symbol table from ELF output file.
%.sym: %.elf
	@echo
	@echo $(MSG_SYMBOL_TABLE) $@
	$(NM) -n $< > $@



# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
	@echo
	@echo $(MSG_LINKING) $@
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)


# Compile: create object files from C source files.
%.o : %.c
	@echo
	@echo $(MSG_COMPILING) $<
	$(CC) -c $(ALL_CFLAGS) $< -o $@


# Compile: create assembler files from C source files.
%.s : %.c
	$(CC) -S $(ALL_CFLAGS) $< -o $@


# Assemble: create object files from assembler source files.
%.o : %.S
	@echo
	@echo $(MSG_ASSEMBLING) $<
	$(CC) -c $(ALL_ASFLAGS) $< -o $@

# Create preprocessed source for use in sending a bug report.
%.i : %.c
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@


# Target: clean project.
clean: begin clean_list end

clean_list :
	@echo
	@echo $(MSG_CLEANING)

# We want to keep the generated hexfiles:
#	$(REMOVE) $(TARGET).hex

	$(REMOVE) $(TARGET).eep
	$(REMOVE) $(TARGET).cof
	$(REMOVE) $(TARGET).elf
	$(REMOVE) $(TARGET).map
	$(REMOVE) $(TARGET).sym
	$(REMOVE) $(TARGET).lss
	$(REMOVE) $(OBJ)
	$(REMOVE) $(LST)
	$(REMOVE) $(SRC:.c=.s)
	$(REMOVE) $(SRC:.c=.d)
	$(REMOVE) $(SRC:.c=.i)
	$(REMOVE) .dep/*
	$(REMOVEDIR) .dep


# Include the dependency files.
include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)


# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff \
clean clean_list program debug gdb-config


###############################################################################
# Based on WinAVR Sample makefile written by Eric B. Weddington,
# Jörg Wunsch, et al.
# Released to the Public Domain.
# Please read the "make" user manual!
#
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device, using avrdude.
#                Please customize the avrdude settings first!
#
# make debug = Start either simulavr or avarice as specified for debugging,
#              with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
#                   bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#
###############################################################################
+627 −0
Original line number Diff line number Diff line
% ainf-20151203.pdf - Lecture Slides on Applied Computer Sciences
% Copyright (C) 2012, 2013, 2015  Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document.  If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document.  If not, see <http://creativecommons.org/licenses/>.

\documentclass[10pt,t]{beamer}

\usepackage{pgslides}
\usepackage{pdftricks}

\newrgbcolor{orange}{0.7 0.2 0.0}

\begin{psinputs}
  \usepackage[utf8]{inputenc}
  \usepackage[german]{babel}
  \usepackage[T1]{fontenc}
  \usepackage{helvet}
  \renewcommand*\familydefault{\sfdefault}
  \usepackage{pstricks,pst-grad,pst-node,pst-plot}
\end{psinputs}

\lstdefinestyle{asm}{basicstyle=\color{structure},
                     language={},
                     gobble=4}

\title{Angewandte Informatik}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{3.\ Dezember 2015}

\begin{document}

\maketitleframe

\sectionnonumber{\inserttitle}

\begin{frame}

  \showsectionnonumber

  \begin{itemize}
    \item[\textbf{1}] \textbf{Einführung}
    \item[\textbf{2}] \textbf{Einführung in C}
    \item[\textbf{3}] \textbf{Bibliotheken}
    \item[\textbf{4}] \textbf{Algorithmen}
      \begin{itemize}
        \item[4.1] Differentialgleichungen
        \item[4.2] Rekursion
        \color{medgreen}
        \item[4.3] Stack und FIFO
        \color{gray}
        \item[4.4] Aufwandsabschätzungen
      \end{itemize}
    \color{red}
    \item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
    \color{gray}
    \item[\makebox(0,0){\textbf{\raisebox{0.5ex}{\dots}}}]
%    \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke}
  \end{itemize}

\end{frame}

\section{Einführung}
\section{Einführung in C}
\section{Bibliotheken}

\section{Algorithmen}
\subsection{Differentialgleichungen}
\subsection{Rekursion}
\subsection{Stack und FIFO}

\begin{frame}[fragile]

  \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>{\vector(1,-1){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>{\vector(1,-1){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>{\vector(1,-1){0.45}}}
        \put(1.0,1.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}}

        \put(4.55,1.05){\only<4>{\vector(1,1){0.45}}}
        \put(5.00,1.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 3}}}

        \put(3.55,1.05){\only<5>{\vector(1,1){0.45}}}
        \put(4.00,1.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}}

        \put(2.55,1.05){\only<6>{\vector(1,1){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>{\vector(1,-1){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>{\vector(1,-1){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>{\vector(1,-1){0.45}}}
        \put(2.0,3.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}}

        \put(3.55,3.05){\only<4>{\vector(1,1){0.45}}}
        \put(4.00,3.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 137}}}

        \put(3.55,2.05){\only<5>{\vector(1,1){0.45}}}
        \put(4.00,2.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}}

        \put(3.55,1.05){\only<6>{\vector(1,1){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

\subsection{Aufwandsabschätzungen}

\begin{frame}[fragile]

  \showsubsection

  Beispiel: Sortieralgorithmen

  \begin{itemize}
    \item
      Maximum suchen\only<2->{: $\mathcal{O}(n)$}
      \hfill
      \begin{minipage}[t]{5.6cm}
        \vspace*{-1.3cm}
        \begin{pdfpic}
          \psset{unit=0.5pt}
          \begin{pspicture}(-20,-20)(250,200)
            \psline[arrows=->](-10,0)(200,0)
            \psline[arrows=->](0,-10)(0,200)
            \psplot[plotpoints=200]{1}{125}{2 x 0.06 mul exp}
            \put(70,190){\mbox{$g(n) \sim 2^n$}}
            \psplot[plotpoints=200]{0}{190}{x x mul 0.005 mul}
            \put(190,190){\mbox{$g(n) \sim n^2$}}
            \psplot[plotpoints=200]{1}{190}{x ln x mul 0.1 mul}
            \put(195,100){\mbox{$g(n) \sim n \log n$}}
            \psplot[plotpoints=200]{0}{190}{x 0.4 mul}
            \put(195,75){\mbox{$g(n) \sim n$}}
            \psplot[plotpoints=200]{1}{190}{x ln 10 mul}
            \put(195,50){\mbox{$g(n) \sim \log n$}}
            \put(205,0){\makebox(0,0)[l]{$n$}}
            \put(-10,210){\makebox(0,0)[l]{$g(n)$}}
            \psplot[plotpoints=200]{1}{190}{30}
            \put(195,25){\mbox{$g(n) \sim 1$}}
          \end{pspicture}
        \end{pdfpic}
        \small
        \begin{description}\itemsep0pt
          \item[$n$:] Eingabedaten
          \item[$g(n)$:] Rechenzeit
        \end{description}
        \vspace*{-10cm}\strut
      \end{minipage}
    \pause[3]
    \item
      Maximum ans Ende tauschen\\
      \textarrow\ Selectionsort\pause: $\mathcal{O}(n^2)$
    \pause
    \item
      Während Maximumsuche prüfen,\\abbrechen, falls schon sortiert\\
      \textarrow\ Bubblesort\pause: $\mathcal{O}(n)$ bis $\mathcal{O}(n^2)$
    \pause
    \item
      Rekursiv sortieren\\
      \textarrow\ Quicksort\pause: $\mathcal{O}(n\log n)$ bis $\mathcal{O}(n^2)$\hfill
  \end{itemize}

\end{frame}

\fi

\sectionnonumber{\inserttitle}

\begin{frame}

  \showsectionnonumber

  \begin{itemize}
    \item[\textbf{1}] \textbf{Einführung}
    \item[\textbf{2}] \textbf{Einführung in C}
    \item[\textbf{3}] \textbf{Bibliotheken}
    \item[\textbf{4}] \textbf{Algorithmen}
      \begin{itemize}
        \item[4.1] Differentialgleichungen
        \item[4.2] Rekursion
        \item[4.3] Stack und FIFO
        \color{gray}
        \item[4.4] Aufwandsabschätzungen
      \end{itemize}
    \item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
      \begin{itemize}
        \color{red}
        \item[5.1] Bit-Operationen
        \item[5.2] I/O-Ports
        \item[5.3] Interrupts
        \item[5.4] volatile-Variable
        \item[5.5] Software-Interrupts
      \end{itemize}
    \color{gray}
    \item[\makebox(0,0){\textbf{\raisebox{0.5ex}{\dots}}}]
%    \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke}
  \end{itemize}

\end{frame}

\section{Hardwarenahe Programmierung}
\subsection{Bit-Operationen}
\subsubsection{Zahlensysteme}

\begin{frame}[fragile]

  \showsection
  \pause
  \vspace*{-\smallskipamount}
  \showsubsection
  \pause
  \vspace*{-\medskipamount}
  \showsubsubsection
  \pause

  \begin{onlyenv}<4>
    \begin{tabular}{rlr}
      Basis & & Beispiel \\[\smallskipamount]
        2 & Binärsystem & 1\,0000\,0011 \\
        8 & Oktalsystem & \lstinline,0403, \\
       10 & Dezimalsystem & \lstinline,259,\\
       16 & Hexadezimalsystem & \lstinline,0x103, \\
      256 & IP-Adressen (IPv4) & 0.0.1.3
    \end{tabular}
  \end{onlyenv}

  \begin{onlyenv}<5>

    Oktal- und Hexadezimal-Zahlen lassen sich ziffernweise\\
    in Binär-Zahlen umrechnen:

    \begin{verbatim}
      000 0        0000 0  1000 8
      001 1        0001 1  1001 9
      010 2        0010 2  1010 A
      011 3        0011 3  1011 B
      100 4        0100 4  1100 C
      101 5        0101 5  1101 D
      110 6        0110 6  1110 E
      111 7        0111 7  1111 F
    \end{verbatim}

  \end{onlyenv}

\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

  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}
\end{frame}

\subsection{I/O-Ports}

\begin{frame}[fragile]

%  \showsection
  \showsubsection
  \vspace*{-1.5\medskipamount}
  {\large\textbf{\color{structure}5.3\quad Interrupts}}

  \bigskip

  Kommunikation mit externen Geräten

  \bigskip

  \begin{center}
    \begin{pdfpic}
      \psset{unit=1cm}%
      \begin{pspicture}(0,0)(10,6)
        \rput(0,0){\psframe[framearc=0.25](2,5)}
        \rput(1,4.5){\makebox(0,0)[t]{Prozessor}}
        \rput(2.0,3.7){\pnode{p0}}
        \rput(2.0,3.3){\pnode{q0}}
        \rput(2.0,1.0){\pnode{i0}}
        \rput(2.12,1.2){\pnode{j0}}
        \rput(2.02,1.3){\pnode{k0}}
        \rput(2.12,1.4){\pnode{l0}}
        \rput(3.5,1.4){\pnode{m0}}
        \rput(8,0){\psframe[framearc=0.25](2,5)}
        \rput(9,4.5){\makebox(0,0)[t]{\shortstack{externes\\Gerät}}}
        \rput(8.0,3.7){\pnode{p1}}
        \rput(7.88,3.3){\pnode{q1}}
        \rput(7.98,3.2){\pnode{r1}}
        \rput(7.88,3.1){\pnode{s1}}
        \rput(6.5,3.1){\pnode{t1}}
        \rput(8.0,1.0){\pnode{i1}}
        \rput(8.0,1.2){\pnode{j1}}
        \ncline{->}{p0}{p1}
        \ncline{q0}{q1}
        \nccurve[angleB=90]{q1}{r1}
        \nccurve[angleA=-90]{r1}{s1}
        \ncline{->}{s1}{t1}
        \rput(2.2,3.8){\makebox(0,0)[lb]{Prozessor schreibt in Output-Port}}
        \rput(2.2,3.1){\makebox(0,0)[lt]{Prozessor liest Input-Port}}
        \ncline{->}{i1}{i0}
        \rput(7.8,1.1){\makebox(0,0)[rb]{externes Gerät ruft Interrupt auf}}
      \end{pspicture}
    \end{pdfpic}
  \end{center}

\end{frame}

\begin{frame}[fragile]

  \showsubsection

  In Output-Port schreiben = Leitungen ansteuern

  \medskip

  Datei: \file{RP6Base/RP6Base\_Examples/RP6Examples\_20080915/\\
  RP6Lib/RP6base/RP6RobotBaseLib.c}

  Suchbegriff: \lstinline{setMotorDir}

  \medskip

  \begin{lstlisting}
    void setMotorDir(uint8_t left_dir, uint8_t right_dir)
    {
      /* ... */
      if(left_dir)
        PORTC |= DIR_L;
      else
        PORTC &= ~DIR_L;
      if(right_dir)
        PORTC |= DIR_R;
      else
        PORTC &= ~DIR_R;
    }
  \end{lstlisting}
  \begin{picture}(0,0)
    \color{red}
    \put(2.2,0.50){\vector(-2,1){0.5}}
    \put(2.25,0.40){\makebox(0,0)[l]{Output-Port}}
    \put(4.7,3.0){\vector(-2,1){0.75}}
    \put(4.7,3.0){\vector(-2,-1){0.75}}
    \put(4.8,3.0){\makebox(0,0)[l]{Manipulation einzelner Bits}}
  \end{picture}

  \vspace*{-1.5cm}
  \strut\hfill\textarrow\ Steuerung der Motordrehrichtung

\end{frame}

\subsection{Interrupts}

\begin{frame}[fragile]

  \showsubsection

  Externes Gerät ruft (per Stromsignal) Unterprogramm auf

  Zeiger hinterlegen: "`Interrupt-Vektor"'

  \medskip

  Datei: \file{RP6Base/RP6Base\_Examples/RP6Examples\_20080915/\\
  RP6Lib/RP6base/RP6RobotBaseLib.c}

  Suchbegriff: \lstinline{ISR}

  \vspace{2.0cm}

  \begin{lstlisting}
    ISR (INT0_vect)
    {
      mleft_dist++;
      mleft_counter++;
      /* ... */
    }
  \end{lstlisting}
  \begin{picture}(0,0)
    \color{red}
    \put(1.9,4.3){\vector(-1,-1){1.4}}
    \put(2.0,4.4){\makebox(0,0)[l]{"`Dies ist ein Interrupt-Handler."'}}
    \put(2.3,3.6){\vector(-1,-1){0.7}}
    \put(2.4,3.6){\makebox(0,0)[l]{Interrupt-Vektor 0 darauf zeigen lassen}}
    \put(3.7,2.9){\makebox(0,0)[l]{Schreibweise herstellerspezifisch!}}
  \end{picture}

  \vspace*{-1.5cm}
  \strut\hfill Aufruf durch Sensor an Encoder-Scheibe\\
  \strut\hfill\textarrow\ Entfernungsmessung

\end{frame}

\subsection{volatile-Variable}

\begin{frame}[fragile]

  \showsubsection

  \begin{lstlisting}
    volatile uint16_t mleft_counter;

    /* ... */

    volatile uint16_t mleft_dist;

    /* ... */

    ISR (INT0_vect)
    {
      mleft_dist++;
      mleft_counter++;
      /* ... */
    }
  \end{lstlisting}
  \begin{picture}(0,0)
    \color{red}
    \put(1.6,5.2){\vector(-1,-1){0.55}}
    \put(1.6,5.2){\vector(-1,1){0.55}}
    \put(1.6,5.2){\makebox(0,0)[l]{"`Immer lesen und schreiben. Nicht wegoptimieren."'}}
  \end{picture}
  \vspace{-3cm}
  \begin{lstlisting}
                                        int main (void)
                                        {
                                          int prev_mleft_dist = mleft_dist;
                                          while (mleft_dist == prev_mleft_dist)
                                            /* just wait */;
                                        }
  \end{lstlisting}

\end{frame}

\subsection{Software-Interrupts}

\begin{frame}[fragile]

  \showsubsection

  \begin{lstlisting}[style=asm]
    mov ax, 0012
    int 10
  \end{lstlisting}
  \pause
  \begin{picture}(0,0)
    \color{red}
    \put(2.8,0.95){\vector(-1,0){0.55}}
    \put(2.9,0.95){\makebox(0,0)[l]{Parameter in Prozessorregister}}
    \put(1.7,0.50){\vector(-1,0){0.55}}
    \put(1.8,0.50){\makebox(0,0)[l]{Funktionsaufruf über Interrupt-Vektor}}
  \end{picture}

  \pause
  Beispiel: VGA-Grafikkarte
  \begin{itemize}
    \item Modus setzen: \lstinline{mov ah, 00}
    \item Grafikmodus: \lstinline{mov al, 12}
    \item Textmodus: \lstinline{mov al, 03}
  \end{itemize}

  \pause
  \bigskip
  Verschiedene Farben: Output-Ports
  \begin{itemize}
    \item \newterm{Graphics Register\/}: Index \lstinline{03CE}, Daten \lstinline{03CF}
    \item Index 0: \newterm{Set/Reset Register}
    \item Index 1: \newterm{Enable Set/Reset Register}
    \item Index 8: \newterm{Bit Mask Register}
    \item Jedes Bit steht für Schreibzugriff auf eine Speicherbank.
    \item 4 Speicherbänke \textarrow\ 16 Farben
  \end{itemize}

\end{frame}

\sectionnonumber{\inserttitle}

\begin{frame}

  \showsectionnonumber

  \begin{itemize}
    \item[\textbf{1}] \textbf{Einführung}
    \item[\textbf{2}] \textbf{Einführung in C}
    \item[\textbf{3}] \textbf{Bibliotheken}
    \item[\textbf{4}] \textbf{Algorithmen}
      \begin{itemize}
        \item[4.1] Differentialgleichungen
        \item[4.2] Rekursion
        \item[4.3] Stack und FIFO
        \color{gray}
        \item[4.4] Aufwandsabschätzungen
      \end{itemize}
    \item[\textbf{5}] \textbf{Hardwarenahe Programmierung}
      \begin{itemize}
        \color{medgreen}
        \item[5.1] Bit-Operationen
        \item[5.2] I/O-Ports
        \item[5.3] Interrupts
        \item[5.4] volatile-Variable
        \item[5.5] Software-Interrupts
      \end{itemize}
    \color{gray}
    \item[\makebox(0,0){\textbf{\raisebox{0.5ex}{\dots}}}]
%    \item[\textbf{6}] \textbf{Ergänzungen und Ausblicke}
  \end{itemize}

\end{frame}

\end{document}
+326 −0
Original line number Diff line number Diff line
% ainf-uebung-20151203.pdf - Exercises on Applied Computer Sciences
% Copyright (C) 2013, 2015  Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document.  If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document.  If not, see <http://creativecommons.org/licenses/>.

\documentclass[a4paper]{article}

\usepackage{pgscript}
\usepackage{pdftricks}
\usepackage{sfmath}

\begin{psinputs}
  \usepackage{pgscript}
%  \definecolor{PracticallyWhite}{rgb}{0.99 0.99 0.99}
  \definecolor{verylightgray}{rgb}{0.95 0.95 0.95}
\end{psinputs}

\newcounter{exercise}
\newcommand{\exercise}[1]{\addtocounter{exercise}{1}\subsection*{Aufgabe \arabic{exercise}: #1}}

\newcounter{points}
\newcommand{\onepoint}{(1 Punkt)\addtocounter{points}{1}}
\newcommand{\points}[1]{(#1 Punkte)\addtocounter{points}{#1}}

\begin{document}

  \thispagestyle{empty}

  \section*{Angewandte Informatik\\Übungsaufgaben -- 3.\ Dezember 2015}

  \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.)

  \exercise{Mikro-Controller}

  \begin{minipage}[t]{10cm}
    An die vier Ports eines ATmega16-Mikro-Controllers 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:

    \begin{lstlisting}[gobble=6]
      #include <avr/io.h>

      int main (void)
      {
        DDRA = DDRB = DDRC = DDRD = 0xff;
        PORTA = 0x1f;
        PORTB = 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}

  \begin{itemize}
    \item[(a)]
      Was bewirkt dieses Programm? (4 Punkte)
      
%      \workspace{15}

      Musterlösung:
      \begin{minipage}[t]{1.5cm}
        \vspace*{-1.0ex}
        \begin{pdfpic}
          \scalebox{0.1}{\psframebox[linewidth=2mm,linecolor=verylightgray,fillstyle=solid,fillcolor=verylightgray]{%
            \begin{minipage}{6.5cm}
              \setlength{\parskip}{\smallskipamount}

              Die Leuchtdioden stellen die Ziffer 4 dar.
              Es leuchten PA0 bis PA4, PB4, PC2 bis PC7 und PC4.
            \end{minipage}}}
        \end{pdfpic}
      \end{minipage}

    \item[(b)]
      Wozu dient die erste Zeile des Hauptprogramms? (2 Punkte)

%      \workspace{10}

      Musterlösung:
      \begin{minipage}[t]{1.5cm}
        \vspace*{-1.0ex}
        \begin{pdfpic}
          \scalebox{0.1}{\psframebox[linewidth=2mm,linecolor=verylightgray,fillstyle=solid,fillcolor=verylightgray]{%
            \begin{minipage}{7cm}
              \setlength{\parskip}{\smallskipamount}

              Sie setzt die Data Direction Registers so,
              daß alle vier Ports komplett als Output-Ports genutzt werden.
              Die Anweisung nutzt den Rückgabewert der Zuweisung für die nächste Zuweisung.
            \end{minipage}}}
        \end{pdfpic}
      \end{minipage}

    \item[(c)]
      Was würde stattdessen die Zeile \lstinline{DDRA & DDRB & DDRC & DDRD = 0xff;} bewirken? (2 Punkte)

%      \workspace{10}

      Musterlösung:
      \begin{minipage}[t]{1.5cm}
        \vspace*{-1.0ex}
        \begin{pdfpic}
          \scalebox{0.1}{\psframebox[linewidth=2mm,linecolor=verylightgray,fillstyle=solid,fillcolor=verylightgray]{%
            \begin{minipage}{7cm}
              \setlength{\parskip}{\smallskipamount}

              Nur \lstinline{DDRD} bekäme einen Wert.
              Die anderen Data Direction Registers würden nur ausgelesen,
              miteinander bitweise und-verknüpft und das Ergebnis verworfen.

              Ergebnis: Nur Port D könnte zuverlässig Leuchtdioden schalten.
              Die anderen Ports wären zufällig für Eingabe oder Ausgabe konfiguriert.
            \end{minipage}}}
        \end{pdfpic}
      \end{minipage}

    \item[(c)]
      Schreiben Sie das Programm so um, daß die dargestellte Figur spiegelverkehrt erscheint. (3 Punkte)

%      \workspace{15}

      Musterlösung:
      \begin{minipage}[t]{1.5cm}
        \vspace*{-1.5ex}
        \begin{pdfpic}
          \scalebox{0.1}{\psframebox[linewidth=2mm,linecolor=verylightgray,fillstyle=solid,fillcolor=verylightgray]{%
            \begin{minipage}{7cm}
              \setlength{\parskip}{\smallskipamount}

              Die Zuweisungen an die Ports müssen wie folgt geändert werden:\\[\smallskipamount]
%              \begin{lstlisting}[gobble=10]
                \lstinline{PORTB = 0xfc;}\\
                \lstinline{PORTA = PORTC = 0x10;}\\
                \lstinline{PORTD = 0x1f;}
%              \end{lstlisting}

            \end{minipage}}}
        \end{pdfpic}
      \end{minipage}

    \item[(d)]
      Wozu dient das \lstinline{while (1)}? (2 Punkte)

%      \workspace{10}

      Musterlösung:
      \begin{minipage}[t]{1.5cm}
        \vspace*{-1.5ex}
        \begin{pdfpic}
          \scalebox{0.1}{\psframebox[linewidth=2mm,linecolor=verylightgray,fillstyle=solid,fillcolor=verylightgray]{%
            \begin{minipage}{7cm}
              \setlength{\parskip}{\smallskipamount}

              Das Programm wird angehalten. Es soll "`nichts mehr"' passieren.
              Da es kein Betriebssystem gibt, das nach \lstinline{return 0} die Kontrolle übernimmt,
              würde ansonsten zufälliger Code ausgeführt.
            \end{minipage}}}
        \end{pdfpic}
      \end{minipage}
  \end{itemize}

\iffalse

  \exercise{Arrays mit Zahlen}

  \begin{minipage}[t]{0.5\textwidth}
    Wir betrachten das folgende Programm:
    \begin{lstlisting}[gobble=6]
      #include <stdio.h>

      void f (int *s0, int *s1)
      {
        while (*s0 >= 0)
        {
          int *s = s1;
          while (*s >= 0)
            if (*s0 == *s++)
              printf ("%d ", *s0);
          s0++;
        }
        printf ("\n");
      }

      int main (void)
      {
        int a[] = { 10, 4, 3, 7, 12, 0, 1, -1 };
        int b[] = { 7, 14, 0, 8, 9, 22, 10, -1 };
        f (a, b);
        return 0;
      }
    \end{lstlisting}
  \end{minipage}\hfill
  \begin{minipage}[t]{0.5\textwidth}
    \vspace*{-\bigskipamount}
    \begin{enumerate}[\quad(a)]
      \item
        Was bewirkt die Funktion \lstinline{f} und warum?\\
        \points{4}
      \item
        Von welcher Ordnung (Landau-Symbol) ist die Funktion und warum?

        Wir beziehen uns hierbei auf die Anzahl der Vergleiche
        in Abhängigkeit von der Länge der Eingabedaten \lstinline{s0} und \lstinline{s1}.
        Für die Rechnung dürfen Sie beide Längen mit $n$ gleichsetzen,
        obwohl sie normalerweise nicht gleich sind.
        \points{2}
      \item
        Was passiert, wenn Sie beim Aufruf der Funktion für einen der
        Parameter den Wert \lstinline{NULL} übergeben und warum?
        \points{2}
      \item
        Was passiert, wenn Sie das Hauptprogramm wie folgt abändern
        (\file{aufgabe-1d.c}) und warum?
        \begin{lstlisting}[gobble=8]
          int main (void)
          {
            int a[] = { 10, 4, 3, 7, 12, 0, 1 };
            int b[] = { 7, 14, 0, 8, 9, 22, 10 };
            f (a, b);
            return 0;
          }
        \end{lstlisting}
        \points{2}
      \item
        Beschreiben Sie -- in Worten und/oder als C-Quelltext --, wie
        sich die Funktion \lstinline{f} effizienter gestalten läßt,
        wenn man die ihr übergebenen Arrays \lstinline{s0} und
        \lstinline{s1} als sortiert voraussetzt.\\
        \points{5}
      \item
        Von welcher
        Ordnung (Landau-Symbol) ist Ihre effizientere Version der Funktion und warum?\\
        \points{2}
    \end{enumerate}
  \end{minipage}

\fi

\end{document}

20151203/blink-1.c

0 → 100644
+17 −0
Original line number Diff line number Diff line
#include <avr/io.h>

#define F_CPU 8000000
#include <util/delay.h>

int main (void)
{
  DDRC = 0x10;
  while (1)
    {
      PORTC |= 0x10;
      _delay_ms (500);
      PORTC &= ~0x10;
      _delay_ms (500);
    }
  return 0;
}

20151203/blink-2.c

0 → 100644
+17 −0
Original line number Diff line number Diff line
#include <avr/io.h>

#define F_CPU 8000000
#include <util/delay.h>

int main (void)
{
  DDRC = 0x10;
  while (1)
    {
      PORTC |= 0x70;
      _delay_ms (500);
      PORTC &= ~0x70;
      _delay_ms (500);
    }
  return 0;
}

20151203/blink-3.c

0 → 100644
+17 −0
Original line number Diff line number Diff line
#include <avr/io.h>

#define F_CPU 8000000
#include <util/delay.h>

int main (void)
{
  DDRC = 0x70;
  while (1)
    {
      PORTC |= 0x70;
      _delay_ms (500);
      PORTC &= ~0x70;
      _delay_ms (500);
    }
  return 0;
}

20151203/leds.jpg

0 → 120000
+1 −0
Original line number Diff line number Diff line
../common/leds.jpg
 No newline at end of file

20151203/pgscript.sty

0 → 120000
+1 −0
Original line number Diff line number Diff line
../common/pgscript.sty
 No newline at end of file

20151203/pgslides.sty

0 → 120000
+1 −0
Original line number Diff line number Diff line
../common/pgslides.sty
 No newline at end of file
Original line number Diff line number Diff line
#include "Text-Grafik-Bibliothek-20x15.h"
#include <stdio.h>
#include "fifo-pg-3.h"

char screen[WIDTH][HEIGHT];

//Setze alle Einträge in display auf c
void clear (char c)
{
 for (int i=0;i<WIDTH;i++)
  {
   for (int j=0;j<HEIGHT;j++)
    {
     screen[i][j]=c;
    }
  }
}

//setze display [x][y] auf c
void putPoint (int x, int y, char c)
{
 screen[x][y]=c;
}

//Gebe display[x][y] zurück
char getPoint (int x, int y)
{
  char c=screen[x][y];
  return c;
}

//Fülle eine Fläche in display, die aus den Zeichen o besteht mit den Zeichen c aus
void fill (int x, int y, char c, char o)
{
  push_pair (x, y);
  while (!fifo_empty ())
    {
      pair p = pop_pair ();
      if (getPoint (p.x, p.y) == o)
	{
	  putPoint (p.x, p.y, c++);
	  push_pair (p.x + 1, p.y);
	  push_pair (p.x - 1, p.y);
	  push_pair (p.x, p.y + 1);
	  push_pair (p.x, p.y - 1);
	}
    }
}

//Gib display aus
void display (void)
{
 for (int i=0;i<HEIGHT;i++)
  {
   for (int j=0;j<WIDTH;j++)
    {
     printf("%c",screen[j][i]);
    }
   printf("\n");
  }
}
+94 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define FIFO_SIZE 42

typedef struct
{
	int x, y;
}
pair;

pair fifo[FIFO_SIZE];
int fifo_read_pointer = 0;
int fifo_write_pointer = 0;

void fatal_error (char *msg)
{
	fprintf (stderr, "%s\n", msg);
	exit (1);
}

void push_pair (int x, int y)
{
	if (fifo_write_pointer < 0 || fifo_write_pointer >= FIFO_SIZE)
		fatal_error ("push_pair: fifo inconsistence");
	else
	{
		printf ("pushing (%d,%d)\n", x, y);
		fifo[fifo_write_pointer].x = x;
		fifo[fifo_write_pointer].y = y;
		fifo_write_pointer++;
		if (fifo_write_pointer >= FIFO_SIZE)
			fifo_write_pointer = 0;
		if (fifo_write_pointer == fifo_read_pointer)
			fatal_error ("fifo overflow");
    }
}

pair pop_pair (void)
{
	pair nix = { 0, 0 };
	if (fifo_read_pointer < 0 || fifo_read_pointer >= FIFO_SIZE)
    {
		fatal_error ("pop_pair: fifo inconsistence");		
		return nix;
    }
	else if (fifo_read_pointer == fifo_write_pointer)
    {
		fatal_error ("fifo underflow");
		return nix;
    }
	else
    {
		printf ("popping (%d,%d)\n", fifo[fifo_read_pointer].x, fifo[fifo_read_pointer].y);
		pair value = fifo[fifo_read_pointer];
		fifo[fifo_read_pointer].x = 0;
		fifo[fifo_read_pointer].y = 0;
		fifo_read_pointer++;
		if (fifo_read_pointer >= FIFO_SIZE)
			fifo_read_pointer = 0;
		return value;
    }
}

void dump_fifo (void)
{
	int i;
	printf ("dump_fifo:");
	for (i = 0; i < FIFO_SIZE; i++)
		printf (" (%d,%d)", fifo[i].x, fifo[i].y);
	printf ("\n");
}

int main (void)
{
	dump_fifo ();
	push_pair (3, 0);
	dump_fifo ();
	push_pair (7, 2);
	dump_fifo ();
	push_pair (23, 23);
	dump_fifo ();
	pop_pair ();
	dump_fifo ();
	pop_pair ();
	dump_fifo ();
	push_pair (42, 137);
	dump_fifo ();
	pop_pair ();
	dump_fifo ();
	pop_pair ();
	dump_fifo ();
	return 0;
}
+94 −0
Original line number Diff line number Diff line
#include <stdio.h>
#include <stdlib.h>

#define FIFO_SIZE 42

typedef struct
{
	int x, y;
}
pair;

pair fifo[FIFO_SIZE];
int fifo_read_pointer = 0;
int fifo_write_pointer = 0;

void fatal_error (char *msg)
{
	fprintf (stderr, "%s\n", msg);
	exit (1);
}

void push_pair (int x, int y)
{
	if (fifo_write_pointer < 0 || fifo_write_pointer >= FIFO_SIZE)
		fatal_error ("push_pair: fifo inconsistence");
	else
	{
		printf ("pushing (%d,%d)\n", x, y);
		fifo[fifo_write_pointer].x = x;
		fifo[fifo_write_pointer].y = y;
		fifo_write_pointer++;
		if (fifo_write_pointer >= FIFO_SIZE)
			fifo_write_pointer = 0;
		if (fifo_write_pointer == fifo_read_pointer)
			fatal_error ("fifo overflow");
    }
}

pair pop_pair (void)
{
	pair nix = { 0, 0 };
	if (fifo_read_pointer < 0 || fifo_read_pointer >= FIFO_SIZE)
    {
		fatal_error ("pop_pair: fifo inconsistence");		
		return nix;
    }
	else if (fifo_read_pointer == fifo_write_pointer)
    {
		fatal_error ("fifo underflow");
		return nix;
    }
	else
    {
		printf ("popping (%d,%d)\n", fifo[fifo_read_pointer].x, fifo[fifo_read_pointer].y);
		pair value = fifo[fifo_read_pointer];
		fifo[fifo_read_pointer].x = 0;
		fifo[fifo_read_pointer].y = 0;
		fifo_read_pointer++;
		if (fifo_read_pointer >= FIFO_SIZE)
			fifo_read_pointer = 0;
		return value;
    }
}

void dump_fifo (void)
{
	int i;
	printf ("dump_fifo:");
	for (i = fifo_read_pointer; i < fifo_write_pointer; i++)
		printf (" (%d,%d)", fifo[i].x, fifo[i].y);
	printf ("\n");
}

int main (void)
{
	dump_fifo ();
	push_pair (3, 0);
	dump_fifo ();
	push_pair (7, 2);
	dump_fifo ();
	push_pair (23, 23);
	dump_fifo ();
	pop_pair ();
	dump_fifo ();
	pop_pair ();
	dump_fifo ();
	push_pair (42, 137);
	dump_fifo ();
	pop_pair ();
	dump_fifo ();
	pop_pair ();
	dump_fifo ();
	return 0;
}

20151203/ujma/fifo.c

0 → 100644
+94 −0

File added.

Preview size limit exceeded, changes collapsed.

20151207/pgscript.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/Makefile

0 → 100644
+606 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/blink-4.c

0 → 100644
+16 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/blink-5.c

0 → 100644
+24 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/pair-fifo.c

0 → 100644
+72 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/pair-stack.c

0 → 100644
+69 −0

File added.

Preview size limit exceeded, changes collapsed.

+12 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/pgscript.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/pgslides.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-0.c

0 → 100644
+16 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-1.c

0 → 100644
+27 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-10.c

0 → 100644
+63 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-11.c

0 → 100644
+65 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-12.c

0 → 100644
+62 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-13.c

0 → 100644
+72 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-14.c

0 → 100644
+74 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-2.c

0 → 100644
+32 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-3.c

0 → 100644
+39 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-4.c

0 → 100644
+40 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-5.c

0 → 100644
+40 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-6.c

0 → 100644
+46 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-7.c

0 → 100644
+70 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-8.c

0 → 100644
+56 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/sort-9.c

0 → 100644
+63 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/textgraph.c

0 → 100644
+56 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/textgraph.h

0 → 100644
+8 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/unions-1.c

0 → 100644
+15 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/unions-2.c

0 → 100644
+15 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/unions-3.c

0 → 100644
+15 −0

File added.

Preview size limit exceeded, changes collapsed.

20151210/unions-4.c

0 → 100644
+33 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/neat-tree-1.c

0 → 100644
+68 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/neat-tree-2.c

0 → 100644
+77 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/neat-tree-3.c

0 → 100644
+77 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/neat-tree-4.c

0 → 100644
+83 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/neat-tree-5.c

0 → 100644
+84 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/neat-tree-6.c

0 → 100644
+85 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/pgscript.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/pgslides.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/sort-0.c

0 → 100644
+16 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/sort-1.c

0 → 100644
+28 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/sort-2.c

0 → 100644
+10 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/sort-3.c

0 → 100644
+17 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/sort-4.c

0 → 100644
+26 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/sort-5.c

0 → 100644
+24 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/sort-6.c

0 → 100644
+24 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/sort-7.c

0 → 100644
+30 −0

File added.

Preview size limit exceeded, changes collapsed.

20151217/sort-8.c

0 → 100644
+35 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/malloc-1.c

0 → 100644
+17 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/malloc-2.c

0 → 100644
+17 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/malloc-3.c

0 → 100644
+17 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/malloc-4.c

0 → 100644
+20 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/malloc-5.c

0 → 100644
+16 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/pgscript.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/pgslides.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/portb.jpg

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/sort-10.c

0 → 100644
+62 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/sort-11.c

0 → 100644
+64 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/sort-12.c

0 → 100644
+64 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/sort-13.c

0 → 100644
+74 −0

File added.

Preview size limit exceeded, changes collapsed.

20160107/sort-9.c

0 → 100644
+31 −0

File added.

Preview size limit exceeded, changes collapsed.

20160111/noreturn-1.c

0 → 100644
+13 −0

File added.

Preview size limit exceeded, changes collapsed.

20160111/random-1.c

0 → 100644
+21 −0

File added.

Preview size limit exceeded, changes collapsed.

+111 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/hallo.c

0 → 100644
+10 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/objects-1.c

0 → 100644
+28 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/objects-2.c

0 → 100644
+28 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/objects-3.c

0 → 100644
+34 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/objects-4.c

0 → 100644
+34 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/objects-5.c

0 → 100644
+34 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/objects-6.c

0 → 100644
+34 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/pgscript.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/pgslides.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/portb.jpg

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20160114/test.c

0 → 100644
+13 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/aufgabe-1.c

0 → 100644
+10 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/aufgabe-1a.c

0 → 100644
+50 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/aufgabe-1b.c

0 → 100644
+50 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/aufgabe-2a.c

0 → 100644
+20 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/aufgabe-2c.c

0 → 100644
+49 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/aufgabe-2d.c

0 → 100644
+49 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/aufgabe-3b.c

0 → 100644
+21 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/join-slides

0 → 100755
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/loesung-1d.c

0 → 100644
+54 −0

File added.

Preview size limit exceeded, changes collapsed.

+58 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/objects-7.c

0 → 100644
+41 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/objects-8.c

0 → 100644
+50 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/objects-9.c

0 → 100644
+64 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/pgscript.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

20160121/pgslides.sty

0 → 120000
+1 −0

File added.

Preview size limit exceeded, changes collapsed.

File changed.

Preview size limit exceeded, changes collapsed.