Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICS124 Session 9 Flowcharting 1. By the end of this section the student will be able to:  Name the three structures of the Structure Theorem  Identify.

Similar presentations


Presentation on theme: "ICS124 Session 9 Flowcharting 1. By the end of this section the student will be able to:  Name the three structures of the Structure Theorem  Identify."— Presentation transcript:

1 ICS124 Session 9 Flowcharting 1

2 By the end of this section the student will be able to:  Name the three structures of the Structure Theorem  Identify the symbols used in flowcharting  Assemble the flowcharting symbols to create the three structures in the Structure Theorem  Properly assemble the three flowchart structures to create a solution to a word problem 2

3 Flowcharting 3

4 Background The third phase of the PDC is Develop Solution into an Algorithm. The points that were made are:  Computers cannot devise a plan or decide to act  Computers can only do what they are told, exactly the way they are told  Computers do what you tell them to do, not what you want them to do  An algorithm is a set of precise instructions which describe the task to be performed and the order in which they are to be carried out’ Flowcharting is a tool that helps develop a solution into an algorithm:  A picture is worth a thousand words  Uses only a limited number of symbols to defined an algorithm of any complexity 4

5 Flowcharting, continued Flowcharts This is where the program starts to take shape. The Structure Theorem states that it is possible to write any computer program by using only THREE basic control structures:  simple sequence  selection  iteration 5

6 Flowcharting, continued Simple sequence The Simple Sequence represents the computer's ability to execute instructions in a step-by-step, sequential manner. Selection The Selection represents the computer's ability to make a decision. By evaluating a condition, alternate execution paths are followed. Iteration Iteration represents the computer's ability to repeat a series of instructions. 6

7 Flowcharting- Simple sequence Flow lines Shows the direction of logic flow within the flowchart Unless otherwise stated the symbols of a flowchart have one flow line entering it, and one flow line exiting it. 7

8 Flowcharting- Simple sequence, continued Terminal Interrupt or Terminator  Used to show the beginning or end of an algorithm  There must be these two symbols (only one each) Start Stop 8

9 Flowcharting- Simple sequence, continued Terminal Interrupt or Terminator, continued  A simple flowchart (that does nothing): Start Stop 9

10 Flowcharting- Simple sequence, continued Process Box  Used to show a processing operation  The operation is described inside the box  Does not show a decision, or the input or output of data Perform a process 10

11 Flowcharting- Simple sequence, continued An Example  Prepare for the exam  Flowcharts are normally written, from the top of the page to the bottom of the page Start Stop Review texts Review Lectures Review Tests Review Labs 11

12 Flowcharting- Simple sequence, continued Off-page / On-page Connector  What happens when you run out of room on the page?  A unique identifier is written inside the symbol so that they can be paired up when reading the flowchart  Like the terminator, in that there is either one flow line entering it, OR one flow indicator exiting it. A Off-page A On-page 12

13 Flowcharting- Simple sequence, continued A three page example Start UVY Z Stop A B WX A B 13

14 Flowcharting- Simple sequence, continued Input / Output Operation  Used to show the input of data, or the output of data  The operation is described inside the box  Does not show a decision, or any processing steps Read valueA 14

15 Flowcharting- Simple sequence, continued Example Develop a program to accept three numbers, add them together, then print their total and average. Write the flowchart 15

16 Flowcharting- Simple sequence, continued Example Develop a program to accept three numbers, add them together, then print their total and average. Write the flowchart Start Read val1, val2, val3 ttl= val1 + val2 + val3 A A avg= ttl / 3 Print ttl, avg Stop 16

17 Flowcharting- Simple sequence, continued Exercise Write a program to help a local Elementary School's library with the overdue fines on books. The librarians don't wish to always charge students for overdue books, however sometimes the number of books that are overdue is too much. When this happens the librarians enter into the program the student's name, the name of the overdue book they borrowed, and the date it was signed out (the librarian reads these fields from the sign-out card). The colour of the card is also entered, as this indicates what the normal sign-out period is for that book. White cards are due back in two weeks, Blue cards in one week, Green cards the next day, and Orange cards in 4 weeks. The colour code of the card is entered as a single character into the program (W, B, G and O). When this information has been entered, the program determines by how much the book is overdue (based on the date the program is run) and the overdue charge, ($0.05 per day). A list is produced that will show the student's name, the name of the book, the number of days the book is overdue and the fine that is payable. Create the IPO Chart and Flowchart 17

18 Flowcharting- Simple sequence, continued Exercise 18

19 Flowcharting- Simple sequence, continued Exercise Start Read stuName, bookName, signout, colourCode overdue=today-signout fine=overdue * 0.05 Print stuName, bookName, colourCode, overdue, fine Stop 19

20 Flowcharting- Selection Selection There will be references for the remainder of flowcharting to "conditions" A condition is a logical expression that is either true or it is false The condition is expressed as some form of a mathematical expression Expressions: A > B SIN(theta) = COS(theta) recordValue = "end of records" 20

21 Flowcharting- Selection, continued Simple Decision Box:  Used to show a change in the path of logic in the program  The condition being tested is written inside the diamond in a mathematical form using information available in the flowchart.  Has 2 flow indicators exiting it  These flow lines MUST be labelled with the result of the decision (e.g. YES, NO, TRUE, FALSE...) A > B + 5 True False 21

22 Flowcharting- Selection, continued Collector  Used to collect the flow lines that were created from a decision box, and restore the logic of the program back to a single stream  THE PATHS FROM A DECISION MUST REJOIN IN A COLLECTOR 22

23 Flowcharting- Selection, continued Example B amount < 0 DB = DB + amount CR = CR + amount C True False 23

24 Flowcharting- Iteration Iteration  Iteration is also referred to as "looping"  The goal of iteration is to repeat a sequence of steps until a certain condition has been met  The iteration is a special case of the decision structure already discussed  The sequence of steps in the loop may consist of simple sequences, decisions, loops 24

25 Flowcharting- Iteration, continued Pre-Test Loop  The condition that terminates the loop is tested before the loop is entered  It is therefore possible to not execute any of the statements within the loop at all Repeated statement(s) False True Conditional Expression Update Statement 25

26 Flowcharting- Iteration, continued Pre-Test Loop, continued This is the traditional form of the pre-test loop- unless you are careful it is easy to violate good structured practice Repeated statement(s) False True Update Statement Condition 26

27 Flowcharting, continued Nesting structures When combining structures, they must be nested. Each structure (Simple Sequence, Simple Decision and Iteration) each have ONE entry point and ONE exit point. This is a rule that cannot be broken: 27

28 Flowcharting, continued Nesting structures, continued Embedding a loop within a decision: BECOMES Loop needed 28

29 Flowcharting, continued Nesting structures, continued Embedding a decision within a loop: BECOMES Decision needed 29

30 Flowcharting, continued Nesting structures, continued Think of the nesting of your program, as a series of self-contained objects. One inside the other. There is no connection / interaction across layers. For example, this is illegal: www.polstore.com - follow the links to Polish Dolls 30


Download ppt "ICS124 Session 9 Flowcharting 1. By the end of this section the student will be able to:  Name the three structures of the Structure Theorem  Identify."

Similar presentations


Ads by Google