-
Express 3FH in decimal, octal, and binary.
-
How many kilobytes is 2Gb? You may express your answer in powers of 2.
-
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.
-
Write a complete program module that does the following:
- Declare a list of 30 students -- each student has a name string,
a CARDINAL student ID, and a REAL GPA.
- Initialize the list to default values using a single statement.
- Write out the list to a file in binary format.
- Display the size of the output file in LOCs.
- 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;
-
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;
-
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.