add Flugi
This commit is contained in:
		
							parent
							
								
									e647fd6232
								
							
						
					
					
						commit
						e6855422d3
					
				
							
								
								
									
										192
									
								
								src/Flugi-tz/Funktion_Flugi.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										192
									
								
								src/Flugi-tz/Funktion_Flugi.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,192 @@
 | 
			
		||||
#include "Funktion_Flugi.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int quiz(char Question[][500], char Answer[], int zahl_h) {
 | 
			
		||||
    char repeat[zahl_h][500]; // Array, um falsche Fragen zu speichern
 | 
			
		||||
    char userAnswer;
 | 
			
		||||
    int incorrectIndices[zahl_h]; // Indizes der falschen Antworten
 | 
			
		||||
    int incorrectCount = 0;  // Anzahl falscher Antworten 
 | 
			
		||||
    srand(time(NULL)); //SL Zufallsgenerator initialisieren                  
 | 
			
		||||
 | 
			
		||||
    int zufallszahl = 0;
 | 
			
		||||
    int i;
 | 
			
		||||
 | 
			
		||||
    // Fragen durchgehen und Antworten überprüfen
 | 
			
		||||
    for (i = 0; i < zahl_h; i++) 
 | 
			
		||||
    {
 | 
			
		||||
        zufallszahl = rand() % zahl_h  ; // SL % 2 räpresentier die Obergrenze
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        printf("Frage %d: %s\n", i + 1, Question[zufallszahl]);//SL Zufallszahl durch i ersetzt
 | 
			
		||||
        scanf(" %c", &userAnswer); // wichtig lehrschlag vor %c
 | 
			
		||||
 | 
			
		||||
        if (userAnswer == Answer[zufallszahl]) {
 | 
			
		||||
            printf("Korrekt!\n");
 | 
			
		||||
        } 
 | 
			
		||||
        else if (userAnswer != Answer[zufallszahl])
 | 
			
		||||
        {
 | 
			
		||||
            printf("Falsch!\n");
 | 
			
		||||
            strcpy(repeat[incorrectCount], Question[i]); // Frage speichern
 | 
			
		||||
            incorrectIndices[incorrectCount] = zufallszahl;        // Index speichern
 | 
			
		||||
            incorrectCount++;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Überprüfen, ob es falsche Antworten gibt
 | 
			
		||||
    if (incorrectCount > 0) {
 | 
			
		||||
        char retry;
 | 
			
		||||
        printf("Du hast %d falsche Antworten. Willst du diese wiederholen? (j/n): ", incorrectCount);
 | 
			
		||||
        scanf(" %c", &retry);
 | 
			
		||||
 | 
			
		||||
        if (retry == 'j' || retry == 'J') {
 | 
			
		||||
            for (int i = 0; i < incorrectCount; i++) {
 | 
			
		||||
                printf("Wiederholung: %s\n", repeat[i]);
 | 
			
		||||
                scanf(" %c", &userAnswer);
 | 
			
		||||
 | 
			
		||||
                if (userAnswer == Answer[incorrectIndices[i]]) {
 | 
			
		||||
                    printf("Jetzt korrekt!\n");
 | 
			
		||||
                } else {
 | 
			
		||||
                    printf("Immer noch falsch.\n");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        printf("Alle Antworten waren korrekt!\n");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return incorrectCount;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Funktion: Baum zeichnen
 | 
			
		||||
void draw_tree(int total , int wrong) {
 | 
			
		||||
    total++;
 | 
			
		||||
    for (int i = 0; i < total - 1; i++) {
 | 
			
		||||
        // Sterne einrücken
 | 
			
		||||
        for (int j = 0; j < total - i - 1; j++) {
 | 
			
		||||
            printf(" ");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Sterne für diese Ebene zeichnen
 | 
			
		||||
        for (int y = 0; y < (2 * i + 1); y++) {
 | 
			
		||||
            if (wrong == 0 && i == 0) {
 | 
			
		||||
                // Besondere goldene Spitze, wenn alles richtig ist
 | 
			
		||||
                printf("\033[1;33m*\033[0m");
 | 
			
		||||
            } else if (i < wrong) {
 | 
			
		||||
                // Ebene gehört zu den falschen Fragen (Rot)
 | 
			
		||||
                printf("\033[1;31m*\033[0m"); // Rote Sterne
 | 
			
		||||
            } else {
 | 
			
		||||
                // Ebene gehört zu den richtigen Fragen (Grün)
 | 
			
		||||
                printf("\033[1;32m*\033[0m"); // Grüne Sterne
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        printf("\n");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Stamm zentrieren
 | 
			
		||||
    for (int i = 0; i < total - 1; i++) {
 | 
			
		||||
        printf(" ");
 | 
			
		||||
    }
 | 
			
		||||
    printf("|\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Funktion: Ergebnisse ausgeben
 | 
			
		||||
void print_results(int total, int wrong) {
 | 
			
		||||
    printf("\n=== Ergebnis der Auswertung ===\n");
 | 
			
		||||
    printf("Gesamtfragen: %d\n", total);
 | 
			
		||||
    printf("Falsche Fragen: %d\n", wrong);
 | 
			
		||||
    printf("Richtige Fragen: %d\n", total - wrong);
 | 
			
		||||
 | 
			
		||||
    // Besondere Nachricht, wenn alles richtig ist
 | 
			
		||||
    if (wrong == 0) {
 | 
			
		||||
        printf("\n Perfekt gemacht! Alle Fragen richtig beantwortet! \n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Hauptfunktion
 | 
			
		||||
int Flugi() {
 | 
			
		||||
    int zahl_h ; // Höhe des Baumes (Gesamtfragen)
 | 
			
		||||
    int wrong_questions; // Anzahl der falschen Fragen
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    FILE *file;                             // File-Pointer
 | 
			
		||||
    char filename[50] = "questions.txt" ;   // Filename
 | 
			
		||||
    int MaxLines = 500;
 | 
			
		||||
    int MaxLength = 500;
 | 
			
		||||
    char lines[MaxLines][MaxLength];        // Array for separate lines
 | 
			
		||||
    int line_count = 0;                     // Counter for number of lines
 | 
			
		||||
 | 
			
		||||
    char Question[MaxLines][MaxLength];     // Array for questions
 | 
			
		||||
    char Answer[MaxLines];                  // Array for answer
 | 
			
		||||
    int qst = 0;
 | 
			
		||||
    int len = 0;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // Open file
 | 
			
		||||
    file = fopen(filename, "r");
 | 
			
		||||
    if (file == NULL) {
 | 
			
		||||
        printf("Fehler: Datei \"%s\" konnte nicht geöffnet werden.\n", filename);
 | 
			
		||||
        return 1; // End program if file can't be opened
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Read lines from the file
 | 
			
		||||
    while (fgets(lines[line_count], MaxLength, file) != NULL) {
 | 
			
		||||
        size_t len = strlen(lines[line_count]);
 | 
			
		||||
        if (len > 0 && lines[line_count][len - 1] == '\n') {
 | 
			
		||||
            lines[line_count][len - 1] = '\0'; // Entferne das '\n'
 | 
			
		||||
            len--; 
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Frage und Antwort trennen
 | 
			
		||||
        if (len > 2) { 
 | 
			
		||||
            Answer[line_count] = lines[line_count][len - 1]; // Letztes Zeichen als Antwort
 | 
			
		||||
            lines[line_count][len - 2] = '\0';              // Kürze Frage um Antwortzeichen
 | 
			
		||||
            strcpy(Question[line_count], lines[line_count]);
 | 
			
		||||
        }
 | 
			
		||||
        line_count++;
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    zahl_h = line_count;
 | 
			
		||||
 | 
			
		||||
    // close file
 | 
			
		||||
    fclose(file);
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    // Output
 | 
			
		||||
    printf("\nDie Datei wurde in %d Zeilen eingelesen:\n", line_count);
 | 
			
		||||
    for (int i = 0; i < line_count; i++) {
 | 
			
		||||
        printf("Zeile %d: %s\n", i + 1, Question[i]);
 | 
			
		||||
        size_t len = strlen(lines[i]);
 | 
			
		||||
        printf("Antwort: %c\n", Answer[i]);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    //char question[2][50]; //= {"Schaffen wir das? (1 = Ja, 0 = Nein)", "Wie geht das? (1 = Einfach, 0 = Schwer)"};
 | 
			
		||||
    //int answer[2] = {1, 0};
 | 
			
		||||
 | 
			
		||||
    // Eingabebefehl
 | 
			
		||||
    printf("Für wahre Aussage: W, für falsch Ausage: F\n");
 | 
			
		||||
 | 
			
		||||
    int incorrectCount = quiz(Question, Answer, zahl_h);
 | 
			
		||||
    printf("Anzahl falscher Antworten: %d\n", incorrectCount);
 | 
			
		||||
 | 
			
		||||
    wrong_questions = incorrectCount;
 | 
			
		||||
 | 
			
		||||
    // Baum zeichnen
 | 
			
		||||
    draw_tree(zahl_h, wrong_questions);
 | 
			
		||||
 | 
			
		||||
    // Ergebnisse ausgeben
 | 
			
		||||
    print_results(zahl_h, wrong_questions);
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
int main()
 | 
			
		||||
{
 | 
			
		||||
   Flugi();
 | 
			
		||||
}
 | 
			
		||||
*/
 | 
			
		||||
							
								
								
									
										30
									
								
								src/Flugi-tz/Funktion_Flugi.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/Flugi-tz/Funktion_Flugi.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,30 @@
 | 
			
		||||
/* Funktion_Flugi.h
 | 
			
		||||
 | 
			
		||||
Autor: Simon Sommer, Simon Ladner, Lucas Defuns, Delia Schmid
 | 
			
		||||
Firma: FHGR
 | 
			
		||||
Version 1.0
 | 
			
		||||
Datum 16.12.2024
 | 
			
		||||
Aenderungen:
 | 
			
		||||
V 1.0 16.12.2024 Erste Version
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#ifndef Funktion_Flugi_H
 | 
			
		||||
#define Funktion_Flugi_H
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <time.h>
 | 
			
		||||
 | 
			
		||||
// Konstanten für die Dateiverwaltung
 | 
			
		||||
#define MAX_LINES 500
 | 
			
		||||
#define MAX_LENGTH 500
 | 
			
		||||
 | 
			
		||||
// Funktionsprototypen
 | 
			
		||||
int quiz(char Question[][MAX_LENGTH], char Answer[], int zahl_h);
 | 
			
		||||
void draw_tree(int total, int wrong);
 | 
			
		||||
void print_results(int total, int wrong);
 | 
			
		||||
 | 
			
		||||
int Flugi();
 | 
			
		||||
 | 
			
		||||
#endif // QUIZ_H
 | 
			
		||||
							
								
								
									
										11
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/main.c
									
									
									
									
									
								
							@ -34,6 +34,7 @@ Datum: 04.12.2024
 | 
			
		||||
#include "Ramen-vz/Ramen_Physik.h"
 | 
			
		||||
#include "Fehlenden-vz/Fehlenden_Elektronik.h"
 | 
			
		||||
#include "Wein-tz/Abbildungsrechner.h"
 | 
			
		||||
#include "Flugi-tz/Funktion_Flugi.h"
 | 
			
		||||
#include "test_prog.h"
 | 
			
		||||
 | 
			
		||||
#include "Main-vz/pipes_test.h"
 | 
			
		||||
@ -180,13 +181,13 @@ void print_menu(int terminal_width, int terminal_height, int line){
 | 
			
		||||
        printf("\n");
 | 
			
		||||
 | 
			
		||||
        print_line("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓", spaces, (0 <= line && line < 1) ? ";31": ";37");
 | 
			
		||||
        print_line("┃  1 Ramen Physik                       ┃", spaces, (0 <= line && line < 1) ? ";31": ";37");
 | 
			
		||||
        print_line("┃  1 Physik                        (vz) ┃", spaces, (0 <= line && line < 1) ? ";31": ";37");
 | 
			
		||||
        print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (0 <= line && line < 2) ? ";31": ";37");
 | 
			
		||||
        print_line("┃  2 Fehlenden Elektronik               ┃", spaces, (1 <= line && line < 2) ? ";31": ";37");
 | 
			
		||||
        print_line("┃  2 Elektronik                    (vz) ┃", spaces, (1 <= line && line < 2) ? ";31": ";37");
 | 
			
		||||
        print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (1 <= line && line < 3) ? ";31": ";37");
 | 
			
		||||
        print_line("┃  3 Abbildungsrechner                  ┃", spaces, (2 <= line && line < 3) ? ";31": ";37");
 | 
			
		||||
        print_line("┃  3 Abbildungsrechner             (tz) ┃", spaces, (2 <= line && line < 3) ? ";31": ";37");
 | 
			
		||||
        print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (2 <= line && line < 4) ? ";31": ";37");
 | 
			
		||||
        print_line("┃  4 Programm                           ┃", spaces, (3 <= line && line < 4) ? ";31": ";37");
 | 
			
		||||
        print_line("┃  4 Numpy                         (tz) ┃", spaces, (3 <= line && line < 4) ? ";31": ";37");
 | 
			
		||||
        print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (3 <= line && line < 5) ? ";31": ";37");
 | 
			
		||||
        print_line("┃  5 Programm                           ┃", spaces, (4 <= line && line < 5) ? ";31": ";37");
 | 
			
		||||
        print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (4 <= line && line < 6) ? ";31": ";37");
 | 
			
		||||
@ -244,7 +245,7 @@ void run_programm(int programm, int width, int height, bool *used){
 | 
			
		||||
        case 0: return_code = Ramen_Physik(); break;
 | 
			
		||||
        case 1: return_code = Fehlenden_Elektronik_main(); break;
 | 
			
		||||
        case 2: return_code = Abbildungsrechner(); break;
 | 
			
		||||
        case 3: return_code = test_gruppe_programmname(); break;
 | 
			
		||||
        case 3: return_code = Flugi(); break;
 | 
			
		||||
        case 4: return_code = test_gruppe_programmname(); break;
 | 
			
		||||
        case 5: return_code = test_gruppe_programmname(); break;
 | 
			
		||||
        case 6: return_code = test_gruppe_programmname(); break;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user