+ All Categories
Home > Documents > COM148X1 Interactive Programming

COM148X1 Interactive Programming

Date post: 31-Dec-2015
Category:
Upload: jin-mcguire
View: 37 times
Download: 1 times
Share this document with a friend
Description:
COM148X1 Interactive Programming. Lecture 5. Topics Today. Flowchart Pseudo-Code Design Approach Array Collection. Flowchart. What is Flowchart. Flowchart is used to represent the design of the program flow - PowerPoint PPT Presentation
Popular Tags:
28
COM148X1 Interactive Programming Lecture 5
Transcript
Page 1: COM148X1 Interactive Programming

COM148X1Interactive Programming

Lecture 5

Page 2: COM148X1 Interactive Programming

Topics Today

Flowchart Pseudo-Code Design Approach Array Collection

Page 3: COM148X1 Interactive Programming

Flowchart

Page 4: COM148X1 Interactive Programming

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

Page 5: COM148X1 Interactive Programming

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

Page 6: COM148X1 Interactive Programming

Flowchart Example

salary =salary + 300

Start

working year > 3?

Enter working year

End

Enter salary

Output salary

yes

no

Output“bonus avail.”

A

B

BA

Page 7: COM148X1 Interactive Programming

Pseudo-Code

Page 8: COM148X1 Interactive Programming

Pseudo-Code

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)

Page 9: COM148X1 Interactive Programming

Pseudo-Code Example

BeginRead working year from userRead salary from userIf working year > 3 then

salary ← salary + 300Output “Bonus Available”

End ifOutput salary

End

Page 10: COM148X1 Interactive Programming

Design Approach

Page 11: COM148X1 Interactive Programming

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

Page 12: COM148X1 Interactive Programming

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

Page 13: COM148X1 Interactive Programming

Top-down Approach

Calculate the Net-Profit

Calculate the Cost Calculate the Gain

Calculate Workers Salary

Calculate Tax

Calculate Insurance

direction of breakdown

Page 14: COM148X1 Interactive Programming

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

Page 15: COM148X1 Interactive Programming

Bottom-up Approach

Calculate the Net-Profit

Calculate the Cost Calculate the Gain

Calculate Workers Salary

Calculate Tax

Calculate Insurance

direction of compose

Page 16: COM148X1 Interactive Programming

Array

Page 17: COM148X1 Interactive Programming

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

Page 18: COM148X1 Interactive Programming

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

Page 19: COM148X1 Interactive Programming

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

10

3

0

4

0

5

Page 20: COM148X1 Interactive Programming

UBound Function

Obtain the largest index of an array Example

For j = 0 To UBound(a)a(i) = 20

Next j

20

a

0

20

1

20

2

20

3

20

4

20

5

Page 21: COM148X1 Interactive Programming

Resize an Array

Redim array_name(max_index) Redim Preserve array_name(max_index) If keyword Preserve is used, the data in origi

nal array will be copied to the new array as long as the new array can hold

Page 22: COM148X1 Interactive Programming

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

Page 23: COM148X1 Interactive Programming

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

Page 24: COM148X1 Interactive Programming

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

Page 25: COM148X1 Interactive Programming

Multi-Dimension Array Example

Dim b(1, 5) As Integerb(1, 3) = 13b(0, 5) = 27Dim i As Integer = UBound(b, 1) ‘i = 1Dim j As Integer = UBound(b, 2) ‘j = 5

0

b

0

0

1

0

2

13

3

0

4

0

5

0 0 0 0 0 270

1

Page 26: COM148X1 Interactive Programming

Collection

Page 27: COM148X1 Interactive Programming

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()

Page 28: COM148X1 Interactive Programming

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()


Recommended