Algorithms and Visual Basic Programming
Exercise
Algorithms
Output: gross pay
Input: hours worked
Algorithm:
enter number of hours worked if hours worked 0 ? 40, then calculate the gross pay ( hours *
display the gross pay otherwise, display an error message end if
If hours worked are not accept the new hour worked is between 40 and 60 hours
Display gross message
Otherwise display error message
Interface
Code
Public Class Form
Private Sub-Form1_Load (sender As Object, e As EventArgs) Handles MyBase.Load
calculates and displays gross pay
Const dblRATE As Double = 8.35
Dim dblHours As Double
Dim dblGross As Double
Double.TryParse (txtHours.Text, dblHours)
' calculate and display gross pay ' or display an error message
If dblHours >= 40 AndAlso dblHours
dblGross = dblHours * dblRATE
lblGross.Text = dblGross.ToString ("C2")
Else
lblGross.Text = "Hours worked error"
End If
End Sub
(Zak, 2013).
Chapter 9: Exercise 9
Algorithms
Output: price
Processing: discount
Input: edition
10% coupon
20% coupon for student edition
Algorithm:
1. enter the edition as well as 10% coupon items
2. if it is Ultimate edition, then:
assign 875.99 as the price if 10% coupon, then:
calculate the discount price * 10%
if Student edition, then:
assign 399.75 as the price if 20% discount, then:
calculate the discount price * 10%
calculate the price: price - discount end if otherwise, do this:
assign 499.99 as the price end if
3. display the price
Interface
Code
Public Class Form1
' displays the price of a software package
Const dblULTIMATE As Double = 875.99
Const dblPROFESSIONAL As Double = 499.99
Const dblPROFESSIONAL As Double = 399.99
Const dblDISC_RATE As Double = 0.1
Dim dblPrice As Double
' determine price
If radUltimate.Checked = True Then
dblPrice = dblULTIMATE
If chkDiscount.Checked = True Then
Dim dblDiscount As Double
dblDiscount = dblPrice * dblDISC_RATE
dblPrice = dblPrice - dblDiscount
End If
Const dblDISC_RATE As Double = 0.2
Dim dblPrice As Double
' determine price
If radStudent.Checked = True Then
dblPrice = dblSTUDENT
If chkDiscount.Checked = True Then
Dim dblDiscount As Double
dblDiscount = dblPrice * dblDISC_RATE
dblPrice = dblPrice - dblDiscount
Else
dblPrice = dblPROFESSIONAL
End If
' display price lblPrice.Text = dblPrice.ToString ("C2")
End Sub
End Class
(Zak, 2013).
Chapter 10: Exercises 3
Output: fee
Input: code
Algorithms
If Code =S then fee= 40
If Code =F, then fee =50
If Code is S65, then fee =30
If Code is C65, then fee = 35
If Code is CH, then fee = 5
Otherwise fee =0
Display fee
Display Stop
Code
Public Class Form1
Private Sub-Form1_Load (sender As Object, e As EventArgs) Handles MyBase.Load
' Display a monthly membership fee
Const intSINGLE As integer =40
Const intFAMILY As integer =50
Const intSINGLE _SENIOR As integer =30
Const intCOUPLE_SENIOR As integer =35
Const intCHILD As integer =5
Dim intFee As Integer
'display fee
1b1 Fee. Text = intFee. ToString ("CO")
End Sub
(Zak, 2013).
Chapter 10: Exercises 16
The "btnDisplay_Click procedure" assists in displaying the input function as well as loop to display sales amount for the user. The procedure also assists in storing the information in an array. The following interface displays the btnDisplay procedure:
Code
Public Class Form1
Private _decSales As Decimal
Private Property decSales (intSub As Integer) As Decimal
Get
Return _decSales
End Get
Set (value As Decimal)
_decSales = value
End Set
End Property
Private Property txtSales As Object
Private Sub-Form1_Load (sender As Object, e As EventArgs) Handles MyBase.Load
' class-level array
Dim decSales () As Decimal = {}
End Sub
Private Sub-btnDisplay_Click (sender As Object,
e As EventArgs) Handles btnDisplay.Click
You’re 80% through this paper. Sign up to read the full paper.
Sign Up Now — Instant Access Already a member? Log inAlways verify citation format against your institution’s current style guide requirements.