Sabtu, 29 Januari 2011

0

[Pascal] Membuat Dokumen Teks Dengan Pascal

  • Sabtu, 29 Januari 2011
  • Nurkholish Ardi Firdaus
  • Share
  • Kode sederhana ini berfungsi untuk membuat data teks,mengedit data teks,menghapus data teks dan melihat keseluruhan data teks yang sudah dimasukkan dalam program ini.









    Program Data_Mata_Kuliah;
    Uses Crt ;
    Const
    
    garis1 = '--------------------------------------------------------------------------------';
    garis2 = '===================================================================';
    garsed1= '--------------------------------------------------------------------';
    garsed2= '====================================================================';
    gar2 = '====================================';
    gar1 = '------------------------------------';
    gar3 = '==========================';
    
    Type
    cod = Record
    {type utk code}
    Kuliah : word;
    Matkul : String[20];
    Dino : string[20];
    Dos : string[20];
    Sks : string[20];
    Ruang : string[20];
    Mahasiswa : real ;
    Mercu : real ;
    {type utk Siswa}
    Nama : String[20];
    End;
    
    Var
    Filecod : File of cod;
    Data : cod;
    Pil,Ul : Char;
    x,y,i : integer;
    
    Procedure Menu;
    Begin
    Clrscr;
    Textcolor(10);
    Writeln('================================================================================');
    Textcolor(23);
    Writeln('#####################  SUGENG RAWUH INGKANG DATA MATA KULIAH  ##################');
    Textcolor(10);
    Writeln('================================================================================');
    Textcolor(white);
    Textcolor(5);
    x:=10; y:=6;
    Gotoxy(x,y);write('PILIH SALAH SIJI');
    Gotoxy(x,y+1);write('1. TAMBAH DATA');
    Gotoxy(x,y+2);Write('2. EDIT DATA');
    Gotoxy(x,y+3);Write('3. HAPUS DATA ');
    Gotoxy(x,y+4);Write('4. TAMPILAN DATA');
    { Gotoxy(x,y+5);Write('4. DAFTAR MAHASISWA');
    Gotoxy(x,y+6);Write('5. PENGAMBILAN MATKUL');}
    Gotoxy(x,y+5);Write('5. MEDAL');
    Gotoxy(10,y+7);Write('Pilih nomer 1 sampai 5>> ');Pil:=Readkey
    End;
    
    Procedure BukaFile;
    Begin
    Assign(Filecod,'cod.txt');
    {$I-};
    Reset(Filecod);
    {$I+};
    End;
    
    Procedure Tambah;
    Var
    Lagi: Char;
    Ada : Boolean;
    i : Integer;
    NOCR: Word;
    
    Begin
    Ul :='Y';
    Lagi:='Y';
    Clrscr;
    BukaFile;
    If IOResult<>0 Then
    Rewrite(Filecod);
    Repeat
    Clrscr;
    Textcolor(8);
    Ada:=False;
    i:=0;
    x:=45;y:=1;
    Gotoxy(x+4,y);Write('TAMBAH DATA MAHASISWA ');
    Gotoxy(x+0,y+1);Write('-----------------------------');
    Gotoxy(x,y+2);Write('Code           : ');Readln(NOCR);
    While (Ada=False) And (i<>Filesize(Filecod)) Do
    Begin
    Seek(Filecod,i);
    Read(Filecod,Data);
    If Data.Kuliah=NOCR Then
    Ada:=True
    Else
    Inc(i);
    End;
    If (Ada=True) Then
    Begin
    
    Gotoxy(x-5,y+7);Write('Code ",NOCR," Niki sampun wonten!');
    End
    Else
    Begin
    Seek(Filecod,Filesize(Filecod));
    Data.Kuliah:=NOCR;
    Gotoxy(X,y+3);Write('Mata kuliah    : ');Readln(Data.Matkul);
    Gotoxy(X,y+4);Write('Dino kuliah    : ');Readln(Data.Dino);
    Gotoxy(X,y+5);Write('Dosen          : ');Readln(Data.Dos);
    Gotoxy(X,y+6);Write('SKS            : ');Readln(Data.Sks);
    Gotoxy(x,y+7);Write('Ruang          : ');Readln(Data.Ruang);
    {Gotoxy(X,y+8);write('Telat Pengembalian code : ');Readln(data.mahasiswa);
    data.Stmik :=data.mahasiswa*500;}
    Write(Filecod,Data);
    End;
    Textcolor(23);
    Gotoxy(x-5,y+8);Write('Tambah data male nopo mboten..?? :: Y/T:: ');Lagi:=Upcase(Readkey);
    Until Lagi<>'Y';
    Close(Filecod);
    End;
    
    Procedure Edit;
    Var
    Lagi : Char;
    Ada : Boolean;
    i : Integer;
    NOCR: Word;
    
    Begin
    Ul :='Y';
    Lagi:='Y';
    Clrscr;
    Textcolor(21);
    BukaFile;
    If IOResult<>0 Then
    Write('Data isih Kosong...!')
    Else
    Begin
    Repeat
    Clrscr;
    Textcolor(21);
    Ada:=False;
    i:=0;
    x:=28;y:=2;
    Gotoxy(x+2,y);Write('------------------');
    Gotoxy(x+2,y+1);Write(' EDIT DATA KULIAH');
    Gotoxy(x+2,y+2);Write('------------------');
    Gotoxy(x+5,y+3);Write('Code : ');Readln(NOCR);
    While (Ada=False) And (i<>Filesize(Filecod)) Do
    Begin
    Seek(Filecod,i);
    Read(Filecod,Data);
    If Data.Kuliah=NOCR Then
    Begin
    Textcolor(10);
    Ada:=True;
    x:=5;y:=15;
    gotoxy(X,y+1);write('------------------------------------------------------------------------');
    gotoxy(X+0,y+2);write('DATA SING ONO                 <<==>>       DATA EDITAN');
    gotoxy(x+0,y+3);write('------------------------------------------------------------------------');
    Gotoxy(X,y+4);Write('Mata kuliah    : ');writeln(Data.matkul);
    Gotoxy(X,y+5);Write('Dino kuliah    : ');writeln(Data.dino);
    Gotoxy(X,y+6);Write('Dosen          : ');writeln(Data.dos);
    Gotoxy(X,y+7);Write('SKS            : ');writeln(Data.sks);
    Gotoxy(X,y+8);Write('Ruang          : ');writeln(data.Ruang);
    End
    Else
    Inc(i);
    End;
    If (Ada=True) Then
    Begin
    Textcolor(10);
    Data.Kuliah:=NOCR;
    x:=48;y:=15;
    Gotoxy(X,y+4);Write('Mata kuliah    : ');readln(Data.matkul);
    Gotoxy(X,y+5);Write('Dino kuliah    : ');readln(Data.dino);
    Gotoxy(X,y+6);Write('Dosen          : ');readln(Data.dos);
    Gotoxy(X,y+7);Write('SKS            : ');readln(Data.sks);
    Gotoxy(X,y+8);Write('Ruang          : ');readln(Data.Ruang);
    Seek(Filecod,i);
    Write(Filecod,Data);
    End
    Else
    Begin
    Textcolor(10);
    Gotoxy(20,12);Write('Code Mahasiswa "',NOCR,'" Niki mboten wonten..!!');
    End;
    Textcolor(10);
    Gotoxy(24,12);Write('Edit mane nopo mboten..?? >> Y/T <<  ');Lagi:=Upcase(Readkey);
    Until Lagi<>'Y';
    End;
    Close(Filecod);
    End;
    
    Procedure Hapus;
    Var
    FileTmp : File of cod;
    Lagi,Hapus : Char;
    Ada : Boolean;
    i : Integer;
    NOCR : Word;
    
    Begin
    Ul :='Y';
    Lagi:='Y';
    Clrscr;
    Repeat
    BukaFile;
    If IOResult<>0 Then
    Write('Data Isih Kosong...!')
    Else
    Begin
    Clrscr;
    Textcolor(7);
    Assign(FileTmp,'cod.tmp');
    Rewrite(FileTmp);
    Ada:=False;
    i:=0;
    x:=3;y:=16;
    Gotoxy(x+2,y);Write('HAPUS DATA MAHASISWA');
    Gotoxy(x+1,y+1);Write('----------------------');
    Gotoxy(x,y+2);Write('Code  : ');Readln(NOCR);
    While (Ada=False) And (i<>Filesize(Filecod)) Do
    Begin
    Seek(Filecod,i);
    Read(Filecod,Data);
    If Data.Kuliah=NOCR Then
    Ada:=True
    Else
    Inc(i);
    End;
    If (Ada=True) Then
    Begin
    Gotoxy(X,y+3);Write('Mata kuliah    : ');writeln(Data.matkul);
    Gotoxy(X,y+4);Write('Dino kuliah    : ');writeln(Data.dino);
    Gotoxy(X,y+5);Write('Dosen          : ');writeln(Data.dos);
    Gotoxy(X,y+6);Write('SKS            : ');writeln(Data.sks);
    Gotoxy(X,y+7);Write('Ruang          : ');writeln(Data.Ruang);
    Gotoxy(x-8,y+9);Write('Sampean arep hapus data niki..?? :: Y/T :: : ');Readln(Hapus);
    If Upcase(Hapus)='Y' Then
    Begin
    For i := 1 to Filesize(Filecod) Do
    Begin
    Seek(Filecod,i-1);
    Read(Filecod,Data);
    If Data.Kuliah<>NOCR Then
    Write(FileTmp,Data);
    End;
    Close(Filecod);
    Assign(Filecod,'cod.txt');
    Erase(Filecod);
    Assign(FileTmp,'cod.tmp');
    Rename(FileTmp,'cod.txt');
    Gotoxy(x-8,y+9);Write(' Code "',NOCR,'" Sampun dihapus...!! ');
    End;
    End
    Else
    Begin
    Gotoxy(x-4,y+9);Write('Code niki mobten wonten...!!');
    End;
    Gotoxy(x-3,y+10);Write('Hapus data liane...?? :: Y/T :: ');Lagi:=Upcase(Readkey);
    End;
    Until Lagi<>'Y';
    End;
    
    Function TotalDenda(TDN:Real;n:integer):Real;
    Begin
    Totaldenda:=TDN+0;
    End;
    
    Procedure Tampil;
    Var
    i,n : Integer;
    TDN : Real;
    
    Begin
    clrscr;
    Ul :='Y';
    TDN:=0;
    BukaFile;
    If IoResult <> 0 Then
    begin
    gotoxy(30,11);
    Write('Ngapunten Data Mboten Wonten !! ');
    end
    Else
    Begin
    Textcolor(9);
    Clrscr;
    x:=4;y:=9;
    textcolor(26);
    gotoxy(x+7,y-3); write(':::::::::::::::::::DATA MATA KULIAH:::::::::::::::::::');
    textcolor(white);
    gotoxy(x,y-2); write(garsed2);
    gotoxy(x,y-1); writeln('| CODE  | MATA KULIAH     | DINO KULIAH | DOSEN      | SKS | RUANG |');
    gotoxy(x,y); write(garsed1);
    i:=0;
    While Not EoF(Filecod) Do
    Begin
    Inc(i);
    Read(Filecod,Data);
    gotoxy(x,y+i); write('| ',i);
    gotoxy(x+3,y+i); write('| '); writeln(data.kuliah);
    gotoxy(x+8,y+i); write('| '); writeln(data.matkul);
    gotoxy(x+26,y+i); write('| '); writeln(data.dino);
    gotoxy(x+40,y+i); write('| '); writeln(data.dos);
    gotoxy(x+53,y+i); write('|  '); writeln(data.sks);
    gotoxy(x+59,y+i); write('| '); writeln(data.ruang);
    gotoxy(x+65,y+i); write('  |');
    TDN:=TDN+Data.mahasiswa;
    End;
    Close(Filecod);
    End;
    Writeln;
    Write('   ====================>> ENTER NGULANG TEKO AWAL <<===================');Readln;
    End;
    
    Procedure View_Denda;
    begin
    end;
    
    Procedure Hapus_KdBuku;
    begin
    end;
    
    Begin
    Repeat
    Menu;
    Case Pil Of
    '1' : Tambah;
    '2' : Edit;
    '3' : Hapus;
    '4' : Tampil;
    '5' : View_Stmik;
    '6' : Hapus_cod;}
    End;
    Until (Ul<>'Y') Or (Pil='5');
    
    End.
    
    
    Jangan Lupa Komentar Yaa..
    Related Posts Plugin for WordPress, Blogger...

    0 Komentar Untuk “[Pascal] Membuat Dokumen Teks Dengan Pascal”

    Posting Komentar

    Berikan komentar positif tentang artikel yang sederhana ini niscaya sobat akan mendapatkan balasannya. Hehehe

    Subscribe