Download presentation
Presentation is loading. Please wait.
Published byAngela Parrish Modified over 9 years ago
1
COM148X1 Interactive Programming Lecture 5
2
Topics Today Flowchart Pseudo-Code Design Approach Array Collection
3
Flowchart
4
What is Flowchart Flowchart is used to represent the design of the program flow There are commonly 5 symbols used in flowchart, symbols in flowchart are connected by arrows terminal input/ output process decision connector
5
Terminal used to represent the start/ end of the program Input/ Output Process Decision Connector used to connect different parts of flowchart when the direct connection among these parts are messy Flowchart Symbols
6
Flowchart Example salary = salary + 300 Start working year > 3? Enter working year End Enter salary Output salary yes no Output “ bonus avail. ” A B B A
7
Pseudo-Code
8
Pseudo-Code is tools other than flowchart to represent the design of program flow Pseudo-Code looks like mixture of program code and human language (mostly English)
9
Pseudo-Code Example Begin Read working year from user Read salary from user If working year > 3 then salary ← salary + 300 Output “Bonus Available” End if Output salary End
10
Design Approach
11
Limitation of Flowchart and Pseudo-Code Both flowchart and pseudo-code become less usable when the program logic becomes too complicated Large program project required programmers to break down the tasks into small pieces until the tasks is simple enough to handle There are two approaches Top-down approach Bottom-up approach
12
Top-down Approach In top down approach, a task will be divided into different smaller tasks. If the smaller tasks’ complexity is still high, the smaller tasks will be further divided until all tasks are manageable
13
Top-down Approach Calculate the Net-Profit Calculate the CostCalculate the Gain Calculate Workers Salary Calculate Tax Calculate Insurance direction of breakdown
14
Bottom-up Approach Unlike top-down approach, bottom-up approach try to search any manageable tasks which can be use to accomplished the main tasks. Then compose all of them to become the main task
15
Bottom-up Approach Calculate the Net-Profit Calculate the CostCalculate the Gain Calculate Workers Salary Calculate Tax Calculate Insurance direction of compose
16
Array
17
What is Array Array is a collection of data of same type Size of array is fixed unless it is being asked to change Array is random access Index of array start from 0
18
Declare Array Dim array_name(max_index) As data_type Example Dim a(5) As Integer 0 a 0 0 1 0 2 0 3 0 4 0 5
19
Access Array Data array_name( index ) Example a(3) = 10 ‘write array Dim b As Integer = a(3) ‘read array a 10 b 0 0 0 1 0 2 3 0 4 0 5
20
UBound Function Obtain the largest index of an array Example For j = 0 To UBound(a) a(i) = 20 Next j 20 a 0 1 2 3 4 5
21
Resize an Array Redim array_name(max_index) Redim Preserve array_name(max_index) If keyword Preserve is used, the data in original array will be copied to the new array as long as the new array can hold
22
Redim Example 1 Redim a(3) 60 a 0 44 1 81 2 72 3 90 4 9 5 Before Redim 0 a 0 0 1 0 2 0 3 After Redim
23
Redim Example 2 Redim Preserve a(3) 60 a 0 44 1 81 2 72 3 90 4 9 5 Before Redim 60 a 0 44 1 81 2 72 3 After Redim
24
Multi-Dimension Array Multi-Dimension Array is the array using multiple index for data access Dim array_name(max_index1, max_index2, …) As data_type
25
Multi-Dimension Array Example Dim b(1, 5) As Integer b(1, 3) = 13 b(0, 5) = 27 Dim i As Integer = UBound(b, 1) ‘i = 1 Dim j As Integer = UBound(b, 2) ‘j = 5 0 b 0 0 1 0 2 13 3 0 4 0 5 0000027 0 1
26
Collection
27
What is Collection Collection is a group of data which can be retrieved either by index or string Collection index started from 1 Dim collection_name As New Collection() Example Dim marks As New Collection()
28
Access Data in Collection Add data to Collection collection.Add(data, key) marks.Add(10,”Jackson”) Retrieve data from Collection collection(key) collection(index) x = marks(“Jackson”) x = marks(0) Remove data from Collection collection.Remove(key) collection.Remove(index) marks.Remove(“Jackson”) marks.Remove(0) Count number of data in Collection collection.Count() cnt = marks.Count()
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.