type dept=(house, sports, drugs, food, liquor) month=1.12 item=record price: real case available: boolean of true: (amount: integer Where: dept) false: (month expected month) enc d
type dept=(house,sports,drugs,food,liquor); month=1..12; item=record price:real; case available:boolean of true:(amount:integer; where:dept); false:(month_expected:month) end;
var il12 item il price: =5. 24 il available =true amount =29 il. where: - liquor 12 price-=324.99; 12. available =false 12. month expect: =8
var i1,i2:item: …… i1.price:=5.24; i1.available:=true; i1.amount:=29; i1.where:=liquor; i2.price:=324.99; i2.available:=false; i2.month_expect:=8;
price 5.24 pce324.99 avallable avallable false amount 29 month_expected q uor where
price available amount where 5.24 true 29 liquor price available month_expected 324.99 false 8
组合类型 1.数组 ①约束数组类型 下标界是静态确定的 type MONTH IS JAN,FEB, MAR,APR, MAY,JUN JUL, AUG, SEP,OCT,NOVDEC) type YEARLY PAY is array(MONTH)of INTEGER type SUMMer PAY is array(MONTH range JUL SEP)of INTEGER
二. 组合类型 1. 数组 ①约束数组类型 ⎯下标界是静态确定的 type MONTH is (JAN,FEB,MAR,APR,MAY,JUN, JUL,AUG,SEP,OCT,NOV,DEC); type YEARLY_PAY is array(MONTH) of INTEGER; type SUMMER_PAY is array(MONTH range JUL..SEP) of INTEGER;
②非约束数组类型 Ada支持动态数组 type SoMe PERIOd PAY ia array MONTH range)of INTEGER type INT VERTOR ia array(INTEGER range <> of Integer type BOOL MAXTRIX iS array(INTEGER range INTEGER range <>)of BOOLEAN ③Ada数组类型由分量的类型下标个数 和下标类型来刻画
②非约束数组类型 ⎯Ada支持动态数组 type SOME_PERIOD_PAY ia array(MONTH range) of INTEGER; type INT_VERTOR ia array(INTEGER range ) of INTEGER; type BOOL_MAXTRIX is array(INTEGER range , INTEGER range ) of BOOLEAN; ③Ada数组类型由分量的类型,下标个数 和下标类型来刻画
④界的确定可在数据对象成为实体时或 参数传递时完成 SPRING MONTH: SOME PERIOD PAY(APRJUN Z: INT VECTOR(100.100) W: INT VERTOR(20. 40) Y: BOOL MAXTRIX(O N,OM) 其中界的值不一定静态给出
④界的确定可在数据对象成为实体时,或 参数传递时完成 SPRING_MONTH:SOME_PERIOD_PAY(APR..JUN); Z:INT_VECTOR(-100..100); W:INT_VERTOR(20..40); Y:BOOL_MAXTRIX(0..N,0..M); 其中, 界的值不一定静态给出
function SUM(X: INT VECTOR)return INTEGER RESULT INTEGER =0 begin for I in X FIRST.X'LAST loop RESULT: RESULT+XD end loop return result end sum 可用不同大小的数组作为实参来调用该函数 如:A:=SUM(Z)+SUM(W)
function SUM(X:INT_VECTOR) return INTEGER; RESULT: INTEGER:=0; begin for I in X’FIRST..X’LAST loop RESULT:= RESULT+X(I); end loop; return RESULT; end SUM; 可用不同大小的数组作为实参来调用该函数 如: A:=SUM(Z)+SUM(W);
⑤可以在过程的局部说明中说明一个数 组它的界依赖于一个参数 TEMPORARY INT VECTOR(X FIRST.XLAST
⑤可以在过程的局部说明中说明一个数 组,它的界依赖于一个参数 TEMPORARY:INT_VECTOR(X’FIRST..X’LAST);
⑥切片:用以选取一维数组若千个相继 LINE: STRING(I.80) LINE(1.11)=(D,e,2a,r32”,2f,ri,e,n,d)
⑥切片:用以选取一维数组若干个相继 分量 LINE:STRING(1..80); LINE(1..11):=(‘D’,’e’,’a’,’r’,’’,’f’,’r’,’i’,’e’,’n’,’d’);
2.记录 ①说明形式 e type COORDINATE is recor X INTEGER range 0..100 Y CHARACTER end recor
2. 记录 ①说明形式 type COORDINATE is record X:INTEGER range 0..100; Y:CHARACTER; end record;