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, 'H:\contoh.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,'H:\contoh.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,'H:\contoh.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, 'H:\contoh.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.
Berikut adalah penulisan coding pada program pascal
Coding 1 |
Coding 2 |
Coding 3 |
Coding 4 |
Data di masukan ke notepad lalu simpan di derektori H /sesuai dengan penyimpanan data masing-masing |
Jalankan Program |
Secara Otomatis Data Akan Muncul |
Setelah itu kembali ke menu dengan menuliskan "y" |
Setelah itu pilih "2" untuk mensortir data |
Dan akan menghasilkan sortiran seperti diatas