program pascal

Program sort_pascal;
uses wincrt;
label z;
label l;
var textfile:text;
FileName, TFile : String;
a:array[1..15] of string;
i,j:integer;
x,v:char;
temp: string;

procedure input;
Begin
clrscr;
Writeln(‘press Enter to input data ‘+
+’ of the text file:’);
readln(FileName);
writeln(‘…….DATA MAHASISWA……’);
writeln(‘————————–‘);
writeln(‘KELAS NAMA NPM’);
writeln(‘————————–‘);
{A .txt file will be assigned to a text variable}
Assign(textfile, ‘C:\gilang.txt’);
Reset(textfile); {‘Reset(x)’ – means open the file x}
Repeat
Readln(textfile,TFile);
Writeln(TFile);
Until Eof(textfile);
Close(textfile);
Readln;
End;

procedure sort;
begin
clrscr;
assign(textfile,’c:\gilang.TXT’);
reset(textfile);
for i:=1 to 15 do readln(textfile,a[i]);
close(textfile);

for i:=1 to 14 do
for j:=i to 15 do
if a[j]<a[i] then
begin
temp:=a[i];
a[i]:=a[j];
a[j]:=temp;
end;

assign(textfile,'c:\gilang.TXT');
rewrite(textfile);
for i:=1 to 15 do writeln(textfile,a[i]);
close(textfile);
end;

procedure output;
Begin
clrscr;
Writeln('Enter the file name '+
+'(with its full path) of the text file:');
readln(FileName);
writeln('========DATA MAHASISWA========');
writeln('————————–');
writeln('KELAS NAMA NPM');
writeln('————————–');
{A .txt file will be assigned to a text variable}
Assign(textfile, 'c:\gilang.txt');
Reset(textfile); {'Reset(x)' – means open the file x}
Repeat
Readln(textfile,TFile);
Writeln(TFile);
Until Eof(textfile);
Close(textfile);
Readln;
End;

begin
z: clrscr;
gotoxy(8,10); write('|################|');
write(' Program sort berdasarkan kelas');
writeln('|###############|');writeln;
gotoxy(9,11);writeln('———————————————————');
gotoxy(20,13);writeln('1.Masukkan Data');
gotoxy(20,14);writeln('2.Pensortiran Data');
gotoxy(20,15);writeln('3.Output');
gotoxy(20,16);writeln('4.Exit ');
gotoxy(1,20);writeln('Masukkan Pilihan (1,2,3,4) : ');readln(x);

case x of
'1' : input;
'2' : sort;
'3' : output;
'4' : goto l;
end;

if x = '2' then
begin
clrscr;
writeln('Selesai(tekan Enter)'); readln;
goto z;
end;
writeln('Apakah anda ingin kembali ke menu? : '); readln(v);
if (v = 'y') or (v = 'Y') then goto z;

l: end.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s