Dalam postingan saya sebelumnya saya membahas tentang Membuat Bangun Datar di bahasa pemrograman pascal. Begitu pun dengan postingan kali ini saya akan membahas hal yang masih ada kaitannya dengan postingan sebelumnya, yaitu saya hanya akan menampilkan source code penulisan di bahasa pascal.
Langsung saja ke pokok pembahasan. Tampilan contoh program tersebut sudah saya tampilkan di postingan saya sebelumnya, dan berikut adalah source code-nya.
Program Bangun_bintang;
Uses Crt;
Var
i,j,k,a : integer;
status : boolean;
x : integer;
Begin
repeat
clrscr;
textcolor(7);
textbackground(blue);
clrscr;
window(2,1,79,3);
textbackground(14);
clrscr;
gotoxy(23,2);
write('=== MEMBUAT BANGUN DATAR ===');
begin
window(2,4,33,4);
textbackground(3);
clrscr;
gotoxy(14,1);
write('MENU');
window(2,5,33,24);
textbackground(green);
clrscr;
gotoxy(2,2);writeln('1. Segitiga Siku Kiri - Atas');
gotoxy(2,3);writeln('2. Segitiga Siku Kiri - Bawah');
gotoxy(2,4);writeln('3. Segitiga Siku Kanan - Atas');
gotoxy(2,5);writeln('4. Segitiga Siku Kanan - Bawah');
gotoxy(2,6);writeln('5. Segitiga Tumpul - Kanan');
gotoxy(2,7);writeln('6. Segitiga Tumpul - Kiri');
gotoxy(2,8);writeln('7. Segitiga Sama Sisi - Atas');
gotoxy(2,9);writeln('8. Segitiga Sama Sisi - Bawah');
gotoxy(2,10);writeln('9. Jajargenjang');
gotoxy(2,11);writeln('0. Keluar');
gotoxy(2,13);writeln('Pilihan Anda : ');
end;
begin
window(34,4,53,4);
textbackground(green);
clrscr;
gotoxy(8,1);
write('PROSES');
window(34,5,53,24);
textbackground(3);
clrscr;
end;
begin
window(54,4,79,4);
textbackground(3);
clrscr;
gotoxy(11,1);
write('OUTPUT');
window(54,5,79,24);
textbackground(green);
clrscr;
end;
begin
window(18,17,33,24);
textbackground(green);
clrscr;
gotoxy(2,1);read(x);
case x of
1:begin
window(34,5,52,24);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 20');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 20) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := 1 to i do
write('');
end;
end;
status := false;
end;
2:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 20');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 20) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := i to a do
write('*');
end;
end;
status := false;
end;
3:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 20');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 20) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := i to a do
begin
textbackground(green);
write(' ');
end;
for k := 1 to i do
begin
textbackground(green);
write('');
end;
end;
end;
status := false;
end;
4:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 20');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 20) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := 1 to i do
begin
textbackground(green);
write(' ');
end;
for k := i to a do
begin
textbackground(green);
write('');
end;
end;
end;
status := false;
end;
5:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 10');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 10) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := 1 to i do
write('');
end;
for i := 1 to a do
begin
writeln;
for j := i to a-1 do
write('');
end;
end;
status := false;
end;
6:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 10');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 10) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := i to a do
begin
textbackground(green);
write(' ');
end;
for k := 1 to i do
begin
textbackground(green);
write('');
end;
end;
for i := 1 to a do
begin
writeln;
for j := 1 to i do
begin
textbackground(green);
write(' ');
end;
write(' ');
for k := i to a-1 do
begin
textbackground(green);
write('');
end;
end;
end;
status := false;
end;
7:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 11');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 11) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := i to a do
begin
textbackground(green);
write(' ');
end;
for k := 1 to i do
begin
textbackground(green);
write(' ');
end;
end;
end;
status := false;
end;
8:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 11');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 11) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := 1 to i do
begin
textbackground(green);
write(' ');
end;
write(' ');
for k := i to a do
begin
textbackground(green);
write(' ');
end;
end;
end;
status := false;
end;
9:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 10');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 10) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := i to a do
begin
textbackground(green);
write(' ');
end;
for k := 1 to i do
begin
textbackground(green);
write(' ');
end;
end;
for i := 1 to a do
begin
writeln;
for k := 1 to i do
begin
write(' ');
end;
for j := i to a-1 do
begin
write(' ');
end;
end;
end;
status := false;
end;
0:exit;
else
begin
window(54,5,79,10);
textbackground(Green);
clrscr;
gotoxy(2,2);
writeln('Pilihan Tidak Ada');
status := false;
readln;
end;
end;
end;
readln;
until status;
end.
Langsung saja ke pokok pembahasan. Tampilan contoh program tersebut sudah saya tampilkan di postingan saya sebelumnya, dan berikut adalah source code-nya.
Program Bangun_bintang;
Uses Crt;
Var
i,j,k,a : integer;
status : boolean;
x : integer;
Begin
repeat
clrscr;
textcolor(7);
textbackground(blue);
clrscr;
window(2,1,79,3);
textbackground(14);
clrscr;
gotoxy(23,2);
write('=== MEMBUAT BANGUN DATAR ===');
begin
window(2,4,33,4);
textbackground(3);
clrscr;
gotoxy(14,1);
write('MENU');
window(2,5,33,24);
textbackground(green);
clrscr;
gotoxy(2,2);writeln('1. Segitiga Siku Kiri - Atas');
gotoxy(2,3);writeln('2. Segitiga Siku Kiri - Bawah');
gotoxy(2,4);writeln('3. Segitiga Siku Kanan - Atas');
gotoxy(2,5);writeln('4. Segitiga Siku Kanan - Bawah');
gotoxy(2,6);writeln('5. Segitiga Tumpul - Kanan');
gotoxy(2,7);writeln('6. Segitiga Tumpul - Kiri');
gotoxy(2,8);writeln('7. Segitiga Sama Sisi - Atas');
gotoxy(2,9);writeln('8. Segitiga Sama Sisi - Bawah');
gotoxy(2,10);writeln('9. Jajargenjang');
gotoxy(2,11);writeln('0. Keluar');
gotoxy(2,13);writeln('Pilihan Anda : ');
end;
begin
window(34,4,53,4);
textbackground(green);
clrscr;
gotoxy(8,1);
write('PROSES');
window(34,5,53,24);
textbackground(3);
clrscr;
end;
begin
window(54,4,79,4);
textbackground(3);
clrscr;
gotoxy(11,1);
write('OUTPUT');
window(54,5,79,24);
textbackground(green);
clrscr;
end;
begin
window(18,17,33,24);
textbackground(green);
clrscr;
gotoxy(2,1);read(x);
case x of
1:begin
window(34,5,52,24);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 20');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 20) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := 1 to i do
write('');
end;
end;
status := false;
end;
2:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 20');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 20) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := i to a do
write('*');
end;
end;
status := false;
end;
3:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 20');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 20) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := i to a do
begin
textbackground(green);
write(' ');
end;
for k := 1 to i do
begin
textbackground(green);
write('');
end;
end;
end;
status := false;
end;
4:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 20');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 20) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := 1 to i do
begin
textbackground(green);
write(' ');
end;
for k := i to a do
begin
textbackground(green);
write('');
end;
end;
end;
status := false;
end;
5:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 10');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 10) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := 1 to i do
write('');
end;
for i := 1 to a do
begin
writeln;
for j := i to a-1 do
write('');
end;
end;
status := false;
end;
6:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 10');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 10) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := i to a do
begin
textbackground(green);
write(' ');
end;
for k := 1 to i do
begin
textbackground(green);
write('');
end;
end;
for i := 1 to a do
begin
writeln;
for j := 1 to i do
begin
textbackground(green);
write(' ');
end;
write(' ');
for k := i to a-1 do
begin
textbackground(green);
write('');
end;
end;
end;
status := false;
end;
7:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 11');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 11) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := i to a do
begin
textbackground(green);
write(' ');
end;
for k := 1 to i do
begin
textbackground(green);
write(' ');
end;
end;
end;
status := false;
end;
8:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 11');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 11) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := 1 to i do
begin
textbackground(green);
write(' ');
end;
write(' ');
for k := i to a do
begin
textbackground(green);
write(' ');
end;
end;
end;
status := false;
end;
9:begin
window(34,5,52,10);
textbackground(cyan);
clrscr;
gotoxy(2,2);write('Maks Alas = 10');
gotoxy(2,4);write('Alas : ');readln(a);
window(55,5,79,24);
textbackground(green);
clrscr;
if (a < 1) or (a > 10) then
begin
gotoxy(2,2);write('Panjang Alas Salah');
end
else
begin
for i := 1 to a do
begin
writeln;
for j := i to a do
begin
textbackground(green);
write(' ');
end;
for k := 1 to i do
begin
textbackground(green);
write(' ');
end;
end;
for i := 1 to a do
begin
writeln;
for k := 1 to i do
begin
write(' ');
end;
for j := i to a-1 do
begin
write(' ');
end;
end;
end;
status := false;
end;
0:exit;
else
begin
window(54,5,79,10);
textbackground(Green);
clrscr;
gotoxy(2,2);
writeln('Pilihan Tidak Ada');
status := false;
readln;
end;
end;
end;
readln;
until status;
end.