Browse Source

merging commit 3

main
Florian Baeseler 11 months ago
parent
commit
ac1f0f8ce8
  1. BIN
      build/test/out/c/casualQuiz.o
  2. 224
      src/casualQuiz.c
  3. 12
      src/casualQuiz.h
  4. 35
      test/test_casualQuiz.c

BIN
build/test/out/c/casualQuiz.o

224
src/casualQuiz.c

@ -1,145 +1,217 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "casualQuiz.h"
#include "casualQuiz.h" //header datei
void casualQuiz() { void casualQuiz() {
printf("Print aus der Funktion Casual Quiz");
int index = 0; int index = 0;
char* easy_fragen[] = { //eingabe der Fragen in ein Array
"Which Disney character famously leaves a glass shoe behind at a royal ball?",
"The hammer and sickle are one of the most recognisable symbols of which political ideology?",
"Which two words traditionally appear onscreen at the termination of a feature film?",
"A person with well-developed abdominal muscles is said to have a what?",
"A magnet would most likely attract which of the following?",
char* fragen[] = { //eingabe der Fragen in ein Array
"Which Disney character famously leaves a glass shoe behind at a royal ball?",
"The hammer and sickle are one of the most recognisable symbols of which political ideology?",
"Which two words traditionally appear onscreen at the termination of a feature film?",
"A person with well-developed abdominal muscles is said to have a what?",
"A magnet would most likely attract which of the following?",
"In the United States, what is traditionally the proper way to adress a judge?",
"Which of these pairs of apps offers roughly the same type of service?",
"A geologist would likely be LEAST helpful for answering questions about which of the following?",
"When a person is rudely ignored, he is said to be 'getting a' what?",
"A common piece of advice goes, 'Be there or be' what?",
"If you're trying to find other players in a game of hide and seek, what are you most likly called?",
"If you're skeptical about something, you should 'take it with a grain of' what?",
"Something in an obvious location is said to be 'right under your' what?",
"When a tree is cut down, the part that remains in the ground is called what?",
"What name is given to the belt machinery in an airport that delivers checked luggage from the plane to baggage reclaim?",
"By definition, a 10-speed bike has 10 what?",
"A lullaby is a song sung to babies to help them do what?",
"In history books, leaders named Alexander and Catherine both share what flattering title?",
"What notable part of the US's topography accounts for roughly 20 percent of the fresh water on Earth?",
"A person who is preparing to work hard is said to be 'rolling up his' what?"
}; };
char* easy_antworten[][4] = { //Eingabe der zugehörigen Antworten in ein array
char* antworten[][4] = { //Eingabe der zugehörigen Antworten in ein array
{"Elsa", "Rapunzel", "Cinderella", "Pocahontas"}, {"Elsa", "Rapunzel", "Cinderella", "Pocahontas"},
{"Republicanism", "Liberalism", "Conservatism", "Communism"}, {"Republicanism", "Liberalism", "Conservatism", "Communism"},
{"The End", "The Termination", "Pizza's ready", "Hotdog Time"}, {"The End", "The Termination", "Pizza's ready", "Hotdog Time"},
{"12-Pack", "6-Pack", "Family Pack", "One-Pack"}, {"12-Pack", "6-Pack", "Family Pack", "One-Pack"},
{"Metal", "Plastic", "Humans", "Water"}, {"Metal", "Plastic", "Humans", "Water"},
{"Your holiness", "Your eminence", "Father", "Your honor"},
{"Snapchat and Instagram", "Whatsapp and Twitter(now 'X')","Lyft and Uber", "Tiktok and Spotify"},
{"Granite Boulders", "Fruity Pebbles", "Precious Stones", "Igneus Rocks"},
{"Hot knee","Cold shoulder", "Burning hand", "Warm toe"},
{"Bare", "Aware", "Square", "All alone a usual"},
{"Butterbean", "Stinky", "Dunce", "It"},
{"Salt", "Sand", "Sugar", "Silicium"},
{"Mattress", "Nose", "Foot", "Boxer Shorts"},
{"Rump", "Leftovers", "Hump", "Stump"},
{"Hangar", "Carousel", "Terminal", "Bagroller"},
{"Wheels", "Spokes", "Gears", "Lives"},
{"Wake up", "Eat", "Fall asleep", "Invest wisely"},
{"The Great", "The Unruly", "The Ego-Consious", "The Ferocious"},
{"Mark Zuckerbergs hot tub", "The Grand Canyon", "Death Valley", "The Great Lakes"},
{"Sleeves", "Curtains", "AC/DC wall poster", "Towels"},
};
int easy_richtigeAntworten[] = { 3,4,1,2,1 }; // int, um die jeweils richtige antwort zu zeigen
int length_frag_array = sizeof(easy_richtigeAntworten) / sizeof(int);
};
int richtigeAntworten[] = { 3,4,1,2,1,4,3,2,2,3,4,1,2,4,2,3,3,1,4,1};
int length_frag_array = sizeof(richtigeAntworten) / sizeof(int); //länge des arrays wird berechnet, damit man die länge vom spiel kennt
int correct = 0; int correct = 0;
int answered = 0; int answered = 0;
int* correctP = &correct;
int* answeredP = &answered;
bool already_played = false;
int* correctP = &correct; // pointer auf die zählervariable for richtige Antworten
int* answeredP = &answered; // pointer auf die zählervariable for beantwortete fragen
bool already_played = false; // initialisieren einer Bool variable zum abchecken ob man schon gespielt hat
bool end = false; bool end = false;
while (end == false) {
already_played = activePlaying(easy_fragen, *easy_antworten, easy_richtigeAntworten, length_frag_array, answeredP, correctP);
printf("korrekte Antworten: %d\n", correct);
printf("bei: %d beantworteten Fragen", answered);
correct = 0;
while (end == false) { //schleife, in der das Programm läuft
already_played = activePlaying(fragen, *antworten, richtigeAntworten, length_frag_array, answeredP, correctP);
printf("You had %d answers correct, while answering %d questions.\n", correct, answered);
end = ftryAgain(already_played); //man wird gefragt ob man nochmal spielen möchte
correct = 0;//zurücksetzen der beiden zählervariablen
answered = 0; answered = 0;
if (already_played == true) {
int sure;
printf("Would you like to play again?\n");
printf("Input 1 to continue Gaming, input 0 to return to the main menu: ");
scanf_s("%d", &sure);
if (sure == 1) printf("Starting the program up again...");
else {
printf("Input not '1', returning to main menu...");
end = true;
}
}
} }
return; return;
} }
bool activePlaying(char* fragen[], char* antworten[], int richtige_antwort[], int size, int* answeredP, int* correctP) { bool activePlaying(char* fragen[], char* antworten[], int richtige_antwort[], int size, int* answeredP, int* correctP) {
int eingabe; int eingabe;
bool richtig; bool richtig;
for (int i = 0; i < size; i++) {
int ansehen;
for (int i = 0; i < size; i++) { // Schleife, die so lange läuft, je nachdem wie viele fragen es gibt
eingabe = 5; eingabe = 5;
richtig = false; richtig = false;
FzeigeFragen(fragen, i);
FzeigeAntworten(antworten, i);
printf("Please type in your answer 1,2,3 or 4: ");
eingabe = FEingabeInteger();
richtig = FcheckaufRichtigkeit(eingabe, richtige_antwort, i);
FzaehlernachAuswahl(richtig, answeredP, correctP);
printf("Bool richtig / falsch: %d\n", richtig);
printf(" %d\n", richtige_antwort[i]);
ansehen = 0;
fzeigeFragen(fragen, i); //frage wird nach gegebenem index ausgegeben
fzeigeAntworten(antworten, i); //Antworten zum gleichen index wie die fragen ausgeben
printf("Reminder: Typing 0 lets you stop the game.\nPlease type in your answer 1,2,3 or 4: ");
eingabe = feingabeInteger(); //eingabe Funktion
richtig = fcheckaufRichtigkeit(eingabe, antworten, richtige_antwort, i); //überprüfung der eingabe anhand des richtige_eingabe arrays und dem index
fzaehlernachAuswahl(richtig, answeredP, correctP); // zähler werden hochgezählt je nach eingabe
printf("\n----------------------------------------------------------------------------------------\n\n");
} }
return true; return true;
} }
void FzeigeFragen(char* fragen[], int index) {
printf("Question: %s\n", fragen[index]);
void fzeigeFragen(char* fragen[], int index) {
printf("Question: %s\n", fragen[index]); //ausgabe Frage bei gegebenem index
} }
void FzeigeAntworten(char* antworten[], int index) {
printf("1) %s\n", antworten[4 * index + 0]);
printf("2) %s\n", antworten[4 * index + 1]);
printf("3) %s\n", antworten[4 * index + 2]);
printf("4) %s\n", antworten[4 * index + 3]);
void fzeigeAntworten(char* antworten[], int index) { //folgende ausgaben bei gegebenem index
printf("1) %s\n", antworten[4 * index + 0]); //ausgabe antwort 1
printf("2) %s\n", antworten[4 * index + 1]); //ausgabe antwort 2
printf("3) %s\n", antworten[4 * index + 2]); //ausgabe antwort 3
printf("4) %s\n", antworten[4 * index + 3]); //ausgabe antwort 4
} }
int FEingabeInteger() {
int eingabeInt;
scanf_s("%d", &eingabeInt);
return eingabeInt;
int feingabeInteger() {
int eingabe; //integer für eingabe initialisiert
scanf_s("%d", &eingabe); //reine ingabe, prints sind vorher schon passiert
return eingabe; // return der eingabe
} }
bool FcheckaufRichtigkeit(int eingabe, int richtige_antwort[], int i) {
switch (eingabe) {
bool fcheckaufRichtigkeit(int eingabe, char* antworten[], int richtige_antwort[], int i) {
int ansehen = 0;
switch (eingabe) {//start vom switch
case 0: { //eingabe 0: abbruch funktion wird aufgerufen
fabbruch();
break;
}
case 1: { case 1: {
printf("Case 1\n");
if (richtige_antwort[i] == 1) {
if (richtige_antwort[i] == 1) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist
printf("Right Answer, well done.\n"); printf("Right Answer, well done.\n");
return true; return true;
} }
else printf("Wrong answer.\n");
else {
printf("Wrong answer.\n"); //wenn eingabe falsch ist
printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: ");
scanf_s("%d", &ansehen);
if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]);
else printf("Continuing...\n");
}
break; break;
} }
case 2: { case 2: {
printf("Case 2\n");
if (richtige_antwort[i] == 2) {
if (richtige_antwort[i] == 2) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist
printf("Right Answer, well done.\n"); printf("Right Answer, well done.\n");
return true; return true;
} }
else printf("Wrong answer.\n");
else {
printf("Wrong answer.\n"); //wenn eingabe falsch ist
printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: ");
scanf_s("%d", &ansehen);
if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]);
else printf("Continuing...\n");
}
break; break;
} }
case 3: { case 3: {
printf("Case 3\n");
if (richtige_antwort[i] == 3) {
if (richtige_antwort[i] == 3) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist
printf("Right Answer, well done.\n"); printf("Right Answer, well done.\n");
return true; return true;
} }
else printf("Wrong answer.\n");
else {
printf("Wrong answer.\n"); //wenn eingabe falsch ist
printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: ");
scanf_s("%d", &ansehen);
if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]);
else printf("Continuing...\n");
}
break; break;
} }
case 4: { case 4: {
printf("Case 4\n");
if (richtige_antwort[i] == 4) {
if (richtige_antwort[i] == 4) { //vergleichen vov der eingabe zu welche richtige zahl hinter dem passenden index versteckt ist
printf("Right Answer, well done.\n"); printf("Right Answer, well done.\n");
return true; return true;
} }
else printf("Wrong answer.\n");
else {
printf("Wrong answer.\n"); //wenn eingabe falsch ist
printf("Would you like to know the right answer?\nInput 1 if you want to see it, 0 if not: ");
scanf_s("%d", &ansehen);
if (ansehen == 1) printf("The right answer was: %d) %s\n", richtige_antwort[i], antworten[4 * i + richtige_antwort[i] - 1]);
else printf("Continuing...\n");
}
break; break;
} }
default: {
printf("Wrong Input!");
default: { // eingabe war was anderes als 1,2,3,4 oder 5
printf("Wrong Input! Going to the next question...\n");
return false; return false;
break; break;
} }
} }
return false; return false;
} }
void FzaehlernachAuswahl(bool richtig, int* answeredP, int* correctP) {
if (richtig == true) {
int plus = *answeredP + 1;
*answeredP = plus;
int add = *correctP + 1;
*correctP = add;
void fzaehlernachAuswahl(bool richtig, int* answeredP, int* correctP) {
if (richtig == true) { //wenn dei eingabe von vorhin richtig war
*answeredP = *answeredP + 1; //hochzählen von der zählervariablen für beantwortete fragen um 1
*correctP = *correctP + 1; //hochzählen von der zählervariablen für korrekte antworten um 1
} }
else {
int plus = *answeredP + 1;
*answeredP = plus;
else { //wenn die eingabe von vorhin falsch war
*answeredP = *answeredP + 1; //hochzählen von der zählervariablen für beantwortete fragen um 1
} }
return; return;
} }
bool ftryAgain(bool already_played) {
if (already_played == true) { //wenn man das spiel schon gespielt hat
int sure;
printf("Would you like to play again?\n");
printf("Input 1 to continue gaming, input 0 to close the game: ");
scanf_s("%d", &sure); //eingabe pb man das spiel nochmal spielen möchte
if (sure == 1) { // nochmal spielen
printf("Starting the program up again...");
return false;
}
else { //beenden
printf("Input not '1', returning to main menu...");
return true;
}
}
else { //wenn man das spiel warum auch immer noch nicht gespielt hat
printf("It looks like you havent played the program yet, starting it up...");
return false;
}
}
void fabbruch() {
int wirklich;
printf("Do you really want to close the program?\nInput 1 to exit, input 0 to continue gaming: ");
scanf_s("%d", &wirklich); //eingabe ob man denn wirklich das programm beenden möchte
if (wirklich == 1) exit(7); //ende mit code 7
else return;//frage wird übersprungen, aber programm läuft weiter
}

12
src/casualQuiz.h

@ -3,10 +3,12 @@
void casualQuiz(); void casualQuiz();
bool activePlaying(char* fragen[], char* antworten[], int richtige_antwort[], int size, int* answeredP, int* correctP); bool activePlaying(char* fragen[], char* antworten[], int richtige_antwort[], int size, int* answeredP, int* correctP);
void FzeigeFragen(char* fragen[], int index);
void FzeigeAntworten(char* antworten[], int index);
int FEingabeInteger();
bool FcheckaufRichtigkeit(int eingabe, int richtige_antwort[], int i);
void FzaehlernachAuswahl(bool richtig, int* answeredP, int* correctP);
void fzeigeFragen(char* fragen[], int index);
void fzeigeAntworten(char* antworten[], int index);
int feingabeInteger();
bool fcheckaufRichtigkeit(int eingabe,char* antworten[], int richtige_antwort[], int i);
void fzaehlernachAuswahl(bool richtig, int* answeredP, int* correctP);
bool ftryAgain(bool already_played);
void fabbruch();
#endif // ende CASUALQUIZ_H #endif // ende CASUALQUIZ_H

35
test/test_casualQuiz.c

@ -20,7 +20,8 @@ void test_FcheckaufRichtigkeit_correct_answer_atIndex1(void){
int TESTindex = 0; int TESTindex = 0;
int TESTrichtige_antwort[]={1}; int TESTrichtige_antwort[]={1};
bool testfall; bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall == true); TEST_ASSERT_TRUE(testfall == true);
@ -30,7 +31,8 @@ void test_FcheckaufRichtigkeit_correct_answer_atIndex2(void){
int TESTindex = 0; int TESTindex = 0;
int TESTrichtige_antwort[]={2}; int TESTrichtige_antwort[]={2};
bool testfall; bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall == true); TEST_ASSERT_TRUE(testfall == true);
@ -40,7 +42,8 @@ void test_FcheckaufRichtigkeit_correct_answer_atIndex3(void){
int TESTindex = 0; int TESTindex = 0;
int TESTrichtige_antwort[]={3}; int TESTrichtige_antwort[]={3};
bool testfall; bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall == true); TEST_ASSERT_TRUE(testfall == true);
@ -49,7 +52,8 @@ void test_FcheckaufRichtigkeit_correct_answer_atIndex3(void){
int TESTindex = 0; int TESTindex = 0;
int TESTrichtige_antwort[]={4}; int TESTrichtige_antwort[]={4};
bool testfall; bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall == true); TEST_ASSERT_TRUE(testfall == true);
@ -59,7 +63,8 @@ void test_FcheckaufRichtigkeit_incorrect_input_higher(void){
int TESTindex = 0; int TESTindex = 0;
int TESTrichtige_antwort[]={3}; int TESTrichtige_antwort[]={3};
bool testfall; bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall != true); TEST_ASSERT_TRUE(testfall != true);
} }
void test_FcheckaufRichtigkeit_incorrect_input_lower(void){ void test_FcheckaufRichtigkeit_incorrect_input_lower(void){
@ -67,7 +72,8 @@ void test_FcheckaufRichtigkeit_incorrect_input_lower(void){
int TESTindex = 0; int TESTindex = 0;
int TESTrichtige_antwort[]={3}; int TESTrichtige_antwort[]={3};
bool testfall; bool testfall;
testfall = FcheckaufRichtigkeit(TESTeingabe, TESTrichtige_antwort, TESTindex);
char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
TEST_ASSERT_TRUE(testfall != true); TEST_ASSERT_TRUE(testfall != true);
} }
void test_FzaehlernachAuswahl(void){ void test_FzaehlernachAuswahl(void){
@ -76,7 +82,7 @@ void test_FzaehlernachAuswahl(void){
int answered = 0; int answered = 0;
int* correctP = &correct; int* correctP = &correct;
int* answeredP = &answered; int* answeredP = &answered;
FzaehlernachAuswahl(richtig, answeredP, correctP);
fzaehlernachAuswahl(richtig, answeredP, correctP);
TEST_ASSERT_EQUAL_INT(1, correct); TEST_ASSERT_EQUAL_INT(1, correct);
TEST_ASSERT_EQUAL_INT(1, answered); TEST_ASSERT_EQUAL_INT(1, answered);
@ -88,7 +94,7 @@ void test_FzaehlernachAuswahl_bei1(void){
int answered = 1; int answered = 1;
int* correctP = &correct; int* correctP = &correct;
int* answeredP = &answered; int* answeredP = &answered;
FzaehlernachAuswahl(richtig, answeredP, correctP);
fzaehlernachAuswahl(richtig, answeredP, correctP);
TEST_ASSERT_EQUAL_INT(2, correct); TEST_ASSERT_EQUAL_INT(2, correct);
TEST_ASSERT_EQUAL_INT(2, answered); TEST_ASSERT_EQUAL_INT(2, answered);
@ -100,7 +106,7 @@ void test_FzaehlernachAuswahl_falsch_bei_0(void){
int answered = 0; int answered = 0;
int* correctP = &correct; int* correctP = &correct;
int* answeredP = &answered; int* answeredP = &answered;
FzaehlernachAuswahl(richtig, answeredP, correctP);
fzaehlernachAuswahl(richtig, answeredP, correctP);
TEST_ASSERT_EQUAL_INT(0, correct); TEST_ASSERT_EQUAL_INT(0, correct);
TEST_ASSERT_EQUAL_INT(1, answered); TEST_ASSERT_EQUAL_INT(1, answered);
@ -112,10 +118,19 @@ void test_FzaehlernachAuswahl_falsch_bei_1(void){
int answered = 1; int answered = 1;
int* correctP = &correct; int* correctP = &correct;
int* answeredP = &answered; int* answeredP = &answered;
FzaehlernachAuswahl(richtig, answeredP, correctP);
fzaehlernachAuswahl(richtig, answeredP, correctP);
TEST_ASSERT_EQUAL_INT(1, correct); TEST_ASSERT_EQUAL_INT(1, correct);
TEST_ASSERT_EQUAL_INT(2, answered); TEST_ASSERT_EQUAL_INT(2, answered);
}
void test_FtryAgain_butalways_played_is_false(void){
bool already_played = false;
bool testbool = true;
testbool = ftryAgain(already_played);
TEST_ASSERT_TRUE(testbool == false);
} }
#endif //Test #endif //Test
Loading…
Cancel
Save