Sabtu, 02 Juli 2011

Membuat program dengan menggunakan record, file dan procedure

uses crt;
type produk = record
     kode  : string[4];
     jumlah: integer;
     end;
var fpro  : file of produk;
    rpro  : produk;
    lg    : char;
    i,j,pil     : integer;
    nama : string[30];
    harga,total : longint;
    totB : real;
    disc: real;
procedure openproduk;
begin
     assign(fpro,'c:\produk.dat');
     {$I-}reset(fpro);
     {$I+}if Ioresult<>0 then rewrite(fpro);
end;
procedure menu;
begin
     clrscr;
     gotoxy(10,5); write('menu utama');
     gotoxy(10,6); write('_______________________');
     gotoxy(10,7); write('1. input produk');
     gotoxy(10,8); write('2. output produk');
     gotoxy(10,9); write('3. keluar');
     gotoxy(10,10); write('______________________');
     gotoxy(10,11); write('pilihan :'); readln(pil);
     end;
procedure input;
begin
     clrscr;
     openproduk;
     repeat
           gotoxy(30,5); write('Input Data Produk');
           gotoxy(30,6); write('________________________________');
           gotoxy(30,7); write('kode      :'); readln(rpro.kode);
           gotoxy(30,8); write('jumlah    :'); readln(rpro.jumlah);
           gotoxy(30,9); write('________________________________');
           gotoxy(30,10); write('input lagi[Y/T] :'); readln(lg);
           seek(fpro,filesize(fpro)); write(fpro,rpro);
           clrscr;
           until upcase(lg)='T';
           end;
procedure output;
begin
     clrscr;
     i:=1;
     openproduk;
        gotoxy(3,1); write('Informasi penjualan produk');
        gotoxy(3,2); write('________________________________________________________________________________');
        gotoxy(3,3); write('no kode  nama         harga     jumlah   totalharga  discount    TotalBayar');
        gotoxy(3,4); write('________________________________________________________________________________');
        seek(fpro,0);
        while not eof(fpro) do
        begin
             seek(fpro,i-1); read(fpro,rpro);
             if rpro.kode='T010' then
             begin
                  nama :='DVD';
                  harga:=650000;
             end
             else if rpro.kode='T011' then
             begin
                  nama :='TV Sony';
                  harga:=1000000;
             end
             else if rpro.kode='T012' then
             begin
                  nama :='TV Polytron';
                  harga:=1200000;
             end;
             total:=rpro.jumlah*harga;
             begin
                  if total>=10000000 then  disc :=total*0.10
                  else  disc :=total*0;
             end;
                  totB :=total-disc;

             gotoxy(3,4+i); write(i:2,' ',rpro.kode,' ',nama);
             gotoxy(24,4+i); write('Rp.',harga:8,' ',rpro.jumlah:3);
             gotoxy(43,4+i); write('Rp.',total);
             gotoxy(56,4+i); write('Rp.',disc:2:0);
             gotoxy(68,4+i); write('Rp.',totB:2:0);
             inc(i);
             end;
             readln;
        end;
        begin
          pil:=0;
          while pil<>3 do
          begin
          menu;
          case pil of
               1 : input;
               2 : output;
          end;
          end;
           close (fpro);
     end.

Tidak ada komentar:

Posting Komentar