In this assignment, I'm supposed to write a program in C (not C++ or C#) that can grade a 10 question T/F quiz for up to 50 students. This course is an intermediate C course and I'm not supposed to use more sophisticated data structures that I know exist, which may be more efficient in doing this.
The data is in a file of the following form.
Quote
TFTFTFTFTF
0123 FFTFTFTFTF
0526 FFTTTFTFTF
7123 FFFFTFTFTF
0123 FFTFTFTFTF
0526 FFTTTFTFTF
7123 FFFFTFTFTF
The first line is the Answer Key.
The second through up to 50 lines are in the format, Student Id (a four digit number) and Student Responses.
Problem Details:
The first line should go into one array.
The Student ID from the 2nd through up to 50 lines should go into a second array.
The number of correct responses from the Student Response should go into a parallel array to the 2nd array. (The actual student responses should not need to be placed in an array). This is based on a comparison of Student Responses to the Answer Key.
It is assumed that the data in the file is correct as is and does not need validation.
I've tried googling the subject and the assignment for some hints on how to write the program, but have had little luck in finding information that might help me solve my problem on my own. My code is as follows right now
#include <stdio.h> int main (void) { char quizkey[10]; int studentid[50]; int numright[50]; FILE *fp1; int i; for(i=0;i<10;i++) quizkey[i] = 0; i=0; if ((fp1=fopen("quiz.txt","r"))==NULL) { printf("quiz.txt failed to open\n"); return 1; } else while((fscanf(fp1,"%c",&quizkey[i]))!=EOF) { fscanf(fp1,"%d",&studentid[i]); // I know I'm doing something wrong somewhere around here. printf("quizkey[%d] is %c\n",i,quizkey[i]); //Possibly here as well. i++; } return 0; }
I've tried separating the problem into 2 parts: one of getting the data into the program, and two, doing the comparison, but the method I'm doing the comparison is by storing the student response into an array and then doing the comparison, but I was told explicitly that this is not needed. The code for this comparison is below. Not sure how to integrate this with the rest of the code above.
#include <stdio.h> int main (void) { char quizkey[10] = { 'T', 'T', 'T', 'T', 'F', 'T', 'F', 'T', 'F', 'T'}; char testcase[10] = { 'T', 'T', 'T', 'T', 'F', 'T', 'F', 'T', 'F', 'T'}; int i; i = 0; int numright; numright = 0; for(i = 0; i < 10; i++) if(quizkey[i] == testcase[i]) numright++; printf("numright is %d:\n",numright); return 0; }
There's more to the assignment, but I think I can figure out the rest of it once I get this first part taken care of.
I would like to understand how to do the problem rather than just a code dump with little to no explanation (A code dump doesn't help me understand how and why the code works. Said understanding would let me be able to apply the idea to other assignments in the future.) Thank you very much for any help you can offer.