Kamis, 10 November 2011

Update dan Insert Data Tabel (PASCAL)

Program dibawah adalah program yang sama seperti sebelumnya tapi sudah ditambahkan dengan program Update dan Insert. berikut kodingannya :

PROGRAM Tugas_table_n_sorting;
USES CRT;
CONST
garis='------------------------------------------------------';
VAR
kelas : ARRAY [1..100] OF STRING[5];
npm : ARRAY [1..100] OF STRING[8];
nama : ARRAY [1..100] OF STRING[15];
c,n,i,j,bar,kelompok,tempatnya_min,x,y,z : INTEGER;
p,q,r,min,temp,cari : STRING;
ketemu : boolean;
LABEL INPUT,MENU,SORT,CETAK,SELESAI;

BEGIN
CLRSCR;
{ pemasukan data dalam array }
INPUT:
WRITE('MAU ISI BERAPA DATA : ');
READLN(N);
FOR i:= 1 TO n DO
BEGIN
CLRSCR;
GOTOXY(30,4); WRITE('DATA KE- ',i:2);
GOTOXY(10,7); WRITE('NPM : '); READLN(NPM[i]);
GOTOXY(10,8); WRITE('NAMA : '); READLN(NAMA[i]);
GOTOXY(10,9); WRITE('KELAS : '); READLN(KELAS[i]);
END;
GOTO CETAK;
{ pilih menu }
MENU:
WRITELN('1) Insert Data.');
WRITELN('2) Update Data.');
WRITELN('3) Sorting Data.');
WRITELN('4) Exit.');
WRITE('PILIH = ');READLN(x);
case x of
1: begin
CLRSCR;
i := i + 1;
GOTOXY(30,4); WRITE('DATA KE- ',i:2);
GOTOXY(10,7); WRITE('NPM : '); READLN(NPM[i]);
GOTOXY(10,8); WRITE('NAMA : '); READLN(NAMA[i]);
GOTOXY(10,9); WRITE('KELAS : '); READLN(KELAS[i]);
n := n + 1;
goto CETAK;
end;
2: begin
WRITE('Masukkan NPM yang akan di Update : ');READLN(CARI);
c := 1;
if (cari = '0') or (cari = '') then
begin
WRITE('Masukkan NPM yang benar !');
end
else
begin
ketemu := false;
while (not ketemu) and (c <= n) do
if NPM[c] = cari then
ketemu := true
else c := c + 1;
if ketemu then
begin writeln('Data yang akan di Update :');
writeln('1. NPM');
writeln('2. NAMA');
writeln('3. KELAS');
writeln('4. KEMBALI');
writeln('PILIH : ');readln(z);
case z of
1: begin
writeln('Masukkan NPM yang baru : ');readln(p);
NPM[c] := p;
goto CETAK;
end;
2: begin writeln('Masukkan NAMA yang baru : ');readln(q);
NAMA[c] := q;
goto CETAK;
end;
3: begin writeln('Masukkan KELAS yang baru : ');readln(r);
KELAS[c] := r;
goto CETAK;
end;
4: goto MENU;
end;
end;
end;
end;
3: goto SORT;
4: goto SELESAI;
end;
SORT:
WRITELN('1) Sort by NAMA.');
WRITELN('2) Sort by KELAS.');
WRITELN('3) Sort by NPM.');
WRITELN('4) Kembali Ke Menu.');
WRITE('PILIH = ');READLN(y);
case y of
1: begin for i := n - 1 downto 1 do
for j := 1 to i do
if nama[j] > nama[j+1] then
begin
temp := kelas[j];
kelas[j] := kelas [j+1];
kelas[j+1] := temp;
temp := npm[j];
npm[j] := npm [j+1];
npm[j+1] := temp;
temp := nama[j];
nama[j] := nama [j+1];
nama[j+1] := temp;
end;
end;
2: begin
for i := n - 1 downto 1 do
for j := 1 to i do
if kelas[j] > kelas[j+1] then
begin
temp := kelas[j];
kelas[j] := kelas [j+1];
kelas[j+1] := temp;
temp := npm[j];
npm[j] := npm [j+1];
npm[j+1] := temp;
temp := nama[j];
nama[j] := nama [j+1];
nama[j+1] := temp;
end;
end;
3: begin
for i := n - 1 downto 1 do
for j := 1 to i do
if npm[j] > npm[j+1] then
begin
temp := kelas[j];
kelas[j] := kelas [j+1];
kelas[j+1] := temp;
temp := npm[j];
npm[j] := npm [j+1];
npm[j+1] := temp;
temp := nama[j];
nama[j] := nama [j+1];
nama[j+1] := temp;
end;
end;
4: begin
goto MENU;
end;
end;
{ cetak atas absen }
CETAK:
CLRSCR;
GOTOXY(5,4); WRITE(GARIS);
GOTOXY(5,5); WRITE('NO');
GOTOXY(9,5); WRITE('NPM');
GOTOXY(20,5); WRITE('NAMA');
GOTOXY(37,5); WRITE('KELAS');
GOTOXY(47,5); WRITE('PARAF');
GOTOXY(5,6); WRITE(GARIS);
{ proses Cetak isi array di absen }
bar:=7;
FOR i:= 1 TO n DO
BEGIN
{ penempatan cetak array }
GOTOXY(5,bar); WRITELN(i:2);
GOTOXY(9,bar); WRITELN(NPM[i]);
GOTOXY(20,bar); WRITELN(NAMA[i]);
GOTOXY(37,bar); WRITELN(KELAS[i]);
GOTOXY(47,bar); WRITELN(i,'. . .');
bar:=bar+1;
END;
GOTOXY(5,bar+1);WRITELN(garis);
READLN;
GOTO MENU;
SELESAI:
END.

1 komentar:

Terima kasih atas kunjungannya ke blog saya.