Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #define LEN 100
- int fgetAnswers(FILE *exam);
- int print_sol(int qcount, char answers []);
- int grade(FILE *exam, int qcount, char answers[]);
- int main()
- {
- int loop_check = 0;
- int questions_count;
- FILE *exam;
- FILE *report;
- if((exam = fopen("examdat.txt", "r")) != NULL)
- {
- questions_count = fgetAnswers(exam);
- }
- else printf("Wrong file name\n");
- return(0);
- }
- int fgetAnswers(FILE *exam)
- {
- int qcount;
- int question_quant1 = 0;
- int question_quant2 = 0;
- int count = 0;
- int id;
- int i;
- char answers[LEN];
- fscanf(exam, "%d", &qcount);
- fscanf(exam, "%s", answers);
- print_sol(qcount, answers);
- grade(exam, qcount, answers);
- return(qcount);
- }
- int print_sol(int qcount, char answers [])
- {
- int i;
- printf("Question ");
- for (i = 1; i <= qcount; ++i)
- {
- printf("%d ", i);
- }
- printf("\nAnswer ");
- for (i = 1; i <= qcount; i++)
- {
- printf ("%c ", answers[i - 1]);
- }
- printf ("\n");
- return (0);
- }
- int grade(FILE *exam, int qcount, char answers [])
- {
- int ident;
- int k;
- int i;
- char stud_ans[qcount];
- int num_right = 0;
- int num_wrong = 0;
- int accuracy;
- int total_miss[qcount];
- for(i = 0; i < qcount; i++)
- total_miss[i] = 0;
- while(!feof(exam))
- {
- fscanf(exam, "%d", &ident);
- fscanf(exam, "%s\n", &stud_ans);
- num_right = 0;
- num_wrong = 0;
- for(k = 0; k < qcount; k++)
- {
- if (stud_ans[k] == answers[k])
- num_right++;
- else
- {
- num_wrong++;
- total_miss[k]++;
- }
- }
- printf("%d ", ident);
- accuracy = (num_right * 100) / qcount;
- printf("%d\n", accuracy);
- }
- printf("Question ");
- for (i = 1; i <= qcount; ++i)
- {
- printf("%d ", i);
- }
- printf("\nMissed by ");
- for (i = 0; i < qcount; ++i)
- {
- printf("%d ", total_miss[i]);
- }
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement