Name: __________________
Student ID: __________________
  1. Express 3FH in decimal, octal, and binary.
  2. How many kilobytes is 2Gb? You may express your answer in powers of 2.
  3. Name the 3 standard I/O libraries used to open/close files, and the differences among them. Name at least two procedures from each library.
  4. Write a complete program module that does the following:
    1. Declare a list of 30 students -- each student has a name string, a CARDINAL student ID, and a REAL GPA.
    2. Initialize the list to default values using a single statement.
    3. Write out the list to a file in binary format.
    4. Display the size of the output file in LOCs.
    5. Read back in from the file only the entry for the 17th student. Hint:
      PROCEDURE NewPos (cid: ChanID;
      	chunks: INTEGER; chunkSize: CARDINAL;
      	from: FilePos): FilePos;
      
  5. Rewrite the following FOR loop code snippet as a general LOOP. Don't worry about the rest of the module (IMPORT, VAR, etc.).
    FOR idx := 0 TO LENGTH (name)
      	DO
    		name[idx] := CAP (name[idx]);
    	END;
    
  6. What is output from executing the following program module? (sysException is the exception that is raised in Stonybrook when dividing an integer by zero.)
    MODULE ExceptTest;
    
    FROM M2EXCEPTION IMPORT
    	M2Exceptions, IsM2Exception, M2Exception;
    FROM EXCEPTIONS IMPORT
    	IsExceptionalExecution;
    FROM STextIO IMPORT
    	WriteString, WriteLn;
    FROM SRealIO IMPORT
    	WriteFixed;
    
    PROCEDURE FloorDivide (num, denom : REAL) : REAL;
    BEGIN
    	RETURN FLOAT ( INT (num) / INT (denom) );
    EXCEPT
    	IF IsExceptionalExecution() AND
    	  (M2Exception() = sysException) THEN
    		WriteString (" div-by-zero!");
    	END;
    END FloorDivide;
    
    BEGIN
    	WriteFixed ( FloorDivide ( 14.2, 5.9 ), 0, 0 );
    	WriteFixed ( FloorDivide (  1.5, 0.5 ), 0, 0 );
    	WriteFixed ( FloorDivide (  6.8, 2.1 ), 0, 0 );
    EXCEPT
    	IF IsExceptionalExecution() THEN
    		WriteString (" bummer!");
    		RETURN;
    	END;
    END ExceptTest.