CS1101C Practical Exam

Session 5 (1600 - 1745 hours)

MCQ Marking

The name of your C program file must be called mcq.c, files with any other name will not be marked.

Your lecturer has asked you to write a program to help him mark the midterm MCQ (Multiple Choice Question) test. The midterm test always has 25 Questions. A file called mcqin.txt is given to you containing the correct answers as well as all the student's responses. A sample mcqin.txt is given below:

               3445121223254153544412443
U001234A02     3445121223254153544412443
U021111X       4232314411131421121341324
U031234A       22323 34112422221*3341224
U032345B         2531* *  34*4212134 4  
U003456Y13     3445121223254153454412443

The layout of the above input file above is:

  1. An answer of 1 corresponds to the answer A, 2 corresponds to the answer B, and so on, with 5 corresponding to the answer E.
  2. The first line of the file consists of the correct answers. The first answer starts at the 16th character of the line. As shown above, the correct answer to Question 1 is 3 (or C), the correct answer to Question 2 is 4 (or D), and so on.
  3. Student answers are contained in the second line onwards, with the student's matriculation number (maximum of 10 characters) followed by the student's answer (which starts from the 16th character of the line). If the student did not shade in any answer, the answer will be shown as a blank (e.g. student U032345B left the first two questions blank). If the student shaded more than one answer, the answer will be shown as a "*". Both blank and "*" must be marked as incorrect.
  4. Each correct answer counts as 1 mark, incorrect answer counts as 0 marks.
  5. The number of students in the file is not known before hand. You can assume that there is always at least one student who took the test.

Your job is to write a program that processes mcqin.txt and produces the output file mcqout.txt, the format of which is given below:

                C D D E A B A B B C B E D A E C E D D D A B D D C
U001234A02  25  C D D E A B A B B C B E D A E C E D D D A B D D C
U021111X     0  d b c b c a d d a a a c a d b a a b a c d a c b d
U031234A     1  b b c b c   c d a a B d b b b b a * c c d a b b d
U032345B     3      b E c a *   *     c D * d b a b a c d   D    
U003456Y13  23  C D D E A B A B B C B E D A E C d e D D A B D D C

The layout of the above output file above is:

  1. All numbers have been converted to its corresponding letter.
  2. The first line consists of all the correct answers in letter form.
  3. The second line onwards consists of the student answers and results. You must follow the sample output above exactly, vertically aligned nicely as shown above.
  4. Example: for the student U001234A02, the score is 25, and there are two blanks before 25 and two blanks after 25. Each of the student's answers are separated by only one blank.
  5. If a student's score is a single digit, right-justify it as shown above.
  6. If a student's answer is correct, print it as an upper case letter.
  7. If a student's answer is incorrect, print it as a lower case letter.
  8. If a student's answer is blank or "*", leave it as it is.
  9. Example: for the student U032345B, the score is 3 (only 3 correct answers, so only 3 upper case letters).
  10. Leave the students in the same order as in the input file.

Assume all input files exist and there are no errors in the input file. Overwrite the output file if it already exists.

A sample input file mcqin.txt has been placed in your directory by the pesetup program.

We will test your program with other mcqin.txt files.

All the best!

Some useful UNIX commands (in case you forgot what you did in Lab 0):

  1. "ls -l": lists all the files in the directory.
  2. "cp a.txt b.txt": copies a.txt to b.txt.
  3. "mv a.txt b.txt": moves / renames a.txt to b.txt.
  4. "cat a.txt": displays the text file a.txt.