Title: Tutorial 7
1Tutorial 7
- Introducing Algorithms, Pseudocode Program
Control
2Algorithm
- Procedure or formula to solve a problem
- The word derives from the name of the
mathematician, Mohammed ibn-Musa al-Khwarizmi
(780 850 A.D.) from Baghdad. His work is the
likely source for the word algebra as well - A problem can be divided into three components
Input, Process, Output
Source http//searchvb.techtarget.com/sDefinition
/0,,sid8_gci211545,00.html
3Example A program is required to read three
numbers, add them together, and print the total.
Example Read the max and min temperatures,
calculate the average, and print the average.
4Pseudocode
- English-like user-friendly informal code
- Tool to detect any logic error prior to actual
coding
- Simple to translate it into real programming code
- Used for developing algorithm
5Example
- Pseudocode
- Set the balance to be 0
- Get the deposit amount from the input box
- Add the deposit amount to the balance
- VB .Net
- decBalance 0
- decDeposit Val (txtDeposit.Text)
- decBalance decBalance decDeposit
6If Then Selection Control
- Executes its instruction(s) when the condition is
met
- Depends on the result of a condition being true
or false.
- If the condition is false, then the entire If
statement is skipped.
- Three key words If, Then, and End If
7Basic Structure
- If condition Then
- code(s) to be executed
- End If
- If intGrade 60 Then
- lblCourseResult.Text Passed
- End If
Continue ?
8(No Transcript)
9Comparison Operators
10Logical Operators
11If ThenElse Selection
- A choice is made between two alternative paths
- Depends on the result of a condition being true
or false
- Only the instruction(s) for the condition that is
evaluated to be true is executed
- Otherwise, skipped
Continue ?
12(No Transcript)
13Nested If Statement
- A choice is made among many alternative paths
- Only the instruction(s) for the condition that is
first evaluated to be true is executed ? the rest
skipped.
- Once the selected instruction(s) are executed,
the entire If statement terminates
14Nested If Statement
If sglTotalAmount 500 Then lblShipping.Text
0 Else If sglTotalAmount 300 Then l
blShipping.Text 10 Else lblShipping.Text
15 End If End If
If condition Then code(s) to be executed El
se If condition Then code(s) to be exe
cuted Else code(s) to be executed End If
End If
15ElseIf Statement
If condition Then code(s) to be executed El
seIf condition Then code(s) to be executed
Else
code(s) to be executed End If
If sglTotalAmount 500 Then lblShipping.Text
0 ElseIf sglTotalAmount 300 Then lblSh
ipping.Text 10 Else lblShipping.Text 15
End If
16ElseIf Statement Example
Continue ?
17(No Transcript)