[Unified-mailman] CP lecture 1

Kristina Lundqvist kristina at MIT.EDU
Thu Mar 11 14:06:09 EST 2004


Mud replies and lecture slides for lecture one are now available via

http://web.mit.edu/16.unified/www/SPRING/Computers/index.html

Attached to this email is also the code used in class today.

..K

---
I. Kristina Lundqvist, Ph.D.
Charles S. Draper Assistant Professor of Aeronautics and Astronautics


Massachusetts Institute of Technology
77 Massachusetts Avenue, 33-406
Cambridge, MA 02139


phone: +1 617-452-2550    fax: +1 617-253-7397
kristina at mit.edu

http://www.mit.edu/~kristina
http://esl.mit.edu/index.html




-------------- next part --------------
-- Lecture 1
-- The code contains "Typical Errors" ...

with Ada.Text_Io;
with Ada.Integer_Text_Io;

procedure Demo_Errors is 

   Upper_Limit : Integer := 10;  
   Lower_Limit : Integer := 10;  

   -- Swap the values of X and Y
   procedure Swap (X : in out Integer; Y : in out Integer  ) is 
      Temp : Integer;  
   begin
      Y:= Y+1;
      Temp:=X;
      X:= Y;
      Y:= Temp;
   end Swap;
   
   My_Unused_Variable : Integer;  
   My_Semantic_Error  : Float;  
   Error              : Integer;  

begin
   
   --My_Semantic_Error := My_Unused_Variable;
   
   if Lower_Limit >= Upper_Limit then
      Swap(Lower_Limit, Upper_Limit);
   end if;
   Error := Upper_Limit - Lower_Limit;

   case Error is
      when -1 =>
         Ada.Text_Io.Put_Line("This should never happen");
      when 0 =>
         Ada.Text_Io.Put_Line("Lower and Upper Limit Equal");
      when 1=>
         Ada.Text_Io.Put_Line("Small Error");
      when others =>
         Ada.Text_Io.Put_Line("Normal Operation");
   end case;

end Demo_Errors;


More information about the Unified-mailman mailing list