Summative Activity Flowcharts and Pseudocode 1 A Procedure






















- Slides: 22

Summative Activity Flowcharts and Pseudocode 1

A ‘Procedure’ v. A set of instructions which describe the steps to be followed in order to carry out an activity. v This can be for any activity: – eg recipe, assembly instructions etc v If it is written in a computer language it is called a program. 2

To solve a problem by writing a computer program! v Make sure you understand the problem! – be clear in your mind what you are trying to achieve. v Plan the solution! – work out how the task should be done on the computer. v Implement the solution! – write the computer program. v Test the solution! – make sure the program does what it is supposed to do. 3

Planning the Solution v The solution must be prepared before any programming starts. – on paper – using computerised tools – in your head v Divide problem into separate tasks if necessary. – called ‘modules’ or ‘components’ These tasks may also be divided. v Tasks must be precisely described. v – the ‘procedure’ must be described 4

Testing the Program v Unit testing – testing modules separately v Integration testing – do the modules work together? v System testing – testing on the computer it will be used on. v User acceptance testing – are they happy with the program? 5

Describing Procedures Precisely v Flowcharts – Diagrams that include words which describe the individual tasks to be carried out and the decisions to be made in regard to carrying out tasks. v Pseudocode – Words that describe the individual tasks and special ‘keywords’ that describe the decisions to be made in regard to carrying out these tasks. 6

Begin Flowcharts Write address on envelope. Yes v Flowchart describing the procedure involved in preparing a set of envelopes for posting. Stick first class stamp on envelope. Is letter urgent? No Stick 2 nd class stamp on envelope Fold letter Lick gum Seal envelope Yes Any more letters? No End 7

Flowcharts v Rectangle represents actions. – can only have one entry point. – can only have one exit point. Open door v Diamond represents a decision. Is Yes No – phrased like a question. door open? – can only have one entry point. – must have one exit point for each possible answer. v Arrows show which action is executed after the previous one. 8

Flowchart Assignment v Design flowcharts for the following tasks! – – Leaving the classroom. Knocking a set of nails into a block of wood. Making a sandwich (choice of ham or cheese) Getting dressed in the morning. Write our your flowcharts and hand them in. 9

Top Down Programming with Stepwise Refinement v Designing a computer program by specifying as little of the details of how the job will be done at the early stages, but gradually defining tasks in more detail at later stages. – – – v Leave details as long as possible! Divide a job into it’s major components. Take each component and specify the major tasks involved. Break each task down into further tasks. This ‘refinement’ can be done as often as required. Top-Down Design is used in all areas of design! 10

Procedure for leaving room v Top down design/stepwise refinement Start Unlock door Walk to door Outside Place hand on door handle Open door Turn handle Move through door Swing door open End Push door Are we inside or outside the room? Inside Pull door Details of ‘swing door open’ Details of ‘Open door’ 11

Data v Identify Data Items – data items are given names (identifiers) – classified as either: u constant – value does not change during the operation of the program. u variable – value may change during operation of program. – data type u numeric (real, fixed, floating, integer) u text (alphanumeric) u other (date, etc) 12

Data v Constant – a piece of data that does not change v Variable – a piece of data that may change – in BASIC or Java. Script programs variables may be used to store constants in which case it is up to the programmer to make sure it does not change during the operation of the program. v Identifier – the name by which the piece of data is known ie. what the variable or constant is called. v Literal – a piece of text that is fixed in a program. – not necessarily given a name. – usually has ““ around it to differentiate it from an identifier (variable name) eg cost “cost” 13

Structured Programming v Modularise your program. – use top-down design methods. – write the program as separate units (subroutines) v Use standard pre-built modules – don’t ‘re-invent the wheel’ – eg ‘Windows’ programming libraries. if available. v Use the 3 basic programming ‘control structures’. v Use Pseudocode (not flowcharts) 14

The Three Programming Control Structures. v All programs can be described by combining the following 3 control structures: Simple Selection (IF-THEN-ELSE) Simple Sequence Simple Repitition (Loop) 15

Pseudocode Words that describe the individual tasks and special ‘keywords’ that describe the decisions to be made in regard to carrying out these tasks. v Keywords for the 3 basic control structures. v Forces the programmer to stick to these structures. v Looks like a programming language but is NOT. It is a strict form of english. v 16

Simple Sequence Start Walk to door Open door Move through door BEGIN Walk to door Open door Move through door END Note the ‘indentation’ End 17

Simple Selection Outside Push door Are we inside or outside the room? Inside IF inside room THEN Pull door ELSE Push door ENDIF Note the ‘indentation’ 18

Simple Repitition WHILE nail is sticking out Hit nail yes hit nail Is nail sticking out? no ENDWHILE Note the ‘indentation’ 19

Hints for writing pseudocode(1) v Identify the appropriate structure for the task to being described. – sequence, selection or repitition v Try these: – Adding up a large set of numbers. – putting ham or cheese onto a slice of bread. – printing out ‘pass’ or ‘fail’ for a student. – addressing and stamping an envelope. – printing out results for a class of students. 20

Hints for writing pseudocode(2) BEGIN. . . . . END IF. . . THEN. . . . ELSE. . . ENDIF WHILE. . . ENDWHILE Write down all the keywords for that structure and fill in the gaps. v The gaps can be filled with ordinary English statements. v The statements can represent complicated procedures which can be described in detail later. v 21

Pseudocode Assignment v Design pseudocode for the following tasks! – – – Leaving the classroom. Making a sandwich (choice of ham or cheese) Adding up a set of numbers. Calculating the average of a set of numbers. Finding the middle of 3 numbers. Printing out results for a class of students. u u <40 is a fail <60 is a pass <70 is a merit >=70 is a distinction Print out your pseudocode and hand it in with your flowcharts for marking. 22