Kamis, 31 Juli 2025

VB MENGGUNAKAN CHECKBOX

 Public Class Form1

    'Buka Menggunakan CheckBox.vbproj


    Private Sub chkTebal_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTebal.CheckedChanged

        If chkTebal.Checked = True Then

            txtTeks.Font = New Font(txtTeks.Font, txtTeks.Font.Style Or FontStyle.Bold)

        Else

            txtTeks.Font = New Font(txtTeks.Font, txtTeks.Font.Style And Not FontStyle.Bold)

        End If

    End Sub


    Private Sub chkMiring_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkMiring.CheckedChanged

        If chkMiring.Checked = True Then

            txtTeks.Font = New Font(txtTeks.Font, txtTeks.Font.Style Or FontStyle.Italic)

        Else

            txtTeks.Font = New Font(txtTeks.Font, txtTeks.Font.Style And Not FontStyle.Italic)

        End If

    End Sub


    Private Sub chkGaris_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkGaris.CheckedChanged

        If chkGaris.Checked = True Then

            txtTeks.Font = New Font(txtTeks.Font, txtTeks.Font.Style Or FontStyle.Underline)

        Else

            txtTeks.Font = New Font(txtTeks.Font, txtTeks.Font.Style And Not FontStyle.Underline)

        End If

    End Sub

End Class


VB PERATAAN TEKS

 Public Class Form1


    Private Sub optKiri_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles optKiri.CheckedChanged

        txtTeks.TextAlign = HorizontalAlignment.Left

    End Sub

    Private Sub optTengah_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optTengah.CheckedChanged

        txtTeks.TextAlign = HorizontalAlignment.Center

    End Sub


    Private Sub OptKanan_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles OptKanan.CheckedChanged

        txtTeks.TextAlign = HorizontalAlignment.Right

    End Sub


    Private Sub optPutih_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles optPutih.Click

        txtTeks.BackColor = Color.White

    End Sub

    Private Sub optKuning_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles optKuning.Click

        txtTeks.BackColor = Color.Yellow

    End Sub

    Private Sub optHijau_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles optHijau.Click

        txtTeks.BackColor = Color.SpringGreen

    End Sub


    Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click

        txtTeks.Text = ""  'Hapus teks

    End Sub


    Private Sub btnTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTutup.Click

        Close()

    End Sub


End Class


VB CALCULATOR

 Public Class Form1


    Dim FirstNumber As Single

    Dim SecondNumber As Single

    Dim AnswerNumber As Single

    Dim ArithmeticProcess As String


    Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click

        txtHasil.Text = txtHasil.Text & 0

    End Sub


    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

        txtHasil.Text = txtHasil.Text & 1

    End Sub


    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click

        txtHasil.Text = txtHasil.Text & 2

    End Sub


    Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click

        txtHasil.Text = txtHasil.Text & 3

    End Sub


    Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click

        txtHasil.Text = txtHasil.Text & 4

    End Sub


    Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click

        txtHasil.Text = txtHasil.Text & 5

    End Sub


    Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click

        txtHasil.Text = txtHasil.Text & 6

    End Sub


    Private Sub btn7_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click

        txtHasil.Text = txtHasil.Text & 7

    End Sub


    Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click

        txtHasil.Text = txtHasil.Text & 8

    End Sub


    Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click

        txtHasil.Text = txtHasil.Text & 9

    End Sub


    Private Sub btnBagi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBagi.Click

        FirstNumber = Val(txtHasil.Text)

        txtHasil.Text = "0"

        ArithmeticProcess = "/"

    End Sub


    Private Sub btnKali_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKali.Click

        FirstNumber = Val(txtHasil.Text)

        txtHasil.Text = "0"

        ArithmeticProcess = "*"

    End Sub


    Private Sub btnKurang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKurang.Click

        FirstNumber = Val(txtHasil.Text)

        txtHasil.Text = "0"

        ArithmeticProcess = "-"

    End Sub


    Private Sub btnTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTambah.Click

        FirstNumber = Val(txtHasil.Text)

        txtHasil.Text = "0"

        ArithmeticProcess = "+"

    End Sub


    Private Sub btnHasil_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHasil.Click

        SecondNumber = Val(txtHasil.Text)

        If ArithmeticProcess = "+" Then

            AnswerNumber = FirstNumber + SecondNumber

        End If

        If ArithmeticProcess = "-" Then

            AnswerNumber = FirstNumber - SecondNumber

        End If

        If ArithmeticProcess = "*" Then

            AnswerNumber = FirstNumber * SecondNumber

        End If

        If ArithmeticProcess = "/" Then

            AnswerNumber = FirstNumber / SecondNumber

        End If

        txtHasil.Text = AnswerNumber

    End Sub


    

End Class

==============================================
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.txtHasil = New System.Windows.Forms.TextBox()
        Me.btn7 = New System.Windows.Forms.Button()
        Me.btn8 = New System.Windows.Forms.Button()
        Me.btn9 = New System.Windows.Forms.Button()
        Me.btnBagi = New System.Windows.Forms.Button()
        Me.btn4 = New System.Windows.Forms.Button()
        Me.btn5 = New System.Windows.Forms.Button()
        Me.btn6 = New System.Windows.Forms.Button()
        Me.btnKali = New System.Windows.Forms.Button()
        Me.btn1 = New System.Windows.Forms.Button()
        Me.btn2 = New System.Windows.Forms.Button()
        Me.btn3 = New System.Windows.Forms.Button()
        Me.btnKurang = New System.Windows.Forms.Button()
        Me.btn0 = New System.Windows.Forms.Button()
        Me.btnCE = New System.Windows.Forms.Button()
        Me.btnTambah = New System.Windows.Forms.Button()
        Me.btnHasil = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'txtHasil
        '
        Me.txtHasil.Font = New System.Drawing.Font("Arial", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtHasil.Location = New System.Drawing.Point(29, 9)
        Me.txtHasil.Multiline = True
        Me.txtHasil.Name = "txtHasil"
        Me.txtHasil.Size = New System.Drawing.Size(231, 38)
        Me.txtHasil.TabIndex = 0
        Me.txtHasil.Text = "0"
        Me.txtHasil.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'btn7
        '
        Me.btn7.Location = New System.Drawing.Point(29, 65)
        Me.btn7.Name = "btn7"
        Me.btn7.Size = New System.Drawing.Size(38, 34)
        Me.btn7.TabIndex = 4
        Me.btn7.Text = "7"
        Me.btn7.UseVisualStyleBackColor = True
        '
        'btn8
        '
        Me.btn8.Location = New System.Drawing.Point(91, 65)
        Me.btn8.Name = "btn8"
        Me.btn8.Size = New System.Drawing.Size(38, 34)
        Me.btn8.TabIndex = 5
        Me.btn8.Text = "8"
        Me.btn8.UseVisualStyleBackColor = True
        '
        'btn9
        '
        Me.btn9.Location = New System.Drawing.Point(155, 65)
        Me.btn9.Name = "btn9"
        Me.btn9.Size = New System.Drawing.Size(38, 34)
        Me.btn9.TabIndex = 6
        Me.btn9.Text = "9"
        Me.btn9.UseVisualStyleBackColor = True
        '
        'btnBagi
        '
        Me.btnBagi.ForeColor = System.Drawing.Color.Red
        Me.btnBagi.Location = New System.Drawing.Point(222, 65)
        Me.btnBagi.Name = "btnBagi"
        Me.btnBagi.Size = New System.Drawing.Size(38, 34)
        Me.btnBagi.TabIndex = 7
        Me.btnBagi.Text = "/"
        Me.btnBagi.UseVisualStyleBackColor = True
        '
        'btn4
        '
        Me.btn4.Location = New System.Drawing.Point(29, 117)
        Me.btn4.Name = "btn4"
        Me.btn4.Size = New System.Drawing.Size(38, 34)
        Me.btn4.TabIndex = 9
        Me.btn4.Text = "4"
        Me.btn4.UseVisualStyleBackColor = True
        '
        'btn5
        '
        Me.btn5.Location = New System.Drawing.Point(91, 117)
        Me.btn5.Name = "btn5"
        Me.btn5.Size = New System.Drawing.Size(38, 34)
        Me.btn5.TabIndex = 10
        Me.btn5.Text = "5"
        Me.btn5.UseVisualStyleBackColor = True
        '
        'btn6
        '
        Me.btn6.Location = New System.Drawing.Point(155, 117)
        Me.btn6.Name = "btn6"
        Me.btn6.Size = New System.Drawing.Size(38, 34)
        Me.btn6.TabIndex = 11
        Me.btn6.Text = "6"
        Me.btn6.UseVisualStyleBackColor = True
        '
        'btnKali
        '
        Me.btnKali.ForeColor = System.Drawing.Color.Red
        Me.btnKali.Location = New System.Drawing.Point(222, 117)
        Me.btnKali.Name = "btnKali"
        Me.btnKali.Size = New System.Drawing.Size(38, 34)
        Me.btnKali.TabIndex = 12
        Me.btnKali.Text = "*"
        Me.btnKali.UseVisualStyleBackColor = True
        '
        'btn1
        '
        Me.btn1.Location = New System.Drawing.Point(29, 169)
        Me.btn1.Name = "btn1"
        Me.btn1.Size = New System.Drawing.Size(38, 34)
        Me.btn1.TabIndex = 14
        Me.btn1.Text = "1"
        Me.btn1.UseVisualStyleBackColor = True
        '
        'btn2
        '
        Me.btn2.Location = New System.Drawing.Point(91, 169)
        Me.btn2.Name = "btn2"
        Me.btn2.Size = New System.Drawing.Size(38, 34)
        Me.btn2.TabIndex = 15
        Me.btn2.Text = "2"
        Me.btn2.UseVisualStyleBackColor = True
        '
        'btn3
        '
        Me.btn3.Location = New System.Drawing.Point(155, 169)
        Me.btn3.Name = "btn3"
        Me.btn3.Size = New System.Drawing.Size(38, 34)
        Me.btn3.TabIndex = 16
        Me.btn3.Text = "3"
        Me.btn3.UseVisualStyleBackColor = True
        '
        'btnKurang
        '
        Me.btnKurang.ForeColor = System.Drawing.Color.Red
        Me.btnKurang.Location = New System.Drawing.Point(222, 169)
        Me.btnKurang.Name = "btnKurang"
        Me.btnKurang.Size = New System.Drawing.Size(38, 34)
        Me.btnKurang.TabIndex = 17
        Me.btnKurang.Text = "-"
        Me.btnKurang.UseVisualStyleBackColor = True
        '
        'btn0
        '
        Me.btn0.Location = New System.Drawing.Point(29, 221)
        Me.btn0.Name = "btn0"
        Me.btn0.Size = New System.Drawing.Size(38, 34)
        Me.btn0.TabIndex = 19
        Me.btn0.Text = "0"
        Me.btn0.UseVisualStyleBackColor = True
        '
        'btnCE
        '
        Me.btnCE.Location = New System.Drawing.Point(91, 221)
        Me.btnCE.Name = "btnCE"
        Me.btnCE.Size = New System.Drawing.Size(38, 34)
        Me.btnCE.TabIndex = 21
        Me.btnCE.Text = "CE"
        Me.btnCE.UseVisualStyleBackColor = True
        '
        'btnTambah
        '
        Me.btnTambah.ForeColor = System.Drawing.Color.Red
        Me.btnTambah.Location = New System.Drawing.Point(222, 221)
        Me.btnTambah.Name = "btnTambah"
        Me.btnTambah.Size = New System.Drawing.Size(38, 34)
        Me.btnTambah.TabIndex = 22
        Me.btnTambah.Text = "+"
        Me.btnTambah.UseVisualStyleBackColor = True
        '
        'btnHasil
        '
        Me.btnHasil.ForeColor = System.Drawing.Color.Blue
        Me.btnHasil.Location = New System.Drawing.Point(155, 221)
        Me.btnHasil.Name = "btnHasil"
        Me.btnHasil.Size = New System.Drawing.Size(38, 34)
        Me.btnHasil.TabIndex = 23
        Me.btnHasil.Text = "="
        Me.btnHasil.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(280, 282)
        Me.Controls.Add(Me.btnHasil)
        Me.Controls.Add(Me.btnTambah)
        Me.Controls.Add(Me.btnCE)
        Me.Controls.Add(Me.btn0)
        Me.Controls.Add(Me.btnKurang)
        Me.Controls.Add(Me.btn3)
        Me.Controls.Add(Me.btn2)
        Me.Controls.Add(Me.btn1)
        Me.Controls.Add(Me.btnKali)
        Me.Controls.Add(Me.btn6)
        Me.Controls.Add(Me.btn5)
        Me.Controls.Add(Me.btn4)
        Me.Controls.Add(Me.btnBagi)
        Me.Controls.Add(Me.btn9)
        Me.Controls.Add(Me.btn8)
        Me.Controls.Add(Me.btn7)
        Me.Controls.Add(Me.txtHasil)
        Me.Name = "Form1"
        Me.Text = "Kalkulator"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents txtHasil As System.Windows.Forms.TextBox
    Friend WithEvents btn7 As System.Windows.Forms.Button
    Friend WithEvents btn8 As System.Windows.Forms.Button
    Friend WithEvents btn9 As System.Windows.Forms.Button
    Friend WithEvents btnBagi As System.Windows.Forms.Button
    Friend WithEvents btn4 As System.Windows.Forms.Button
    Friend WithEvents btn5 As System.Windows.Forms.Button
    Friend WithEvents btn6 As System.Windows.Forms.Button
    Friend WithEvents btnKali As System.Windows.Forms.Button
    Friend WithEvents btn1 As System.Windows.Forms.Button
    Friend WithEvents btn2 As System.Windows.Forms.Button
    Friend WithEvents btn3 As System.Windows.Forms.Button
    Friend WithEvents btnKurang As System.Windows.Forms.Button
    Friend WithEvents btn0 As System.Windows.Forms.Button
    Friend WithEvents btnCE As System.Windows.Forms.Button
    Friend WithEvents btnTambah As System.Windows.Forms.Button
    Friend WithEvents btnHasil As System.Windows.Forms.Button

End Class
===================================

VB HitungNilaiUjian

 Module HitungNilaiUjian

    'Buka HitungNilaiUjian.vbproj

    Sub Main()

        Dim nilaiIndeks As Char

        Dim nilaiUTS As Single, nilaiUAS As Single, nilaiAkhir As Single

        nilaiUTS = InputBox("Masuk nilai UTS:")

        nilaiUAS = InputBox("Masuk nilai UAS:")

        Debug.Print("Nilai UTS = " & nilaiUTS)

        Debug.Print("Nilai UAS = " & nilaiUAS)

        'Rumus untuk hitung nilai akhir ujian

        nilaiAkhir = (0.4 * nilaiUTS) + (0.6 * nilaiUAS)

        'Mengkonversi ke nilai abjad

        If (nilaiAkhir >= 80) Then

            nilaiIndeks = "A"

        ElseIf (nilaiAkhir >= 70) Then

            nilaiIndeks = "B"

        ElseIf (nilaiAkhir >= 50) Then

            nilaiIndeks = "C"

        ElseIf (nilaiAkhir >= 30) Then

            nilaiIndeks = "D"

        Else  '(nilaiAkhir < 30)

            nilaiIndeks = "E"

        End If


        Debug.Print("Nilai Akhir = " & nilaiAkhir)

        Debug.Print("Nilai Abjab = " & nilaiIndeks)


    End Sub


End Module


VB HitungLuasLingkaran

 Module HitungLuasLingkaran


    'Buka HitungLuasLingkaran.vbproj

    Function HitungLuasLingkaran(ByVal radius As Double)

        Const pi = 3.142

        HitungLuasLingkaran = pi * radius * radius

    End Function


    Sub Main()

        Dim radius As Double, luas As Double

        'Terima input

        radius = InputBox("Masukkan radius: ")

        'Hitung luas lingkaran

        luas = HitungLuasLingkaran(radius)

        'Tampil pada screen

        MsgBox("Luas Lingkaran = " & luas)

    End Sub


End Module


VB HitungJmlhFaktorial

 Module HitungJmlhFaktorial

    'Buka HitungJmlhFaktorial.vbproj

    Sub Main()

        Dim a, b, c, x, fact As Integer

        a = 0 : b = 0 : c = 1 : fact = 1

        x = InputBox("Masuk jumlah utk hitung: ")

        For a = 1 To x

            fact = 1 : c = a

            Do While (c >= 1)

                fact = fact * c : c = c - 1

            Loop

            b = b + fact

        Next a

        Debug.Print("Jumlah Factorial " & (a - 1) & "! = " & b)

    End Sub


End Module


VB HitungJmlhBilangan

 Module HitungJmlhBilangan

    'Buka HitungJmlhBilangan.vproj

    Sub Main()

        Dim i As Integer, x As Integer, hasil As Integer

        hasil = 0

        x = InputBox("Masuk jumlah bilangan: ")

        For i = 1 To x

            hasil = hasil + i

            If (i <> x) Then

                Debug.Print(i & " + " & vbNullChar)

            Else

                Debug.Print(i & " = " & vbNullChar)

            End If

        Next i

        Debug.Print(hasil)

    End Sub

End Module


VB HitungGajiBersih

 Module HitungGajiBersih

    'Buka HitungGajiBersih.vbproj


    Sub Main()

        Const cnTJ1 = 1000 : Const cnTJ2 = 750

        Const cnTJ3 = 500 : Const cnTJ4 = 250

        Const cnTM1 = 500 : Const cnTM2 = 200

        Const cnTM3 = 100 : Const cnTM4 = 0

        Dim tingkat As Integer, basic As Single, tjn As Single, gross As Single, pajak As Single, net As Single

        tingkat = InputBox("Masuk Tingkat Jbtn: ")

        basic = InputBox("Masukkan Gaji pokok: ")

        Select Case (tingkat)

            Case 1

                tjn = cnTJ1 + cnTM1

            Case 2

                tjn = cnTJ2 + cnTM2

            Case 3

                tjn = cnTJ3 + cnTM3

            Case 4

                tjn = cnTJ4 + cnTM4

            Case Else

                MsgBox("Tidak ada tingkat jabatan yang dipilih", vbCritical, "Pesan")

                Debug.Print("Rincian tidak tersedia utk tingkat: " & tingkat) : GoTo Akhir

        End Select


        gross = basic + tjn


        If (gross <= 2000) Then

            pajak = 0

        ElseIf (gross <= 4000) Then

            pajak = gross * 0.03

        ElseIf (gross <= 5000) Then

            pajak = gross * 0.05

        Else

            pajak = gross * 0.08

        End If


        net = gross - pajak


        Debug.Print("Tingkat Jabatan: " & tingkat)

        Debug.Print("Jumlah Tunjungan terima: " & tjn)

        Debug.Print("Gaji pokok: " & basic)

        Debug.Print("Pajak dikenakan: " & pajak)

        Debug.Print("Gaji bersih sesudah pajak: " & net)

Akhir:

    End Sub

End Module


VB HitungFaktorial

 Module HitungFaktorial

    'Buka HitungFaktorial.vbproj

    Sub Main()

        Dim bilangan As Integer, hasil As Integer, i As Integer

        bilangan = InputBox("Masuk bilangan ingin: ")

        hasil = 1 : i = bilangan

        Debug.Print(bilangan & "! = " & vbNullChar)

        'iterasi untuk menampilkan urutan bilangan dalam faktorial

        Do While (i >= 1)

            Debug.Print(i & vbNullChar)

            If (i <> 1) Then

                Debug.Print(" x " & vbNullChar)

            Else

                Debug.Print(" = " & vbNullChar)

            End If

            hasil = hasil * i : i = i - 1

        Loop

        'Tampilkan akhir hasil dari faktorial

        Debug.Print(hasil)

    End Sub

End Module


VB HitungNilaiMasaDepan

 Public Class HitungNilaiMasaDepan


    Private Sub btnHitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHitung.Click

        Dim setoranBln As Decimal = CDec(txtSetoranBln.Text)

        Dim bunga As Integer = CDec(txtBunga.Text)

        Dim tahun As Integer = CInt(txtTahun.Text)


        Dim bungaBln As Decimal = bunga / 12 / 100

        Dim bulan As Integer = tahun * 12


        Dim nilaiMasaDepan As Decimal = Me.NilaiMasaDepan(setoranBln, bungaBln, bulan)

        txtNilaiMasaDepan.Text = FormatCurrency(nilaiMasaDepan)

        txtSetoranBln.Select()

    End Sub


    Private Function NilaiMasaDepan(ByVal setoranBln As Decimal, ByVal bungaBln As Decimal, ByVal Bulan As Integer) As Decimal

        NilaiMasaDepan = 0

        For i As Integer = 1 To Bulan

            NilaiMasaDepan = (NilaiMasaDepan + setoranBln) * (1 + bungaBln)

        Next

        Return NilaiMasaDepan

    End Function


    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

        Me.Close()

    End Sub

End Class


VB HitungLuas

 Module HitungLuas

    'Buka Hitung Luas Lingkaran.vbproj

    Sub HitungLuas(ByVal radius As Double)

        Dim luas As Double

        Const pi = 3.142

        luas = pi * radius * radius

        'Tampil pada screen

        MsgBox("Luas Lingkaran1 = " & luas)

    End Sub


    Sub Main()

        Dim radius As Double, luas As Double

        'Terima input

        radius = InputBox("Masukkan radius: ")

        'Hitung luas lingkaran

        Call HitungLuas(radius)

        MsgBox("Luas Lingkaran2 = " & luas)

    End Sub

End Module


VB HitungFaktur

 Public Class frmHitungFaktur


    Private Sub btnHitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHitung.Click

        Dim subTotal As Decimal = CDec(txtSubTotal.Text)

        Dim diskonPercent As Decimal = 0.25D

        Dim diskonDollar As Decimal = subTotal * diskonPercent

        Dim total As Decimal = subTotal - diskonDollar


        txtDiskonPercent.Text = FormatPercent(diskonPercent, 1)

        txtDiskonDollar.Text = FormatCurrency(diskonDollar)

        txtTotal.Text = FormatCurrency(total)


        txtSubTotal.Select()

    End Sub


    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

        Close()

    End Sub


End Class


VB EvaluasiTipeData

 Module EvaluasiTipeData

    'Buka EvaluasiTipeData.vbproj

    Sub Main()

        Dim testVarType As VariantType

        testVarType = Nothing

        Debug.Print("Tipe variabel = " & VarType(testVarType))

        testVarType = ""

        Debug.Print("Tipe variabel = " & VarType(testVarType))

        testVarType = 12345

        Debug.Print("Tipe variabel = " & VarType(testVarType))

        testVarType = 12345.678

        Debug.Print("Tipe variabel = " & VarType(testVarType))

        testVarType = "Visual Basic"

        Debug.Print("Tipe variabel = " & VarType(testVarType))

        testVarType = #8/1/1973#

        Debug.Print("Tipe variabel = " & VarType(testVarType))

    End Sub

End Module


VB DemoWhileWend3

 Module DemoWhileWend3

    'Buka DemoWhileWend3

    Sub Main()

        Dim status As Boolean, a As Integer

        status = True : a = 1

        While (status = True)

            Debug.Print(a & " " & vbNullChar)

            a = a + 1

            If a > 10 Then

                status = False

            End If

        End While

    End Sub

End Module


VB DemoWhileWend2

 Module DemoWhileWend2

    'Buka DemoWhileWend2.vbproj

    Sub Main()

        Dim a As Integer, Jwb As Char

        a = 1 : Jwb = "Y"


        While (Jwb = "Y" Or Jwb = "y")

            Debug.Print("Loop ke- " & a)

            a = a + 1

            Jwb = InputBox("Ingin coba lagi (Y/N)")

        End While

    End Sub

End Module


VB DemoWhileWend1

 Module DemoWhileWend1

    'Buka DemoWhileWend1.vbproj

    Sub Main()

        Dim a As Integer

        a = 1  'inisialisasi

        While a <= 10

            Debug.Print(a & " " & vbNullChar)

            a = a + 1  'iterasi

        End While

    End Sub

End Module


VB DemoStop

 Module DemoStop

    'Buka DemoStop.vbproj


    Sub Main()

        Dim a As Integer

        For a = 1 To 10

            Debug.Print(a & " " & vbNullChar)

            Stop

        Next a

    End Sub


End Module


VB DemoSelect2

 Module DemoSelect2

    'Buka DemoSelect2.vbproj

    Sub Main()

        Dim Angka As Integer


        Angka = InputBox("Masuk satu angka: ")

        Debug.Print("Angka = " & Angka)

        Select Case Angka

            Case Is < 0

                Debug.Print("Angka negatif")

            Case 1

                Debug.Print("Angka 1")

            Case 2 To 5

                Debug.Print("Angka 2 s/d 5")

            Case 6, 8, 10

                Debug.Print("Angka 6, 8 atau 10")

            Case 12, 14, 16 To 20, 25 To 30

                Debug.Print("Angka 12, 14, 16 s/d 20, 25 s/d 30")

            Case Else

                Debug.Print("Angka Lain-lain")

        End Select

    End Sub

End Module


VB DemoSelect1

 Module DemoSelect1

    'Buka DemoSelect1.vbproj

    Sub Main()

        Dim noHari As Integer

        noHari = InputBox("Ketik nomor hari:")

        Select Case (noHari)

            Case 1

                Debug.Print("Hari ke-" & noHari & " = Senin")

            Case 2

                Debug.Print("Hari ke-" & noHari & " = Selasa")

            Case 3

                Debug.Print("Hari ke-" & noHari & " = Rabu")

            Case 4

                Debug.Print("Hari ke-" & noHari & " = Kamis")

            Case 5

                Debug.Print("Hari ke-" & noHari & " = Jumat")

            Case 6

                Debug.Print("Hari ke-" & noHari & " = Sabtu")

            Case 7

                Debug.Print("Hari ke-" & noHari & " = Minggu")

            Case Else

                Debug.Print("Tidak ada hari ke-" & noHari)

        End Select

    End Sub

End Module


DemoOnErrorResumeNext2

 Module DemoOnErrorResumeNext2

    'Buka DemoOnErrorResumeNext2.vbproj

    Sub Main()

        On Error Resume Next

        Dim a, b, c As Integer


        'Inisialisasi variabel

        a = 1 : b = "Satu"""

        c = a + b

        Debug.Print("Nilai a + b = " & c)

        Debug.Print("Selesai")

    End Sub

End Module


VB DemoOnErrorResumeNext1

 Module DemoOnErrorResumeNext1

    'Buka DemoOnErrorResumeNext1.vbproj

    Sub Main()

        Dim a, b, c As Integer

        a = 1 : b = "Satu"

        c = a + b

        Debug.Print("Nilai a + b = " & c)

        Debug.Print("Selesai")

    End Sub


End Module


VB DemoOnErrorGoto

 Module DemoOnErrorGoto

    'Buka DemoOnErrorGoto.vbproj

    Sub Main()

        On Error GoTo ErrorHandler

        Dim a, b, c

        'Inisialisasi variabel

        a = 1 : b = "Satu"

        c = a + b

        Debug.Print("Nilai a + b = " & c)

        Exit Sub

ErrorHandler:

        MsgBox("Salah - Type Mismatch")

        Resume Next

    End Sub


End Module


VB DemoIif

 Module DemoIif

    'Buka DemoIif.vbproj

    Sub Main()

        Dim Kelamin As Char, Status As Char

        Kelamin = InputBox("Jenis Kelamin (L/P): ")

        Status = IIf(Kelamin = "L" Or Kelamin = "l", "Lelaki", "Perempuan")

        Debug.Print("Jenis Kelamin: " & Status)

    End Sub


End Module


VB DemoIfTigaKondisi

 Module DemoIfTigaKondisi

    'Buka DemoIfTigaKondisi.vbproj

    Sub Main()

        Dim bilangan As Integer


        bilangan = InputBox("Masukkan bilangan: ")

        If (bilangan < 0) Then

            Debug.Print(bilangan & " adalah bilangan NEGATIF")

        ElseIf (bilangan = 0) Then

            Debug.Print(bilangan & " adalah NOL")

        Else

            Debug.Print(bilangan & " adalah bilangan POSITIF")

        End If

    End Sub


End Module


VB DemoIfSatuKondisi2

 Module DemoIfSatuKondisi2

    'Buka DemoIfSatuKondisi2.vbproj


    Sub Main()

        Dim nilaiUAS As Integer


        nilaiUAS = InputBox("Masuk nilai UAS: ")

        Debug.Print("Nilai UAS: " & nilaiUAS)


        If (nilaiUAS >= 50) Then

            Debug.Print("Lulus UAS")

        End If

    End Sub


End Module


VB DemoIfSatuKondisi1

 Module DemoIfSatuKondisi1

    'Buka proyek DemoIfSatuKondisi1.vbproj


    Sub Main()

        Dim a As Integer, b As Integer


        a = 7 : b = 10

        Debug.Print("Nilai a = " & a)

        Debug.Print("Nilai b = " & b)


        If (a < b) Then

            Debug.Print("Nilai a < b")

        End If

    End Sub


End Module


VB DemoIfDuaKondisi

 Module DemoIfDuaKondisi

    'Buka DemoIfDuaKondisivbproj

    Sub Main()

        Dim nilaiUAS As Integer

        'nilaiUAS = InputBox("Masuk nilai UAS: ")

        Debug.Print("Nilai UAS: " & nilaiUAS)


        If (nilaiUAS >= 50) Then

            Debug.Print("Lulus UAS")

        Else

            Debug.Print("Gagal UAS")

        End If

    End Sub


End Module


VB DemoGoTo

 Module DemoGoTo

    'Buka DemoGoTo.vbproj

    Sub Main()

        Dim number As Integer, myString As String

        number = InputBox("Masuk nomor (1/2)")


        ' Evaluasi nomor dan loncat ke label yang terkait

        If number = 1 Then GoTo Line1 Else GoTo Line2


Line1:

        myString = "Nomor = 1"

        GoTo LastLine    ' Loncat ke label LastLine

Line2:

        myString = "Nomor = 2 (atau lain-lain)"

LastLine:

        Debug.Print(myString)


    End Sub


End Module


VB DemoFor2

 Module DemoFor2

    'Buka DemoFor2.vbproj

    Sub Main()

        'For bersarang

        Dim a As Integer, b As Integer

        For a = 1 To 5

            For b = a To 5

                Debug.Print(b & " " & vbNullChar) 'nilai b pada baris sama

            Next b

            Debug.Print("")

        Next a

    End Sub

End Module


VB DemoFor1

Module DemoFor1
    'Buka DemoFor1.vbproj
    Sub Main()
        Dim a As Integer, b As Integer
        For a = 1 To 10
            Debug.Print(a & " " & vbNullChar)  'nilai a pada haris yg sama
        Next a
        Debug.Print("")     'tampilkan baris kosong
        'Menggunakan STEP
        For b = 10 To 1 Step -1
            Debug.Print(b & " " & vbNullChar) 'nilai b pada baris yg sama
        Next b
    End Sub
End Module

VB DemoExit

 Module DemoExit

    'Buka DemoExit.vbproj

    Sub Main()

        Dim a As Integer

        For a = 1 To 10

            Debug.Print(a & " " & vbNullChar)

            If a > 5 Then

                Exit For  'keluar dari For

            End If

        Next a

    End Sub

End Module


VB DemoDoWhileDoLoop

 Module DemoDoWhileDoLoop

    'Buka DemoDoWhileDoLoop.vbproj

    Sub Main()

        Dim a As Integer

        'Contoh Do While/Loop

        a = 6

        Do While (a < 5)

            Debug.Print("Do While..Loop - " & a)

            a = a + 1

        Loop

        'Contoh Do/Loop While

        a = 6

        Do

            Debug.Print("Do..Loop While - " & a)

            a = a + 1

        Loop While (a < 5)

    End Sub


End Module


VB DemoDoWhile

 Module DemoDoWhile

    'Buka DemoDoWhile.vbproj


    Sub Main()

        Dim a As Integer

        a = 1  'inisialisasi

        Do While (a <= 10)

            Debug.Print(a & " " & vbNullChar)

            a = a + 1 'iterasi

        Loop

    End Sub


End Module


VB DemoDoLoop

 Module DemoDoLoop

    'Buka DemoDoLoop.vbproj

    Sub Main()

        Dim a As Integer

        a = 1  'inisialisasi

        Do

            Debug.Print(a & " " & vbNullChar)

            a = a + 1  'iterasi

        Loop While (a <= 10)

    End Sub

End Module


VB CaturWulan

 Module CaturWulan

    'Buka CaturWulan.vbproj

    Sub Main()

        Dim bulan As String, Caturwulan As String, noBulan As Integer

        noBulan = InputBox("Ketik no bulan: ")

        Select Case (noBulan)

            Case 1 : bulan = "Jan"

            Case 2 : bulan = "Feb"

            Case 3 : bulan = "Mar"

            Case 4 : bulan = "Apr"

            Case 5 : bulan = "Mei"

            Case 6 : bulan = "Jun"

            Case 7 : bulan = "Jul"

            Case 8 : bulan = "Agu"

            Case 9 : bulan = "Sep"

            Case 10 : bulan = "Okt"

            Case 11 : bulan = "Nop"

            Case 12 : bulan = "Des"

            Case Else : Debug.Print("Tidak ada bulan ke-" & noBulan)

        End Select


        Select Case (noBulan)

            Case 1 To 4 : Caturwulan = "I"

            Case 5 To 8 : Caturwulan = "II"

            Case 9 To 12 : Caturwulan = "III"

            Case Else : Debug.Print("Tidak ada Caturwulan yang terkait") : GoTo Akhir

        End Select


        Debug.Print("Bulan ke-" & noBulan & " (" & bulan & ") masuk ke caturwulan-" & Caturwulan)

Akhir:

    End Sub

End Module


VB CariAngkaPalingBesar

 Module CariAngkaPalingBesar

    'Buka CariAngkaPalingBesar.vbproj

    Sub Main()

        Dim a As Long, b As Long, c As Long

        a = InputBox("Masuk nilai ke-1:")

        b = InputBox("Masuk nilai ke-2:")

        c = InputBox("Masuk nilai ke-3:")

        Debug.Print("Nilai a = " & a)

        Debug.Print("Nilai b = " & b)

        Debug.Print("Nilai c = " & c)

        If (a > b) And (a > c) Then

            Debug.Print("Nilai terbesar = " & a)

        ElseIf b > c Then

            Debug.Print("Nilai terbesar = " & b)

        Else

            Debug.Print("Nilai terbesar = " & c)

        End If

    End Sub


End Module


JAVA DEMO ANIMASI TEKS

  import java.awt.*;

 import java.awt.event.*;

 import javax.swing.*;


 public class DemoAnimasi extends JFrame {

 public DemoAnimasi() {

 // Menciptakan suatu PanelPesanBergerak untuk menampilkan suatu pesan bergerak

 add(new PanelPesanBergerak("Pesan bergerak?"));

 }


 /** Metode utama */

 public static void main(String[] args) {

 DemoAnimasi frame = new DemoAnimasi();

 frame.setTitle("DemoAnimasi");

 frame.setSize(280, 100);

 frame.setLocationRelativeTo(null); // Pusat frame

 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 frame.setVisible(true);

 }


 // Kelas inner: Menampilkan suatu pesan bergerak

 static class PanelPesanBergerak extends JPanel {

 private String pesan = "JAVA itu Tangguh!";

 private int xKoordinat = 0;

 private int yKoordinat = 20;


 public PanelPesanBergerak(String pesan) {

 this.pesan = pesan;


 // Menciptakan suatu timer

 Timer timer = new Timer(1000, new TimerListener());

 timer.start();

 }


 /** Menggambar pesan */

 protected void paintComponent(Graphics g) {

 super.paintComponent(g);


 if (xKoordinat > getWidth()) {

 xKoordinat = -20;

 }

 xKoordinat += 5;

 g.drawString(pesan, xKoordinat, yKoordinat);

 }


 class TimerListener implements ActionListener {

 /** Menangani ActionEvent */

 public void actionPerformed(ActionEvent e) {

 repaint();

 }

 }

 }

 }

JAVA class AbstractGraph

  import java.util.*;


 public abstract class AbstractGraph<V> implements Graph<V> {

 protected List<V> verteks; // Menyimpan verteks-verteks

 protected List<List<Integer>> tetangga; // List kebertetanggaan


 /** Menciptakan suatu graf dari semua tepi dan verteks yang disimpan di dalam array */

 protected AbstractGraph(int[][] tepi, V[] verteks) {

 this.verteks = new ArrayList<V>();

 for (int i = 0; i < verteks.length; i++)

 this.verteks.add(verteks[i]);


 createAdjacencyLists(tepi, verteks.length);

 }


 /** Menciptakan suatu graf dari semua tepi dan verteks yang disimpan di dalam List */

 protected AbstractGraph(List<Edge> tepi, List<V> verteks) {

 this.verteks = verteks;

 createAdjacencyLists(tepi, verteks.size());

 }


 /** Menciptakan suatu graf untuk verteks-verteks integer 0, 1, 2 dan list tepi */

 protected AbstractGraph(List<Edge> tepi, int jumlahVerteks) {

 verteks = new ArrayList<V>(); // Menciptakan verteks

 for (int i = 0; i < jumlahVerteks; i++) {

 verteks.add((V)(new Integer(i))); // verteks adalah {0, 1, ...}

 }

 createAdjacencyLists(tepi, jumlahVerteks);

 }


 /** Menciptakan suatu graf dari verteks-verteks integer 0, 1, dan array tepi */

 protected AbstractGraph(int[][] tepi, int jumlahVerteks) {

 verteks = new ArrayList<V>(); // Menciptakan verteks

 for (int i = 0; i < jumlahVerteks; i++) {

 verteks.add((V)(new Integer(i))); // verteks adalah {0, 1, ...}

 }

 createAdjacencyLists(tepi, jumlahVerteks);

 }


 /** Menciptakan list kebertetanggaan untuk setiap verteks */

 private void createAdjacencyLists(

 int[][] tepi, int jumlahVerteks) {

 // Menciptakan suatu list berantai

 tetangga = new ArrayList<List<Integer>>();

 for (int i = 0; i < jumlahVerteks; i++) {

 tetangga.add(new ArrayList<Integer>());

 }


 for (int i = 0; i < tepi.length; i++) {

 int u = tepi[i][0];

 int v = tepi[i][1];

 tetangga.get(u).add(v);

 }

 }


 /** Menciptakan list kebertetanggaaan untuk setiap verteks */

 private void createAdjacencyLists(

 List<Edge> tepi, int jumlahVerteks) {

 // Menciptakan suatu list berantai

 tetangga = new ArrayList<List<Integer>>();

 for (int i = 0; i < jumlahVerteks; i++) {

 tetangga.add(new ArrayList<Integer>());

 }


 for (Edge tepi1: tepi) {

 tetangga.get(tepi1.u).add(tepi1.v);

 }

 }


 /** Mengembalikan jumlah verteks di dalam graf */

 public int getSize() {

 return verteks.size();

 }


 /** Mengembalikan verteeks-verteks di dalam graf */

 public List<V> getVertices() {

 return verteks;

 }


 /** Mengembalikan objek untuk verteks tertentu */

 public V getVertex(int indeks) {

 return verteks.get(indeks);

 }


 /** Mengembalikan indeks untuk objek verteks tertentu */

 public int getIndex(V v) {

 return verteks.indexOf(v);

 }


 /** Mengembalikan tetangga-tetangga verteks dengan indeks tertentu */

 public List<Integer> getNeighbors(int indeks) {

 return tetangga.get(indeks);

 }


 /** Mengembalikan derajat untuk verteks tertentu */

 public int getDegree(int v) {

 return tetangga.get(v).size();

 }


 /** Mengembalikan matriks kebertetanggaan */

 public int[][] getAdjacencyMatrix() {

 int[][] matriksKebertetanggaan = new int[getSize()][getSize()];


 for (int i = 0; i < tetangga.size(); i++) {

 for (int j = 0; j < tetangga.get(i).size(); j++) {

 int v = tetangga.get(i).get(j);

 matriksKebertetanggaan[i][v] = 1;

 }

 }


 return matriksKebertetanggaan;

 }


 /** Menampilkan matriks kebertetanggaan */

 public void printAdjacencyMatrix() {

 int[][] matriksKebertetanggaan = getAdjacencyMatrix();

 for (int i = 0; i < matriksKebertetanggaan.length; i++) {

 for (int j = 0; j < matriksKebertetanggaan[0].length; j++) {

 System.out.print(matriksKebertetanggaan[i][j] + " ");

 }


 System.out.println();

 }

 }


 /** Menampilkan semua tepi */

 public void printEdges() {

 for (int u = 0; u < tetangga.size(); u++) {

 System.out.print("Verteks " + u + ": ");

 for (int j = 0; j < tetangga.get(u).size(); j++) {

 System.out.print("(" + u + ", " +

 tetangga.get(u).get(j) + ") ");

 }

 System.out.println();

 }

 }


 /** Edge sebagai kelas inner di dalam kelas AbstractGraph */

 public static class Edge {

 public int u; // Verteks awal dari tepi

 public int v; // Verteks akhir dari tepi


 /** Menciptakan suatu tepi untuk (u, v) */

 public Edge(int u, int v) {

 this.u = u;

 this.v = v;

 }

 }


 /** Mendapatkan suatu pohon DFS mulai dari vertkes v */

 /** Akan didiskusikan pada bagian 12.6 */

 public Tree dfs(int v) {

 List<Integer> urutanPencarian = new ArrayList<Integer>();

 int[] orangtua = new int[verteks.size()];

 for (int i = 0; i < orangtua.length; i++)

 orangtua[i] = -1; // Menginisialisasi orangtua[i] dengan -1


 // Menandai verteks yang dikunjungi

 boolean[] isVisited = new boolean[verteks.size()];


 // Mencari secara rekursif

 dfs(v, orangtua, urutanPencarian, isVisited);


 // Menghasilkan suatu pohon pencarian

 return new Tree(v, orangtua, urutanPencarian);

 }


 /** Metode rekursif untuk pencarian DFS */

 private void dfs(int v, int[] orangtua, List<Integer> urutanPencarian,

 boolean[] isVisited) {

 // Menyimpan verteks yang dikunjungi

 urutanPencarian.add(v);

 isVisited[v] = true; // Verteks v dikunjungi


 for (int i : tetangga.get(v)) {

 if (!isVisited[i]) {

 orangtua[i] = v; // Orangtua dari verteks i adalah v

 dfs(i, orangtua, urutanPencarian, isVisited); // Pencarian rekursif

 }

 }

 }


 /** Memulai pencarian bfs dari verteks v */

 /** Akan didiskusikan dalam bagian 12.7 */

 public Tree bfs(int v) {

 List<Integer> urutanPencarian = new ArrayList<Integer>();

 int[] orangtua = new int[verteks.size()];

 for (int i = 0; i < orangtua.length; i++)

 orangtua[i] = -1; // Menginisialisasi orangtua[i] dengan -1


 java.util.LinkedList<Integer> antrian =

 new java.util.LinkedList<Integer>(); // list digunakan sebagai suatu antrian

 boolean[] isVisited = new boolean[verteks.size()];

 antrian.offer(v); // Membuat v sebagai antrian

 isVisited[v] = true; // Menandainya karena dikunjungi


 while (!antrian.isEmpty()) {

 int u = antrian.poll(); // Membongkar antrian ke u

 urutanPencarian.add(u); // Mencari u

 for (int w : tetangga.get(u)) {

 if (!isVisited[w]) {

 antrian.offer(w); // // Membuat w sebagai antrian

 orangtua[w] = u; // Orangtua dari w adalah u

 isVisited[w] = true; // Menandainya karena dikunjungi

 }

 }

 }


 return new Tree(v, orangtua, urutanPencarian);

 }


 /** Tree sebagai kelas inner di dalam kelas AbstractGraph */

 /** Akan didiskusikan pada bagian 12.5 */

 public class Tree {

 private int akar; // Akar pohon

 private int[] orangtua; // Menyimpan orangtua untuk setiap verteks

 private List<Integer> urutanPencarian; // Menyimpan urutan pencarian


 /** Menciptakan suatu pohon dengan akar, orangtua, dan urutanPencarian */

 public Tree(int akar, int[] orangtua, List<Integer> urutanPencarian) {

 this.akar = akar;

 this.orangtua = orangtua;

 this.urutanPencarian = urutanPencarian;

 }


 /** Menciptakan suatu pohon dengan akar dan orangtua

   * tanpa urutan yang ditentukan */

 public Tree(int akar, int[] orangtua) {

 this.akar = akar;

 this.orangtua = orangtua;

 }


 /** Mengembalikan akar dari pohon */

 public int getRoot() {

 return akar;

 }


 /** Memuat orangtua dari verteks v */

 public int getParent(int v) {

 return orangtua[v];

 }


 /** Mengembalikan suatu array yang memuat urutan pencarian */

 public List<Integer> getSearchOrders() {

 return urutanPencarian;

 }


 /** Mengembalikan jumlah verteks yang ditemukan */

 public int getNumberOfVerticesFound() {

 return urutanPencarian.size();

 }


 /** Mengembalikan jalur verteks dari suatu indeks verteks ke akar */

 public List<V> getPath(int indeks) {

 ArrayList<V> jalur = new ArrayList<V>();


 do {

 jalur.add(verteks.get(indeks));

 indeks = orangtua[indeks];

 }

 while (indeks != -1);


 return jalur;

 }


 /** Menampilkan suatu jalur dari akar ke verteks v */

 public void printPath(int indeks) {

 List<V> jalur = getPath(indeks);

 System.out.print("Suatu jalur dari " + verteks.get(akar) + " ke " +

 verteks.get(indeks) + ": ");

 for (int i = jalur.size() - 1; i >= 0; i--)

 System.out.print(jalur.get(i) + " ");

 }


 /** Menampilkan keseluruhan pohon */

 public void printTree() {

 System.out.println("Akar adalah: " + verteks.get(akar));

 System.out.print("Tepi-tepi: ");

 for (int i = 0; i < orangtua.length; i++) {

 if (orangtua[i] != -1) {

 // Menampilkan suatu tepi

 System.out.print("(" + verteks.get(orangtua[i]) + ", " +

 verteks.get(i) + ") ");

 }

 }

 System.out.println();

 }

 }

 }


C++ system("pause");

 #include <iostream>

#include <iomanip>

#include <stdio.h>

using namespace std;

int main(){

cout<<"tes";

return 0;

system("pause");

}

C++ Fahrenheit ke Celius

 #include <iostream>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;


int main(int argc, char** argv) {

int celcius;

int fahrenheit;

cout<<"Enter temperature in Fahreheit";

cin>>fahrenheit;

cout<<endl;

celcius=5/9*(fahrenheit-32);

cout<<fahrenheit<<" degree F = "<<celcius<<" degree C "<<endl;

return 0;

}

C++ #include deque 1

 


 

#include <iostream>

#include <deque>           // std::deque

 

int main() {  

   std::deque<int> d(5);

  

   std::cout<<"d.size(): "<<d.size()<<std::endl;

  

   // menentukan nilai elemen-elemen deque

   for (size_t i=0; i<d.size(); i++) {

      d[i] = (i+1) * 10;

   } 

  

   // menampilkan elemen-elemen deque

   std::cout<<"Isi d: ";

   for (size_t i=0; i<d.size(); i++) {

      std::cout<<d[i]<<" ";

   }

  

   return 0;

}

C++ #include array 9

 

#include <iostream>

#include <array> // std::array


int main() {   

   std::array<int, 5> a = {10,20,30,40,50};

   

   for (size_t i=0; i<a.size(); i++) {

      std::cout<<"a.at("<<i<<"): "<<a.at(i)<<std::endl;

   }   

   

   std::cout<<"\na.front(): "<<a.front()<<std::endl;

   std::cout<<"a.back(): "<<a.back()<<std::endl;   

   

   return 0;

}


C++ #include array 8


#include <iostream>

#include <array>              // std::array

 

int main() {  

   std::array<std::string, 4> a = {"C","C++","Python","Ruby"};

  

   std::string s = "C++";    // elemen yang dicari

   int indeks = -1, i=0;

  

   for (auto it = a.begin(); it != a.end(); ++it, i++) {

      if ((*it).compare(s) == 0) {

         indeks = i;        

         break;

      }

   }

  

   if (indeks > -1) {

      std::cout<<s<<" ditemukan pada indeks ke-"<<indeks<<std::endl;

   } else {

      std::cout<<s<<" tidak ditemukan"<<std::endl;

   }

  

   return 0;

}

C++ #include array 7

 

#include <iostream>

#include <array>              // std::array

 

int main() {  

   std::array<std::string, 4> a = {"C","C++","Python","Ruby"};

  

   std::cout<<"Penelusuran maju:"<<std::endl;

   for (auto it = a.begin(); it != a.end(); ++it) {

      std::cout<<*it<<std::endl;

   }  

  

   std::cout<<"\nPenelusuran mundur:"<<std::endl;

   for (auto it = a.rbegin(); it != a.rend(); ++it) {

      std::cout<<*it<<std::endl;

   }

  

   return 0;

}

C++ #include array 6

 

#include <iostream>

#include <array>              // std::array

 

int main() {  

   std::array<std::string, 4> a = {"C","C++","Python","Ruby"};

  

   std::array<std::string,4>::reverse_iterator it;

   for (it = a.rbegin(); it != a.rend(); ++it) {

      std::cout<<*it<<std::endl;

   }

  

   return 0;

}

C++ #include array 5

 

#include <iostream>

#include <array>              // std::array

 

int main() {  

   std::array<std::string, 4> a = {"C","C++","Python","Ruby"};

  

   std::array<std::string,4>::iterator it;

   for (it = a.begin(); it != a.end(); ++it) {

      std::cout<<*it<<std::endl;

   }

  

   return 0;

}

C++ #include array 4

 

#include <iostream>

#include <array>              // std::array

 

int main() {  

   std::array<int, 5> a = {10};

  

   std::array<int,5>::iterator it = a.begin();

   while (it != a.end()) {

      std::cout<<*it<<" ";

      it++;

   }

  

   return 0;

}

C++ #include array 3

 


#include <iostream>

#include <array>              // std::array

 

int main() {  

   std::array<int, 5> a = {10,20,30,40,50};

  

   // menelusuri isi kontainer dari depan ke belakang

   std::cout<<"Penelusuran dengan arah maju:"<<std::endl;

   std::array<int,5>::iterator it = a.begin();

   while (it != a.end()) {

      std::cout<<*it<<" ";

      it++;

   }

  

   std::cout<<"\n\nPenelusuran dengan arah mundur:"<<std::endl;

   std::array<int,5>::reverse_iterator it1 = a.rbegin();

   while (it1 != a.rend()) {

      std::cout<<*it1<<" ";

      it1++;

   }

  

   return 0;

}

C++ #include array 2

 

#include <iostream>

#include <array> // std::array


int main() {   

   std::array<int, 5> a;

   

   // mengisi elemen-elemen array

   for (auto i {0}; i<5; i++) {

      a[i] = (i+1) * 10;

   }

   

   // menelusuri isi kontainer secara terbalik

   std::array<int,5>::reverse_iterator it = a.rbegin();

   while (it != a.rend()) {

      std::cout<<*it<<" ";

      it++;

   }

   

   return 0;

}


C++ #include array 1

 


 

#include <iostream>

#include <array>              // std::array

 

int main() {  

   std::array<int, 5> a;

  

   // mengisi elemen-elemen array

   for (auto i {0}; i<5; i++) {

      a[i] = (i+1) * 10;

   }

  

   // menelusuri isi kontainer dan menampilkan elemen-elemennya

   std::array<int,5>::iterator it = a.begin();

   while (it != a.end()) {

      std::cout<<*it<<" ";

      it++;

   }  

  

   return 0;

}

C++ #include list

 

/******************************************************

Nama file: stl_list.cpp

*******************************************************/

 

#include <iostream>

#include <list>                   // std::list

 

int main() {  

   int a[] = {10,20,30,40,50};

   std::list<int> l(a, a + sizeof(a)/sizeof(int));

  

   // penelusuran maju

   std::cout<<"Penelusuran maju:"<<std::endl;

   std::list<int>::iterator it;

   for (it=l.begin(); it!=l.end(); ++it) {

      std::cout<<*it<<" ";

   }

  

   std::cout<<"\n\nPenelusuran mundur:"<<std::endl;

   std::list<int>::reverse_iterator it1;

   for (it1=l.rbegin(); it1!=l.rend(); ++it1) {

      std::cout<<*it1<<" ";

   }

  

   return 0;

}

C++ SAMPLE CODE 16d

 #include<iostream>

#include<algorithm>

using namespace std;


int main()

{

   int S[12] = {10, 24, 12, 22, 34, 51, 171, 13, 16, 176, 56, 42};


   partial_sort(S, S+6, S+12); // mengurutkan sampai s+6


   for ( int i =0; i<12; i++)

      cout << S[i] <<" ";

   cout<<"\n";


   return 0; 

}

=====================

#include<iostream>

# include<algorithm>

using namespace std;


int main()

   int S[12] = {10, 24, 12, 22, 34, 51, 171, 115, 20, 176, 56, 42 };

   int A [6];


   partial_sort_copy (S, S+12, A, A+6);


   cout<<"S = ";

   for ( int i =0; i<12; i++)

      cout << S[i] <<" ";


   cout<<"\nA = ";

   for (int k =0; k<6; k++)

      cout << A[k] <<" ";


   cout<<"\n";

   return 0 ;

}

=======================

#include<iostream>

#include<numeric>

using namespace std;


int main()

{

   int S[8] = {2, 3, 4, 5, 6, 7, 8, 9};

   int A[8];


   cout<< "S = ";

   for (int i = 0; i<8; i++)

      cout << S[i] <<" ";


   partial_sum(S, S+8, A);


   cout<<"\nA = ";

   for (int k =0; k<8; k++)

      cout << A[k] <<" ";


   cout<<"\n";

   return 0 ;

}

==============================

#include<iostream>

#include<algorithm>

using namespace std;


bool Genap(int m)  //definisi dari fungsi untuk angka genap

{

   return !(m%2) ? true : false;

}


int main()

{

   int S[] = {5, 6, 8, 7, 4, 3, 8, 10, 11, 12};


   partition(S, S+10, Genap);


   //mempartisi dan menempatkan angka-angka genap di depan.

   for ( int i =0; i<10 ; i++)

      cout<< S[i]<<" ";


   return 0;

}

==========================

#include <iostream>

#include<algorithm>

using namespace std;


void main()

{

   char A[4] = "XYZ";


   for( int k =0; k<6;k++)

   { 

      next_permutation (A, A+3);

      cout<<A<<" ";

   }

   cout<<"\n";


   for( int i =0; i<6;i++)

   {

      prev_permutation (A, A+3);

      cout<<A<<" ";

   }

   cout<<"\n";

}

====================

#include <iostream>

#include<algorithm>

using namespace std;


void main()

{   

   char A[7] = "ABCDEF";


   for(int k = 0; k<5; k++)

   {

      random_shuffle(A, A+6);

      cout<<A<<" ";

   }

   cout<<"\n";

}

======================

#include<iostream>

#include<algorithm>

#include<functional>

#include <vector>

using namespace std;


vector <int> V;


int main()

{

   int S[] = {5, 6, 8, 7, 8, 3, 8, 10, 8, 12};


   for (int i = 0; i<10; i++)

      V.push_back (S[i]); //menciptakan sebuah vektor V dengan elemen-elemen dari S


   cout<<"V = ";

   vector<int>::iterator iter; //deklarasi iterator

   for (iter= V.begin(); iter <V.end(); iter++)

      cout<< *iter<<" ";  //Menampilkan elemen-elemen dari V

   cout<<endl;


   int Hitung = count(V.begin(), V.end(), 8); //Menghitung jumlah elemen dengan nilai 8

   cout<<"Jumlah elemen dengan nilai 8 = "<<Hitung<<endl;


   remove (V.begin(), V.end() , 8); //Menghapus elemen-elemen dengan nilai 8

   for ( int j = 0; j<Hitung; j++)

      V.pop_back( ) ;

   

   cout<<"Sekarang V = ";

   for (iter= V.begin(); iter <V.end(); iter++)

      cout<< *iter<<" "; //Menampilkan elemen-elemen setelah penghapusan

   cout<<endl;


   Hitung = count_if(V.begin(), V.end(), bind2nd(less<int>(),6));

   cout<<"Jumlah elemen yang bernilai kurang dari 6 = "<<Hitung;


   remove_if(V.begin(), V.end(), bind2nd(less<int>(),6));

   //Menghapus elemen-elemen yang bernilai kurang dari 6

   for (int k = 0; k<Hitung; k++)

      V.pop_back( ) ;


   cout<<"\nVektor baru setelah dua penghapusan:"<<endl;

   cout<<"V = ";

   for (iter= V.begin(); iter < V.end(); iter++)

      cout<<*iter<<" ";


   cout<<endl;

   return 0;

}

=======================

#include<iostream>

#include<algorithm>

#include<functional>

#include <vector>

using namespace std;


vector <int> V;


int main()

{

   int S[] = {5, 6, 8, 7, 8, 3, 8, 10, 8, 12};


   for (int i =0 ; i<10;i++)

      V.push_back (S[i]);


   vector<int>:: iterator iter;

   for (iter= V.begin(); iter <V.end(); iter++)

      cout<< *iter<<" ";

   cout<<endl;


   replace (V.begin(), V.end(), 8, 9); // mengganti 8 dengan 9


   for (iter= V.begin(); iter <V.end(); iter++)

      cout<< *iter<<" ";

   cout<<endl;


   replace_if(V.begin(), V.end(), bind2nd(less<int>(),9), 5);

   //mengganti elemen-elemen yang kurang dari 9 dengan 5

   

   cout<<"Vektor baru setelah dua kali penggantian:"<<endl;

   for (iter= V.begin(); iter <V.end(); iter++)

      cout<< *iter<<" ";

   cout<<endl;

   

   return 0;

}

=====================

#include <iostream>

#include<algorithm>

using namespace std;


void main()

{

   char A[] = "ABCDEFGH";


   int n = strlen(A);

   reverse(A, A+n);

   

   cout<<A<<endl;

}

==========================

#include<iostream>

#include<algorithm>

using namespace std;


void main()

{

   int S1[] = {11, 12, 13, 15, 16, 17, 18, 19 ,20};


   cout<<"S1= ";

   rotate ( S1, S1+4,S1+9);

   for (int j =0; j<9; j++)

      cout << S1[j]<<" ";

}

=======================

#include<iostream>

#include<algorithm>

using namespace std;


int main()

{

   char Set1[] = {"ACDGHIJKTUVZ"};

   char Set2[] = {"BCDKMNPUV"};

   char Setx[12];

   char Setxy[15];

   char SetA[20];

   char SetU[25];


   cout<<"Set1 = "<<Set1<<endl;

   cout<<"Set2 = "<<Set2<<endl;


   char* Sety = set_difference(Set1, Set1+12, Set2, Set2+9, Setx);

   *Sety =0;

   cout<<"set_difference = "<<Setx<<endl;


   char* Setz = set_intersection(Set1, Set1+12, Set2, Set2+9,Setxy);

   *Setz =0;

   cout <<"set_intersection = "<<Setxy<<endl;


   char* Setm = set_symmetric_difference(Set1, Set1+12, Set2,Set2+9, SetA);

   *Setm = 0;

   cout <<"Set_symmetric_difference = "<<SetA<<endl;


   char* Setn = set_union(Set1, Set1+12, Set2, Set2+9, SetU);

   *Setn =0;

   cout <<"Union dari Set1 dan Set2 = "<<SetU<<endl;


   return 0 ;

}

========================

#include<iostream>

# include<algorithm>

using namespace std;


int main()

{

   int S1[] = {11, 12, 19, 13, 16, 20, 24, 22};


   sort(S1, S1+8);


   for (int i =0; i<8; i++)

      cout <<S1[i]<<" ";

   cout<<"\n";


   return 0 ;

}

=======================

#include<iostream>

#include<algorithm>

using namespace std;


void main()

{

   int S1[] = {11, 12, 19, 13, 16, 20, 24, 22};

   int S2[] = {1, 2, 3, 4, 5, 6, 7, 8};


   cout<<"S1= ";

   swap_ranges(S1, S1+4, S2+4);

   for ( int j =0; j<8; j++)

      cout<<S1[j]<<" ";


   cout<<"\nS2= ";

   for ( int k =0; k<8; k++)

      cout<<S2[k]<<" ";

   cout<<endl;

}

======================

#include<iostream>

#include<list>

using namespace std;


list<char> L1;


void main()

   for (int i=0; i<6;i++)

   {

      L1.push_back(65 + i);

      L1.push_back(65 + i);

   }


   cout<<"List awal adalah berikut:"<<endl;

   list<char>::iterator T1;

   for ( T1 = L1.begin() ; T1!=L1.end() ; T1++ )

      cout <<" "<<*T1 ;

   cout<<endl;


   L1.unique();

   cout<<"Setelah penghapusan duplikat, list menjadi: "<<endl;

   for (T1 = L1.begin() ; T1!=L1.end() ; T1++ )

      cout <<" "<<*T1 ;


   L1.reverse();

   cout<<"\nSetelah pembalikan list: \n";

   for ( T1 = L1.begin() ; T1!=L1.end() ; T1++ )

      cout <<" "<<*T1 ;


   cout<<"\nSetelah penghapusan F dari list: \n";

   L1.remove ('F');

   for ( T1 = L1.begin() ; T1!=L1.end() ; T1++ )

      cout <<" "<<*T1 ;

   cout << endl;

}

======================

#include<iostream>

# include<algorithm>

using namespace std;


int main()

{

   int S1[] = {11, 121, 19, 122, 260, 203, 240, 22};

   int* ptr = upper_bound (S1, S1+8, 122);


   cout<<"Batas atas adalah "<<*ptr<< endl;

   cout<<"Indeksnya adalah "<< ptr - S1 <<" di dalam array."<<endl;


   return 0 ;

}