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

  1.                                        -- Chapter 6 - Program 2
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Enum is
  6.  
  7.    type DAY is (MON, TUE, WED, THU, FRI, SAT, SUN);
  8.    subtype WORK_DAY is DAY range MON..FRI;
  9.    subtype PLAY_DAY is DAY range SAT..SUN;
  10.  
  11.    type HEAVENLY_BODY is (MOON, SUN, EARTH, MARS);
  12.    Big_Sphere : HEAVENLY_BODY;
  13.  
  14.    package Day_IO is new Text_IO.Enumeration_IO(DAY);
  15.    use Day_IO;
  16.  
  17.    package Body_IO is new Text_IO.Enumeration_IO(HEAVENLY_BODY);
  18.    use Body_IO;
  19.  
  20.    Day_Of_Week : DAY;
  21.    Today       : DAY;
  22.    Happy_Day   : PLAY_DAY;
  23.    Bowling_Day : DAY range THU..SAT;
  24.    Index       : INTEGER;
  25.  
  26. begin
  27.  
  28.    Day_Of_Week := WED;                       -- WED
  29.    Day_Of_Week := DAY'FIRST;                 -- MON
  30.    Day_Of_Week := DAY'LAST;                  -- SUN
  31.    Day_Of_Week := DAY'PRED(Day_Of_Week);     -- SAT
  32.    Day_Of_Week := DAY'SUCC(PLAY_DAY'FIRST);  -- SUN
  33.    Index := DAY'POS(MON);                    -- 0
  34.    Index := DAY'POS(WED);                    -- 2
  35.    Day_Of_Week := DAY'VAL(1);                -- TUE
  36.  
  37.    for Day_Of_Week in WORK_DAY loop
  38.       Put("We are in the workday loop");
  39.       New_Line;
  40.    end loop;
  41.  
  42.    Today := THU;
  43.    if Today <= WED then
  44.       Put("Early in the week");
  45.       New_Line;
  46.    end if;
  47.  
  48.    if Today >= WED then
  49.       Put("Late in the week");
  50.       New_Line;
  51.    end if;
  52.  
  53.    Today := SUN;
  54.    Big_Sphere := SUN;
  55.  
  56.    Today := DAY'(SUN);
  57.    Big_Sphere := HEAVENLY_BODY'(SUN);
  58.  
  59.    Put(Today);
  60.    Put(DAY'PRED(Today));
  61.    Put_Line(" from type DAY.");
  62.    Put(Big_Sphere);
  63.    Put(HEAVENLY_BODY'PRED(Big_Sphere));
  64.    Put_Line(" from type HEAVENLY_BODY");
  65.  
  66. end Enum;
  67.  
  68.  
  69.  
  70.  
  71. -- Result of execution
  72.  
  73. -- We are in the workday loop
  74. -- We are in the workday loop
  75. -- We are in the workday loop
  76. -- We are in the workday loop
  77. -- We are in the workday loop
  78. -- Late in the week
  79. -- SUNSAT from type DAY.
  80. -- SUNMOON from type HEAVENLY_BODY
  81.  
  82.