Operasi File

Berikut merupakan contoh program yang menggunakan operasi file pada bahasa pascal



dan berikut ini merupakan source code dari program di atas

Program filee;
Uses Crt;

Var
    data : Text;
    nama,nim : String;
    no,shift,pilih,i : byte;
    jawab : Char;

Begin
Repeat
ClrScr;
        Writeln('  Program File Text Sederhana');
        Writeln;
        Writeln('       1. Masukkan Data');
        Writeln('       2. Lihat Data');
        Writeln('       3. Hapus Data');
        Writeln('       4. Keluar');
        Writeln('    ------------------------');
        Write('      Pilihan Anda : ');Readln(pilih);

        Case Pilih of
        1 : Begin
                clrscr;
                Assign(data,'praktikum.txt');
                rewrite(data);
                Repeat
                inc(i);
                writeln(' Data - ',i);                                            writeln(' -------------------------------------');
                write(' Nama     : '); readln(nama); writeln(data,nama);
                write(' NIM      : '); readln(nim);  writeln(data,nim);
                write(' Shift    : '); readln(shift);writeln(data,shift);
                write(' No. Meja : '); readln(no);   writeln(data,no);
                writeln(data,' ');
                Write(' Memasukan Lagi (Y/T) : '); readln(jawab);
                writeln(' -------------------------------------');
                writeln;

                Until UpCase(jawab) = 'T';
                Close(data);
             End;

        2 : Begin
                clrscr;
                Assign(data,'praktikum.txt');
                reset(data);
                i:= 0;
                   while not eof(data) do
                   begin
                   inc(i);
                        readln(data,nama);  readln(data,nim);
                        readln(data,shift); readln(data,no);
                        readln(data);
                        writeln(' Data - ',i);
                        writeln(' -------------------------------------');
                        writeln(' Nama     : ',nama);
                        writeln(' NIM      : ',nim);
                        writeln(' Shift    : ',shift);
                        writeln(' No. Meja : ',no);
                        writeln(' -------------------------------------');
                        writeln;
                   end; readln;
             End;

        3 : Begin
                clrscr;
                write(' Data akan dihapus [Y/T] : '); readln(jawab);
                if upcase (jawab) = 'Y' then
                Assign(data,'praktikum.txt');
                Erase(data);
            End;

       else End;
until pilih=4;
End.

Operasi File Operasi File Reviewed by Ardiansyahsw on 09.16 Rating: 5

Tidak ada komentar:

Events

Diberdayakan oleh Blogger.