Program Perulangan Turbo Pascal

29 Jan 20130 komentar

Pelajaran Turbo Pascal hari ini dikampus, bingung mau menamai apa nih program. Karena didalamnya banyak bentuk-bentuk program seperti bintang, belah ketupat, X, segitiga, dan lain-lain
Dari pada galau, mending kasih nama Program Perulangan Turbo Pascal saja :D
Referensi buat teman-temanku 1SIA6
Berikut source code nya

USES CRT,GRAPH;
VAR
 A,B : INTEGER;
 PIL : BYTE;

CONST
 JDL1 : STRING = 'WELCOME TO MY PROGRAMS';
 JDL2 : STRING = 'PILIH SALAH SATU MENU BERIKUT INI';
 GARIS : STRING = '_________________________________';

PROCEDURE KETUPAT;
BEGIN
 CLRSCR;
 FOR A := 9 DOWNTO 1 DO
 BEGIN
  FOR B := 1 TO 9 DO
  BEGIN
   IF ((A >= 5) AND (B >= A - 4) AND (B <= 10 - (A - 4))) OR
      ((A < 5) AND (B <= A + 4) AND (B >= 10 - (A + 4))) THEN
    WRITE('*')
   ELSE WRITE(' ');
  END;
  WRITELN;
 END;
 REPEAT UNTIL KEYPRESSED;
END;

PROCEDURE HURUF_X;
BEGIN
 CLRSCR;
 FOR A := 1 TO 10 DO
 BEGIN
  FOR B := 1 TO 10 DO
  BEGIN
   IF (B = A) OR (B = 11 - A) THEN WRITE('*')
   ELSE WRITE(' ');
  END;
  WRITELN;
 END;
 REPEAT UNTIL KEYPRESSED;
END;

PROCEDURE KANANBAWAH;
BEGIN
 CLRSCR;
 FOR A := 10 DOWNTO 1 DO
 BEGIN
  FOR B := 1 TO 10 DO
  BEGIN
   IF B >= A THEN WRITE('*')
   ELSE WRITE(' ');
  END;
  WRITELN;
 END;
 REPEAT UNTIL KEYPRESSED;
END;

PROCEDURE KIRIBAWAH;
BEGIN
 CLRSCR;
 FOR A := 1 TO 10 DO
 BEGIN
  FOR B := 1 TO A DO WRITE('*');
  WRITELN;
 END;
 REPEAT UNTIL KEYPRESSED;
END;
{PROGRAM UTAMA}
BEGIN
 TEXTCOLOR(YELLOW);
 TEXTBACKGROUND(2);
 REPEAT
  PIL := 0;
  CLRSCR;
  GOTOXY((80 - LENGTH(JDL1)) DIV 2,02); WRITE(JDL1);
  GOTOXY((80 - LENGTH(JDL2)) DIV 2,03); WRITE(JDL2);
  GOTOXY((80 - LENGTH(GARIS)) DIV 2,04); WRITE(GARIS);
  GOTOXY(20,07); WRITE('[1]. SUSUNAN BINTANG SUDUT KIRI BAWAH');
  GOTOXY(20,08); WRITE('[2]. SUSUNAN BINTANG SUDUT KANAN BAWAH');
  GOTOXY(20,09); WRITE('[3]. SUSUNAN BINTANG BERBENTUK KETUPAT');
  GOTOXY(20,10); WRITE('[4]. SUSUNAN BINTANG BERBENTUK HURUF X');
  GOTOXY(20,11); WRITE('[5]. KELUAR DARI PROGRAM');
  GOTOXY(20,12); WRITE('PILIHAN [1..5]                     : ');
  GOTOXY(57,12); READ(PIL);
  CASE PIL OF
   1 : KIRIBAWAH;
   2 : KANANBAWAH;
   3 : KETUPAT;
   4 : HURUF_X;
   5 :
  ELSE
   CLRSCR;
   GOTOXY(20,12); WRITE('NOMOR YANG ANDA MASUKKAN SALAH...!');
   REPEAT UNTIL KEYPRESSED;
  END;
 UNTIL PIL = 5;
END.
Jika program dijalankan, hasilnya seperti ini
Masukkan angka 1 – 5. Pilih salah satu, dan lihat hasilnya ;)
Bagikan Artikel :

Artikel yang terkait

Posting Komentar

 
Copyright © 2012 - 2013. Doza 's Blog - All Rights Reserved
Template Created by Creating Website