Nicko Prasetio

Gunadarma University

34110962

Senin, 17 Oktober 2011

Program Sortir Data (MatKul Struktur&Organisasi Data)

Coding Program Sortir data menggunakan Pascal

coding :

Program output_pascal;
uses crt;
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(‘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, ‘a:\data45.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,’a:\data45.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]begin
temp:=a[i];
a[i]:=a[j];
a[j]:=temp;
end;

assign(textfile,’a:\data46.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, ‘a:\data46.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;
writeln(‘——————-’);
writeln(‘Program Sorting’);
writeln(‘——————-’);
writeln(’1.Masukkan Data’);
writeln(’2.Sortir Data’);
writeln(’3.Output’);
writeln(’4.Exit Menu’);
writeln(‘Masukkan (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.

Keterangan :
- buat datanya dulu di filetext/notepad lalu simpan di direktory c atau d atau lainnya tanpa dimasukan ke dalam folder.

- pada syntaks diatas, tiap coding untuk menginput data (Assign(textfile, ‘a:\data46.txt’);) diganti menjadi tempat dimana data tersimpan .
cth : Assign(textfile, ‘a:\data45.txt’); => Assign(textfile, ‘c:\data88.txt’);

- untuk syntaks pada procedure output, coding ( Assign(textfile, ‘c:\data88.txt’); ) diubah kembali sesuai dimana output tersebut akan disimpan. (jangan disamakan dengan file input)

cth : Assign(textfile, ‘a:\data46.txt’); => Assign(textfile, ‘c:\data89.txt’);

Tidak ada komentar:

Posting Komentar