Compare commits

..
20 Commits
Author SHA1 Message Date
oeztuerkta87697 a4e732ced9 Merge remote-tracking branch 'origin/main' 2025-06-12 12:51:49 +02:00
oeztuerkta87697 814421d43d MA4 2025-06-12 12:49:53 +02:00
zwanzigda85419 06683f9a75 30.1.3 2025-06-10 16:01:07 +02:00
zwanzigda85419 38fbd0d2a8 26 2025-06-09 15:19:02 +02:00
zwanzigda85419 dbe7ecfd43 26 2025-06-05 18:05:06 +02:00
oeztuerkta87697 5dfa85ffa5 Merge remote-tracking branch 'origin/main' 2025-05-22 20:11:16 +02:00
oeztuerkta87697 d2e28940b1 28.4.4 2025-05-22 20:10:46 +02:00
zwanzigda85419 8a31953c27 MA-3 2025-05-22 18:35:37 +02:00
zwanzigda85419 7b1b698fd3 MA-2 2025-05-22 14:35:18 +02:00
oeztuerkta87697 82f7af17c3 MA2 2025-05-22 13:24:12 +02:00
oeztuerkta87697 9c53700d01 MA2 2025-05-20 18:41:53 +02:00
zwanzigda85419 08072dd34f MA-2 2025-05-19 22:48:47 +02:00
zwanzigda85419 14ad2d456d 28.6.2 2025-05-16 12:18:00 +02:00
zwanzigda85419 1ab4aac4ca 28.6.2 2025-05-14 18:32:32 +02:00
zwanzigda85419 dc67ce69c4 28.6.2 2025-05-14 18:30:00 +02:00
zwanzigda85419 2c4163b42a MA-1 2025-05-12 18:28:15 +02:00
zwanzigda85419 746742c044 MA-1 2025-05-12 18:15:52 +02:00
zwanzigda85419 317225170d 27.3 2025-05-09 11:29:53 +02:00
zwanzigda85419 0ae838071b Merge remote-tracking branch 'origin/main' 2025-05-09 11:09:16 +02:00
zwanzigda85419 ba4dc12e99 27.3 2025-05-09 11:08:54 +02:00
29 changed files with 101961 additions and 8 deletions
BIN
View File
Binary file not shown.
+52
View File
@@ -0,0 +1,52 @@
/**********************************************************************\
* Kurzbeschreibung:
* "Funktionstest" - 2 komplexe Zahlen einlesen
* und alle implementierten Funktionen aus complex.c zum Test aufrufen
*
* Datum: Autor:
*
*
\**********************************************************************/
/*--- #includes ------------------------------------------------------*/
#define _CRT_SECURE_NO_WARNINGS //VC++: keine scanf() Warnungen
#include <stdio.h>
#include "complex.h"
/*--- #defines -------------------------------------------------------*/
/*--- Lokale Datentypen (typedef) ------------------------------------*/
/*--- Modulglobale static Variablen ----------------------------------*/
/*--- Prototypen lokaler Funktionen ----------------------------------*/
/*--- Funktionsdefinitionen ------------------------------------------*/
/*--- main -----------------------------------------------------------*/
int main(void)
{
double real = 0, imag = 0;
printf("1. Zahl eingeben\nRealteil: ");
scanf("%lf", &real);
printf("Imaginaerteil:");
scanf("%lf", &imag);
Complex zahl1 = {real, imag};
printf("2. Zahl eingeben\nRealteil: ");
scanf("%lf", &real);
printf("Imaginaerteil:");
scanf("%lf", &imag);
Complex zahl2 = {real, imag};
printf("\nx = (%.3lf + %.3lf""i)", zahl1.real, zahl1.imag);
printf("\ny = (%.3lf + %.3lf""i)\n\n", zahl2.real, zahl2.imag);
addComplex(zahl1 ,zahl2);
subComplex(zahl1 ,zahl2);
mulComplex(zahl1 ,zahl2);
divComplex(zahl1 ,zahl2);
}
+114
View File
@@ -0,0 +1,114 @@
/**********************************************************************\
* Kurzbeschreibung:
* "Funktionstest" - Matrizen mit Werten erzeugen
* und alle implementierten Funktionen aus matrixOp.c zum Test aufrufen
*
* Datum: Autor:
*
*
\**********************************************************************/
/*--- #includes ------------------------------------------------------*/
#define _CRT_SECURE_NO_WARNINGS //VC++: keine scanf() Warnungen
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "matrixOp.h"
/*--- #defines -------------------------------------------------------*/
/*--- Lokale Datentypen (typedef) ------------------------------------*/
/*--- Modulglobale static Variablen ----------------------------------*/
/*--- Prototypen lokaler Funktionen ----------------------------------*/
/*--- Funktionsdefinitionen ------------------------------------------*/
/*--- main -----------------------------------------------------------*/
int main(void) {
unsigned int zeilen, spalten;
float startWert;
printf("Test verschiedener Funktionen der Bibliothek\n");
printf("Gewuenschte Matrizen-Groesse eingeben\n");
printf(" Zeilen, Spalten (> 0; z.B. 3,4): ");
scanf("%u,%u", &zeilen, &spalten);
Matrix a = createMatrix(spalten, zeilen);
printf("Matrix Elemente eingeben (F. Test nur 1.Elem., weitere Elemente werden mit +1 erzeugt)\n");
printf(" Element in [1,1] (z.B.: 4.5): ");
scanf("%f", &startWert);
float wert = startWert;
for (unsigned int y = 0; y < zeilen; y++) {
for (unsigned int x = 0; x < spalten; x++) {
setEntryAt(a, x, y, wert);
wert += 1.0f;
}
}
printf("\nTest Create Zero und Rand:\n");
Matrix zero = createMatrixZero(spalten, zeilen);
printf("CreateMatrixZero: a[%d,%d]=\n", spalten, zeilen);
printMatrix(zero);
printf("\nInfo: Called srand!\n");
srand((unsigned int)time(NULL));
Matrix randMat = createMatrixRand(spalten, zeilen);
printf("CreateMatrixRand: a[%d,%d]=\n", spalten, zeilen);
printMatrix(randMat);
printf("\nTests mit eingegebenen Werten:\n");
printf("CreateMatrix: a[%d,%d]=\n", spalten, zeilen);
printMatrix(a);
Matrix b = copyMatrix(a);
printf("\nCreateMatrix: b[%d,%d]=\n", spalten, zeilen);
printMatrix(b);
Matrix sum = addMatrix(a, b);
printf("\nc[%d,%d]= a + b =\n", sum.spalten, sum.zeilen);
printMatrix(sum);
Matrix diff = subMatrix(a, b);
printf("\nc[%d,%d]= a - b =\n", diff.spalten, diff.zeilen);
printMatrix(diff);
Matrix bT = transposeMatrix(b);
printf("\nc[%d,%d]= b^T\n", bT.spalten, bT.zeilen);
printMatrix(bT);
Matrix c = multMatrix(a, bT); // a * b^T
printf("a * b^T = c\n");
// Nur die obere linke 2x2-Matrix drucken
printf("{\n");
for (int y = 0; y < 2; y++) {
printf(" ");
for (int x = 0; x < 2; x++) {
printf("%6.2f", getEntryAt(c, x, y));
if (x < 1) printf(" ");
}
printf("\n");
}
printf("}\n");
printf("\ndet(c) = %.2f\n", determMatrix(c));
// Speicher freigeben
destroyMatrix(&a);
destroyMatrix(&b);
destroyMatrix(&sum);
destroyMatrix(&diff);
destroyMatrix(&zero);
destroyMatrix(&randMat);
destroyMatrix(&bT);
destroyMatrix(&c);
return 0;
}
+47
View File
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <string.h>
int main(){
char name[50], vorname[50], strasse[50], hausnummer[50], plz[50], wohnort[50], telefon[50], fax[50];
int n;
char *filename = "adresse.txt", *ptr;
printf("Dieses Programm liest eine Adresse ein und schreibt\ndiese Adresse n mal in die Datei 'adresse.txt'\n");
printf("Vorname:");
fgets(vorname, sizeof(vorname), stdin);
printf("Nachname:");
fgets(name, sizeof(name), stdin);
printf("Strasse:");
fgets(strasse, sizeof(strasse), stdin);
printf("Hausnummer:");
fgets(hausnummer, sizeof(hausnummer), stdin);
printf("Postleitzahl:");
fgets(plz, sizeof(plz), stdin);
printf("Wohnort:");
fgets(wohnort, sizeof(wohnort), stdin);
printf("Telefon:");
fgets(telefon, sizeof(plz), stdin);
printf("Fax:");
fgets(fax, sizeof(fax), stdin);
printf("Wie oft soll Adresse in Datei geschrieben werden:");
scanf("%d", &n);
ptr = strchr(strcat(vorname, name), '\n');
ptr[0] = ' ';
ptr = strchr(strcat(strasse, hausnummer), '\n');
ptr[0] = ' ';
ptr = strchr(strcat(plz, wohnort), '\n');
ptr[0] = ' ';
FILE *fp = fopen(filename, "w");
for (int i = 0; i < n; ++i) {
fprintf(fp, "%s%s%s\nTel. %sFax %s", vorname, strasse, plz, telefon, fax);
fprintf(fp, "--------------------------------------------------\n");
}
fclose(fp);
}
+28
View File
@@ -0,0 +1,28 @@
Alexander Fleischmann
Bergenstrasse 172a
50636 Nordhofen
Tel. 1233/213213
Fax 9808/89798
--------------------------------------------------
Alexander Fleischmann
Bergenstrasse 172a
50636 Nordhofen
Tel. 1233/213213
Fax 9808/89798
--------------------------------------------------
Alexander Fleischmann
Bergenstrasse 172a
50636 Nordhofen
Tel. 1233/213213
Fax 9808/89798
--------------------------------------------------
Alexander Fleischmann
Bergenstrasse 172a
50636 Nordhofen
Tel. 1233/213213
Fax 9808/89798
--------------------------------------------------
+178
View File
@@ -0,0 +1,178 @@
/**********************************************************************\
* Kurzbeschreibung: automat.c
* Stellt Funktionen zur Realisierung eines Automaten zur Verf�gung,
* die �ber die in der automat.h vorgegebene C-Schnittstelle
* mit einer grafischen Schnittstelle kommunizieren.
*
* Datum: Autor: Grund der Aenderung:
*
*
\**********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "automat.h"
/*--- #defines -------------------------------------------------------*/
/* Macro zur Ermittlung der Array Groesse */
#define SIZE_OF(a) (sizeof((a)) / sizeof(*(a)))
#define NR_OF_STATES (I - A + 1)
/*--- Datentypen (typedef) -------------------------------------------*/
/* Definition der Zustaende */
typedef enum
{
A = 0,
B,
C,
D,
E,
F,
G,
H,
I
} state_t;
/* Definition der fsm-spezifischen Variablen */
/* Struktur zur Beschreibung eines Uebergangs mit "Don't Care"-Moeglichkeit */
typedef struct
{
int input;
int mask;
state_t nxtstate;
} fsm_state_t;
/* Struktur zur Beschreibung aller Uebergaenge eines Zustands */
typedef struct
{
const fsm_state_t *transitions;
int nrOfTransitions;
state_t defaultNxtState;
} fsm_full_state_t;
/*--- Modulglobale static Variablen ----------------------------------*/
/* Definition der Zustandsvariablen */
static state_t s_curstate = A; /* Initialisierung */
/* Definition aller Zustandsuebergaenge fuer jeden Zustand */
static const fsm_state_t s_transitions_A[] =
{/* input mask nxtstate */
{0x002, ~0x004, B},
{0x003, ~0x004, C}};
static const fsm_state_t s_transitions_B[] =
{/* input mask nxtstate */
{0x002, ~0x004, C},
{0x003, ~0x004, D}};
static const fsm_state_t s_transitions_C[] =
{/* input mask nxtstate */
{0x002, ~0x004, D},
{0x003, ~0x000, F},
{0x007, ~0x000, H}};
static const fsm_state_t s_transitions_D[] =
{/* input mask nxtstate */
{0x002, ~0x000, F},
{0x003, ~0x004, E},
{0x006, ~0x000, H}};
static const fsm_state_t s_transitions_E[] =
{
/* input mask nxtstate */
{0x000, ~0x005, D},
{0x002, ~0x000, F},
{0x006, ~0x000, H}};
static const fsm_state_t s_transitions_F[] =
{
/* input mask nxtstate */
{0x002, ~0x001, G},
{0x006, ~0x001, I},
{0x004, ~0x001, H}};
static const fsm_state_t s_transitions_G[] =
{
/* input mask nxtstate */
{0x000, ~0x001, F},
{0x004, ~0x001, H},
{0x006, ~0x001, I},
};
static const fsm_state_t s_transitions_H[] =
{
/* input mask nxtstate */
{0x000, ~0x001, A},
{0x002, ~0x000, B},
{0x003, ~0x000, C},
{0x006, ~0x001, I}};
static const fsm_state_t s_transitions_I[] =
{
/* input mask nxtstate */
{0x000, ~0x001, A},
{0x002, ~0x000, B},
{0x003, ~0x000, C},
{0x004, ~0x001, H}};
/* Definition der Uebergangstabelle */
/* Die Reihenfolge der Zustaende in der enum Definition muss der
* Reihenfolge der Zustaende in der Uebergangstabelle entsprechen
* [Zeile] [Spalte] */
static const fsm_full_state_t s_state_table[NR_OF_STATES] =
{
/* transitions nrOfTransitions defaultNxtState */
{s_transitions_A, SIZE_OF(s_transitions_A), A},
{s_transitions_B, SIZE_OF(s_transitions_B), B},
{s_transitions_C, SIZE_OF(s_transitions_C), C},
{s_transitions_D, SIZE_OF(s_transitions_D), D},
{s_transitions_E, SIZE_OF(s_transitions_E), E},
{s_transitions_F, SIZE_OF(s_transitions_F), F},
{s_transitions_G, SIZE_OF(s_transitions_G), G},
{s_transitions_H, SIZE_OF(s_transitions_H), H},
{s_transitions_I, SIZE_OF(s_transitions_I), I}};
/* Definition der Ausgaenge */
static const fsm_action_t s_out_table[NR_OF_STATES] =
{
/* display muenz_rueck kaffee_los guthaben, display_string */
{false, false, false, 0, "Warten"}, /* state A */
{false, false, false, 1, "1 Euro"}, /* state B */
{false, false, false, 2, "2 Euro"}, /* state C */
{false, false, false, 3, "3 Euro"}, /* state D */
{false, true, false, 3, "3 Euro + M"}, /* state E */
{true, false, false, 4, "4 Euro"}, /* state F */
{true, true, false, 4, "4 Euro + M"}, /* state G */
{true, false, true, 0, "Glühwein"}, /* state H */
{true, true, true, 0, "Glühwein + M"}, /* state I */
};
/*--- Funktionsdefinition --------------------------------------------*/
void automat_reset(void)
{
printf("---- automat_reset ----\n");
s_curstate = A;
}
/*--- Funktionsdefinition --------------------------------------------*/
void automat_transition(BOOL becher, BOOL muenze, BOOL muenz_wert)
{
printf("---- automat_transition becher(%0d) muenze(%0d) muenz_wert(%0d) ----\n",
becher, muenze, muenz_wert);
int bitTrain = (becher << 2 | muenze << 1 | muenz_wert);
fsm_full_state_t curState = s_state_table[s_curstate];
for (int i = 0; i < curState.nrOfTransitions; i++)
{
if ((curState.transitions[i].input & curState.transitions[i].mask) == (bitTrain & curState.transitions[i].mask))
{
s_curstate = curState.transitions[i].nxtstate;
}
}
}
/*--- Funktionsdefinition --------------------------------------------*/
fsm_action_t automat_output(void)
{
return s_out_table[s_curstate];
}
+44
View File
@@ -0,0 +1,44 @@
/**********************************************************************\
* Kurzbeschreibung: automat.h
* Stellt Funktionen zur Realisierung eines Automaten zur Verfügung,
* die über die in der automat.h vorgegebene C-Schnittstelle
* mit einer grafischen Schnittstelle kommunizieren.
*
* Datum: Autor: Grund der Aenderung:
*
*
\**********************************************************************/
#ifndef AUTOMAT_H
#define AUTOMAT_H
/*--- #defines -------------------------------------------------------*/
#define true 1
#define false 0
/*--- Datentypen (typedef) -------------------------------------------*/
typedef int BOOL;
typedef struct {
BOOL display;
BOOL muenz_rueck;
BOOL kaffee_los;
int guthaben;
const char * display_string;
} fsm_action_t;
/*--- Prototypen globaler Funktionen ---------------------------------*/
/*--------------------------------------------------------------------*
* Setzt den Automat in IDLE state *
*--------------------------------------------------------------------*/
extern void automat_reset(void);
/*--------------------------------------------------------------------*
* Fuehrt Zustandsuebergaenge durch *
*--------------------------------------------------------------------*/
extern void automat_transition(BOOL becher, BOOL muenze, BOOL muenz_wert);
/*--------------------------------------------------------------------*
* Gibt Informationen ueber aktuellen Zustand zurueck *
*--------------------------------------------------------------------*/
extern fsm_action_t automat_output(void);
#endif /* AUTOMAT_H */
+14
View File
@@ -0,0 +1,14 @@
#include <stdio.h>
typedef int BOOL;
int main(void)
{
BOOL becher = 0;
BOOL muenze = 0;
BOOL muenz_wert = 1;
char bitTrain = (becher << 2 | muenze << 1 | muenz_wert);
printf("%#08x", bitTrain);
return 0;
}
+123
View File
@@ -0,0 +1,123 @@
#include "checker.h"
#include <stdio.h>
typedef struct {
BOOL reset;
BOOL muenz_wert;
BOOL muenze;
BOOL becher;
} fsm_input_t;
typedef struct {
fsm_input_t input;
fsm_action_t output;
} fsm_transaction_t;
#include "s_transaction_list.h"
static const int s_transaction_list_size =
sizeof(s_transaction_list) / sizeof(*s_transaction_list);
#define ERROR_STRING_SIZE 1000
static char s_error_string[ERROR_STRING_SIZE] = { 0 };
static void checker_propagate_input(fsm_input_t input);
static BOOL checker_compare(fsm_action_t o1, fsm_action_t o2);
static void checker_write_error_string(
fsm_action_t current, fsm_input_t input,
fsm_action_t actual, fsm_action_t expected);
static void checker_clear_error_string(void);
/*****************************************************************************/
/* implementation of extern functions ****************************************/
/*****************************************************************************/
BOOL checker_check()
{
fsm_action_t last_out;
fsm_action_t new_out;
int i;
automat_reset();
for (i = 0; i < s_transaction_list_size; i++) {
last_out = automat_output();
checker_propagate_input(s_transaction_list[i].input);
new_out = automat_output();
if (!checker_compare(new_out, s_transaction_list[i].output)) {
checker_write_error_string(last_out, s_transaction_list[i].input,
new_out, s_transaction_list[i].output);
return false;
}
}
checker_clear_error_string();
return true;
}
const char * checker_error_string() { return s_error_string; }
/*****************************************************************************/
/* implementation of static functions ****************************************/
/*****************************************************************************/
void checker_propagate_input(fsm_input_t input)
{
if (input.reset) automat_reset();
else automat_transition(input.becher, input.muenze, input.muenz_wert);
}
BOOL checker_compare(fsm_action_t o1, fsm_action_t o2)
{
return o1.display == o2.display &&
o1.muenz_rueck == o2.muenz_rueck &&
o1.kaffee_los == o2.kaffee_los &&
o1.guthaben == o2.guthaben;
}
void checker_write_error_string(
fsm_action_t current, fsm_input_t input,
fsm_action_t actual, fsm_action_t expected)
{
if (input.reset) {
/* actually wanna use snprintf, but it's defined in c99 */
sprintf(s_error_string,
"Ausgangsvektor enthält nicht die erwarteten Werte:\n"
"Letzter Zustand: disp:%d rueck:%d los:%d guthaben:%d \"%s\"\n"
"Eingang: Reset\n"
"Ausgang: disp:%d rueck:%d los:%d guthaben:%d \"%s\"\n"
"Erwartet: disp:%d rueck:%d los:%d guthaben:%d",
current.display, current.muenz_rueck, current.kaffee_los,
current.guthaben, current.display_string,
actual.display, actual.muenz_rueck, actual.kaffee_los,
actual.guthaben, actual.display_string,
expected.display, expected.muenz_rueck, expected.kaffee_los,
expected.guthaben);
} else {
/* actually wanna use snprintf, but it's defined in c99 */
sprintf(s_error_string,
"Ausgangsvektor enthält nicht die erwarteten Werte:\n"
"Letzter Zustand: disp:%d rueck:%d los:%d guthaben:%d \"%s\"\n"
"Eingang: becher:%d muenze:%d muenz_wert:%d\n"
"Ausgang: disp:%d rueck:%d los:%d guthaben:%d \"%s\"\n"
"Erwartet: disp:%d rueck:%d los:%d guthaben:%d",
current.display, current.muenz_rueck, current.kaffee_los,
current.guthaben, current.display_string,
input.becher, input.muenze, input.muenz_wert,
actual.display, actual.muenz_rueck, actual.kaffee_los,
actual.guthaben, actual.display_string,
expected.display, expected.muenz_rueck, expected.kaffee_los,
expected.guthaben);
}
}
void checker_clear_error_string()
{
s_error_string[0] = '\0';
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef __CHECKER_H__
#define __CHECKER_H__
#include "automat.h"
extern BOOL checker_check(void);
extern const char * checker_error_string(void);
#endif /* __CHECKER_H__ */
+107
View File
@@ -0,0 +1,107 @@
/**********************************************************************\
* Kurzbeschreibung: complex.c
* Bietet Funktionen zum Rechnen mit komplexen Zahlen
*
* Datum: Autor: Grund der Aenderung:
*
*
\**********************************************************************/
/*--- #includes ------------------------------------------------------*/
#include <float.h>
#include <stdio.h>
#include "complex.h"
/*--- #defines -------------------------------------------------------*/
/*--- Lokale Datentypen (typedef) ------------------------------------*/
/*--- Modulglobale static Variablen ----------------------------------*/
/*--- Prototypen lokaler Funktionen ----------------------------------*/
/*--- Funktionsdefinitionen ------------------------------------------*/
/*--------------------------------------------------------------------*\
* Addition komplexer Zahlen: x + y
* Rueckgabe: Ergebnis im Typ "Complex"
\*--------------------------------------------------------------------*/
Complex addComplex(Complex x, Complex y)
{
Complex summe;
summe.real = x.real + y.real;
summe.imag = x.imag + y.imag;
printf("Summe: x + y = ");
printComplex(summe);
return summe;
}
/*--------------------------------------------------------------------*\
* Subtraktion komplexer Zahlen: x - y
* Rueckgabe: Ergebnis im Typ "Complex"
\*--------------------------------------------------------------------*/
Complex subComplex(Complex x, Complex y)
{
Complex diff;
diff.real = x.real - y.real;
diff.imag = x.imag - y.imag;
printf("Differenz: x - y = ");
printComplex(diff);
return diff;
}
/*--------------------------------------------------------------------*\
* Multiplikation komplexer Zahlen: x * y
* Rueckgabe: Ergebnis im Typ "Complex"
\*--------------------------------------------------------------------*/
Complex mulComplex(Complex y, Complex x) {
Complex prod;
prod.real = (x.real * y.real)-(x.imag * y.imag);
prod.imag = (x.real * y.imag) + (x.imag * y.real);
printf("Produkt: x * y = ");
printComplex(prod);
return prod;
}
/*--------------------------------------------------------------------*\
* Division komplexer Zahlen: x / y
* Rueckgabe: Ergebnis im Typ "Complex"; im Fehlerfall 0. bzw. ERROR_C
\*--------------------------------------------------------------------*/
Complex divComplex(Complex x, Complex y)
{
Complex quotient = {};
if(y.real != 0 && y.imag != 0 )
{
quotient.real = (x.real * y.real + x.imag * y.imag) / (y.real * y.real + y.imag * y.imag);
quotient.imag = (x.imag * y.real - x.real * y.imag) / (y.real * y.real + y.imag * y.imag);
printf("Quotient: x / y = ");
printComplex(quotient);
return quotient;
}
return quotient;
}
/*--------------------------------------------------------------------*\
* Lesbar formatierte Ausgabe einer komplexen Zahl
\*--------------------------------------------------------------------*/
int printComplex(Complex z)
{
printf("(%.3f + %.3f""i)\n", z.real, z.imag);
return 0;
}
+56
View File
@@ -0,0 +1,56 @@
/**********************************************************************\
* Kurzbeschreibung: complex.h
* Bietet Funktionen zum Rechnen mit komplexen Zahlen
*
* Datum: Autor: Grund der Aenderung:
* 01.10.2015 Dr. Lurz Neuerstellung
*
\**********************************************************************/
#ifndef COMPLEX_H
#define COMPLEX_H
/*--- #includes ------------------------------------------------------*/
/*--- #defines -------------------------------------------------------*/
#define ERROR_C 0.
/*--- Datentypen (typedef) -------------------------------------------*/
typedef struct t_complex {
double real;
double imag;
} Complex;
/*--- Prototypen globaler Funktionen ---------------------------------*/
/*--------------------------------------------------------------------*\
* Addition komplexer Zahlen: x + y
* Rueckgabe: Ergebnis im Typ "Complex"
\*--------------------------------------------------------------------*/
Complex addComplex(Complex x, Complex y);
/*--------------------------------------------------------------------*\
* Subtraktion komplexer Zahlen: x - y
* Rueckgabe: Ergebnis im Typ "Complex"
\*--------------------------------------------------------------------*/
Complex subComplex(Complex x, Complex y);
/*--------------------------------------------------------------------*\
* Multiplikation komplexer Zahlen: x * y
* Rueckgabe: Ergebnis im Typ "Complex"
\*--------------------------------------------------------------------*/
Complex mulComplex(Complex x, Complex y);
/*--------------------------------------------------------------------*\
* Division komplexer Zahlen: x / y
* Rueckgabe: Ergebnis im Typ "Complex"; im Fehlerfall 0. bzw. ERROR_C
\*--------------------------------------------------------------------*/
Complex divComplex(Complex x, Complex y);
/*--------------------------------------------------------------------*\
* Lesbar formatierte Ausgabe einer komplexen Zahl
\*--------------------------------------------------------------------*/
int printComplex(Complex z);
#endif /*COMPLEX_H*/
BIN
View File
Binary file not shown.
+116
View File
@@ -0,0 +1,116 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct eintrag {
char name[50];
int telefon;
struct eintrag *next_name;
struct eintrag *next_tel;
} Eintrag;
void einfuegen(Eintrag **kopf_name, Eintrag **kopf_tel, char *name, int tel) {
Eintrag *neu = malloc(sizeof(Eintrag));
strcpy(neu->name, name);
neu->telefon = tel;
neu->next_name = NULL;
neu->next_tel = NULL;
Eintrag **p = kopf_name;
while (*p && strcmp((*p)->name, name) < 0)
p = &(*p)->next_name;
neu->next_name = *p;
*p = neu;
p = kopf_tel;
while (*p && (*p)->telefon < tel)
p = &(*p)->next_tel;
neu->next_tel = *p;
*p = neu;
}
void liste_name_ausgeben(Eintrag *kopf) {
printf("\n...Liste nach Namen sortiert...\n");
while (kopf) {
printf("%s (Tel.: %d)\n", kopf->name, kopf->telefon);
kopf = kopf->next_name;
}
}
void liste_tel_ausgeben(Eintrag *kopf) {
printf("\n...Liste nach Telefonnummer sortiert...\n");
while (kopf) {
printf("%d (%s)\n", kopf->telefon, kopf->name);
kopf = kopf->next_tel;
}
}
void speicher_freigeben(Eintrag *kopf) {
Eintrag *temp;
while (kopf) {
temp = kopf->next_name;
free(kopf);
kopf = temp;
}
}
int main() {
Eintrag *kopf_name = NULL, *kopf_tel = NULL;
char name[50];
char eingabe[100];
int tel;
char wahl;
printf("Namens- und Telefonliste\n");
printf("========================\n");
do {
printf("\nN - Einfuegen neuer Namen mit Telefonnummer\n");
printf("A - Ausgeben der Liste\n");
printf("E - Ende\n");
printf("Deine Wahl:");
scanf("%c", &wahl);
getchar();
switch (wahl) {
case 'N':
case 'n':
while (1) {
printf("Name:");
fgets(name, sizeof(name), stdin);
name[strcspn(name, "\n")] = 0;
if (strlen(name) == 0)
break;
printf("Tel:");
fgets(eingabe, sizeof(eingabe), stdin);
tel = atoi(eingabe);
einfuegen(&kopf_name, &kopf_tel, name, tel);
}
break;
case 'A':
case 'a':
liste_name_ausgeben(kopf_name);
liste_tel_ausgeben(kopf_tel);
break;
case 'E':
case 'e':
// Ende
break;
default:
printf("Ungueltige Eingabe.\n");
}
} while (wahl != 'E' && wahl != 'e');
speicher_freigeben(kopf_name);
return 0;
}
+80
View File
@@ -0,0 +1,80 @@
#include "io.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
/******************************************************************************/
/* Module intern macros *******************************************************/
/******************************************************************************/
/* unfortunatly can't write this code as function, because of stack management
* => use makro instead */
#define DO_PRINTING(output_str) \
do { \
if (output_str != NULL) { \
va_list args; \
va_start(args, output_str); \
vprintf(output_str, args); \
va_end(args); \
} \
} while (0)
/******************************************************************************/
/* Implementations ************************************************************/
/******************************************************************************/
char * io_read_string(char * read_buffer, size_t buffer_size,
const char * output_str, ...)
{
char * ret, * ptr;
DO_PRINTING(output_str);
ret = fgets(read_buffer, buffer_size, stdin);
if (ret == NULL) return NULL;
/* search for \n */
ptr = strchr(read_buffer, '\n');
/* if found write \0 instead of \n */
if (ptr) *ptr = '\0';
/* else buffer is not read completly => clear buffer */
else while (getchar() != '\n');
return read_buffer;
}
int io_read_signed_number(const char * output_str, ...)
{
int number;
while (1) {
int ret;
DO_PRINTING(output_str);
ret = scanf("%d", &number);
/* clear buffer */
while (getchar() != '\n');
if (ret == 1) break;
else printf("Eingabefehler!!!\n");
}
return number;
}
unsigned int io_read_unsigned_number(const char * output_str, ...)
{
unsigned int number;
while (1) {
int ret;
DO_PRINTING(output_str);
ret = scanf("%u", &number);
/* clear buffer */
while (getchar() != '\n');
if (ret == 1) break;
else printf("Eingabefehler!!!\n");
}
return number;
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef __IO_H__
#define __IO_H__
#include <stddef.h> /* for size_t */
/* prints the given string (if not NULL) and reads a string from stdin and
* removes \n
* the functions returns the value of fgets */
extern char * io_read_string(char * read_buffer, size_t buffer_size,
const char * output_str, ...);
/* prints the given string (if not NULL) and reads signed number from stdin */
extern int io_read_signed_number(const char * output_str, ...);
/* prints the given string (if not NULL) and reads unsigned number from stdin */
extern unsigned int io_read_unsigned_number(const char * output_str, ...);
#endif /* __IO_H__ */
+42
View File
@@ -0,0 +1,42 @@
/*--- #includes ------------------------------------------------------*/
#define _CRT_SECURE_NO_WARNINGS //VC++: keine scanf() Warnungen
#include <stdio.h>
#include "queue.h"
/*--- #defines -------------------------------------------------------*/
/*--- Datentypen (typedef) -------------------------------------------*/
/*--- Prototypen lokaler Funktionen ----------------------------------*/
/*--- main -----------------------------------------------------------*/
int main(void)
{
int n, z, i=1, nr;
do {
printf("Wie viele Personen: ");
nr = scanf("%d", &n); getchar();
} while (nr != 1 || n < 0);
do {
printf("Wie vielte ist auszusondern: ");
nr = scanf("%d", &z); getchar();
} while (nr != 1 || z < 0);
for (i = 1; i <= n; i++) // Queue füllen
put(i);
while (!isEmpty()) {
for (i = 1; i < z; i++) { // z-1 Zahlen aus Queue lesen
if (put(get()) == FALSE) { // und wieder am Ende der Queue einfügen
fprintf(stderr, "Fehler beim Einfügen\n");
return 1;
}
}
printf("%d, ", get()); // z. Zahl aus Queue lesen und ausgeben
// Diese Zahl nicht mehr einfügen
}
printf("\n");
return 0;
}
BIN
View File
Binary file not shown.
+70
View File
@@ -0,0 +1,70 @@
#include <stdio.h>
#include "view.h"
#include "automat.h"
#include "checker.h"
void insert_1_euro(void)
{
view_set_coin(1);
automat_transition(view_has_cup(), true, false);
}
void insert_2_euro(void)
{
view_set_coin(2);
automat_transition(view_has_cup(), true, true);
}
void toggle_cup(void)
{
view_set_coin(0);
view_toggle_cup();
automat_transition(view_has_cup(), false, false);
}
void check(void)
{
printf("\n");
if (checker_check()) {
printf("Der Zustandsautomat ist correct\n");
} else {
printf("%s\n", checker_error_string());
}
printf("\nWeiter mit Return ...");
while (getchar() != '\n');
automat_reset();
}
int main(void)
{
int finished = 0;
automat_reset();
view_reset();
while (!finished) {
view_menu_t selection;
view_show(automat_output());
selection = view_menu();
switch (selection) {
case VIEW_1_EURO: insert_1_euro(); break;
case VIEW_2_EURO: insert_2_euro(); break;
case VIEW_CUP: toggle_cup(); break;
case VIEW_RESET: automat_reset(); view_reset(); break;
case VIEW_CHECK: check(); break;
case VIEW_EXIT: finished = 1; break;
case VIEW_INVALID: break;
}
}
return 0;
}
+211
View File
@@ -0,0 +1,211 @@
/**********************************************************************\
* Kurzbeschreibung: matrixOp.c
* Bietet Funktionen fuer Operationen mit Matrizen
*
* Datum: Autor: Grund der Aenderung:
*
*
\**********************************************************************/
/*--- #includes ------------------------------------------------------*/
#include <float.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "matrixOp.h"
/*--------------------------------------------------------------------*\
* Erstellt eine neue Matrix (cM)
* - reserviert lediglich den notwendigen Speicher
* - dynamische Verwaltung von Speicher muss mit malloc() und free()
* durchgef<65>hrt werden; dynamische Arrays sind nicht erlaubt !!!
\*--------------------------------------------------------------------*/
Matrix createMatrix(unsigned int spalten, unsigned int zeilen) {
Matrix m;
m.spalten = spalten;
m.zeilen = zeilen;
m.mElement = (MatTyp *)malloc(sizeof(MatTyp) * spalten * zeilen);
return m;
}
/*--------------------------------------------------------------------*\
* Erstellt und initialisiert eine neue Matrix (zM)
* - reserviert den notwendigen Speicher
* - befuellt die Matrix mit 0
\*--------------------------------------------------------------------*/
Matrix createMatrixZero(unsigned int spalten, unsigned int zeilen) {
Matrix m = createMatrix(spalten, zeilen);
if (m.mElement != NULL) {
for (unsigned int i = 0; i < spalten * zeilen; i++) {
m.mElement[i] = 0.0;
}
}
return m;
}
/*--------------------------------------------------------------------*\
* Erstellt und initialisiert eine neue Matrix (rM)
* - reserviert den notwendigen Speicher
* - befuellt die Matrix mit Zufallszahlen
\*--------------------------------------------------------------------*/
Matrix createMatrixRand(unsigned int spalten, unsigned int zeilen) {
Matrix m = createMatrix(spalten, zeilen);
srand((unsigned int)time(NULL));
for (unsigned int i = 0; i < spalten * zeilen; i++) {
m.mElement[i] = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
}
return m;
}
/*--------------------------------------------------------------------*\
* Kopiert eine Matrix und gibt die Kopie zurueck (yM)
\*--------------------------------------------------------------------*/
Matrix copyMatrix(const Matrix toCopy) {
Matrix copy = createMatrix(toCopy.spalten, toCopy.zeilen);
for (unsigned int i = 0; i < toCopy.spalten * toCopy.zeilen; i++) {
copy.mElement[i] = toCopy.mElement[i];
}
return copy;
}
/*--------------------------------------------------------------------*\
* "Loescht" eine Matrix (dM)
* - gibt reservierten Speicher wieder frei !
* - in der urspruenglichen, uebergebenen Matrix bleiben die Werte erhalten!
\*--------------------------------------------------------------------*/
void deleteMatrix(Matrix toDelete) {
free(toDelete.mElement);
}
/*--------------------------------------------------------------------*\
* "Loescht / Zerstoert" eine uebergegebene Matrix (ddM)
* - gibt Speicher wieder frei, setzt alle Werte auf NULL bzw. "0" !
* - Beachte Unterschiede zur vorigen Funktion !!!
\*--------------------------------------------------------------------*/
void destroyMatrix(Matrix *pToDestroy) {
if (pToDestroy->mElement != NULL) {
free(pToDestroy->mElement);
pToDestroy->mElement = NULL;
pToDestroy->spalten = 0;
pToDestroy->zeilen = 0;
}
}
/*--------------------------------------------------------------------*\
* Gibt den Eintrag der Matrix an der Stelle (xPos, yPos) zurueck (gE)
* Rueckgabe im Fehlerfall: ERROR
\*--------------------------------------------------------------------*/
MatTyp getEntryAt(const Matrix ma, unsigned int xPos, unsigned int yPos) {
if (xPos >= ma.spalten || yPos >= ma.zeilen) return ERROR;
return ma.mElement[yPos * ma.spalten + xPos];
}
/*--------------------------------------------------------------------*\
* Setzt den Eintrag der Matrix an der Stelle (xPos, yPos) (sE)
* Rueckgabe: TRUE, im Fehlerfall: FALSE
\*--------------------------------------------------------------------*/
Bool setEntryAt(Matrix ma, unsigned int xPos, unsigned int yPos, MatTyp value) {
if (xPos >= ma.spalten || yPos >= ma.zeilen) return FALSE;
ma.mElement[yPos * ma.spalten + xPos] = value;
return TRUE;
}
/*--------------------------------------------------------------------*\
* Gibt eine Matrix im Kommandofenster "schoen formatiert" aus (pM)
\*--------------------------------------------------------------------*/
void printMatrix(const Matrix ma) {
printf("\n");
for (unsigned int y = 0; y < ma.zeilen; y++) {
printf("( ");
for (unsigned int x = 0; x < ma.spalten; x++) {
printf("%6.2f ", getEntryAt(ma, x, y));
}
printf(")\n");
}
}
/*--------------------------------------------------------------------*\
* Addiert zwei Matrizen (aM)
* Rueckgabe:
* - Ergebnis der Addition in neu erzeugter Matrix
* - Rueckgabe im Fehlerfall: Matrix der Groesse "0"
\*--------------------------------------------------------------------*/
Matrix addMatrix(const Matrix ma, const Matrix mb) {
if (ma.spalten != mb.spalten || ma.zeilen != mb.zeilen) {
return createMatrix(0, 0);
}
Matrix result = createMatrix(ma.spalten, ma.zeilen);
for (unsigned int i = 0; i < ma.spalten * ma.zeilen; i++) {
result.mElement[i] = ma.mElement[i] + mb.mElement[i];
}
return result;
}
/*--------------------------------------------------------------------*\
* Subtrahiert zwei Matrizen (sM)
* Rueckgabe: "ma - mb"
* - Ergebnis der Subtraktion in neu erzeugter Matrix
* - Rueckgabe im Fehlerfall: Matrix der Groesse "0"
\*--------------------------------------------------------------------*/
Matrix subMatrix(const Matrix ma, const Matrix mb) {
if (ma.spalten != mb.spalten || ma.zeilen != mb.zeilen) {
return createMatrix(0, 0);
}
Matrix result = createMatrix(ma.spalten, ma.zeilen);
for (unsigned int i = 0; i < ma.spalten * ma.zeilen; i++) {
result.mElement[i] = ma.mElement[i] - mb.mElement[i];
}
return result;
}
/*--------------------------------------------------------------------*\
* Multipliziert zwei Matrizen (mM)
* Rueckgabe: "ma * mb"
* - Ergebnis der Multiplikation in neu erzeugter Matrix
* - Rueckgabe im Fehlerfall: Matrix der Groesse "0"
\*--------------------------------------------------------------------*/
Matrix multMatrix(const Matrix ma, const Matrix mb) {
if (ma.spalten != mb.zeilen) return createMatrix(0, 0);
Matrix result = createMatrix(mb.spalten, ma.zeilen);
for (unsigned int y = 0; y < result.zeilen; y++) {
for (unsigned int x = 0; x < result.spalten; x++) {
float sum = 0.0;
for (unsigned int k = 0; k < ma.spalten; k++) {
sum += getEntryAt(ma, k, y) * getEntryAt(mb, x, k);
}
setEntryAt(result, x, y, sum);
}
}
return result;
}
/*--------------------------------------------------------------------*\
* Transponiert eine Matrix (tM)
* Rueckgabe: "ma^T"
\*--------------------------------------------------------------------*/
Matrix transposeMatrix(const Matrix ma) {
Matrix transposed = createMatrix(ma.zeilen, ma.spalten);
for (unsigned int y = 0; y < ma.zeilen; y++) {
for (unsigned int x = 0; x < ma.spalten; x++) {
setEntryAt(transposed, y, x, getEntryAt(ma, x, y));
}
}
return transposed;
}
/*--------------------------------------------------------------------*\
* Gibt die Determinante der Matrix ma zurueck (dt)
* Rueckgabe im Fehlerfall: ERROR
* !!! Optional / Implementation freiwillig !!!
* fuer kleine Matrizen reicht ein einfacher Algorithmus
* wer moechte kann auch ein effizientes Verfahren implementieren
\*--------------------------------------------------------------------*/
double determMatrix(const Matrix ma) {
if (ma.spalten < 2 || ma.zeilen < 2) return ERROR;
float a = getEntryAt(ma, 0, 0);
float b = getEntryAt(ma, 1, 0);
float c = getEntryAt(ma, 0, 1);
float d = getEntryAt(ma, 1, 1);
return a * d - b * c;
}
+132
View File
@@ -0,0 +1,132 @@
/**********************************************************************\
* Kurzbeschreibung: matrixOp.h
* Bietet Funktionen fuer Operationen mit Matrizen
*
* Datum: Autor: Grund der Aenderung:
* 01.10.2015 Dr. Lurz Neuerstellung
*
\**********************************************************************/
#ifndef MATRIXOP_H
#define MATRIXOP_H
/*--- #includes ------------------------------------------------------*/
#include <float.h>
/*--- #defines -------------------------------------------------------*/
#define TRUE 1
#define FALSE 0
#define ERROR FLT_MAX
/*--- Datentypen (typedef) -------------------------------------------*/
typedef float MatTyp;
typedef struct t_matrix {
MatTyp *mElement;
unsigned int spalten;
unsigned int zeilen;
} Matrix;
typedef int Bool;
/*--- Prototypen globaler Funktionen ---------------------------------*/
/*--------------------------------------------------------------------*\
* Erstellt eine neue Matrix (cM)
* - reserviert lediglich den notwendigen Speicher
* - dynamische Verwaltung von Speicher muss mit malloc() und free()
* durchgeführt werden; dynamische Arrays sind nicht erlaubt !!!
\*--------------------------------------------------------------------*/
Matrix createMatrix(unsigned int spalten, unsigned int zeilen);
/*--------------------------------------------------------------------*\
* Erstellt und initialisiert eine neue Matrix (zM)
* - reserviert den notwendigen Speicher
* - befuellt die Matrix mit 0
\*--------------------------------------------------------------------*/
Matrix createMatrixZero(unsigned int spalten, unsigned int zeilen);
/*--------------------------------------------------------------------*\
* Erstellt und initialisiert eine neue Matrix (rM)
* - reserviert den notwendigen Speicher
* - befuellt die Matrix mit Zufallszahlen
\*--------------------------------------------------------------------*/
Matrix createMatrixRand(unsigned int spalten, unsigned int zeilen);
/*--------------------------------------------------------------------*\
* Kopiert eine Matrix und gibt die Kopie zurueck (yM)
\*--------------------------------------------------------------------*/
Matrix copyMatrix(const Matrix toCopy);
/*--------------------------------------------------------------------*\
* "Loescht" eine Matrix (dM)
* - gibt reservierten Speicher wieder frei !
* - in der urspruenglichen, uebergebenen Matrix bleiben die Werte erhalten!
\*--------------------------------------------------------------------*/
void deleteMatrix(Matrix toDelete);
/*--------------------------------------------------------------------*\
* "Loescht / Zerstoert" eine uebergegebene Matrix (ddM)
* - gibt Speicher wieder frei, setzt alle Werte auf NULL bzw. "0" !
* - Beachte Unterschiede zur vorigen Funktion !!!
\*--------------------------------------------------------------------*/
void destroyMatrix(Matrix *pToDestroy);
/*--------------------------------------------------------------------*\
* Gibt den Eintrag der Matrix an der Stelle (xPos, yPos) zurueck (gE)
* Rueckgabe im Fehlerfall: ERROR
\*--------------------------------------------------------------------*/
MatTyp getEntryAt(const Matrix ma, unsigned int xPos, unsigned int yPos);
/*--------------------------------------------------------------------*\
* Setzt den Eintrag der Matrix an der Stelle (xPos, yPos) (sE)
* Rueckgabe: TRUE, im Fehlerfall: FALSE
\*--------------------------------------------------------------------*/
Bool setEntryAt(Matrix ma, unsigned int xPos, unsigned int yPos, MatTyp value);
/*--------------------------------------------------------------------*\
* Gibt eine Matrix im Kommandofenster "schoen formatiert" aus (pM)
\*--------------------------------------------------------------------*/
void printMatrix(const Matrix ma);
/*--------------------------------------------------------------------*\
* Addiert zwei Matrizen (aM)
* Rueckgabe:
* - Ergebnis der Addition in neu erzeugter Matrix
* - Rueckgabe im Fehlerfall: Matrix der Groesse "0"
\*--------------------------------------------------------------------*/
Matrix addMatrix(const Matrix ma, const Matrix mb);
/*--------------------------------------------------------------------*\
* Subtrahiert zwei Matrizen (sM)
* Rueckgabe: "ma - mb"
* - Ergebnis der Subtraktion in neu erzeugter Matrix
* - Rueckgabe im Fehlerfall: Matrix der Groesse "0"
\*--------------------------------------------------------------------*/
Matrix subMatrix(const Matrix ma, const Matrix mb);
/*--------------------------------------------------------------------*\
* Multipliziert zwei Matrizen (mM)
* Rueckgabe: "ma * mb"
* - Ergebnis der Multiplikation in neu erzeugter Matrix
* - Rueckgabe im Fehlerfall: Matrix der Groesse "0"
\*--------------------------------------------------------------------*/
Matrix multMatrix(const Matrix ma, const Matrix mb);
/*--------------------------------------------------------------------*\
* Transponiert eine Matrix (tM)
* Rueckgabe: "ma^T"
\*--------------------------------------------------------------------*/
Matrix transposeMatrix(const Matrix ma);
/*--------------------------------------------------------------------*\
* Gibt die Determinante der Matrix ma zurueck (dt)
* Rueckgabe im Fehlerfall: ERROR
* !!! Optional / Implementation freiwillig !!!
* fuer kleine Matrizen reicht ein einfacher Algorithmus
* wer moechte kann auch ein effizientes Verfahren implementieren
\*--------------------------------------------------------------------*/
double determMatrix(const Matrix ma);
#endif /*MATRIXOP_H*/
+124
View File
@@ -0,0 +1,124 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct schueler {
char name[50];
char vorname[50];
int note;
struct schueler *next
}Schueler;
void einfuegen (Schueler *head, char *name, char *vorname, int note ){
Schueler* current = head;
Schueler *neu = malloc(sizeof(Schueler));
while(current->next != NULL) {
current = current->next;
}
strcpy(neu->name, name);
strcpy(neu->vorname, vorname);
neu->note = note;
neu->next = NULL;
current -> next = neu;
}
void printList(Schueler *head){
Schueler* current = head -> next;
int counter = 1;
while(current->next != NULL) {
printf("%d. %s \t\t%s \t\t%d \n",counter, current -> name, current -> vorname, current -> note);
counter++;
current = current->next;
}
printf("%d. %s \t\t%s \t\t%d \n",counter, current -> name,current -> vorname, current -> note);
}
void durch(int *spiegel) {
for (int i = 1; i <= 6 ; ++i) {
printf("Note %d:", i);
for (int j = 0; j < spiegel[i-1]; ++j) {
printf("*");
}
printf("\n");
}
}
int main (){
Schueler anker;
char name[50], vorname[50], note_eingabe[10];
int note, counter = 1, temp = 0, spiegel[6] = {};
double durchschnitt = 0;
anker.next= NULL;
do {
printf("----Eingabe des %d.Schuelers----\n", counter);
printf("Name:");
fgets(name, sizeof(name), stdin);
if(strcmp(name, "\n") == 0){
break;
}
name[strcspn(name, "\n")] = '\0';
printf("Vorname:");
fgets(vorname, sizeof(vorname), stdin);
vorname[strcspn(vorname, "\n")] = '\0';
printf("Note:");
fgets(note_eingabe, sizeof(note_eingabe), stdin);
note_eingabe[strcspn(note_eingabe, "\n")] = '\0';
note = atoi(note_eingabe);
switch (note) {
case 1:
spiegel[0] += 1;
break;
case 2:
spiegel[1] +=1;
break;
case 3:
spiegel[2] += 1;
break;
case 4:
spiegel[3] += 1;
break;
case 5:
spiegel[4] += 1;
break;
case 6:
spiegel[5] += 1;
break;
}
einfuegen(&anker, name, vorname, note);
temp += note;
counter++;
}while(1);
printf("Name \tVorname \tNote\n");
printf("---------------------------------------------------\n");
printList(&anker);
printf("....Durchschnittsnote: %.2f\n", (double)temp / (counter - 1));
printf("...Notenspiegel\n");
durch((int *)spiegel);
}
+18 -8
View File
@@ -4,18 +4,17 @@
int main()
{
int eingabe;
int *zahlenBisN = (int *)malloc(100 * sizeof(int)); // Speicher wird dynamisch für 100 Zeichen reserviert
int *zahlenBisN;
do
{
zahlenBisN = (int *)malloc(100 * sizeof(int)); // Speicher wird dynamisch für 100 Zeichen reserviert
printf("%s", "Bis wohin sollen die Primzahlen berechnet werden (Ende=0) ? ");
scanf("%d", &eingabe);
if(eingabe > 100) // Wenn mehr Speicher benötigt wird, dann wird mit realloc mehr speicher reserviert
{
free(zahlenBisN); // Der Speicher von der default reservierung wird freigegeben, damit er erneut reserviert werden kann
zahlenBisN = (int *)realloc(zahlenBisN, eingabe * sizeof(int));
}
// Array wird mit zahlen von 1 bis n gefüllt
for (int i = 0; i < eingabe; ++i)
@@ -23,7 +22,18 @@ int main()
zahlenBisN[i] = i+1;
}
// Jede nicht Primzahl wird entfernt
// Sieb des Eratosthenes
for (int i = 1; i < eingabe; ++i) {
if (zahlenBisN[i] != 0){
for (int j = zahlenBisN[i]; j <= eingabe; ++j) {
if (zahlenBisN[j] % zahlenBisN[i] == 0)
zahlenBisN[j] = 0;
}
}
}
// Ursprünglicher Primzahlgenerator
/*// Jede nicht Primzahl wird entfernt
for (int i = 0; i < eingabe; ++i)
{
for (int j = 2; j < i; j++ ) {
@@ -32,7 +42,7 @@ int main()
zahlenBisN[i] = 0;
}
}
}
}*/
// Alle zahlen die noch im String vorhanden sind und nicht 0 sind werden ausgegeben
for (int i = 1; i < eingabe; ++i)
@@ -42,7 +52,7 @@ int main()
printf("%10d", zahlenBisN[i]);
}
}
printf("\n");
printf("\n");
free(zahlenBisN); // Speicher wird erneut freigegeben um Memory leaks zu verhindern
}while(eingabe != 0); // Das Programm wird so oft wiederholt bis 0 eingegeben wird
free(zahlenBisN); // Speicher wird erneut freigegeben um Memory leaks zu verhindern
}
+100
View File
@@ -0,0 +1,100 @@
/*--- #includes ------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include "queue.h"
/*--- #defines -------------------------------------------------------*/
/*--- Lokale Datentypen (typedef) ------------------------------------*/
Jose* head = NULL;
Jose* tail = NULL;
/*--- Modulglobale static Variablen ----------------------------------*/
/*--- Prototypen lokaler Funktionen ----------------------------------*/
/*--- Funktionsdefinitionen ------------------------------------------*/
/*--------------------------------------------------------------------*\
* Einfuegen in Liste
* Parameter:
* zahl fügt die übergebene Zahl 'zahl' am Ende der Liste ein
* Return Wert:
* TRUE wenn noch genug Speicherplatz vorhanden
* FALSE wenn kein Speicherplatz mehr allokiert werden konnte
*--------------------------------------------------------------------*/
Bool put(int zahl)
{
Jose* j = (Jose*)malloc(sizeof(Jose));
if(!j){
printf("Es kann kein Speicher mehr allokiert werden!");
return FALSE;
}
j->value = zahl;
j->next = NULL;
j->prev = tail;
if(tail)
tail->next = j;
else
head = j;
tail = j;
return TRUE;
}
/*--------------------------------------------------------------------*\
* Auslesen aus Liste
* Parameter:
* keine
* Return Wert:
* Zahl am Anfang der Liste oder aber QLEER, wenn Liste leer ist.
*--------------------------------------------------------------------*/
int get(void)
{
int valueHead;
Jose* tmp;
if(head == NULL)
return QLEER;
tmp = head;
valueHead = tmp->value;
head = head->next;
if (head == NULL) {
tail = NULL;
} else {
head->prev = NULL;
}
free(tmp);
return valueHead;
}
/*--------------------------------------------------------------------*\
* Pruefen der Liste
* Parameter:
* keine
* Return Wert:
* liefert TRUE, wenn Queue leer ist, sonst FALSE
*--------------------------------------------------------------------*/
Bool isEmpty(void)
{
if(head == NULL)
return TRUE;
else
return FALSE;
}
/*int main(){
put(69);
put(70);
put(80);
get();
get();
get();
get();
}*/
+57
View File
@@ -0,0 +1,57 @@
#ifndef QUEUE_H
#define QUEUE_H
/*--- #includes ------------------------------------------------------*/
#include <limits.h>
#include <stdio.h>
/*--- #defines -------------------------------------------------------*/
#define TRUE 1
#define FALSE 0
#define QLEER INT_MIN
/*--- Datentypen (typedef) -------------------------------------------*/
typedef int Bool;
typedef struct Jose {
int value;
struct Jose* next;
struct Jose* prev;
} Jose;
extern Jose* head;
extern Jose* tail;
/*--- Prototypen globaler Funktionen ---------------------------------*/
/*--------------------------------------------------------------------*\
* Einfuegen in Liste
* Parameter:
* zahl fügt die übergebene Zahl 'zahl' am Ende der Liste ein
* Return Wert:
* TRUE wenn noch genug Speicherplatz vorhanden
* FALSE wenn kein Speicherplatz mehr allokiert werden konnte
* Hinweis:
* - dynamische Verwaltung von Speicher muss mit malloc() und free()
* durchgeführt werden; dynamische Arrays sind nicht erlaubt !!!
*--------------------------------------------------------------------*/
Bool put(int zahl);
/*--------------------------------------------------------------------*\
* Auslesen aus Liste
* Parameter:
* keine
* Return Wert:
* Zahl am Anfang der Liste oder aber QLEER, wenn Liste leer ist.
*--------------------------------------------------------------------*/
int get(void);
/*--------------------------------------------------------------------*\
* Pruefen der Liste
* Parameter:
* keine
* Return Wert:
* liefert TRUE, wenn Queue leer ist, sonst FALSE
*--------------------------------------------------------------------*/
Bool isEmpty(void);
#endif /*QUEUE_H*/
+100002
View File
File diff suppressed because it is too large Load Diff
+115
View File
@@ -0,0 +1,115 @@
#include "view.h"
#include "io.h"
#include <stdio.h>
#define S_MACHINE_HEAD \
" /-----------------------------------\\\n" \
" | %33s |\n" \
" \\-----------------------------------/\n" \
" \n" \
" /~~~~~~~~~~~/| \n" \
" / /#########/ / |\n" \
" / /_________/ / |\n" \
" =============== /||\n" \
" | %03d EUR |/ ||\n" \
" |_____________|/ ||\n" \
" | \\___..___/ ||\n" \
" | || ||\n"
#define S_MACHINE_NO_COFFEE \
" | ||\n" \
" | ||\n" \
" | ||\n"
#define S_MACHINE_COFFEE \
" | ) ( ||\n" \
" | ( ) ) ||\n" \
" | ) ( ( ||\n" \
#define S_MACHINE_NO_CUP \
" _________ | ||\n" \
" .-'---------| |_______________||\n" \
" ( C|/\\/\\/\\/\\/| | / |\n" \
" '-./\\/\\/\\/\\/| _|_ _ _ _ _ _ _/ |\n" \
" '_________' | | / \n" \
" '-------' |_______________|/ \n" \
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"
#define S_MACHINE_CUP \
" | _________ ||\n" \
" .-'---------|___||\n" \
" ( C|/\\/\\/\\/\\/| / |\n" \
" _'-./\\/\\/\\/\\/|_/ |\n" \
" | '_________' | / \n" \
" |____'-------'__|/ \n" \
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"
#define S_MACHINE_NO_COIN_RETURN "\n"
#define S_MACHINE_INVALID_COIN_RETURN \
" -> keine Muenze verfuegbar !!!\n"
#define S_MACHINE_COIN_RETURN \
" -> %0d Euro zurueck\n"
/* machine status variables */
static int s_has_cup = 0;
static int s_coin_value = 0;
/* function implementations */
void view_show(fsm_action_t out_vector)
{
int i;
for (i = 0; i < 100; i++) printf("\n");
printf(S_MACHINE_HEAD, out_vector.display_string, out_vector.guthaben);
if (out_vector.kaffee_los) printf(S_MACHINE_COFFEE);
else printf(S_MACHINE_NO_COFFEE);
if (s_has_cup) printf(S_MACHINE_CUP);
else printf(S_MACHINE_NO_CUP);
if (out_vector.muenz_rueck) {
if (s_coin_value) printf(S_MACHINE_COIN_RETURN, s_coin_value);
else printf(S_MACHINE_INVALID_COIN_RETURN);
} else {
printf(S_MACHINE_NO_COIN_RETURN);
}
}
view_menu_t view_menu()
{
int read = io_read_signed_number(
"\n"
" 0) Einwurf 1 Euro\n"
" 1) Einwurf 2 Euro\n"
" 2) Becher verstellen\n"
" 3) Reset\n"
" 4) Automatischer Testlauf\n"
" 5) Programm beenden\n"
"\n"
" Auswahl: ");
switch (read) {
case 0: return VIEW_1_EURO;
case 1: return VIEW_2_EURO;
case 2: return VIEW_CUP;
case 3: return VIEW_RESET;
case 4: return VIEW_CHECK;
case 5: return VIEW_EXIT;
default: return VIEW_INVALID;
}
}
void view_toggle_cup() { s_has_cup = s_has_cup ? 0 : 1; }
int view_has_cup() { return s_has_cup; }
void view_set_coin(int value) { s_coin_value = value; }
void view_reset()
{
s_has_cup = 0;
s_coin_value = 0;
}
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include "automat.h"
typedef enum { VIEW_1_EURO, VIEW_2_EURO, VIEW_CUP, VIEW_RESET, VIEW_CHECK, VIEW_EXIT, VIEW_INVALID } view_menu_t;
extern void view_show(fsm_action_t out_vector);
extern view_menu_t view_menu(void);
extern void view_toggle_cup(void);
extern int view_has_cup(void);
extern void view_set_coin(int value);
extern void view_reset(void);
+88
View File
@@ -0,0 +1,88 @@
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
void ausgabeBinaer(int wert) {
for (int i = 31; i >= 0; i--) {
int bit = (wert >> i) & 1;
printf("%d", bit);
if (i % 8 == 0 && i != 0)
printf(" ");
}
printf("\n");
}
int main(int argc, char *argv[])
{
char eingabe[100] = {0};
for (int i = 1; i < argc; i++) {
strcat(eingabe, argv[i]);
if (i < argc - 1)
strcat(eingabe, " ");
}
char *pptr, *nptr;
char fehlerChar;
int wert, fehlerWert = 0;
bool b = false, o = false, h = false, fehler = false;
do {
if (!(strpbrk(eingabe, " -123456789")))
break;
nptr = strchr(eingabe, ' ') + 1;
pptr = strtok(eingabe, " ");
if (pptr[0] == '-' && pptr[1] == '-')
for (int i = 0; pptr[i]; ++i) {
switch (pptr[i]) {
case 'b':
b = true;
break;
case 'o':
o = true;
break;
case 'h':
h = true;
break;
case '-':
break;
default:
fehlerChar = pptr[i];
fehler = true;
break;
}
}
else if ((pptr[0] >= '0' && pptr[0] <= '9') || (pptr[0] == '-' && pptr[1] != '-')) {
if (fehlerWert == 0) {
wert = atoi(pptr);
fehlerWert++;
} else
fehler = true;
}
if (nptr != NULL + 1)
strcpy(eingabe, nptr);
} while (nptr != NULL + 1);
if (fehler == false) {
printf("Dezimal: %d\n", wert);
if (b) {
printf("Dual: ");
ausgabeBinaer(wert);
}
if (o)
printf("Oktal: %o\n", wert);
if (h)
printf("Hexadezimal: %x\n", wert);
if (b == 0 && o == 0 && h == 0) {
printf("Dual: ");
ausgabeBinaer(wert);
printf("Oktal: %o\n", wert);
printf("Hexadezimal: %x\n", wert);
}
} else if (fehler == true) {
if (fehlerChar)
printf("...... Unerlaubte Option --%c\n", fehlerChar);
if (fehlerWert == 1)
printf("usage: zahlsys [--boh] zahl\n...... Es muss genau eine Zahl angegeben sein\n");
}
}