Please Translate these sentence depends on your own language in your country

Penting Untuk Pengunjung

Jika sulit mengingat link blog saya, cukup mencari melalui Google menggunakan kata kunci
"ramazotob"
By enda fiVers
Follow

Contoh Dasar Pemrograman Freebasic

Contoh 1 :

Rem Ainmasi Tulisan Dari Atas Ke Bawah
Dim X as Integer
Dim Bawah as Integer
Dim Pjkata as Integer
Const Kata="ANG_NDHY"
Pjkata=Len(kata)

'Hitung Posisi Bawah Kolom
Bawah=(25-Pjkata)/2

'Looping
For X=1 To Bawah
Locate x,36
Print Kata

'Menentukan waktu bergerak
Sleep 300
Locate x,36
Print String(Pjkata," ")

Next
Locate x,36
Print Kata

Sleep
End



Contoh 2 :

Rem Animasi Tulisan Bergerak dari Kiri Ketengah Layar
Dim X as Integer , Tengah as Integer
Dim Pjkata as Integer
Const Kata="ANIMASI"

'Hitung Panjang Kata
Pjkata=Len(Kata)

'Hitung Posisi Tengah Kolom
Tengah=(80-Pjkata)/2

'Looping
For X=1 To Tengah
Locate 12,X
Print Kata

'Menentukan Waktu Bergerak
Sleep 300
Locate 12,X
Print String(Pjkata," ")

Next
Locate 12,Tengah
Print Kata
Sleep
End



Contoh 3 :

rem cetak bilangan dalam bentuk array
cls
dim bilangan(5) AS integer, total as integer
dim x as integer, j as integer

for x = 1 to 5
input "ketik bilangan = "; bilangan(x)

next

cls
'cetak judul tabel
locate 2,10
print "NO."
LOCATE 2,20
PRINT "bilangan"
locate 3,10
print string (18,"_")

for j = 1 to 5
locate j+3,10
print j

locate j+3,20
print bilangan (j)

'hitung total

next

locate 9,10

print string (18,"_")

locate 10,10
print "total :"
locate 10,20
print total
sleep
end



Contoh 4 :

Rem cetak kalimat 20 kali
cls
dim x AS integer
const kal= "saya belajar algoritma"
for X=1 TO 20
print kal
next
sleep
end



Contoh 5 :

rem cetak kartu hasil studi
dim km (8) as string, mtk (8) as string, sks (8) as integer
dim ipk as integer, nh(8) as string, bb(8) as integer, ti as integer
dim jm(8) as integer, sm as string, jms as integer, jsks as integer
dim x as integer, j as integer,nm as string,npm as double

data "mkb001"
data "mkb002"
data "mkb003"
data "mkk001"
data "mkk002"
data "mkk003"
data "mkk004"
data "mkk005"

'cetak judul
locate 2,30:print "KARTU HASIL STUDI"
locate 3,31:print "SEMESTER GANJIL"
locate 4,32:print "TA.2009/2010"
LOCATE 5,30:print "_________________"
print : print

locate 7,25:input"Nama:";nm
locate 7,25:input"Nama:";nm
locate 8,25:input"NPM:";npm
locate 8,25:input"NPM:";npm
Print:print

locate 10,5 : print string (76,"_")
locate 11,5 : print "No"
locate 11,10 : print "Kode MTK"
locate 11,20 : print "MTK"
locate 11,40 : print "SKS"
locate 11,45 : print "Nilai Huruf"
Locate 11,60 : print "Bobot"
locate 11,70 : print "Jumlah Mutu"
locate 12,5 : print string (76,"_")

'cetak data
for x = 1 to 8
read km(x)
if ucase (km(x)) = "MKB001" then
mtk (x) = "paket prog.aplikasi"
sks (x) = 3
elseif ucase (km(x)) = "MKB002" then
mtk (x) = "algoritma"
sks (x) = 3
elseif ucase (km(x)) = "MKB003" then
mtk(x) = "ms.access"
sks (x) = 3
elseif ucase (km(x)) = "MKK001" then
mtk(x) = "manaj.umum"
sks(x) = 3
elseif ucase (km(x)) ="MKK002" then
mtk (x) = "peng.tek.informatika"
sks (x) = 2
elseif ucase (km(x)) = "MKK003" then
mtk(x) = "matematika"
sks(x) = 3
elseif ucase (km(x)) ="MKK004" then
mtk(x) = "b.inggris"
sks(x) =2
else
mtk(x) = "pend. agama"
sks (x) = 2
end if

locate x+12,5 : print x
locate x+12,10 :print km(x)
locate x+12,20 :print mtk(x)
locate x+12,40 :print sks(x)
locate x+12,48:input nh(X)
locate x+12,48:print nh(x)

'cetak nilai huruf dan bobot
if ucase (nh(x)) ="A" then
bb(x) = 4
elseif ucase (nh(x)) ="B" then
bb(x) = 3
elseif ucase (nh(x)) ="C" then
bb(x)= 2
elseif ucase (nh(x)) ="D" then
bb(x)= 1
else
bb(x)= 0
end if

locate x+12,60:print bb(x)

'hitung jumlah mutu
jm(x) = sks(x) * bb(x)
jms = jms + jm(x)
jsks = jsks + sks(x)
ti = jms/jsks
locate x+12,73: print jm(x)

'sks maksimal
if ti <=1.00 then
sm = "12sks"
elseif ti <=2.00 then
sm = "16sks"
elseif ti <=2.50 then
sm = "18sks"
elseif ti <=2.99 then
sm = "22sks"
else
sm = "24sks"
end if

next

locate 21,5:print string (76,"_")
locate 22,5:print "Total ipk =";ti
locate 22,30:print "sks maksimal =";sm

sleep
end



Contoh 6 :

rem aplikasi menghitung nilai siswa
rem menggunakn sub module dan fungsi ciptaan
cls
DIM shared nilaiujian as integer
'fungsi ciptaan
function NHuruf (Nilai AS single) as string
DIM hasil as string
IF Nilai <=40 then
hasil = "E"
Elseif Nilai <=45 then
hasil = "D"
Elseif Nilai <=64 then
hasil = "C"
Elseif Nilai <=74 then
hasil = "B"
Elseif Nilai <=100 then
hasil = "A"
End if

'panggil fungsi
NHuruf = hasil
END FUNCTION
Function status (NAngka as single) as string
if NAngka >= 55 then
status="Lulus"
Elseif NAngka <54 then
status="tidak lulus"
End if
end function

'sub modul
sub cetakjudul (teks as string, baris as integer)
dim kolom as integer
kolom = (80-Len(Teks))/2
color 14
locate baris, kolom
print teks
end sub

SUB inputdata
dim nama as string
dim NPM as string
input "Nama Mahasiswa ="; Nama
input "NPM Mahasiswa ="; NPM
input "Nilai Ujian ="; Nilaiujian
print:print
End sub

'main program
'panggil prosedur dan fungsi ciptaan
const j1="Aplikasi Menghitung Nilai Siswa"
const j2="Menggunakan sub modul dan fungsi"
const j3="________________________________"
'panggil prosedur cetak judul
CETAKJUDUL j1,2
CETAKJUDUL j2,3
CETAKJUDUL j3,4
'panggil prosedur input data
color 15
Inputdata
'panggil fungsi NHuruf + status
color 12
print"Nilai Huruf ="; NHuruf (NilaiUjian)
Print "Status ="; status (NilaiUjian)
sleep
End



Contoh 7 :


Rem cetak nilai 3-40 dilayar
dim I AS integer
for I=3 TO 40
Print 1
next
sleep
end



Contoh 8 :

rem menghitung Gaji Bersih PT. ARISA MANDIRI
Dim NK as string, Gol as string, TI as integer, TK as integer, GP as integer
dim TG as integer, Pot as integer
dim GB as integer
dim ulang as string *1

print "Menghitung Gaji Bersih PT. ARISA MANDIRI"

ulang="Y"
ulang="y"
while ulang ="Y" or ulang ="y"

input"Nama Karyawan=";NK
input"Golongan=";Gol

'menentukan Golongan
if Gol="A" or Gol="a" then
GP=500000
TI=125000
TK=100000
elseif Gol="B" or Gol="b" then
GP=750000
TI=150000
TK=200000
elseif Gol="C" or Gol="c" then
GP=850000
TI=175000
TK=300000
endif

'Menghitung Total Gaji
TG=GP+TI+TK

' Menghitung potongan
if TG >=700000 then
Pot=0.1*TG
elseif TG<700000 then
Pot=0.05*TG
endif

'Menghitung Gaji Bersih
GB=TG-Pot

'cetak hasil
print"Nama Karyawan=";NK
print"Golongan=";Gol
print"Tunjangan Insetive=";TI
print"Tunjangan Karyawan=";TK
print"Gaji Pokok=";GP
print"Total Gaji=";TG
print"Potongan=";Pot
print"Gaji Bersih=";GB


locate 23,1
input"isi data lagi(Y/T)=";ulang

wend
end



Contoh 9 :

REM PEMBAYARAN RAWAT INAP PASIEN
CLS

SCREEN 18, 30, 4, 1

DIM SHARED KK AS INTEGER,KP AS STRING

'FUNGSI CIPTAAN
'FUNGSI NAMAKAMAR
FUNCTION NKAMAR(KK AS INTEGER)AS STRING
IF KK = 01 THEN
NKAMAR = "? Kelas III"
ELSEIF KK = 02 THEN
NKAMAR = "? Kelas II"
ELSEIF KK = 03 THEN
NKAMAR = "? Kelas I"
ELSEIF KK = 04 THEN
NKAMAR = "? Kelas VIP"
ELSEIF KK = 05 THEN
NKAMAR = "? Kelas SVIP"
ELSE
NKAMAR = "? Coba Ulangi lagi.."
END IF
END FUNCTION

'FUNGSI TARIF KAMAR/HARI
FUNCTION TKAMAR(KK AS INTEGER)AS SINGLE
IF KK = 01 THEN
TKAMAR = 80000
ELSEIF KK = 02 THEN
TKAMAR = 350000
ELSEIF KK = 03 THEN
TKAMAR = 600000
ELSEIF KK = 04 THEN
TKAMAR = 1000000
ELSEIF KK = 05 THEN
TKAMAR = 1600000
END IF
END FUNCTION

'SUB MODUL
SUB CETAKJUDUL (TEKS AS STRING, BARIS AS INTEGER)
DIM KOLOM AS INTEGER
KOLOM = (80-LEN(TEKS))/2
COLOR 11

LOCATE BARIS, KOLOM
PRINT TEKS
END SUB

SUB INPUTDATA
DIM NAMA AS STRING,LI AS INTEGER,BKAMAR AS DOUBLE
LOCATE 8,13:INPUT "Nama Pasien ="; Nama
LOCATE 9,13:INPUT "Umur ="; UM
LOCATE 10,13:INPUT "Kode Pasien =";KP
LOCATE 11,13:INPUT "Kode Kamar ="; KK
LOCATE 12,13:INPUT "Lama Inap ="; LI

'PROSES
IF KK = 01 THEN
BKAMAR = LI * 80000
ELSEIF KK = 02 THEN
BKAMAR = LI * 350000
ELSEIF KK = 03 THEN
BKAMAR = LI * 600000
ELSEIF KK = 04 THEN
BKAMAR = LI * 1000000
ELSEIF KK = 05 THEN
BKAMAR = LI * 1600000
ELSE
BKAMAR = 0
END IF

PRINT:PRINT

LOCATE 21,18:PRINT "TOTAL BIAYA =";BKAMAR
END SUB

'MAIN PROGRAM
'PANGGIL PROSEDUR DAN FUNGSI CIPTAAN
CONST J0 = "--------------------------------"
CONST J1 = "||----------------------------||"
CONST J2 = "|| RS Internasional Bintaro ||"
CONST J3 = "||Pembayaran Rawat Inap Pasien||"
CONST J4 = "||----------------------------||"
CONST J5 = "--------------------------------"
CONST J6 = "|-------------------------------------------------------|"

'PANGGIL PROCEDUR JUDUL
CETAKJUDUL (J0,1)
CETAKJUDUL (J1,2)
CETAKJUDUL (J2,3)
CETAKJUDUL (J3,4)
CETAKJUDUL (J4,5)
CETAKJUDUL (J5,6)
CETAKJUDUL (J6,14)

'PANGGIL PROCEDURE INPUT DATA
COLOR 14
INPUTDATA

'PANGGIL FUNGSI TKAMAR + STATUS

COLOR 14
LOCATE 10,13:PRINT "Kelas Kamar =";NKAMAR(KK)
LOCATE 20,13:PRINT "Tarif Kamar/Hari =";TKAMAR (KK)

SLEEP
END



Contoh 10 :

rem aplikasi menghitung nilai siswa
rem menggunakan sub module dan ciptaaan

cls
dim shared nilaiujian as integer

'fungsi ciptaan
function nhuruf ( nilai as single ) as string
dim hasil as string
if nilai < = 40 then
hasil = "e"
elseif nilai < = 54 then
hasil = "d"
elseif nilai < = 64 then
hasil = "c"
elseif nilai < = 74 then
hasil = "b"
elseif nilai < = 100 then
hasil = "a"

end if

'panggil fungsi
nhuruf = hasil

end function


function status (nangka as single) string
if nangka >= 55 then
status = "lulus"

elseif nangka < 54 then
status = "tidak lulus"

'
sub modul
sub cetakjudul ( teks as string, baris as integer )
dim kolom as integer
print teks
end sub

color 14
locate baris kolom
print teks
end sub

sub input data

dim nama as string,
dim npm as string

input "nama mahasiswa = ;"nama
input "npm mahasiswa = ;"nmp
input "nilai ujian =;" nilai ujian

print : print

end sub

'main program
'panggil prosedur dan fungsi ciptaan

const J1 = "aplikasi menghitung nilai siswa"
const J2 = "menggunakan sub model dan fungsi"
const J3 = "________________________________"

'panggil prosedur cetak judul
cetak judul J1, 2
cetak judul J2,3
cetak judul J3, 4

'panggil prosedure input data
color 15
input data

'panggil fungsi nhuruf + status(nilai ujian)
print "status = ;" nhuruf(nilai ujian)
print "status = ;" status ( niali ujian)

sleep
end



Contoh 11 :

REM MEMBUAT FORMAT HURUF
REM NAMA FUNGSI ADALAH : TITLE CASE
CLS
'HURUF KAPITAL
FUNCTION TITLECASE (TEKS AS STRING) AS STRING
DIM I AS INTEGER,HASIL AS STRING,KARAKTER AS STRING
DIM PJKATA AS INTEGER
PJKATA=LEN(TEKS)
FOR I=1 TO PJKATA
IF I=1 THEN
KARAKTER=UCASE(LEFT(TEKS,1))
ELSEIF MID(TEKS,I-1,1)=""THEN
KARAKTER=UCASE(MID(TEKS,I,1))
ELSE
KARAKTER=LCASE(MID(TEKS,I,1))
END IF
HASIL = HASIL + KARAKTER
NEXT
TITLECASE = HASIL
END FUNCTION
'MAIN PROGRAM
DIM KALIMAT AS STRING
INPUT "KETIK SEMBARANG KALIMAT:";KALIMAT
PRINT "FORMAT TITLECASE=";TITLECASE(KALIMAT)
SLEEP
END



Contoh 12 :

rem membuat fungsi baris
cls
'luas persegi panjang
function luasPP(L as integer,P as integer)as integer
dim hasil as integer
hasil= P*L
LuasPP= Hasil
end function
'main program
dim L1 AS INTEGER,P1 AS INTEGER
INPUT "ketik Lebar:";L1
INPUT "Ketik panjang:";P1
PRINT "LUAS PERSEGI PANJANG :"; LUASPP(L1,P1)
SLEEP
END



Contoh 13 :

rem membuat prosedur sendiri
rem mengganti perintah locate
sub posisi (baris as integer,kolom as integer)

locate baris,kolom

end sub
'main program
dim teks as string
input "ketik sembarang teks:";teks
'tempatkan pada baris 12 dan kolom 25
cls
posisi 12,25
print teks
sleep
end



Contoh 14 :

rem mencetak kata ditengah layar
cls
sub tengah (teks as string,baris as integer)
dim kolom as integer
kolom = (80-len(teks))/2
locate baris,kolom
print teks
end sub
'main program
color 3
tengah "Ramadhan Putra",12
sleep
end



Contoh 15 :

Rem program penjumlahan bilangan dari 4-16
cls
dim j AS integer,jumlah AS integer
for j=4 TO 16
jumlah=jumlah+j
If j <16 j="16" style="font-weight: bold;">Contoh 16 :

rem rincian biaya pemasukan
cls
dim nt as string,kt as string,kk as string
dim li as integer,nk as string,sk as string
dim tk as single,bk as single,pt as single
dim tb as double,tanya as string,sd as string
tanya="Y"
while tanya="Y" or tanya="y"
cls
locate 2,30
print"rincian biaya pemasukan"
locate 3,32
print"hotel citra mandiri"
locate 4,33
print"bulan oktober 2009"
locate 5,30
print"_______________________"
print:print
input"ketik nama tamu:";nt
input"ketik kode tamu:";kt
input"ketik kode kamar:";kk
input"ketik lama inap:";li
locate 10,30
print"hari"
if kk="ag" then
nk="anggrek"
tk=85000
elseif kk="bg" then
nk="bogenville"
tk=125000
elseif kk="mw" then
nk="mawar"
tk=185000
else
print"anda salah isi kode kamar"
tk=0
end if
print"nama kamar:";nk
locate 15,34
print"rincian biaya kamar"
locate 16,34
print"___________________"
print:print
print"tarif kamar/hari:";tk
bk=li*tk
print"biaya kamar:";bk
if li>4 then
pt=bk/25%
else
pt=0
print"potongan:";pt
locate 23,1
print"________"
tb=tk+bk-pt
print"total biaya kamar:";tb
locate 28,1
print"simpan data(Y/T):";tanya
locate 29,1
print"ulangi isi data lagi:";tanya
end if
wend



Contoh 17 :

rem cetak bilangan dalam bentuk array
cls
dim bilangan(5) AS integer, total as integer
dim x as integer, j as integer

for x = 1 to 5
input "ketik bilangan = "; bilangan(x)

next

cls

SCREEN 18, 32, 4, 1

'cetak judul tabel
locate 2,10
print "NO."
LOCATE 2,20
PRINT "bilangan"
locate 3,10
print string (18,"_")

for j = 1 to 5
locate j+3,10
print j

locate j+3,20
print bilangan (j)

'hitung total

next

locate 9,10

print string (18,"_")

locate 10,10
print "total :"
locate 10,20
print total

sleep
end

0 komentar:

:10 :11 :12 :13 :14 :15 :16 :17
:18 :19 :20 :21 :22 :23 :24 :25
:26 :27 :28 :29 :30 :31 :32 :33
:34 :35 :36 :37 :38 :39

Silahkan Kirim Komentar Anda

Silahkan Berkomentar dengan Sopan.
Anda bersikap Sopan, Saya pun jadi Segan :)

→Klik Background 2x Untuk Kembali ke Atas←