FloridaTech - College of Engineering
CSE1001 - LABORATORY

Author: Jamal Faik

Lab Assignment 10 : Exceptions


An Example
...function safe_division (a, b : Integer) return Integer is
......q : Integer;
...begin
......q := a / b;
...exception
......when CONTSRAINT_ERROR => return Integer'Last;
...end safe_division;

Another Example
...procedure P is
...begin
......P;
...exception
......when STORAGE_ERROR => P;
...end P;

Problem 1
Define a type Day than models the days of the week then write a function Tomorrow that returns the following day of a certain day. You function should not contain any control statement.
Problem 2 Rewrite the function factorial that computes the factorial of an integer (n) according to the following rules :
Note : No if or case statement are allowed in this function
Problem 3 : A Compression Idea
Write a program that reads a file of Naturals and ouput one integer which we would call the signature of the file. Values other than integers should be ignored. The mechanism of producing one integer from a list of Naturals relies on Cantor bijection between N x N and N (where N is the set of Naturals).
Cantor(x,y) = (x+y-1)(x+y-2)/2 + y
The procedure to follow to produce the signature of a file is the following :
Suppose your file contains the following numbers : 10 11 12 13 14 15 16 17 18 19 20 The process is (uniquely) reversible and from the signature of the file, you can produce one unique list of numbers (composing the file)