22
`

`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Embed Size (px)

Citation preview

Page 1: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

`

Page 2: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Lecture OverviewLecture Overview

• Structure Programming• Basic Control of Structure

Programming• Selection• Logical Operations• Iteration• Flowchart

Page 3: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Structured Structured ProgrammingProgramming

• Structured programming (also called modular programming) is a subset of procedural programming that enforces a logical structure on the program being written.

• The structured program makes it easier and more efficient to understand and modify.

Page 4: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Structured Programming Structured Programming (cont’d)(cont’d)

• A structured programming is written using simple control structures to organize the solution to a problem.

• A simple structure is usually defined to be a sequence, a selection, or a repetition.

Page 5: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Basic Control StructuresBasic Control Structures

• A sequence structure contains steps that is performed one after another.

• A selection structure contains one set of steps that is performed if a condition is true, and another set of steps that is performed if the condition is false.

• A repetition/iteration structure contains a set of steps that is repeated as long as a condition is true.

Page 6: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Selection (IF..THEN..ELSE)Selection (IF..THEN..ELSE)

• IF…THEN..ELSE– In an IF statement, the instructions following the

THEN part of the IF statement are executed if the condition is TRUE

– A more comprehensive set of conditions can be created by adding an ELSE statement

– E.g.• If I’ve got an assignment to finish I’ll have to do it,

otherwise I’ll go to see the football match with you next week.

• When the alarm goes off get out straight out of bed, unless it’s a weekend in which case you can stay in bed a bit longer.

Page 7: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Selection (CASE)Selection (CASE)

• CASE– The CASE statement is frequently used for

coding the choice between item lists, such as those found in screen menus.

– A conditional control structure that appears in most modern programming languages and allows a selection to be made between several (multiple) sets of program statements.

– E.g.• ATM Machine transactions.• Vendor Machine

Page 8: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Logical OperationsLogical Operations

• Logical Operators:• = is equal to• >= is greater than or equal

to• <= is less than or equal to• <> is not equal to

• Logical Operations:– AND, OR, NOT, NAND, NOR,

XOR

Page 9: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

IterationIteration

• REPEAT UNTIL which tests at the end of a block of code, so the sequence of instructions are always repeated at least once

• WHILE which tests at the start of a block of code so it is possible that the instructions in the loop may never be executed

• FOR Loop which is controlled by a count given from known conditions

Page 10: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

FlowchartFlowchart

• A flowchart is a graphical or symbolic representation of a process.

• Each step in the process is represented by a different symbol and contains a short description of the process step.

• The flowchart symbols are linked together with arrows showing the process flow direction

• Flowchart uses a diagram to describe the steps in algorithm

Page 11: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart SymbolsFlowchart Symbols

Termination (Start/End)

Input/ output

Process/Computation

Comparison

Connector

Page 12: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart SequentialFlowchart Sequential

Block BBlock B

Block ABlock A

Page 13: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart Selection (If Flowchart Selection (If Else)Else)

Block BBlock B Block ABlock A

condcondFalse/NoTrue/Yes

Page 14: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart Selection Flowchart Selection (Case)(Case)

Page 15: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart Iteration Flowchart Iteration (Repeat Until)(Repeat Until)

Page 16: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart Iteration (Do Flowchart Iteration (Do While)While)

Page 17: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart Iteration (For Flowchart Iteration (For Loop)Loop)

Page 18: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart Connector Block Flowchart Connector Block andandOff Page ConnectorOff Page Connector

Page 19: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart ExamplesFlowchart Examples

The diagrams shown illustrates how to compute the sum of two numbers

Page 20: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart ExamplesFlowchart Examples

The process of processing is shown as arrows linking the symbols

Page 21: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

Flowchart ExamplesFlowchart Examples

Create a flowchart for inputting your employee’s name. If the first letter starts from A to J then display “ First Category” , if K to T then display “ Second Category” otherwise display Third Category

Create a flowchart for inputting your employee’s name. If the first letter starts from A to J then display “ First Category” , if K to T then display “ Second Category” otherwise display Third Category

If student's grade is greater than or equal to 60Print "passed“ else Print "failed“If student's grade is greater than or equal to 60Print "passed“ else Print "failed“

Set the counter to 0. If the counter is more than 10 then customer receives free value meal otherwise no free value meal.

Set the counter to 0. If the counter is more than 10 then customer receives free value meal otherwise no free value meal.

Page 22: `. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart

SummarySummary

• Basic Control Structures:– Sequence– Selection

• IF..THEN..ELSE..• CASE

– Iteration/Repetition• REPEAT UNTIL• WHILE• FOR

• A flowchart is a graphical or symbolic representation of a process.