with Ada.Text_IO;
use Ada.Text_IO;
procedure Enum is
type DAY is (MON,TUE,WED,THU,FRI,SAT,SUN);
subtype WORK_DAY is DAY range MON..FRI;
subtype PLAY_DAY is DAY range SAT..SUN;
type HEAVENLY_BODY is (MOON,SUN,EARTH,MARS);
Big_Sphere : HEAVENLY_BODY;
package DAY_IO is new Ada.Text_IO.Enumeration_IO(DAY);
use DAY_IO;
package BODY_IO is new Ada.Text_IO.Enumeration_IO(HEAVENLY_BODY);
use BODY_IO;
Day_Of_Week:DAY;
Today :DAY;
Happy_Day :PLAY_DAY;
Bowling_Day:Day range THU..SAT;
Index :Integer;
begin
Day_Of_Week :=WED; -- WED
Day_Of_Week :=DAY'First; -- MON
Day_Of_Week :=DAY'Last; -- SUN
Day_Of_Week :=DAY'Pred(Day_Of_Week); -- SAT
Day_Of_Week :=DAY'Succ(PLAY_DAY'First); -- SUN
Index:=DAY'Pos(MON); -- 0
Index:=DAY'Pos(WED); -- 2
Day_Of_Week := DAY'Val(1); --TUE
for Day_Of_Week in WORK_DAY loop
Put("We are in the workday loop");
New_Line;
end loop;
Today:=THU;
if Today=WED then
Put("Late in the week");
New_Line;
end if;
Today:=SUN;
Big_Sphere:=SUN;
Today:=Day'(SUN);
Big_Sphere:=HEAVENLY_BODY'(SUN);
Put(Today);
Put(DAY'Pred(Today));
Put_Line(" from the type DAY ");
Put(Big_Sphere);
Put(HEAVENLY_BODY'Pred(Big_Sphere));
Put_Line(" from type Heavenly_body");
end Enum;
dos diosas
原创文章 143获赞 62访问量 2305
关注
私信
展开阅读全文