home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / vici_102 / examples / trans.e < prev   
Text File  |  1993-02-13  |  2KB  |  92 lines

  1. class Trans
  2. feature
  3.     Create is
  4.     local
  5.         a,b: ARRAY2[INTEGER];
  6.         x,y: INTEGER
  7.     do
  8.         a.create(5,2);
  9.         io.putstring("Width: ");  io.putint(a.width); io.new_line;
  10.         io.putstring("Height: "); io.putint(a.height); io.new_line;
  11.         
  12.         -- a initialisieren
  13.         FROM x:= 1
  14.         UNTIL x > a.width
  15.         LOOP
  16.             FROM y:= 1
  17.             UNTIL y > a.height
  18.             LOOP
  19.                 a.put(10*x + y, y, x);
  20.                 y:= y + 1
  21.             END;
  22.             x:= x + 1
  23.         END;
  24.         
  25.         print(a);
  26.         io.new_line;
  27.         
  28.         b:= transpose(a);
  29.         
  30.         print(b);
  31.         io.new_line;
  32.     end;
  33.     
  34.     print(a: ARRAY2[INTEGER]) IS
  35.     REQUIRE NOT a.Void
  36.     LOCAL x,y: INTEGER
  37.     DO
  38.         FROM x:= 1
  39.         UNTIL x > a.width
  40.         LOOP
  41.             FROM y:= 1
  42.             UNTIL y > a.height
  43.             LOOP
  44.                 io.putint(a.item(y,x));
  45.                 io.putchar('\t');
  46.                 y:= y + 1
  47.             END;
  48.             io.new_line;
  49.             x:= x + 1
  50.         END;
  51.     END;
  52.     
  53.     
  54.     transpose(a: ARRAY2[INTEGER]): ARRAY2[INTEGER] IS
  55.     REQUIRE NOT a.Void
  56.     LOCAL x,y: INTEGER
  57.     DO
  58.         Result.Create(a.width, a.height);
  59.         
  60.         FROM
  61.             x:= 1
  62.         INVARIANT
  63.             x <= a.width + 1;
  64.             ForAll j:[1..x-1]. ForAll i: [1..a.height]. a.item(i,j) = Result.item(j,i)
  65.         VARIANT
  66.             a.width + 1 - x
  67.         UNTIL
  68.             x > a.width
  69.         LOOP
  70.             FROM
  71.                 y:= 1
  72.             INVARIANT
  73.                 y <= a.height + 1;
  74.                 ForAll i: [1..y-1]. a.item(i,x) = Result.item(x,i)
  75.             VARIANT
  76.                 a.height + 1 - y
  77.             UNTIL
  78.                 y > a.height                
  79.             LOOP
  80.                 Result.put(a.item(y,x),x,y);
  81.                 y:= y + 1
  82.             END;
  83.             x:= x + 1
  84.         END
  85.     ENSURE
  86.         NOT Result.Void;
  87.         Result.width = a.height AND Result.height = a.width;
  88.         ForAll j:[1..a.width]. ForAll i: [1..a.height]. a.item(i,j) = Result.item(j,i)
  89.     end
  90. end
  91.     
  92.