Jumat, 15 Februari 2008

ALGORITMA PASCAL

GABUNGAN ANTARA WHILE , FOR, CASE, PROCEDURE

uses wincrt;
procedure office;
vara,jml : integer;
nm,word,exl,pp : string;

begin
clrscr;
writeln(’DATA NILAI OFFICE’);
writeln(’——-----------————’);
write(’Jumlah Siswa :’); readln(jml);
for a := 1 to jml do
begin
write(’Nama ‘,a,’:');readln(nm);
write(’Nilai Ms.Word =’);readln(word);
write(’Nilai Ms.Excel =’);readln(exl);
write(’Nilai Ms.Power Point =’); readln(pp);
end;
end;

procedure desain;
vara,jml : integer;
nm,ps,cd : string;
begin
clrscr;
writeln(’DATA NILAI DESAIN’);
writeln(’—-----------—————’);
write(’Jumlah Siswa :’); readln(jml);
for a := 1 to jml do
begin
write(’Nama ‘,a,’:'); readln(nm);
write(’Nilai Photoshop =’); readln(ps);
write(’Nilai Corel Draw =’); readln(cd);
end;
end;

procedure pemrograman;
var a,jml : integer;
nm,nl : string;

begin
clrscr;
writeln(’DATA NILAI PEMROGRAMAN’);
writeln(’—------------------——————–’);
write(’Jumlah Siswa :’); readln(jml);
for a := 1 to jml do
begin
write(’Nama ‘,a,’:'); readln(nm);
write(’Nilai Nilai =’); readln(nl);
end;
end;


var pil,jwb : char;
begin
jwb := ‘Y’;
while (jwb = ‘Y’) or (jwb = ‘y’) do
begin
writeln(’PROGRAM INPUT DATA NILAI’);
writeln(’======================================’);
writeln(’1.MICROSOFT OFFICE’);
writeln(’2.DESAIN GRAFIS’);
writeln(’3.PEMROGRAMAN’);
writeln(’======================================’);
writeln(”);
write(’Pilihan Anda [1/2/3] = ‘); readln(pil);
case pil of‘1′ : office;‘2′ : desain;‘3′ : pemrograman;
else writeln(’Pilihan Anda Salah’);
end;
writeln(’————————’);
write(’Kembali Ke Menu [Y/T] = ‘);
readln(jwb);
clrscr;
end;
end.


GABUNGAN WHILE DAN IF

uses wincrt;
var ket :string;
pilihan,jwb : char;
pjg,lbr,ls,kl,r :integer;
p,l,t,vol : integer;volt,rt,tt :real;pi,lsl,kll :real;beginjwb := ‘Y’;
while (jwb = ‘Y’) or (jwb = ‘y’) do
begin
writeln(’Menu Pilihan ‘);
writeln(’———————————---------—’);
writeln(’a. Mencari luas & keliling Persegi ‘);
writeln(’b. Mencari luas & keliling lingkaran’);
writeln(’c. Mencari volume balok ‘);
writeln(’d. Mencari volume tabung ‘);
writeln(’————————————’);
write(’Pilihan Anda [a,b,c,d] : ‘);readln(pilihan);
pi :=3.14;
case pilihan of‘A’,'a’ : ket:= ‘Pilihan A’;
‘B’,'b’ : ket:= ‘Pilihan B’;
‘C’,'c’ : ket:= ‘Pilihan C’;
‘D’,'d’ : ket:= ‘Pilihan D’;
else ket:= ‘pilihan anda salah’;
end;
clrscr;
writeln(’Keterangan :’,ket);
if (pilihan = ‘a’) or (pilihan = ‘A’) then
begin
writeln(’Mencari luas & keliling Persegi’);
writeln(’——————————-----------’);
write(’nilai panjang : ‘);readln(pjg);
write(’nilai lebar : ‘);readln(lbr);
writeln(’ ‘);
ls := pjg * lbr;
kl :=2 * (pjg * lbr);
writeln(’Luas Persegi : ‘,ls);
writeln(’Keliling Persegi :’,kl);
writeln(’——————————-’);
write(’kembali ke menu utama [Y/T] :’); readln(jwb);
clrscr;
endelse
if (pilihan = ‘b’) or (pilihan = ‘B’) then

begin
writeln(’Mencari luas & keliling lingkaran’);
writeln(’——————————-’);
write(’nilai jari-jari : ‘);readln(r);
writeln(’ ‘);
lsl :=pi * r * r;
kll :=2 * pi * r;
writeln(’Luas Lingkaran :’,lsl:8:0);
writeln(’Keliling Lingkaran :’,kll:8:0);
writeln(’——————————-’);
write(’kembali ke menu utama [Y/T] :’); readln(jwb);
clrscr;
end

else if (pilihan =’c') or (pilihan =’C') then

begin
writeln(’Mencari volume balok’);
writeln(’——————————-’);
write(’nilai panjang : ‘);readln(p);
write(’nilai lebar : ‘);readln(l);
write(’nilai tinggi : ‘);readln(t);
writeln(’ ‘);
vol := p*l*t;
writeln(’volume balok :’,vol);
writeln(’——————————-’);
write(’kembali ke menu utama [Y/T] :’); readln(jwb);
clrscr;
endelse if (pilihan =’d') or (pilihan =’D') then
begin
writeln(’Mencari volume tabung’);
writeln(’——————————-’);
write(’jari-jari alas : ‘);readln(rt);
write(’tinggi tabung : ‘);readln(tt);
writeln(’ ‘);
volt := pi*(rt*rt)*tt;
writeln(’volume Tabung :’,volt:8:0);
writeln(’——————————-’);
write(’kembali ke menu utama [Y/T] :’); readln(jwb);
clrscr;
end;
end;
end.

GABUNGAN PROCEDURE DAN FUNCTION

uses wincrt;
procedure cash;
var nb : string;
hb,jml,tot : real;

begin
clrscr;
writeln(’PENJUALAN CASH’);
writeln(’——————’);
write(’Nama Barang :’); readln(nb);
write(’Harga Barang :’); readln(hb);
write(’Jumlah :’); readln(jml);
tot := hb * jml;
writeln(’Total = ‘,tot:8:0);
end;

procedure kredit;
var nb : string;
hb,jml,tot,la,ba : real;
begin

clrscr;
writeln(’PENJUALAN KREDIT’);
writeln(’——————’);
write(’Nama Barang :’); readln(nb);
write(’Harga Barang :’); readln(hb);
write(’Jumlah :’); readln(jml);
tot := hb * jml;
writeln(’Total = ‘,tot:8:0);
write(’Lama Angsuran : ‘); readln(la);
ba := tot/la;
writeln(’Besar Angsuran : ‘,ba:8:0);
end;

var pil,jwb : char;
begin
jwb := ‘Y’;
while (jwb = ‘Y’) or (jwb = ‘y’) do
begin
writeln(’DAFTAR PENJUALAN BARANG’);
writeln(’==========================’);
writeln(’1.PENJUALAN CASH’);
writeln(’2.PENJUALAN KREDIT’);
writeln(’==========================’);
writeln(”);
write(’Pilihan Anda [1/2] = ‘); readln(pil);
case pil of‘1′ : cash;‘2′ : kredit;
else writeln(’Pilihan Anda Salah’);
end;

writeln(’————————’);
write(’Kembali Ke Menu [Y/T] = ‘); readln(jwb);
clrscr;
end;
end.

GABUNGAN FUNCTION DAN FOR

uses wincrt;
var a,jml,nl,i : integer;
nm,nama,ket : string;
function kapital(ns : string) : string;
var i : integer;
begin
for i := 1 to length(ns) do
ns[i] := upcase(ns[i]);
kapital := ns;
end;

begin
writeln(’INPUT DATA NILAI’);
writeln(’==================’);
write(’Jumlah Siswa :’); readln(jml);
writeln(”);
for a := 1 to jml do
begin
write(’Nama ‘,a,’:'); readln(nm);
write(’Nilai =’); readln(nl);
writeln (’———————-’);
if nl > 85 thenket := ‘LULUS’ else ket := ‘GAGAL’;
nama := kapital(nm);
writeln(’Nama ‘,a,’:',nama);
writeln(’Keterangan’,a,’ :’,ket);
writeln(”);
end;
end.

ARRAY

uses wincrt;
var jml,a,b : integer;
nm,ket : array[1..40] of string;nl : array[1..40] of integer;

begin
writeln(’INPUT DATA NILAI’);
writeln(’==================’);
write(’Jumlah Siswa :’);
readln(jml);writeln(”);
for a := 1 to jml do

begin
write(’Nama ‘,a,’:'); readln(nm[a]);write(’Nilai =’); readln(nl[a]);writeln (”);
if nl[a] > 85 thenket[a] := ‘LULUS’
else ket[a] := ‘GAGAL’;
end;

for b := 1 to jml do
begin
writeln(’Nama ‘,b,’:',nm[b]);writeln(’Keterangan’,b,’ :’,ket[b]);writeln(”);end;
end.

GABUNGAN ARRAY DAN FOR

uses wincrt;
var jml,a,b: integer;
nm,ket : array[1..40] of string;hrg,jmlh,tot : array[1..40] of real;
begin
write(’Jumlah Data : ‘); readln(jml);
writeln(”);
for a := 1 to jml do
begin
write(’Nama Barang : ‘); readln(nm[a]);
write(’Harga : ‘); readln(hrg[a]);
write(’Jumlah : ‘); readln(jmlh[a]);
writeln(”);
end;

clrscr;

gotoxy(05,2);write(’===================================================’);
gotoxy(05,3); write(’Nama’);
gotoxy(15,3); write(’Harga’);
gotoxy(30,3); write(’Jumlah’);
gotoxy(50,3); write(’Total’);
gotoxy(05,4); write(’===================================================’);

for b := 1 to jml do
begin
tot[b] := hrg[b]*jmlh[b];
gotoxy(05,5+b); writeln(nm[b]);gotoxy(15,5+b); writeln(hrg[b]:8:0);gotoxy(30,5+b); writeln(jmlh[b]:8:0);gotoxy(50,5+b); writeln(tot[b]:8:0);
end;
end.

Tidak ada komentar: