Download Software Development

Transcript
HIGH LEVEL LANGUAGE PROGRAMMING – BASIC CONSTRUCTS
First, the initial comment lines and variable declarations:
Private Sub cmdOK_Click()
‘ code for the OK button
‘ by A. Programmer 30/12/03
‘ variable declarations
Dim max_mark As Integer
Dim first_name As String
Dim surname As String
Dim mark As Integer
Dim percent As Single
Dim grade As String
Dim init1 As String
Dim init2 As String
Next, storing the user inputs from the text boxes into variables
(pseudocode steps 1 to 4):
‘ store user inputs
max_mark = txtMax.Text
first_name = txtName.Text
surname = txtSurname.Text
mark = txtMark.Text
Note use of a comment line
to indicate the purpose of
the code.
Next, the calculation of the percentage mark (pseudocode step 5):
‘ calculate percentage mark
percent = (mark / max_mark) * 100
Step 6 is the calculation of the grade from the percentage, using a series
of If statements. The statements for grades A and Fail are
straightforward. For grades B, C and D, complex conditions are
required using And …
‘ calculate grade
If percent >= 70 Then grade = “A”
If percent >= 60 And percent < 70 Then grade = “B”
If percent >= 50 And percent < 60 Then grade = “C”
If percent >= 45 And percent < 50 Then grade = “D”
If percent < 45 Then grade = “Fail”
SOFTWARE DEVELOPMENT (INT 2, COMPUTING)
97