program updatefile(input, output); uses wincrt; const max=40; var inputfile, outputfile:text; stdid, stdname :array[1..max] of string; procedure insertrecord; var complete:boolean; i,j :integer; newid, newname, id, name:string; begin writeln('*** Inserting Record Information ***'); write('Enter the new student Registration No. : '); readln(newid); write('Enter the new student name: '); readln(newname); i:=0; complete :=false; while not complete do begin i:=i+1; readln(inputfile, id); readln(inputfile, name); if newid < id then begin stdid[i] :=newid; stdname[i]:=newname; i :=i+1; stdid[i]:=id; stdname[i]:=name; complete:=true end else if eof(inputfile) then begin stdid[i] :=id; stdname[i] :=name; i :=i+1; stdid[i] :=newid; stdname[i]:=newname; complete :=true end else begin stdid[i]:=id; stdname[i]:=name end end; if complete then while not eof(inputfile) do begin i:=i+1; readln(inputfile, id); readln(inputfile, name); stdid[i]:=id; stdname[i]:=name; end; for j:=1 to i do begin writeln(outputfile, stdid[i]); writeln(outputfile, stdname[i]); end end; (*** Main Program ***) begin assign(inputfile, 'data4.txt'); assign(ouyputfile, 'result.txt'); reset(inputfile); rewrite(outputfile); insertrecord; close(inputfile); close(outputfile) end.