031.Ada语言中更进一步自定义类型实例

                                       -- Chapter 7 - Program 3
with Ada.Text_IO;
use Ada.Text_IO;

procedure MoreDers is

                                  -- Some floating point types
   type    NEW_FLOAT1 is digits 5;
   type    NEW_FLOAT2 is digits 5 range 1.0..12.0;
   type    DER_FLOAT  is new FLOAT;
   type    LIM_FLOAT  is new FLOAT range 0.0..555.5;
   subtype SUB_FLOAT  is     DER_FLOAT range -2.3..12.8;

                                  -- Some fixed point types
   type    NEW_FIXED1 is delta 0.5  range 1.0..12.0;
   type    NEW_FIXED2 is delta 0.05 range 1.0..12.0;
   type    DER_FIXED  is new NEW_FIXED1;
   type    LIM_FIXED  is new NEW_FIXED1 range 1.0..5.5;
   subtype SUB_FIXED  is     DER_FIXED range 2.1..2.8;

                                  -- Some CHARACTER types
   type    DER_CHAR   is new CHARACTER;
   type    ALPHA_CHAR is new CHARACTER range 'A'..'Z';
   subtype HEX_CHAR   is     ALPHA_CHAR range 'A'..'F';

                                  -- Some enumerated types
   type    DAY         is (MON, TUE, WED, THU, FRI, SAT, SUN);
   type    WEEKDAY     is new DAY range MON..FRI;
   subtype BOWLING_DAY is WEEKDAY range WED..THU;

                                  -- Some floating point objects
   Direction : FLOAT;
   Speed     : DER_FLOAT := 100.0;
   Length    : LIM_FLOAT := 72.41;
   Size      : SUB_FLOAT := 4.3;

begin

   Direction := 1.2 + FLOAT(Length + LIM_FLOAT(Speed * Size));

end MoreDers;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值