Data dengan Turbo Pascal
Diposting oleh
Kun Fa Yakun
di
21.05
PROGRAM MENU_FILE;
USES CRT;
TYPE MHS = RECORD
NAMA : ARRAY [1..30] OF STRING [15];
ALAMAT : ARRAY [1..30] OF STRING [15];
KELAS : ARRAY [1..30] OF STRING [5];
END;
VAR FILEMHS : FILE OF MHS;
RECORDMHS : ARRAY [1..50] OF MHS;
PIL : CHAR;
LABEL RETURN;
PROCEDURE INPUT_DATA;
VAR N,I : INTEGER;
BEGIN
CLRSCR;
ASSIGN(FILEMHS,'M_SISWA.DAT');
REWRITE(FILEMHS);
WRITE(' BANYAKNYA DATA : ');READLN(N);
FOR I := 1 TO N DO
BEGIN
WITH RECORDMHS[I] DO
BEGIN
WRITELN;
WRITELN(' DATA KE-',I);
WRITE(' NAMA MAHASISWA : ');READLN(NAMA[I]);
WRITE(' ALAMAT : ');READLN(ALAMAT[I]);
WRITE(' KELAS : ');READLN(KELAS[I]);
END;
WRITE(FILEMHS,RECORDMHS[I]);
END;
CLOSE(FILEMHS);
END;
PROCEDURE ADD_DATA;
VAR N,I,X : INTEGER;
BEGIN
CLRSCR;
ASSIGN(FILEMHS,'M_SISWA.DAT');
RESET(FILEMHS);
N := FILESIZE(FILEMHS);
IF IORESULT <> 0 THEN REWRITE(FILEMHS);
SEEK(FILEMHS,N);
WRITE(' BANYAKNYA DATA TAMBAHAN = ');READLN(X);
FOR I := 1 TO X DO
BEGIN
WRITELN;
WRITELN(' BANYAKNYA DATA = ',N);
N := N + 1;
WITH RECORDMHS[N] DO
BEGIN
WRITELN;
WRITELN(' DATA KE-',N);
WRITE(' NAMA MAHASISWA : ');READLN(NAMA[N]);
WRITE(' ALAMAT : ');READLN(ALAMAT[N]);
WRITE(' KELAS : ');READLN(KELAS[N]);
END;
WRITE(FILEMHS,RECORDMHS[N]);
END;
CLOSE(FILEMHS);
END;
PROCEDURE EDIT_DATA;
VAR FOUND : BOOLEAN;
MORE : CHAR;
NAME : STRING[15];
N,I : INTEGER;
BEGIN
CLRSCR;
ASSIGN(FILEMHS,'M_SISWA.DAT');
RESET(FILEMHS);
N := FILESIZE(FILEMHS);
MORE := 'Y';
WHILE UPCASE(MORE) = 'Y' DO
BEGIN
FOUND := FALSE;
WRITE(' NAMA MAHASISWA YANG MAU DI-EDIT DATANYA : ');READLN(NAME);
FOR I := 1 TO N DO
BEGIN
SEEK(FILEMHS,I-1);
READ(FILEMHS,RECORDMHS[I]);
IF RECORDMHS[I].NAMA[I] = NAME THEN
BEGIN
FOUND := TRUE;
WITH RECORDMHS[I] DO
BEGIN
WRITELN;
WRITELN(' DATA YANG AKAN DIKOREKSI');
WRITELN(' NAMA MAHASISWA : ',NAMA[I]);
WRITELN(' ALAMAT : ',ALAMAT[I]);
WRITELN(' KELAS : ',KELAS[I]);
WRITELN;
WRITELN(' DATA KOREKSI');
WRITE(' NAMA MAHASISWA : ');READLN(NAMA[I]);
WRITE(' ALAMAT : ');READLN(ALAMAT[I]);
WRITE(' KELAS : ');READLN(KELAS[I]);
WRITELN;
END;
END;
SEEK(FILEMHS,I-1);
WRITE(FILEMHS,RECORDMHS[I]);
END;
IF NOT FOUND THEN
WRITELN(CHAR(7),' DATA TIDAK ADA');
WRITE(' EDIT DATA LAGI (Y/T) ? ');READLN(MORE);
WRITELN;
END;
CLOSE(FILEMHS);
END;
PROCEDURE LINES;
VAR I : INTEGER;
BEGIN
FOR I := 1 TO 43 DO
WRITE('-');
END;
PROCEDURE VIEW_DATA;
VAR N,I : INTEGER;
BEGIN
CLRSCR;
ASSIGN(FILEMHS,'M_SISWA.DAT');
RESET(FILEMHS);
WHILE NOT EOF(FILEMHS) DO
BEGIN
N := FILESIZE(FILEMHS);
FOR I := 1 TO N DO
BEGIN
READ(FILEMHS,RECORDMHS[I]);
WITH RECORDMHS[I] DO
BEGIN
GOTOXY (35,2);WRITELN('DATA MAHASISWA');
GOTOXY (20,4);LINES;
GOTOXY (21,5);WRITELN('NO NAMA ALAMAT KELAS');
GOTOXY (20,6);LINES;
GOTOXY (21,6+I);WRITE(I:2);
GOTOXY (25,6+I);WRITE(NAMA[I]);
GOTOXY (41,6+I);WRITE(ALAMAT[I]);
GOTOXY (57,6+I);WRITELN(KELAS[I]);
END;
END;
GOTOXY (20,7+I);LINES;
END;
CLOSE(FILEMHS);
READLN;
END;
BEGIN
REPEAT
RETURN :
CLRSCR;
GOTOXY (28,3);WRITELN('<<< MENU FILE >>>');
GOTOXY (23,5);WRITELN('1. FILE BARU DAN INPUT DATA');
GOTOXY (23,6);WRITELN('2. TAMBAH DATA');
GOTOXY (23,7);WRITELN('3. KOREKSI DATA BERDASAR NAMA');
GOTOXY (23,8);WRITELN('4. TAMPILKAN DATA');
GOTOXY (23,9);WRITELN('5. SELESAI');
GOTOXY (23,11);WRITE('PILIHAN ANDA : ');READLN(PIL);
IF NOT (PIL IN ['1'..'5']) THEN
BEGIN
WRITELN(CHAR(7));
GOTOXY (23,13);WRITELN('PILIH YANG BENER DONG !!!');
READLN;
GOTO RETURN;
END;
CASE PIL OF
'1' : INPUT_DATA;
'2' : ADD_DATA;
'3' : EDIT_DATA;
'4' : VIEW_DATA;
END;
UNTIL PIL = '5';
END.
referensi :
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar