		CSI2131 Winter 2005
	Assignment#2 Part-1 Solution 


The Records in the given file have the following fields:
--------------------------------------------------------

Field-1: Year (4-digit field)

Field-2: Semester (Fall, Winter or Summer)

Field-3: Course code (3 letters and 4 numbers) 

Field-4: Course section (one character or, empty)

Field-5: Course title

Field-6: Instructor's name

Field-7: Course web page (optional)

Field-8: Instructor's home page (optional)


RECORD STRUCTURE USED FOR THE COMPACT DATA-FILE:
------------------------------------------------
We use variable-length Records containing 
- some fixed length fields (fields 1-4) and, 
- some variable length fields (fields 5-8).
There is NO length indicator.
Each variable length field ends with a special seperator character('|').

The first four bytes of the record contain field-1 to field-4 encoded as follows:

BYTE-1 : Contains "year" and "term" fields. 
The "term" is encoded as 0, 1 or, 2 (0=Fall/1=Winter/2=Summer). 
The "year" is encoded as a number between 0-84 (incl.). This is used to represent 
the range of years 1997 to 2081 (So, 1997->0, 1998->1, ... 2081->84).
Note that we have 3*85=255 possible (year,term) combinations, so we can store them 
in one byte (One byte can contain 256 different numbers.)
To store these together in one byte, we use the following trick:
The "year" value is multiplied by 3 and add the "term" value to it, and this number is stored in byte-1.
When retrieving a Record, we get back the "year" and "term" from this number, 
by dividing it by 3. The remainder (0-2) gives us the "term" and the quotient(0-84) gives the "year" value.

BYTE-2 & 3 : Contains the Course Code. 
For the first part of the code (CSI,CEG etc.) we have 5 possible values, 
which we encode by the numbers 0-4.(0=CEG,1=CSI,2=ELG,3=GNG,4=SEG)
For the last 4 digits in the code, the range is from "0000" to "9999", which is 
stored as the corressponding binary number(0-9999). 
To store both values combined using the trick above, we need at least 16 bits(2 bytes) for the (5*10000=50,000) possible codes. 

BYTE-4 : Contains the Course Section. We store this field as the ASCII code of 
the letter representing the section.

Starting from byte-5, we store the variable length fields (field-5 to field-8) 
each seperated by the '|' character. ( Note that we need a seperator at the end 
of the last field but none at the start of the first.)

TOTAL BYTES USED: 4 + 4 + number of characters in fields-5 to 8.

The first four bytes of the record contain the "key" part of the record. 
This can be stored in a long int variable which can be used in the index.


EXAMPLE OF A RECORD:
--------------------
Year: 2005
Term: Winter
Code: CSI2131
Section: B
Course Name: File Mangement
Instructor Name: Lucia Moura
Course Webpage: http://www.site.uottawa.ca/~lucia/courses/2131-05/
Professor's Homepage: http://www.site.uottawa.ca/~lucia/

This Record is stored as follows:
---------------------------------
"year" value = 2005-1997 = 8
"term" value = 1 (for Winter)
So, Byte-1 contains the number 8*3+1 = 25 
"CSI" => 1
"2131" => 2131
Byte(2,3) contains the number 2131*5+1 = 10656
"section" value = 66 (ASCII code for B)
Byte-4 contians the number 66 (same as the char 'B')

Byte-5 onwards, we store the following string of characters:
"File Mangement|Lucia Moura|http://www.site.uottawa.ca/~lucia/courses/2131-05/|http://www.site.uottawa.ca/~lucia/|"

Note: The above record takes 117 bytes in the compact datafile.




ASSUMPTIONS ABOUT THE DATA:
---------------------------
1. The value of the "year" field is assumed to range from 1997 to 2081.
Note that 1997 was chosen because it was the year when SITE came into 
existence and these courses were started. Alternately we could have chosen 
to start from 1999, because it is the earliest value in the given file.
The maximum value allowed is 2081, which means that this program can be 
used only upto the year 2081. 
(This is fine because, by that time, the guy who programmed this would 
be dead, so no-one would be able to complain anyway ;-))

2. The course code should start with the letters "CSI", "SEG", "ELG", 
"CEG", or "GNG", followed with exactly four digits.

3. The course section can be only an upper-case letter (A-Z) or, it may be blank.

4. The fields 5 to 8, could consists of any number of characters. 
So, there is no restriction on the sizes of these fields.
