Daniel's Tech Blog

Cloud Computing, Cloud Native & Kubernetes

9. AP Praktikum

Das 9. AP Praktikum ist nun auch fertig gestellt, die Abnahme der Aufgaben steht nächste Woche an! Hier die Lösungen dazu:

Aufgabe 1:

#include <stdio.h>
#include “stringFunctions.h”

int laenge_arrayschreibweise(char x[])
{
int i=0;
while(x[i++]);
return (i-1);
}

int laenge_pointerschreibweise(char *x)
{
char *tmp = x;
while(*x++);
return(x-tmp-1);
}

void copy_arrayschreibweise(char x[], char y[])
{
int i=0;
while(y[i++]=x[i]);
}

void copy_pointerschreibweise(char *x, char *y)
{
while(*y++=*x++);
}

Aufgabe 2:

public class Schnapszahl {
public static void main(String[] args)
{

int array[][] = new int[16][16];
int i, j=0, x=0;

for(i=0; i<16; i++)
{
while(j<16)
{
array[i][j]=TextIO.getInt();
if(array[i][j]%11==0) x++;
TextIO.put(array[i][j], 6);
j++;
}
TextIO.putln(“”);
j=0;
}

TextIO.putln(“—————————————————“);
TextIO.putln(“Es sind “+x+” Schnapszahlen vorhanden!”);
return;
}
}

Aufgabe 3:

public class IntegerStack{

private int top;
private int[] stack;

public IntegerStack(int laenge)
{
top=0;
stack = new int[laenge];
}

public void push(int zahl)
{
if(top<stack.length) stack[top++]=zahl;
else throw new IndexOutOfBoundsException(“Der Stack ist voll, es können keine weiteren Elemente hinzugefügt werden! Das Programm wird beendet!”);
}

public int pop()
{
return stack [–top];
}

public boolean is_empty()
{
return(top==0);
}
}

public class StackMain{

public static void main(String[] args)
{
TextIO.putln(“Geben Sie die Stackgröße an!”);

int x = TextIO.getlnInt();
IntegerStack myStack = new IntegerStack(x);

int sum=0;

TextIO.putln(“”);
TextIO.putln(“Geben Sie nun Zahlen ein! Zum Beenden 0 eingeben!”);

while((x=TextIO.getlnInt())!=0)
{
myStack.push(x);
}

TextIO.putln(“—————————————————————–“);
TextIO.putln(“Ausgabe:”);
TextIO.putln(“—————————————————————–“);

while(!myStack.is_empty())
{
TextIO.putln(x=myStack.pop());
sum+=x;
}

TextIO.putln(“Die Summe ist: ” +sum);

return;
}
}


Posted

in

WordPress Cookie Notice by Real Cookie Banner