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

Vorbereitung und Übungsaufgaben 13.11.2017

parent 1c5ecf00
No related branches found
No related tags found
No related merge requests found
Showing
with 1426 additions and 0 deletions
#include "answer.h"
int answer (void)
{
return 23;
}
extern int answer (void);
#include <stdio.h>
int main (void)
{
int n, i, divisors;
for (n = 0; n < 100; n++)
divisors = 0;
for (i = 0; i < n; i++)
if (n % i == 0)
divisors++;
if (divisors = 2)
printf ("%d ist eine Primzahl.\n", n);
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
float t = 0.0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glRotatef (t, 0.5, 1.0, 0.0);
glutSolidCube (0.5);
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutMainLoop ();
glutTimerFunc (50, timer_handler, 0);
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glutSolidCube (0.75);
glFlush ();
glutSwapBuffers ();
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutDisplayFunc (draw);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glRotatef (-30.0, 0.5, 1.0, 0.0);
glutSolidCube (0.75);
glFlush ();
glutSwapBuffers ();
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutDisplayFunc (draw);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
float t = 0.0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glRotatef (t, 0.5, 1.0, 0.0);
glutSolidCube (0.5);
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
float t = 0.0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glPushMatrix ();
glRotatef (t, 0.5, 1.0, 0.0);
glutSolidCube (0.5);
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
float t = 0.0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glPushMatrix ();
glRotatef (20.0 * t, 0.5, 1.0, 0.0);
glutSolidCube (0.5);
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
eine kleine Hexe.
File added
This diff is collapsed.
File added
% hp-uebung-20171113.pdf - Exercises on Low-Level Programming / Applied Computer Sciences
% Copyright (C) 2013, 2015, 2016, 2017 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Datum-Bibliothek, Primzahlen, rotierender Würfel
\documentclass[a4paper]{article}
\usepackage{pgscript}
\begin{document}
% \thispagestyle{empty}
\section*{Hardwarenahe Programmierung / Angewandte Informatik\\
Übungsaufgaben -- 13.\ November 2017}
\exercise{Datum-Bibliothek}
Schreiben Sie eine Bibliothek \file{dates.c} (mit Header-Datei \file{dates.h})
zur Behandlung von Datumsangaben.
Diese soll enthalten:
\begin{itemize}
\item
einen \lstinline{struct}-Datentyp \lstinline{date},
der eine Datumsangabe speichert,
\item
eine Funktion \lstinline{void date_print (date *d)}, die ein Datum ausgibt,
\item
eine Funktion \lstinline{int date_set (date *d, int day, int month, int year)},
die ein Datum auf einen gegebenen Tag setzt
und zurückgibt, ob es sich um ein gültiges Datum handelt (0 = nein, 1 = ja),
\item
eine Funktion \lstinline{void date_next (date *d)},
die ein Datum auf den nächsten Tag vorrückt.
\end{itemize}
\exercise{Fehlerhaftes Programm: Primzahlen}
\begin{minipage}[t]{5.5cm}
Das nebenstehende Primzahlsuchprogramm (Datei: \gitfile{hp}{20171113}{aufgabe-2.c})
soll Zahlen ausgeben, die genau zwei Teiler haben, ist aber fehlerhaft.
\smallskip
Korrigieren Sie das Programm derart, daß ein Programm entsteht,
welches alle Primzahlen kleiner 100 ausgibt.% \points 5
\end{minipage}\hfill
\begin{minipage}[t]{9cm}
\vspace*{-0.5cm}
\begin{lstlisting}[gobble=6]
#include <stdio.h>
int main (void)
{
int n, i, divisors;
for (n = 0; n < 100; n++)
divisors = 0;
for (i = 0; i < n; i++)
if (n % i == 0)
divisors++;
if (divisors = 2)
printf ("%d ist eine Primzahl.\n", n);
return 0;
}
\end{lstlisting}
\end{minipage}
\exercise{Fehlerhaftes Programm: Rotierender Würfel}
Das auf der nächsten Seite abgedruckte OpenGL-Programm
(Datei: \gitfile{hp}{20171113}{aufgabe-3.c}) soll einen sich
gleichmäßig drehenden Würfel darstellen, ist jedoch fehlerhaft.
(Die Datei \gitfile{hp}{20171113}{opengl-magic.h} sowie die zugehörige C-Datei
\gitfile{hp}{20171113}{opengl-magic.c} sind die aus der Vorlesung bekannten Beispiel-Dateien,
die Sie zusammen mit diesen Übungsaufgaben herunterladen können.)
\begin{itemize}
\item[(a)]
Warum sieht man lediglich ein leeres Fenster?
Welchen Befehl muß man ergänzen, um diesen Fehler zu beheben?
% \points{4}
\end{itemize}
Nach der Fehlerbehebung in Aufgabenteil (a)
zeigt das Programm einen sich drehenden Würfel.
% (Sie können sich diesen während der Klausur jederzeit vorführen lassen.)
\begin{itemize}
\item[(b)]
Erklären Sie das Drehverhalten des Würfels. % \points{4}
\item[(c)]
Welche Befehle muß man ergänzen,
um eine gleichförmige Drehung zu erhalten? % \points{4}
\end{itemize}
\filbreak
\begin{lstlisting}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
float t = 0.0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glRotatef (t, 0.5, 1.0, 0.0);
glutSolidCube (0.5);
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutMainLoop ();
glutTimerFunc (50, timer_handler, 0);
return 0;
}
\end{lstlisting}
\end{document}
../common/io-ports-and-interrupts.pdf
\ No newline at end of file
../common/logo-hochschule-bochum-cvh-text.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
Vor langer, langer Zeit
gab es einmal
#include "hexe.h"
Die lebte in einem Wald.
#if defined(__APPLE__) || defined(MACOSX)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif
#include "opengl-magic.h"
void init_opengl (int *argcp, char **argv, char *window_name)
{
glutInit (argcp, argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (1024, 768);
glutCreateWindow (window_name);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (20.0, -1.33333, 3.0, 7.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glTranslatef (0.0, 0.0, -5.0);
glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
static GLfloat light0_position[] = { 1.0, 0.0, 1.0, 0.0 };
glLightfv (GL_LIGHT0, GL_POSITION, light0_position);
}
void set_material_color (float r, float g, float b)
{
GLfloat color[] = { r, g, b };
glMaterialfv (GL_FRONT, GL_AMBIENT, color);
glMaterialfv (GL_FRONT, GL_DIFFUSE, color);
}
#if defined(__APPLE__) || defined(MACOSX)
void glutSolidCylinder (double radius, double height, int slices, int stacks)
{
GLUquadricObj *q = gluNewQuadric ();
gluCylinder (q, radius, radius, height, slices, stacks);
gluDeleteQuadric (q);
}
#endif
#ifndef OPENGL_MAGIC_H
#define OPENGL_MAGIC_H
extern void init_opengl (int *argcp, char **argv, char *window_name);
extern void set_material_color (float r, float g, float b);
#ifdef __MACOSX__
extern void glutSolidCylinder (double radius, double height, int slices, int stacks);
#endif
#endif /* OPENGL_MAGIC_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment