#include <stdio.h>#define NUM_QUEST 10 // number of questions#define NUM_CLASS_DAYS 5 // number of class days in a weektypedef enum { MON, TUE, WED, THU, FRI }class_days_t; // variabletypedef enum { F, T }logic_t; // variableint test( logic_t ans[], logic_t stu[], int num_q ); // function prototypevoid empty( void ); // function prototypeint main ( void ){ logic_t answer[NUM_QUEST]; // array for anwers int score[NUM_CLASS_DAYS] = { 0, 0 , 0, 0, 0 }; // student's score array logic_t ans_stu[NUM_QUEST]; // array of student's anwers class_days_t j; int ch; int a = 0; // counter for conditional cases int i; for( j = MON; j <= FRI; j++ ) { switch ( j ) { case MON: printf("\nEnter the answers of the Monday test using\n"); printf("T (true) and F (false):\n"); while( a < NUM_QUEST ) { ch = getchar(); if( ch == 'T' ) { answer[a] = T; a++; } else if( ch == 'F' ) { answer[a] = F; a++; } else { printf("Invalid data please enter the data again\n"); printf("The %d. character should be T or F\n", a + 1); printf("Enter the last %d answers\n", NUM_QUEST - a); empty(); // emptying the input buffer } } empty(); printf("\n\n"); printf("Enter the answer's of the student for the\n"); printf("Monday test as 1 (T) or 0 (F)\n"); score[j] = test( answer, ans_stu, NUM_QUEST ); printf("Test score of Monday:\n"); printf(" %d\n\n", score[j] ); printf("Student's answer for Monday:\n"); for( i = 0; i < NUM_QUEST; i++ ) { printf("%s", (ans_stu[i] - 48) == 0 ? "F " : "T "); } printf("\n\n"); a = 0; // resetting a counter break; case TUE: printf("\nEnter the answers of the Tuesday test using\n"); printf("T (true) and F (false):\n"); while( a < NUM_QUEST ) { ch = getchar(); if( ch == 'T' ) { answer[a] = T; a++; } else if( ch == 'F' ) { answer[a] = F; a++; } else { printf("Invalid data please enter the data again\n"); printf("The %d. character should be T or F\n", a + 1); printf("Enter the last %d answers\n", NUM_QUEST - a); empty(); // emptying the input buffer } } empty(); printf("\n\n"); printf("Enter the answer's of the student for the\n"); printf("Tuesday test as 1 (T) or 0 (F)\n"); score[j] = test( answer, ans_stu, NUM_QUEST ); printf("Test score of Tuesday:\n"); printf(" %d\n\n", score[j] ); printf("Student's answer for Tuesday:\n"); for( i = 0; i < NUM_QUEST; i++ ) { printf("%s", (ans_stu[i] - 48) == 0 ? "F " : "T "); } printf("\n\n"); a = 0; // resetting a counter break; case WED: printf("\nEnter the answers of the Wednesday test using\n"); printf("T (true) and F (false):\n"); while( a < NUM_QUEST ) { ch = getchar(); if( ch == 'T' ) { answer[a] = T; a++; } else if( ch == 'F' ) { answer[a] = F; a++; } else { printf("Invalid data please enter the data again\n"); printf("The %d. character should be T or F\n", a + 1); printf("Enter the last %d answers\n", NUM_QUEST - a); empty(); // emptying the input buffer } } empty(); printf("\n\n"); printf("Enter the answer's of the student for the\n"); printf("Wednesday test as 1 (T) or 0 (F)\n"); score[j] = test( answer, ans_stu, NUM_QUEST ); printf("Test score of Wednesday:\n"); printf(" %d\n\n", score[j] ); printf("Student's answer for Wednesday:\n"); for( i = 0; i < NUM_QUEST; i++ ) { printf("%s", (ans_stu[i] - 48) == 0 ? "F " : "T "); } printf("\n\n"); a = 0; // resetting a counter break; case THU: printf("\nEnter the answers of the Thursday test using\n"); printf("T (true) and F (false):\n"); while( a < NUM_QUEST ) { ch = getchar(); if( ch == 'T' ) { answer[a] = T; a++; } else if( ch == 'F' ) { answer[a] = F; a++; } else { printf("Invalid data please enter the data again\n"); printf("The %d. character should be T or F\n", a + 1); printf("Enter the last %d answers\n", NUM_QUEST - a); empty(); // emptying the input buffer } } empty(); printf("\n\n"); printf("Enter the answer's of the student for the\n"); printf("Thursday test as 1 (T) or 0 (F)\n"); score[j] = test( answer, ans_stu, NUM_QUEST ); printf("Test score of Thursday:\n"); printf(" %d\n\n", score[j] ); printf("Student's answer for Thursday:\n"); for( i = 0; i < NUM_QUEST; i++ ) { printf("%s", (ans_stu[i] - 48) == 0 ? "F " : "T "); } printf("\n\n"); a = 0; // resetting a counter break; case FRI: printf("\nEnter the answers of the Friday test using\n"); printf("T (true) and F (false):\n"); while( a < NUM_QUEST ) { ch = getchar(); if( ch == 'T' ) { answer[a] = T; a++; } else if( ch == 'F' ) { answer[a] = F; a++; } else { printf("Invalid data please enter the data again\n"); printf("The %d. character should be T or F\n", a + 1); printf("Enter the last %d answers\n", NUM_QUEST - a); empty(); // emptying the input buffer } } empty(); printf("\n\n"); printf("Enter the answer's of the student for the\n"); printf("Friday test as 1 (T) or 0 (F)\n"); score[j] = test( answer, ans_stu, NUM_QUEST ); printf("Test score of Friday:\n"); printf(" %d\n\n", score[j] ); printf("Student's answer for Friday:\n"); for( i = 0; i < NUM_QUEST; i++ ) { printf("%s", (ans_stu[i] - 48) == 0 ? "F " : "T "); } printf("\n\n"); a = 0; // resetting a counter break; } }}/* test checks how many correct answers that student has */int test( logic_t ans[], logic_t stu[], int num_q ){ int i = 0, sc = 0; while( i < num_q ) { stu[i] = getchar(); if( stu[i] == 49 || stu[i] == 48 ) { if( (stu[i] - 48) == ans[i] ) { sc++; } i++; } else { printf("Invalid data please enter the data again\n"); printf("The %d. character should be 1 or 0\n", i + 1); printf("Enter the last %d answers\n", num_q - i); empty(); } } empty(); return sc;}/* clear empties the input buffer of all characters */void empty( void ){ char hold = 0; do { scanf("%c", &hold); }while(hold != '\n');}