Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman
MODUL PRAKTIKUM BAHASA PEMROGRAMAN (PASCAL)
SELAMAT MENCOBA Apapun yang anda Pikirkan ataupun apapun yang anda Kerjakan, Ubahlah kedalam bentuk Doa dan liat apa yang akan Terjadi By. Mario Teguh Ada 3 (tiga) tahapan sesorang dapat menguasai komputer dan menggunakan computer dengan baik dan berhasil; 1. Membaca Buku Komputer 2. Mencoba langsung pada suatu Komputer 3. Menulis suatu program komputer By. Jogiyanto
Halaman : 53
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman
Simpan file Praktikum dengan Mahasiswa) Contoh: 15001P1
NIM
(Nomor
Induk
{PRAKTIKUM I} PROGRAM PERTAMA; BEGIN WRITELN ('HALO ... Universitas Sulawsi Barat'); WRITE ('INI ADALAH '); WRITELN ('PROGRAM SAYA UJI COBA'); WRITE ('YANG PERTAMA'); WRITE ('DI LAB KOMPUTER'); READLN END. {PRAKTIKUM II} PROGRAM FORMAT_OUTPUT; USES CRT; CONST A=25; B:INTEGER=12; VAR C,D :REAL; E,F :INTEGER; BEGIN CLRSCR; WRITELN(A); WRITELN(B); READLN(C); WRITELN('C =',C); WRITELN('C =',C:4); WRITELN('C =',C:21:3); READLN(D); WRITELN('C + D =',C+D); WRITELN('C + D =',C+D:10:2); READLN(E,F); WRITELN('E =',E); WRITELN('F =',F:7); WRITELN('E * F =',E*F); WRITELN('E DIV F =',E DIV F); WRITELN('E MOD F =',E MOD F); WRITELN('E < F BERNILAI,',E
Halaman : 54
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman {PRAKTIKUM III} PROGRAM HITUNG_GAJI; USES CRT; CONST GAJI_PER_JAM = 5000; LEMBUR_PER_JAM = 10000; VAR NIP : STRING[6]; NAMA : STRING; JA : BYTE; JJK : INTEGER; JJL : INTEGER; GAJI,UANG_LEMBUR,GAJI_BERSIH :LONGINT; BEGIN CLRSCR; {CETAK JUDUL} GOTOXY(10,2) WRITE(' MENGHITUNG GAJI'); GOTOXY(10,3); WRITE('-------------------------------'); {MEMASUKKAN DATA-DATA PEGAWAI} GOTOXY(10,4) WRITE('NIP :'); READLN(NIP); GOTOXY(10,5); WRITE('NAMA PEGAWAI :'); READLN(NAMA); GOTOXY(10,6); WRITE('JUMLAH ANAK :'); READLN(JA); GOTOXY(10,7); WRITE('JUMLAH JAM KERJA :'); READLN(JJK); GOTOXY(10,8); WRITE('JUMLAH JAM LEMBUR :'); READLN(JJL); {MENGHITUNG GAJI PEGAWAI} GAJI :=JJK * GAJI_PER_JAM UANG_LEMBUR :=JJL * LEMBUR_PER_JAM; GAJI_BERSIH =GAJI + UANG_LEMBUR; {MENCETAK HASIL PERHITUNGAN} GOTOXY(10,9); WRITE('UANG LEMBUR :',UANG_LEMBUR); GOTOXY(10,10); WRITE('GAJI BERSIH :', _BERSIH); GOTOXY(10,11); WRITE('---------------------------------'); READLN; END.
Halaman : 55
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman {PRAKTIKUM IV} PROGRAM HITUNG_GAJI; USES CRT; CONST GAJI_PER_JAM=5000; LEMBUR_PER_JAM=6000; VAR NIP : STRING[6]; NAMA : STRING; GAPOK : LONGINT; JK,STATUS : CHAR; JA : BYTE; GPK,TUNJ_ANAK,TUNJ_KLRG,GAJI_BERSIH : LONGINT; BEGIN CLRSCR; {CETAK JUDUL} GOTOXY(10,2); WRITE(' MENGHITUNG GAJI'); GOTOXY(10,3); WRITE('----------------------------------'); {MEMASUKKAN DATA-DATA PEGAWAI} GOTOXY(10,4); WRITE('NIP :');READLN(NIP); GOTOXY(10,5); WRITE('NAMA PEGAWAI :');READLN(NAMA); GOTOXY(10,6); WRITE('STATUS [B/K] :');READLN(STATUS); GOTOXY(10,7); IF (STATUS = 'B')OR(STATUS = 'B')THEN WRITE('JUMLAH ANAK :0') ELSE BEGIN WRITE('JUMLAH ANAK :');READLN(JA); END; GOTOXY(10,8); WRITE('JENIS KELAMIN [L/P] :');READLN(K); GOTOXY(10,9); WRITE('GAJI POKOK :');READLN(GAPO); {MENGHITUNG GAJI PEGAWAI} IF(STATUS ='K')AND(JA>0)THEN BEGIN IF JA>10 THEN TUNJ_ANAK := 10000*3 ELSE TUNJ_ANAK := 10000*JA; END; IF STATUS ='K' THEN BEGIN TUNJ_KLRG := 30000; END; GAJI BERSIH := GAPOK+TUNJ_ANAK+TUNJ_KLRG; {MENCETAK HASIL PROSES} GOTOXY(10,10); WRITE('TUNJANGAN ANAK :',TUNJ_ANAK:12); GOTOXY(10,11); WRITE('TUNJANGAN KELUARGA :',TUNJ_KLRG:12); GOTOXY(10,12); WRITE('GAJI BERSIH :',GAJI_BERSIH:12); GOTOXY(10,13); WRITE('-----------------------------------'); READLN; END.
Halaman : 56
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman {PRAKTIKUM V} PROGRAM JML_BIL; USES CRT; CONST BATAS_AWAL=0; BATAS_AKHIR=20; VAR I,JML:INTEGER; BEGIN CLRSCR; {CETAK JUDUL} WRITELN('JUMLAH BILANGAN BULAT 0-20'); WRITELN('--------------------------'); I:=BATAS AWAL; JML:=0 WHILE I<=BATAS_AKHIR DO BEGIN WRITELN(I); JML:= JML+1; I:= I+1 END; WRITELN('JUMLAH BILANGAN BULAT DARI ',BATAS_AWAL,' SAMPAI ',BATAS_AKHIR , 'ADALAH = ',JML); READKEY; END. {PRAKTIKUM VI} PROGRAM KONVERSI_SUHU; USES CRT; VAR SUHU_AWAL,SUHU_AKHIR,KENAIKAN : INTEGER; CELCIUS,FAHRENHEIT,REAMOUR : REAL; BEGIN CLRSCR; {INPUT DATA }; WRITE(‘SUHU AWAL = ‘); READLN(SUHU_AWAL); WRITE(‘SUHU AKHIR = ‘); READLN(SUHU_AKHIR); WRITE(‘KENAIKAN SUHU = ‘); READLN(KENAIKAN); { CETAK TOP TABEL } WRITELN(‘----------------------------------------------‘); WRITELN(‘ CELCIUS FAHRENHEIT REAMOUR ‘); WRITELN(‘----------------------------------------------‘); CELCIUS:=SUHU_AWAL; WHILE CELCIUS<=SUHU_AKHIR DO BEGIN FAHRENHEIT := 9/5 * CELSCIUS + 32; REAMOUR := 4/5 * CELCIUS; CELCIUS := CELCIUS + KENAIKAN; END; WRITELN(‘--------------------------------------------‘); READLN; END. Halaman : 57
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman {PRAKTIKUM VII} PROGRAM JUMLAH_MATRIKS; USES CRT; CONST MAX=10; TYPE DIM=ARRAY[1..MAX,1..MAX] OF REAL; VAR A,B,C:DIM; I,J,M,N:INTEGER; EROR:BOOLEAN; PILIH:CHAR; BEGIN CLRSCR; REPEAT TEXTCOLOR(9);WRITE('BERAPA DIMENSI MATRIKS A:');READLN(N); TEXTCOLOR(10);WRITE('BERAPA DIMENSI MATRIKS B:');READLN(M); UNTIL M=N; IF N>=1 THEN BEGIN FOR I:=1 TO N DO BEGIN FOR J:=1 TO N DO BEGIN WRITE('A(',I:1,',',J:1,')=');READLN(A[I,J]); END; END; WRITELN; IF M>=1 THEN BEGIN FOR I:=1 TO M DO BEGIN FOR J:=1 TO M DO BEGIN WRITE('B(',I:1,',',J:1,')=');READLN(B[I,J]); END; END; END; WRITELN; REPEAT WRITELN('J:JUMLAHKAN K:KURANGKAN'); WRITE('PILIHAN ANDA(J/K)?');READLN(PILIH); UNTIL(UPCASE(PILIH)='J')OR (UPCASE(PILIH)='K'); CASE PILIH OF 'J','J':BEGIN FOR I:=1 TO N DO BEGIN FOR J:=1 TO N DO BEGIN C[I,J]:=A[I,J]+B[I,J]; END; END; END; 'K','K':BEGIN Halaman : 58
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman FOR I:=1 TO N DO BEGIN FOR J:=1 TO N DO BEGIN C[I,J]:=A[I,J]-B[I,J]; END; END; END; END; CLRSCR; WRITELN('MATRIKS A'); FOR I:=1 TO N DO BEGIN FOR J:=1 TO N DO BEGIN WRITE(A[I,J]:10:2); END; WRITELN; END; WRITELN; WRITELN('MATRIKS B'); FOR I:=1 TO N DO BEGIN FOR J:=1 TO N DO BEGIN WRITE(B[I,J]:10:2); END; WRITELN; END; WRITELN; TEXTCOLOR(14);WRITELN('MATRIKS HASIL'); FOR I:=1 TO N DO BEGIN FOR J:=1 TO N DO BEGIN WRITE(C[I,J]:10:2); END; WRITELN; END; END; WHILE NOT KEYPRESSED DO BEGIN GOTOXY(20,25); TEXTCOLOR(13+128);WRITE('TEKAN APA SAJA'); END; END. {PRAKTIKUM VIII} PROGRAM TANYASISWA; USES CRT; VAR NAMA:ARRAY[1..25] OF STRING[25]; NILAI:ARRAY[1..25] OF REAL; Halaman : 59
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman SEM:ARRAY[1..25] OF INTEGER; NOSTB:ARRAY[1..25] OF LONGINT; JUMLAHNILAI,RATA:REAL; I,BANYAKSISWA:BYTE; BEGIN CLRSCR; {BAGIAN MEMBACA DATA} I:=1; WRITE('NAMA SISWA(ISI"X"JIKA SELESAI):'); READLN(NAMA[I]); WRITE('NO STAMBUK(ISI"1"JIKA SELESAI):'); READLN(NOSTB[I]); WRITE('SEMESTER(ISI"1"JIKA SELESAI):'); READLN(SEM[I]); WRITE('NILAI UJIAN(ISI"1"JIKA SUDAH SELESAI): '); READLN(NILAI[I]); WHILE NAMA[I]<>'X'DO BEGIN INC(I) WRITE('NAMA SISWA(ISI"X"JIKA SELESAI):'); READLN(NAMA[I]); WRITE('NO STAMBUK(ISI"1"JIKA SELESAI):); READLN(NOSTB[I]); WRITE('SEMESTER(ISI"1"JIKA SELESAI):') READLN(SEM[I]); WRITE('NILAI UJIAN(ISI"1"JIKA SUDAH SELESAI): '); READLN(NILAI[I]) END; BANYAKSISWA:I-1; JUMLAHNILAI:=0; FOR I:=1 TO BANYAKSISWA DO JUMLAHNILAI:=JUMLAHNILAI+NILAI[I]; RATA:=JUMLAHNILAI/BANYAKSISWA; {CETAK JUDUL} CLRSCR; WRITELN(' DAFTAR NILAI UJIAN PASCAL'); WRITELN('=================================================='); WRITELN(' NAMA SISWA NO.STAMBUK SEMESTER NILAI UJIAN'); WRITELN('=================================================='); FOR I:=1 TO BANYAKSISWA DO WRITELN(NAMA[I]:5,NOSTB[I]:13,SEM[I]:14,NILAI[I]:16:2); WRITELN; WRITELN('================================================='); WRITELN('NILAI RATA_RATA :',RATA:20:2); READLN; END.
Halaman : 60
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman {PRAKTIKUM IX} PROGRAM TANYA_HITUNG; USES CRT; VAR X,Y,Z:REAL; PROCEDURE HITUNG; BEGIN CLRSCR; WRITE('NILAI X:'); READLN(X); WRITE('NILAI Y:'); READLN(Y); Z:=X+Y; WRITELN('NILAI Z:',Z:5:2); END; BEGIN{PROGRAM UTAMA} HITUNG; READKEY; END. {PRAKTIKUM IXA} PROGRAM TANYA_HITUNG; USES CRT; VAR X,Y,Z:REAL; PROCEDURE HITUNG; BEGIN CLRSCR; WRITE('NILAI A:'); READLN(B); WRITE('NILAI A:'); READLN(A); Z:=A+A; WRITELN('NILAI Z:',B:5:2); END; BEGIN{PROGRAM UTAMA} HITUNG; READKEY; END. {PRAKTIKUM X} PROGRAM TANYAMHS; USES CRT; VAR NAMA:ARRAY[1..25] OF STRING[25]; NILAI:ARRAY[1..25] OF REAL; JUMLAHNILAI,RATA:REAL; I,BANYAKMHS:BYTE;
PROCEDURE BACADATA; BEGIN CLRSCR; {BAGIAN MEMBACA DATA} Halaman : 61
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman I:=1; WRITE('NAMA MHS(ISI"X" JIKA SELESAI):'); READLN(NAMA[I]); WHILE NAMA[I]<>'X' DO BEGIN WRITE('NILAI UJIAN :');READLN(NILAI[I]); INC(I); WRITE('NAMA MHS(ISI "X" JIKA SELESAI):'); READLN(NAMA[I]); END; BANYAKMHS:=I-1; END; PROCEDURE HITUNGRATA; BEGIN JUMLAHNILAI:=0; FOR I := 1 TO BANYAKMHS DO JUMLAHNILAI:=JUMLAHNILAI+NILAI[I]; RATA:=JUMLAHNILAI/BANYAKMHS; END; PROCEDURE CETAK; BEGIN {CETAK JUDUL} CLRSCR; TEXTCOLOR(13+128);WRITELN('DAFTAR NILAI UJIAN PASCAL'); TEXTCOLOR(11);WRITELN('==================================='); TEXTCOLOR(9+128);WRITELN(' NAMA NILAI UJIAN'); TEXTCOLOR(2);WRITELN('===================================='); TEXTCOLOR(15); FOR I:=1 TO BANYAKMHS DO WRITELN(NAMA[I]:10,NILAI[I]:20:2); WRITELN; TEXTCOLOR(14);WRITELN('==================================='); TEXTCOLOR(4+128);WRITELN('NILAI RATA-RATA :',RATA:6:2); READLN; END; BEGIN {PROGRAM UTAMA} BACADATA; HITUNGRATA; CETAK; READKEY; END.
{PRAKTIKUM XI} PROGRAM HITUNG_LUAS_LINGKARAN; TYPE HASIL=RECORD JARIJARI:REAL; KELILING:REAL; LUAS:REAL; END; Halaman : 62
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman VAR LINGKARAN:HASIL; BEGIN WITH LINGKARAN DO BEGIN WRITE('JARI-JARI LINGKARAN?');READLN(JARIJARI); KELILING:=2*3.14*JARIJARI; LUAS:=3.14*SQR(JARIJARI); WRITELN; WRITELN('KELILING LINGKARAN =',KELILING:7:2); WRITELN('LUAS LINGKARAN =',LUAS:7:2); END; END. {PRAKTIKUM XII} PROGRAM TANYASISWA; USES CRT; TYPE REC_NILAI = RECORD; NAMA : ARRAY[1..25] OF STRING[25]; NILAI : ARRAY[1..25] OF REAL; END; VAR DATA_NILAI : REC_NILAI; JUMLAHNILAI,RATA:REAL; I,BANYAKSISWA:BYTE; PROCEDURE BACADATA; BEGIN CLRSCR; {BAGIAN MEMBACA DATA} I:=1; WRITE('NAMA SISWA(ISI"X" JIKA SELESAI):'); READLN(NAMA[I]); WHILE NAMA[I]<>'X' DO BEGIN WRITE('NILAI UJIAN :');READLN(NILAI[I]); INC(I); WRITE('NAMA SISWA(ISI "X" JIKA SELESAI):'); READLN(DATANILAI.NAMA[I]); END; BANYAKSISWA:=I-1; END; PROCEDURE HITUNGRATA; BEGIN JUMLAHNILAI:=0; FOR I := 1 TO BANYAKSISWA DO JUMLAHNILAI:=JUMLAHNILAI + DATANILAI.NILAI[I]; RATA:=JUMLAHNILAI/BANYAKSISWA; END; PROCEDURE CETAK; BEGIN Halaman : 63
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman {CETAK JUDUL} CLRSCR; TEXTCOLOR(13+128);WRITELN(' DAFTAR NILAI UJIAN PASCAL'); TEXTCOLOR(11);WRITELN('==================================='); TEXTCOLOR(9+128);WRITELN('NAMA SISWA NILAI UJIAN'); TEXTCOLOR(2);WRITELN('===================================='); TEXTCOLOR(15); FOR I:=1 TO BANYAKSISWA DO WITH DATANILAI DO BEGIN WRITELN(NAMA[I]:10,NILAI[I]:10:2); END; WRITELN; TEXTCOLOR(14);WRITELN('==================================='); TEXTCOLOR(4+128);WRITELN('NILAI RATA-RATA :',RATA:6:2); READLN; END; BEGIN {PROGRAM UTAMA} BACADATA; HITUNGRATA; CETAK; READKEY; END. {PRAKTIKUM XIII} PROGRAM ISI_BERKAS; USES CRT; CONST JUMLAH_MK = 5; TYPE B_NILAI = 1..100; NILAI = RECORD NAMA_MHS : STRING[25]; NO_MHS : STRING[5]; ANGKATAN : STRING[5]; NILAI UJIAN : ARRAY[1..JUMLAH_MK] OF B_NILAI; NILAI_RATA: REAL; END; D_NILAI = FILE OF NILAI; VAR DAF_NILAI : D_NILAI; NILAI : NILAI; I,J : INTEGER; LAGI : CHAR; BEGIN ASSIGN(DAF_NILAI,’NILAI.DAT’); REWRITE(DAF_NILAI); I:=0; REPEAT INC(I); CLRSCR; WRITELN(‘MENGISI DATA PADA BERKAS “NILAI.DAT” ‘); Halaman : 64
Universitas Sulawesi Barat Fakultas Teknik Program Studi Teknik Informatika Dosen Pengasuh Matakuliah Bahsa Pemrograman WRITELN(‘--------------------------------------------‘); WRITELN; WRITELN(‘MENGISI REKAMAN KE : ‘,I:2); WRTELN(‘----------------------------------------------‘); WRITELN; WITH NILAI_MHS DO BEGIN NILAI_RATA := 0,0; WRITE(‘NAMA MAHASISWA :’); READLN(NAMA_MHS); WRITE(‘NOMOR MASASISWA :’); READLN(NO_MHS); WRITE(‘ANGKATAN :’); READLN(ANGKATAN); FOR J:=1 TO JUMLAH_MK DO BEGIN WRITE(‘NILAI MK’,J,’ :’); READLN(NILAI_UJIAN[I]); NILAI_RATA := NILAI_RATA + NILAI_UJIAN[I]; END; NILAI_RATA := NILAI_RATA / JUMLAH_MK; END; WRITELN(DAF_NILAI,NILAI_MHS); GOTOXY(1,20); WRITE(‘AKAN MENGISI LAGI ? YA / TIDAK ?’); READLN(LAGI); UNTIL NOT(LAGI INI [‘Y’,’y’]); CLOSE(DAF_NILAI); END.
Halaman : 65