Tutorial 7 - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Tutorial 7

Description:

Tutorial 7. Introducing Algorithms, Pseudocode & Program Control. Algorithm. Procedure or formula to solve a problem ... His work is the likely source for the ... – PowerPoint PPT presentation

Number of Views:152
Avg rating:3.0/5.0
Slides: 18
Provided by: Yun5
Category:

less

Transcript and Presenter's Notes

Title: Tutorial 7


1
Tutorial 7
  • Introducing Algorithms, Pseudocode Program
    Control

2
Algorithm
  • 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
3
Example 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.
4
Pseudocode
  • 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

5
Example
  • 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

6
If 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

7
Basic Structure
  • If condition Then
  • code(s) to be executed
  • End If
  • If intGrade 60 Then
  • lblCourseResult.Text Passed
  • End If

Continue ?
8
(No Transcript)
9
Comparison Operators
10
Logical Operators
11
If 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)
13
Nested 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

14
Nested 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
15
ElseIf 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
16
ElseIf Statement Example
Continue ?
17
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com