Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Upcoming SlideShare
×

# Pemrograman komputer 8 (prosedur)

673 views

Published on

unj fmipa-fisika

Published in: Education
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

### Pemrograman komputer 8 (prosedur)

1. 1. Pemrograman Komputer Pertemuan 08 Function Bambang Heru Iswanto, Dr.rer.nat M.Si <ul><li>Jurusan Fisika </li></ul><ul><li>Fakultas Matematika dan Ilmu Pengetahuan Alam </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
2. 2. Learning Outcomes <ul><li>Pada akhir pertemuan ini, diharapkan mahasiswa </li></ul><ul><li>akan mampu : </li></ul><ul><li>Menerapkan penggunaan fungsi </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
3. 3. Outline Materi <ul><li>What is Function </li></ul><ul><li>Features in a Function </li></ul><ul><li>Uses of a Function </li></ul><ul><li>Function Called in an IF Statement </li></ul><ul><li>Function Called on an Output Line </li></ul><ul><li>Function Used for Conversion </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
4. 4. What is Function <ul><li>Often, a procedure is needed to do some specific task and return one single value. Examples: </li></ul><ul><ul><li>Validate an input value </li></ul></ul><ul><ul><li>Convert some value, like: </li></ul></ul><ul><ul><ul><li>a sum of money from sterling to euros </li></ul></ul></ul><ul><ul><ul><li>or a temperature from degrees Fahrenheit to degrees Celsius </li></ul></ul></ul><ul><li>In such cases, a special type of procedure, called a function, can be used. </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
5. 5. Features of a Function <ul><li>Is similar to a procedure in that it: </li></ul><ul><ul><li>has a specific identifying name </li></ul></ul><ul><ul><li>carries out a specific task </li></ul></ul><ul><ul><li>may or may not take parameters </li></ul></ul><ul><ul><li>is called or invoked by another procedure or program </li></ul></ul><ul><li>Is different in that: </li></ul><ul><ul><li>it has a data type associated with it </li></ul></ul><ul><ul><li>it returns a single value to the calling program </li></ul></ul><ul><ul><li>the function name itself contains the value being returned </li></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
6. 6. Uses of Function <ul><li>Unlike procedures, functions can be used within other command, e.g. </li></ul><ul><ul><li>As part of a condition in an IF statement </li></ul></ul><ul><ul><ul><li>If IsValid(rateFig) Then . . . </li></ul></ul></ul><ul><ul><li>As part of the output from a Me.Print statement </li></ul></ul><ul><ul><ul><li>Me.Print “Rata - Rata ” & HitungAvg(sum, number) </li></ul></ul></ul><ul><ul><li>As part of an assignment statement </li></ul></ul><ul><ul><ul><li>rupiah = HitungRupiah(uang) </li></ul></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
7. 7. Function Called in an IF Statement <ul><li>Private Function IsValid (reply as string) as boolean </li></ul><ul><li>IsValid = False </li></ul><ul><li>If reply = “Yes” Or reply = “No” Then </li></ul><ul><li>IsValid = True </li></ul><ul><li>End If </li></ul><ul><li>End Function </li></ul><ul><li>Calling the function: </li></ul><ul><li>If IsValid(rateFig) Then </li></ul><ul><li>Me.Print . . . . . </li></ul><ul><li>Else . . . . </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
8. 8. Function Called on an Output Line <ul><li>Private Function HitungAvg (s as Integer, n as Integer) as single </li></ul><ul><li>CalcAvg = s/n </li></ul><ul><li>End Function </li></ul><ul><li>Calling the function: </li></ul><ul><li>Me.Print “Rata – Ratanya : ” & HitungAvg(sum, number) </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
9. 9. Function Used for Conversion <ul><li>Private Function HitungRupiah (UangDollar as Currency) as Currency </li></ul><ul><li>HitungRupiah = UangDollar * 9700 </li></ul><ul><li>End Function </li></ul><ul><li>Calling the function: </li></ul><ul><li>Dim UangDollar as Currency, UangRupiah as Currency </li></ul><ul><li>UangDollar = InputBox(“Masukkan jumlah Dollar&quot;) </li></ul><ul><li>UangRupiah = HitungRupiah(UangDollar) </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
10. 10. TERIMA KASIH 01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |