Computer Science 159.102 Assignment 1
Due 29th July 2002


This Assignment involves writing a simple C program to work out which tutorial group each student of 159102 is in. You can work out which group you are in by adding the digits in your ID number; finding the remainder when this is divided by 4 and adding 1.
For example, 98054847 is in group (9+8+0+5+4+8+4+7)%4 +1 = (45)%4 +1 = 2.
Your program must read a file called id.txt (found at http://cs-alb-pc3.massey.ac.nz/notes/59102/id.txt or on the H: drive) containing a list of ID numbers and print the group number for each student. The list of IDs is terminated by -1.

Your program must be a single source file written in standard ANSI C for gcc or borlandc. Your program must not accept any input and must only print the list of group numbers and then exit. Use the following as the basis of your program.

#include <stdio.h>

int main() {
  FILE *f;
 
  f=fopen("id.txt","r"); // do not change this line in any way or you will lose marks

  // the rest of main goes in here

  return 0;
}   

The id.txt file must be in the same directory as the program. The output from your program should look like:

00006939 4
00041327 2
00060046 1
00063878 1
00065722 3
00071668 1
00071692 2
00075027 2
00076120 1
00081221 3
....

This assignment is worth 5% of the total for this paper. Marks will be awarded as follows:

6/10 - How well it works
2/10 - Documentation
2/10 - Programming style and elegance of your solution

Marks will be subtracted for obvious copying and for late submissions.

You must submit your assignments electronically using the web page:

http://cs-alb-pc3.massey.ac.nz/notes/59102/ . No paper submissions will be accepted.


M Johnson 2002