Presentation is loading. Please wait.

Presentation is loading. Please wait.

Matakuliah : D0524 / Algoritma dan Pemrograman Komputer

Similar presentations


Presentation on theme: "Matakuliah : D0524 / Algoritma dan Pemrograman Komputer"— Presentation transcript:

1 Matakuliah : D0524 / Algoritma dan Pemrograman Komputer
Tahun : 2005 Versi : Pertemuan 08 Function

2 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Menerapkan penggunaan fungsi

3 Function Called in an IF Statement Function Called on an Output Line
Outline Materi What is Function Features in a Function Uses of a Function Function Called in an IF Statement Function Called on an Output Line Function Used for Conversion

4 What is Function Often, a procedure is needed to do some specific task and return one single value. Examples: Validate an input value Convert some value, like: a sum of money from sterling to euros or a temperature from degrees Fahrenheit to degrees Celsius In such cases, a special type of procedure, called a function, can be used.

5 Is similar to a procedure in that it:
Features of a Function Is similar to a procedure in that it: has a specific identifying name carries out a specific task may or may not take parameters is called or invoked by another procedure or program Is different in that: it has a data type associated with it it returns a single value to the calling program the function name itself contains the value being returned

6 Unlike procedures, functions can be used within other command, e.g.
Uses of Function Unlike procedures, functions can be used within other command, e.g. As part of a condition in an IF statement If IsValid(rateFig) Then . . . As part of the output from a Me.Print statement Me.Print “Rata - Rata ” & HitungAvg(sum, number) As part of an assignment statement rupiah = HitungRupiah(uang)

7 Function Called in an IF Statement
Private Function IsValid (reply as string) as boolean IsValid = False If reply = “Yes” Or reply = “No” Then IsValid = True End If End Function Calling the function: If IsValid(rateFig) Then Me.Print Else

8 Function Called on an Output Line
Private Function HitungAvg (s as Integer, n as Integer) as single CalcAvg = s/n End Function Calling the function: Me.Print “Rata – Ratanya : ” & HitungAvg(sum, number)

9 Function Used for Conversion
Private Function HitungRupiah (UangDollar as Currency) as Currency HitungRupiah = UangDollar * 9700 End Function Calling the function: Dim UangDollar as Currency, UangRupiah as Currency UangDollar = InputBox(“Masukkan jumlah Dollar") UangRupiah = HitungRupiah(UangDollar)


Download ppt "Matakuliah : D0524 / Algoritma dan Pemrograman Komputer"

Similar presentations


Ads by Google