###### tags: `Pascal Programming D1` # Search(p.403) ## Ver I (5/10/2021) program search; type ExamType = record Name : string[30]; Mark : 0..100 end; const Num = 11; var Student : array[1..Num] of ExamType; position : integer; procedure InputData; var Examfile : text; count : integer; begin assign(Examfile, 'exam.txt'); reset(Examfile); count := 0; while not eof(Examfile) do begin count := count + 1; with Student[count] do begin readln(Examfile, Name); readln(Examfile, Mark) end; end; close(Examfile) end; procedure Search(var index : integer); var target : string; found : boolean; count : integer; begin write('Enter name of student: '); readln(target); found := false; count := 0; index := 0; repeat count := count + 1; with Student[count] do if Name = target then begin index := count; found := true end; until found or (count = Num); writeln(' Number of iterations =', count) end; procedure DisplayResult(index : integer); begin if index = 0 then writeln('Record not found!') else with Student[Index] do begin writeln( 'Record found!'); writeln( 'Student name = ', Name); writeln( 'Exam mark = ', Mark); end; end; begin InputData; Search(position); DisplayResult(position) end. ## exam.txt ADA 72 BRIAN 55 CINDY 69 DANIEL 81 HENRY 75 PAUL 60 PETER 89 PRISCA 73 SAM 77 SAMUEL 68 VINCENT 70