

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


program insertion; (*------------------------------------------------------------------
function lookup (L: Ltype; X: integer; numL: integer): integer; (* loop up license number X in array L ) var i: integer; begin lookup := 0; for i := 1 to numL do if L[i] = X then lookup := i end; ( lookup *)
procedure insert(var L: Ltype; X: integer; var numL: integer); (* insert new license number X in array L ) ( ASSUMES X NOT ALREADY PRESENT ) begin if numL = MAXL then writeln(’** overflow **’) else begin numL := numL + 1; L[numL] := X end end; ( insert *)
procedure loadL(var Lfile: text; var L: Ltype; var numL: integer); (* read from file LIC.DAT into L ) begin reset(Lfile, ’LIC.DAT’); numL := 0; while not eof(Lfile) and (numL < MAXL) do begin numL := numL + 1; readln(Lfile, L[numL]) end end; ( loadL *)
procedure dumpL(var Lfile: text; L: Ltype; numL: integer); (* write array L into file LIC.DAT ) var i: integer; begin rewrite(Lfile, ’LIC.DAT’); writeln(’** dummping L **’); for i := 1 to numL do begin writeln(Lfile, L[i]); writeln(L[i]) end; close(Lfile) end; ( dumpL *)
begin loadL(Lfile, L, numL); writeln(’Please enter new license #’); readln(X); while X <> 0 do begin if lookup(L, X, numL) > 0 then writeln(’Tow the car with license:’, X)
else begin insert(L, X, numL); writeln(’Give a warning to car with license:’, X) end; readln(X) end; dumpL(Lfile, L, numL) end. INITIAL RUN: Please enter new license # 47 Give a warning to car with license: 47 23 Give a warning to car with license: 23 0 *** dummping L *** 47 23 SECOND RUN: Please enter new license # 56 Give a warning to car with license: 56 47 Tow the car with license: 47 23 Tow the car with license: 23 56 Tow the car with license: 56 0 *** dummping L *** 47 23 56 THIRD RUN: Please enter new license # 89 Give a warning to car with license: 89 56 Tow the car with license: 56 77 Give a warning to car with license: 77 23 Tow the car with license: 23 33 Give a warning to car with license: 33 99 Give a warning to car with license: 99 61 Give a warning to car with license: 61 19 Give a warning to car with license: 19 21 Give a warning to car with license: 21 39 *** overflow *** Give a warning to car with license: 39 0 *** dummping L *** 47 23 56 89 77 33 99 61 19 21