index — ti25-glauchau-code @ 09d73841af4561ceec95929fc271e9680a1ee92d

Meine Lösungen (oder auch nicht) für die Programmieraufgaben in der TI25 an der Staatlichen Studienakademie Glauchau

pa/2025-10-17: basic implementation l1

cli based
questions not randomized
crispy-caesus crispy@crispy-caesus.eu
Mon, 20 Oct 2025 23:34:14 +0200
commit

09d73841af4561ceec95929fc271e9680a1ee92d

parent

9363c86cbf8f98ce528790adc4b19b129a3263bb

A discord_programmieraufgaben/2025-10-17_2/fragen.txt

@@ -0,0 +1,4 @@

+Wie alt ist Jasper?;19 +Warum ist die Banane krumm?;Weil niemand in den Urwald zog und sie wieder grade bog +Was ist der Name dieser Hochschule?;Staatliche Studienakademie Glauchau +Wie heißt das Linux-Maskottchen?;Tux
A discord_programmieraufgaben/2025-10-17_2/quiz.cpp

@@ -0,0 +1,81 @@

+#include <string> +#include <vector> +#include <iostream> +#include <fstream> +#include <cctype> + +using namespace std; + +vector<string> split(string s, const string& delimiter) { + vector<string> tokens; + size_t pos = 0; + while ((pos = s.find(delimiter)) != string::npos) { + tokens.push_back(s.substr(0, pos)); + s.erase(0, pos + delimiter.length()); + } + tokens.push_back(s); + return tokens; +} + +void string_tolower(string& str) { +for (char& chr : str) { + chr = tolower(chr); + } +} + +string read_file(const string& filename) { + ifstream file(filename); + if (!file.is_open()) { + cerr << "Error: Could not open " << filename << endl; + return ""; + } + string line, content; + while (getline(file, line)) content += line + "\n"; + return content; +} + +vector<vector<string>> create_question_array(const string& fileText) { + vector<vector<string>> question_array; + vector<string> lines = split(fileText, "\n"); + for (string& line : lines) { + if (!line.empty()) question_array.push_back(split(line, ";")); + } + return question_array; +} + +vector<vector<string>> get_questions(const string& filename) { + string fileText = read_file(filename); + vector<vector<string>> questionArray = create_question_array(fileText); + + return questionArray; +} + +void ask_questions(vector<vector<string>>& question_array) { + unsigned int score= 0, index = 1; + + for (vector<string>& question : question_array) { + string answer; + cout << index << ". "; + cout << question[0] << endl << " "; + getline(cin, answer); + + string_tolower(answer); + string_tolower(question[1]); + if (answer == question[1]) { + score++; + cout << " Richtig! "; + } else { + cout << " Falsch! "; + } + cout << "[" << score << "/" << question_array.size() << "]\n\n"; + + index++; + } +} + +int main() { + cout << "Willkommen im Knusprigen Quiz" << endl; + vector<vector<string>> question_array = get_questions("fragen.txt"); + ask_questions(question_array); + return 0; +}