ANGKA KE TULISAN – V.2

uses crt;
var sBilangan,sJenis,sJenisTotal,sDigitDepan,sBilPot : string;
iDigit : integer;
j,k,bTriplet,bTriplet2,iDigitDepan,i : byte;
y,HurufDitulis,panjang,awal,akhir : byte;
sBilPotKat : string;

function BilanganValid(Bilangan : string) : boolean;
var i : byte;
valid,nilai : boolean;
begin
if length(Bilangan) > 30 then BilanganValid := false
else
begin
nilai := true;
for i := 1 to length(Bilangan) do
begin
if (ord(Bilangan[i]) >= 48) and (ord(Bilangan[i]) <= 57) then valid := true
else valid := false;
nilai := (nilai and valid);
end;
BilanganValid := nilai;
end;
end;

function DigitBernilai(Kar : char) : boolean;
var nilai : boolean;
begin
if Kar <> ‘0’ then nilai := true else nilai := false;
DigitBernilai := nilai;
end;

function TripletBernilai(Kar : string) : boolean;
var nilai : array[1..5] of boolean;
i  : byte;
nilai2 : boolean;
begin
nilai2 := false;
for i := 1 to length(Kar) do
begin
if Kar[i] <> ‘0’ then  nilai[i] := true else nilai[i] := false;
nilai2 := (nilai2 or nilai[i]);
end;
TripletBernilai :=  nilai2;
end;

function UbahKeKata(sBil : string) : string;
var i,j  : byte;
kata : string;
begin
kata := ”;
i := 1;
while i <= length(sBil) do
begin
{ Untuk bilangan dua digit dimana digit pertama = 1}
if (sBil[i] = ‘1’) and (length(sBil)-i = 1) then
begin
case sBil[i+1] of
‘0’ : kata := kata + ‘sepuluh ‘;
‘1’ : kata := kata + ‘sebelas ‘;
‘2’ : kata := kata + ‘dua belas ‘;
‘3’ : kata := kata + ‘tiga belas ‘;
‘4’ : kata := kata + ’empat belas ‘;
‘5’ : kata := kata + ‘lima belas ‘;
‘6’ : kata := kata + ‘enam belas ‘;
‘7’ : kata := kata + ‘tujuh belas ‘;
‘8’ : kata := kata + ‘delapan belas ‘;
‘9’ : kata := kata + ‘sembilan belas ‘;
end;
i := i + 1;
end else
begin
case sBil[i] of
‘0’ : kata := kata + ”;
‘1’ : if i <> length(sBil) then kata := kata + ‘se’
else kata := kata + ‘satu ‘;
‘2’ : kata := kata + ‘dua ‘;
‘3’ : kata := kata + ‘tiga ‘;
‘4’ : kata := kata + ’empat ‘;
‘5’ : kata := kata + ‘lima ‘;
‘6’ : kata := kata + ‘enam ‘;
‘7’ : kata := kata + ‘tujuh ‘;
‘8’ : kata := kata + ‘delapan ‘;
‘9’ : kata := kata + ‘sembilan ‘;
end;
case (length(sBil)-i) of
1 : if DigitBernilai(sBil[i]) = true then kata := kata + ‘puluh ‘;
2 : if DigitBernilai(sBil[i]) = true then kata := kata + ‘ratus ‘;
end;
end;
i := i + 1;
end;
UbahKeKata := kata;
end;

begin
clrscr;
sBilangan   := ”;
sJenis      := ”;
sJenisTotal := ”;
sDigitDepan := ”;
write(‘Sembarang bilangan : ‘);readln(sBilangan);

if BilanganValid(sBilangan) = true then
begin
iDigit := length(sBilangan);
bTriplet := iDigit div 3;
iDigitDepan := iDigit – (bTriplet * 3);
panjang := iDigitDepan;
awal := 1;

if (iDigitDepan <> 0) then
begin
akhir := iDigitDepan;
bTriplet := bTriplet + 1;
end
else
akhir := 3;

bTriplet2 := bTriplet-1;

for i := 1 to bTriplet  do
begin
sBilPot := copy(sBilangan,awal,akhir);
sBilPotKat := UbahKeKata(sBilPot);
sJenisTotal := sJenisTotal + sBilPotKat;
{      if (bTriplet2 >= 0) and (bTriplet2 <= 9) then
begin}
case bTriplet2 of
0 : if TripletBernilai(sBilPot) = true then sJenis := ” else sJenis := ”;
1 : if TripletBernilai(sBilPot) = true then sJenis := ‘ribu ‘ else sJenis := ”;
2 : if TripletBernilai(sBilPot) = true then sJenis := ‘juta ‘ else sJenis := ”;
3 : if TripletBernilai(sBilPot) = true then sJenis := ‘milyard ‘ else sJenis := ”;
4 : if TripletBernilai(sBilPot) = true then sJenis := ‘trilyun ‘ else sJenis := ”;
5 : if TripletBernilai(sBilPot) = true then sJenis := ‘ributrilyun ‘ else sJenis := ”;
6 : if TripletBernilai(sBilPot) = true then sJenis := ‘milyardtrilyun ‘ else sJenis := ”;
7 : if TripletBernilai(sBilPot) = true then sJenis := ‘trilyuntrilyun ‘ else sJenis := ”;
8 : if TripletBernilai(sBilPot) = true then sJenis := ‘ribu trilyuntrilyun ‘ else sJenis := ”;
9 : if TripletBernilai(sBilPot) = true then sJenis := ‘milyard trilyuntrilyun ‘ else sJenis := ”;
end;
{      end;}

sJenisTotal := sJenisTotal + sJenis;
if (iDigitDepan <> 0) and (i = 1) then awal := awal + iDigitDepan
else awal := awal + 3;
akhir := 3;
bTriplet2 := bTriplet2 – 1;
end;

gotoxy(10,5);write(‘Bilangan    : ‘,sBilangan);
gotoxy(10,6);write(‘Dalam Kata  : ‘);
if length(sJenisTotal) < 51 then
begin
gotoxy(25,6);write(sJenisTotal);
readln;
end
else
begin
i := 1;
HurufDitulis := 1;
y := 6;
gotoxy(24,y);
if length(sJenisTotal) < 255 then
begin
while i <= length(sJenisTotal) do
begin
write(sJenisTotal[i]);
if (HurufDitulis > 40) and (sJenisTotal[i] = ‘ ‘) then
begin
HurufDitulis := 1;
y := y + 1;
gotoxy(24,y);
end;
i := i + 1;
HurufDitulis := HurufDitulis + 1;
end;
end
else
begin
gotoxy(24,6);write(‘Angkamu panjang banget,lebih 255 karakter.’);
gotoxy(24,7);write(‘Maaf belum tertangani.’);
end;
readln;
end;
end
else
begin
writeln(‘Bilangan yang anda masukkan tidak benar’);
writeln(‘Ada pengetikan angka yang salah dengan’);
writeln(‘karakter lain. Or bilangannya kegedean.’);
readln;
end;
end.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: