Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. #define LEN 100
  5.  
  6. int fgetAnswers(FILE *exam);
  7.  
  8. int print_sol(int qcount, char answers []);
  9.  
  10. int grade(FILE *exam, int qcount, char answers[]);
  11.  
  12. int main()
  13. {
  14. int loop_check = 0;
  15. int questions_count;
  16. FILE *exam;
  17. FILE *report;
  18.  
  19. if((exam = fopen("examdat.txt", "r")) != NULL)
  20. {
  21. questions_count = fgetAnswers(exam);
  22. }
  23.  
  24. else printf("Wrong file name\n");
  25.  
  26. return(0);
  27. }
  28.  
  29. int fgetAnswers(FILE *exam)
  30. {
  31. int qcount;
  32. int question_quant1 = 0;
  33. int question_quant2 = 0;
  34. int count = 0;
  35. int id;
  36. int i;
  37. char answers[LEN];
  38.  
  39. fscanf(exam, "%d", &qcount);
  40. fscanf(exam, "%s", answers);
  41. print_sol(qcount, answers);
  42. grade(exam, qcount, answers);
  43. return(qcount);
  44. }
  45.  
  46. int print_sol(int qcount, char answers [])
  47. {
  48. int i;
  49. printf("Question ");
  50.  
  51. for (i = 1; i <= qcount; ++i)
  52. {
  53. printf("%d ", i);
  54. }
  55. printf("\nAnswer ");
  56.  
  57. for (i = 1; i <= qcount; i++)
  58. {
  59. printf ("%c ", answers[i - 1]);
  60. }
  61. printf ("\n");
  62. return (0);
  63. }
  64.  
  65. int grade(FILE *exam, int qcount, char answers [])
  66. {
  67. int ident;
  68. int k;
  69. int i;
  70. char stud_ans[qcount];
  71. int num_right = 0;
  72. int num_wrong = 0;
  73. int accuracy;
  74. int total_miss[qcount];
  75.  
  76.  
  77. for(i = 0; i < qcount; i++)
  78. total_miss[i] = 0;
  79.  
  80. while(!feof(exam))
  81. {
  82. fscanf(exam, "%d", &ident);
  83. fscanf(exam, "%s\n", &stud_ans);
  84. num_right = 0;
  85. num_wrong = 0;
  86.  
  87. for(k = 0; k < qcount; k++)
  88. {
  89. if (stud_ans[k] == answers[k])
  90. num_right++;
  91. else
  92. {
  93. num_wrong++;
  94. total_miss[k]++;
  95. }
  96. }
  97.  
  98. printf("%d ", ident);
  99.  
  100. accuracy = (num_right * 100) / qcount;
  101. printf("%d\n", accuracy);
  102.  
  103. }
  104.  
  105. printf("Question ");
  106. for (i = 1; i <= qcount; ++i)
  107. {
  108. printf("%d ", i);
  109. }
  110.  
  111. printf("\nMissed by ");
  112. for (i = 0; i < qcount; ++i)
  113. {
  114. printf("%d ", total_miss[i]);
  115. }
  116.  
  117. return (0);
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement