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

Beispielprogramme 5.2.2018, Klausur vom WS 2016/17

parent 481c9891
No related branches found
No related tags found
No related merge requests found
Showing
with 401 additions and 0 deletions
#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"
#include <math.h>
static void perspective (GLdouble fovY, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
GLdouble fW, fH;
fH = tan (fovY / 360.0 * M_PI) * zNear;
fW = fH * aspect;
glFrustum (-fW, fW, -fH, fH, zNear, zFar);
}
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 ();
perspective (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 */
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/freeglut.h>
#include <math.h>
#include "opengl-magic.h"
#define phi0 0.5 /* geg. Anfangswert */
#define omega0 0.0 /* geg. Anfangswert */
#define dt 0.05
#define g 9.81
#define l 1.0
double t = 0.0;
double phi_with_sin = phi0;
double omega_with_sin= omega0;
double phi_without_sin = phi0;
double omega_without_sin= omega0;
void draw_pendulum (double phi)
{
glPushMatrix ();
glRotatef (90, 1.0, 0.0, 0.0);
glTranslatef (0.0, 0.0, -0.75);
glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0);
glTranslatef (0.0, 0.0, -1.0);
glutSolidCylinder (0.01, 1.0, 13, 1);
glutSolidSphere (0.1, 31, 10);
glPopMatrix ();
glutSwapBuffers ();
}
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (0.8, 0.8, 1.0);
draw_pendulum (phi_with_sin);
set_material_color (1.0, 0.8, 0.8);
draw_pendulum (phi_without_sin);
set_material_color (0.8, 1.0, 0.8);
double A = phi0;
double B = 0.5 * M_PI; /* 90° */
double phi_analytic = A * sin (sqrt (g / l) * t + B);
draw_pendulum (phi_analytic);
glFlush ();
}
void timer_handler (int value)
{
t += dt;
phi_with_sin += dt * omega_with_sin; /* geg. Differentialgleichung */
omega_with_sin += - dt * g / l * sin (phi_with_sin); /* geg. Differentialgleichung */
/* _ohne_ Kleinwinkelnäherung */
phi_without_sin += dt * omega_without_sin; /* geg. Differentialgleichung */
omega_without_sin += - dt * g / l * phi_without_sin; /* geg. Differentialgleichung */
/* _mit_ Kleinwinkelnäherung */
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Pendulum");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutPostRedisplay ();
glutMainLoop ();
return 0;
}
File added
% hp-klausur-20170206.pdf - Examination on Applied Computer Sciences
% Copyright (C) 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/>.
\documentclass[a4paper]{article}
\usepackage{pgscript}
\newcounter{exercise}
\newcommand{\exercise}[1]{\addtocounter{exercise}{1}\subsection*{Aufgabe \arabic{exercise}: #1}}
\usepackage{enumerate}
\usepackage{ifthen}
\newcommand{\workspacexyt}[3]{%
\begin{center}
\setlength{\unitlength}{0.5cm}
\begin{picture}(#1,#2)
\color[rgb]{0.7,0.7,0.7}
\put(0,0){\line(1,0){#1}}
\multiput(0,1)(0,1){#2}{\line(1,0){#1}}
\put(0,0){\line(0,1){#2}}
\multiput(1,0)(1,0){#1}{\line(0,1){#2}}
\put(0,0){\makebox(#1,#2)[c]{\color[rgb]{0.2,0.2,0.2}#3}}
\end{picture}
\end{center}}
\newcommand{\workspace}[1]{\workspacexyt{30}{#1}{}}
\newcounter{points}
\newcommand{\points}[1]{\ifthenelse{#1=1}{(1 Punkt)}{(#1 Punkte)}\addtocounter{points}{#1}}
\newcommand{\klausur}[2]{%
\clearpage
\setcounter{page}{1}
\setcounter{points}{0}
\setcounter{exercise}{0}
\gdef\username{#1}
\gdef\password{#2}
\input{klausur}
}
\begin{document}
\klausur{29}{ksVY3vujsxPY}
\klausur{04}{vgxMA7CUpvKU}
\klausur{27}{jvdyX9njbR3H}
\klausur{09}{gKwJpPh47jYa}
\klausur{59}{dkKUPaau7Fhj}
\klausur{42}{TPfkYRyuJ9nj}
\klausur{50}{UFJXeK7kmjx3}
\klausur{47}{w4zJ7FmdNrrn}
\klausur{25}{aVVcfUfA4hPC}
\klausur{06}{iMRzsngTr3qn}
\klausur{45}{rPedu3apVMEe}
\klausur{58}{dFLiTg4szWEJ}
\klausur{22}{eTw4twmmmvkc}
\klausur{34}{fECEPEr7AhCK}
\klausur{07}{nL7xXAYwjf4T}
\klausur{56}{mXp4wEtPhmpU}
\klausur{35}{V9Azdb7iiM9N}
\klausur{52}{3KgnTniUspRg}
\klausur{51}{egAyjkmacRR7}
\klausur{10}{hCE3M3vePijb}
\klausur{53}{u4MJwRoezoyY}
\klausur{21}{ztnXs39dAjti}
\klausur{33}{H7YThwhwqks3}
\klausur{46}{9VfP4jxAaA7R}
\klausur{28}{sfga4xMeRXmo}
\klausur{30}{WXysjjvR7JVY}
\klausur{37}{gHKtMRkVooC3}
\klausur{15}{Jj7tHtuvqoap}
\klausur{20}{LbEir4FXKnhM}
\klausur{36}{4amqxVwgfg3H}
\klausur{24}{Vp3UajsUJjRb}
\klausur{57}{n7UxFccciFM9}
\klausur{44}{7qMmVrNjsyVC}
\klausur{01}{U47zYi9VEq7b}
\klausur{31}{FEaKnuLERoR4}
\klausur{19}{Fad4YbupUdnw}
\klausur{38}{73PrJCCNykMx}
\klausur{13}{o7hEzFRTWvqW}
\klausur{32}{pcU3KNrXcdhz}
\klausur{39}{YxnuYP3YhvYa}
\klausur{49}{pmoqjfwCN7n4}
\klausur{16}{fjsYm3dvEMPC}
\klausur{54}{A3kPxXivfHvs}
\klausur{23}{CgF4AUNAKVPj}
\klausur{14}{HoAcL47KaWwf}
\klausur{02}{ucNHnuweEX4o}
\klausur{41}{NTV3WRofwxvK}
\klausur{48}{mJnuCVEzm9uR}
\klausur{55}{rk4M4nrHT77u}
\klausur{17}{eJV9uzxfstpo}
\klausur{05}{nozT7izzJ3xJ}
\klausur{12}{riVaeFUH4NHA}
\klausur{03}{b7LCnwTRJsrV}
\klausur{40}{dFRbW7kfkzaL}
\klausur{00}{mJaiepppsFc9}
\klausur{11}{KeRwm3bCwJkr}
\klausur{18}{KxdE7thMPdkx}
\klausur{08}{zi7PdpsFjd37}
\klausur{43}{nkfAu4UnAHpE}
\klausur{26}{mFnsXk7PuFRP}
\end{document}
#include <stdio.h>
int main (void)
{
int a;
scanf ("%d", &a);
printf ("a = %d\n", a);
return 0;
}
#include <stdio.h>
int main (void)
{
int a, b;
scanf ("%d %d", &a, &b);
printf ("a = %d, b = %d\n", a, b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a, b;
scanf ("%d , %d", &a, &b);
printf ("a = %d, b = %d\n", a, b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a, b;
scanf ("%d und %d", &a, &b);
printf ("a = %d, b = %d\n", a, b);
return 0;
}
#include <stdio.h>
int main (void)
{
char s[100];
scanf ("%s", s);
printf ("s = \"%s\"\n", s);
return 0;
}
#include <stdio.h>
int main (void)
{
char s1[100], s2[100];
scanf ("%s %s", s1, s2);
printf ("s1 = \"%s\", s2 = \"%s\"\n", s1, s2);
return 0;
}
#include <stdio.h>
int main (void)
{
char s[100];
scanf ("%s", &s);
printf ("s = \"%s\"\n", s);
return 0;
}
#include <stdio.h>
int main (void)
{
char *s;
scanf ("%s", s);
printf ("s = \"%s\"\n", s);
return 0;
}
#include <stdio.h>
int main (void)
{
char *s = 42;
scanf ("%s", s);
printf ("s = \"%s\"\n", s);
return 0;
}
#include <stdio.h>
int main (void)
{
char buffer[100];
char *s = buffer;
scanf ("%s", s);
printf ("s = \"%s\"\n", s);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char *s = malloc (100);
scanf ("%s", s);
printf ("s = \"%s\"\n", s);
return 0;
}
#include <stdio.h>
int main (void)
{
int a;
scanf ("%c", &a);
printf ("a = %d\n", a);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char *s = malloc (100);
scanf ("%s", s);
printf ("s = \"%s\"\n", s);
free (s);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char *s = malloc (1);
scanf ("%s", s);
printf ("s = \"%s\"\n", s);
free (s);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char *s = malloc (100);
fgets (s, 100, stdin);
printf ("s = \"%s\"\n", s);
free (s);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment