1 / 28

COM148X1 Interactive Programming

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

jin-mcguire
Télécharger la présentation

COM148X1 Interactive Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COM148X1Interactive 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. Flowchart Symbols • 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

  6. Flowchart Example A Start Output “bonus avail.” Enter working year Enter salary salary = salary + 300 working year > 3? B yes no Output salary A End B

  7. Pseudo-Code

  8. 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)

  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 direction of breakdown Calculate the Net-Profit Calculate the Cost Calculate the Gain Calculate Workers Salary Calculate Insurance Calculate Tax

  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 direction of compose Calculate the Net-Profit Calculate the Cost Calculate the Gain Calculate Workers Salary Calculate Insurance Calculate Tax

  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 a 0 0 0 0 0 0 0 1 2 3 4 5

  19. Access Array Data • array_name( index ) • Example • a(3) = 10 ‘write array • Dim b As Integer = a(3) ‘read array a 0 0 0 10 0 0 0 1 2 3 4 5 b 10

  20. UBound Function • Obtain the largest index of an array • Example • For j = 0 To UBound(a) a(i) = 20Next j a 20 20 20 20 20 20 0 1 2 3 4 5

  21. Resize an Array • Redim array_name(max_index) • RedimPreserve 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) a a 60 44 81 72 90 9 0 0 0 0 0 1 2 3 4 5 0 1 2 3 Before Redim After Redim

  23. Redim Example 2 • Redim Preserve a(3) a a 60 44 81 72 90 9 60 44 81 72 0 1 2 3 4 5 0 1 2 3 Before Redim 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 Integerb(1, 3) = 13b(0, 5) = 27Dim i As Integer = UBound(b, 1) ‘i = 1Dim j As Integer = UBound(b, 2) ‘j = 5 b 0 0 0 0 0 27 0 0 0 0 13 0 0 1 0 1 2 3 4 5

  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

More Related