program BubbleSort; uses crt; const cls_size=50; var name : array[1..cls_size] of string; phone : array[1..cls_size] of integer; i, nstudent, pass : integer; classfile : text; class : string[2]; sorted : Boolean; procedure swap( var first , second : string ); var temp : string; begin Temp := first; first := second; second := Temp; end; begin { Main Program } clrscr; write('Class :'); readln(class); writeln; writeln('Telephone Directory in alphabetic order'); writeln('======================================='); writeln; assign(classfile, class+'phone.dat'); reset(classfile); nstudent:=0; while (not eof(classfile)) do begin nstudent:=nstudent+1; readln(classfile, name[nstudent]); readln(classfile, phone[nstudent]); end; close(classfile); sorted:=false; pass:=1; while (pass name[I+1] then begin sorted:=false; swap(name[i], name[i+1]); swap(phone[i], phone[i+1]); end; end; pass:=pass+1; end; writeln; assgin(classfile,class+'phone.dat'); rewrite(classfile); for i:=1 to nstudent do begin writeln(' ',name[i]:(25-length(name[i])), phone[i] ); writeln(classfile, name[i]); writeln(classfile, phone[i]); end; close(classfile); end. { Main Program }