CS1101C Practical Exam

Question 3 (xxxx - xxxx hours)

Test Mark Re-Processing

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

The deadline for this lab is Wednesday 12 November 2008, xx:xx:xx hours. Strictly no submissions will be accepted after the deadline.

The midterm test is over, marks have been processed and placed on the website in a nice easy-to-read format. Unfortunately, in his haste, the careless lecturer has lost the original data; he has assigned you the task of recreating the original data from the nice easy-to-read format.

Text File

Assume that the text file containing the nice easy-to-read format is always called “nice1.txt” and that this file always exists. (It has been copied into your directory by the “pesetup” command.) Let us look at the file's contents:

| NT081234X | 18 | E C D a C | B A D E e | D c a c C | D e B C E | a D A B A | a |
| NT085703H | 22 | E C D c C | B A D E D | D A c e C | D e B C E | B D A B A | D |
| U080001A  | 14 | E C D c C | e A D a a | D A b d C | a a B a E | B D e B b | a |
| U080002B  | 10 | E e a d b | e A D a b | e c c e b | e B e C E | B a A B b | D |
| U080003E  | 13 | E d D c C | B b D a c | e c D A C | e a e C d | B D A e b | D |
| U080005H  |  8 | E C a d e | e b D b D | e A a A d | b d c b d | d a e B b | D |
| U080007J  | 18 | d C a c C | e b D E D | D A a A C | D B B C E | B D e a A | D |
| U080009L  | 15 | E e D c b | B A D E b | e e c A d | b B B C E | B D A a A | a |
| U080010M  | 14 | c C c c C | c A D E b | D d D A C | D B e C d | a D e a A | c |
| U080011N  |  4 | c e b c b | d c D c e | e e e c d | c B c C c | d c b a b | D |
| U080012R  | 15 | E C e E C | B A b a b | a e D c b | c a B C E | a D A B A | D |
| U080014U  |  9 | E C a b b | a d D b a | e A b c C | e a a C c | B c e B b | D |
| U080016W  |  7 | E e b a d | B b b E c | a d c c C | D a B b d | d D c a d | b |
| U080017X  |  8 | d e D c C | a A D d b | e c a c C | b a B C c | a a A c e | c |
| U080018Y  | 17 | E C D b C | d A a E b | e A D A C | e B B C c | B D b B e | D |
| U080020Y  | 16 | a e D d C | c d D d D | e c b A C | D B B C E | B D A B A | c |
| U080021X  |  9 | E C e d e | c d D a e | e c D A C | e e e a d | B c b c A | D |
| U080025W  | 14 | d e D c C | e A D a c | e A D A C | D B B a a | a a A e A | D |
| U080028U  |  6 | E e a a e | e d c a b | e e c e C | D e e d E | d D e a c | D |
| U080030R  | 20 | E e D c C | B A D E b | e A b A C | D B e C E | B D A B A | D |
| U080033N  |  5 | E a a c e | e d b a a | c e a e C | c a e a c | B b e c A | D |
Each line consists of a student's answers and the mark received. The first column consists of the student's matriculation number (which has at most nine characters). The second column consists of the student's mark. Student's answers then follow; note that after every fifth answer, we have a vertical bar as a separator. If the student's answer is correct, it is shown as an upper-case letter; if it is incorrect, it is shown as a lower-case letter. There are always 26 questions in the test.

Your task is to read in this data from the text file, and recreate the “raw” data format (display it on the screen), which is shown below:

NT081234X 53413214554313345235141211
NT085703H 53433214544135345235241214
U080001A  53433514114124311215245221
U080002B  55142514125335252535211224
U080003E  54433224135341351534241524
U080005H  53145524245111424324415224
U080007J  43133524544111342235245114
U080009L  55432214525531422235241111
U080010M  33333314524441342534145113
U080011N  35232434355553432333432124
U080012R  53553212121543231235141214
U080014U  53122144215123351133235224
U080016W  55214222531433341224443142
U080017X  45433114425313321233111353
U080018Y  53423411525141352233242254
U080020Y  15443344445321342235241213
U080021X  53545344155341355514232314
U080025W  45433514135141342211111514
U080028U  55115543125535345545445134
U080030R  55433214525121342535241214
U080033N  51135542113515331513225314

Answer key: 53453214544141342235241214
Each line consists of the student's matriculation number followed by the student's answer in numeric format; A maps to 1, B maps to 2, and so on. Follow the sample output precisely.

After reading in all student's information, display the answer key. Note that the original answer key is lost! But it can be recreated from the student's answers; because fortunately, for every question, at least one student has gotten it right. You can assume this to always be true.

Note that the number of lines in the text file is not known. You are to read the file until you reach the end of the text file.

Important Notes

Do not use any structures or any form of dynamic memory allocation (using malloc or calloc) in your program, else no credit will be given.

Remember to submit your program frequently using the submit testrepro.c command, and check your submission using the check command.

All the best!

UNIX commands

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

  1. dir”: 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”: shows the contents of a.txt.