Contoh program file pada pascal
Source Code :
uses crt;
var
pil
:char;
data
:text;
nama,nim,isi :string;
a :byte;
procedure menu1;
begin
assign(data,'D:\data.txt');
rewrite(data);
clrscr;
writeln('>>
Buat File');
writeln;
writeln('File berhasil dibuat di D:\data.txt');
readkey;
close(data);
end;
procedure menu2;
begin
assign(data,'D:\data.txt');
append(data);
clrscr;
writeln('>> Input Data');
writeln;
write
('Nama : ');readln(nama);
writeln(data,nama);
write ('NIM
: ');readln(nim);
writeln(data,nim);
close(data);
end;
procedure menu3;
begin
assign(data,'D:\data.txt');
reset(data);
clrscr;
writeln('>>
Lihat Data ');
writeln;
a:=1;
while
not eof(data) do
begin
readln(data,isi);
if a mod 2=1 then
writeln('Nama : ',isi) else
begin
writeln('NIM : ',isi);
writeln;
end;
inc(a);
end;
close(data);
readkey;
end;
procedure menu4;
begin
assign(data,'D:\data.txt');
erase(data);
clrscr;
writeln('>>
Hapus File');
writeln;
writeln('File
berhasil dihapus');
readkey;
end;
begin
repeat
clrscr;
writeln('Menu UTAMA');
writeln;
writeln('1.
Buat File');
writeln('2.
Input Data');
writeln('3.
Lihat Data');
writeln('4.
Hapus File');
writeln('0.
Keluar');
writeln;
write
('Pilihan : ');pil:=readkey;
case
pil of
'1':menu1;
'2':menu2;
'3':menu3;
'4':menu4;
end;
until pil='0';
end.
|
Output Program :
1. Menu Utama.
3. Input Data
4. Isi File.
6. Hapus File.
EmoticonEmoticon