Last updated by Roedy Green ©1985-1999 Canadian Mind Products.
{ Figure 3 Abundance } Program Depend; { How Pascal uses explicit subscripts in arrays } { This program stores the Names and Birthdates of two } { dependent children in an array big enough to hold up to 15 } { dependents. Then it prints them out. } Const MaxDependents = 15; { the maximum number of dependents we could ever possibly have } Type Dependent = Record ChildsName : String[30]; ChildsBirthDate : Packed Array [1 .. 8] OF Char { stored MM/DD/YY as character } { should be between 1950 Jan 01 and Today } { this program does not enforce this } End; { Record } Var HighWaterDependents : 0 .. MaxDependents; { how many dependents we currently have } DependentNumber : 1 .. MaxDependents; { index of the dependent we are looking at now } Dependents : Array [1 .. MaxDependents] of Dependent; Procedure MaintainHighWater; Begin { corral a bad subscript back safely in bounds } If DependentNumber < 1 Then DependentNumber := 1; If DependentNumber > MaxDependents Then DependentNumber := MaxDependents; { Keep track of the largest subscript used so far } If DependentNumber > HighWaterDependents Then HighWaterDependents := DependentNumber End; { MaintainHighWater } Procedure SetupDependents; Begin DependentNumber := 1; MaintainHighWater; Dependents [DependentNumber].ChildsName := 'Bruce'; Dependents [DependentNumber].ChildsBirthDate := '03/26/54'; DependentNumber := 2; MaintainHighWater; Dependents [DependentNumber].ChildsName := 'Brock'; Dependents [DependentNumber].ChildsBirthDate := '31/12/61' End { SetupDependents }; Procedure PrintDependents; Begin For DependentNumber := 1 To HighWaterDependents DO Begin Writeln (Lst,DependentNumber:2, ' ', Dependents [DependentNumber].ChildsBirthDate, ' ', Dependents [DependentNumber].ChildsName) End; { For } Write(Lst, Char(12)) { eject the paper - works on most printers } End; { PrintDependents } Begin { Depend } HighWaterDependents := 0; SetupDependents; PrintDependents End. { Depend }
![]() |
![]() |
![]() | |
![]() |
Canadian Mind Products | You can get an updated copy of this page from http://mindprod.com/jglossa.html | The Mining Company's
Focus on Java Best of the Net Award |