home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog4 / swapsome.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.3 KB  |  70 lines

  1.                                  -- Chapter 28 - Program 1
  2.    generic
  3.       type ITEM is range <>;   -- integer class only
  4.    procedure Exchange_Data(X,Y : in out ITEM);
  5.  
  6.    procedure Exchange_Data(X,Y : in out ITEM) is
  7.    Temp : ITEM;
  8.    begin
  9.       Temp := X;
  10.       X := Y;
  11.       Y := Temp;
  12.    end Exchange_Data;
  13.  
  14. -- This is the beginning of the main program which uses the generic
  15. -- procedure defined above.
  16. with Exchange_Data;
  17. with Text_IO;
  18. use Text_IO;
  19.  
  20. procedure SwapSome is
  21.  
  22.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  23.    use Int_IO;
  24.  
  25.    type MY_INT is new INTEGER range 1..128;
  26.  
  27.    procedure SwapInt is new Exchange_Data(INTEGER);
  28.    procedure SwapNew is new Exchange_Data(MY_INT);
  29.  
  30.    Index1 : INTEGER := 17;
  31.    Index2 : INTEGER := 33;
  32.    Limit1 : MY_INT  := 3;
  33.    Limit2 : MY_INT  := 7;
  34.  
  35. begin
  36.  
  37.    SwapInt(Index1,Index2);
  38.    SwapNew(Limit1,Limit2);
  39.  
  40.    Put(Index1);
  41.    Put(Index2);
  42.    New_Line;
  43.    Put(INTEGER(Limit1));
  44.    Put(INTEGER(Limit2));
  45.    New_Line(2);
  46.  
  47.    SwapInt(Index1,INTEGER(Limit1));
  48.    SwapNew(MY_INT(Index2),Limit2);
  49.  
  50.    Put(Index1);
  51.    Put(Index2);
  52.    New_Line;
  53.    Put(INTEGER(Limit1));
  54.    Put(INTEGER(Limit2));
  55.    New_Line(2);
  56.  
  57. end SwapSome;
  58.  
  59.  
  60.  
  61.  
  62. -- Result of Execution
  63.  
  64. --    33    17
  65. --     7     3
  66. --
  67. --     7     3
  68. --    33    17
  69.  
  70.