0% found this document useful (0 votes)
2 views

UNIT 3b - Data Types, Variables and Flowcharts

The document introduces structured program design, focusing on sequential, selection, and iterative processing. It explains various selection statements such as if, if...else, and switch, as well as iterative structures like while loops. Additionally, it discusses stacking structures for solving logic problems and provides exercises for practical application.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

UNIT 3b - Data Types, Variables and Flowcharts

The document introduces structured program design, focusing on sequential, selection, and iterative processing. It explains various selection statements such as if, if...else, and switch, as well as iterative structures like while loops. Additionally, it discusses stacking structures for solving logic problems and provides exercises for practical application.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

BIT 157

INTRODUCTION TO STRUCTURED
PROGRAM DESIGN

LINDA AMOAKO BANNING, PhD


UNDERSTANDING
STRUCTURE
SEQUENTIAL PROCESSING
• In a sequence:
• Perform an action or task
• Perform the next action in order
• There can be any number of tasks
• There is no chance to skip any
task
• Once started, it must be
continued step-by-step until the
sequence ends.
SELECTION/DECISION PROCESSING
● During a selection:
○ A question is asked
○ An action is taken based on the
answer
○ No matter the path taken, the next
task is executed.
SELECTION STATEMENTS
● if
● if … else
● Nested if ….. else
● switch
● case
SELECTION STATEMENTS
1. The if selection statement is called a single-selection structure
It selects or ignores a single action (group of actions)
2. The if…else statement is called a double selection structure
It selects between two different action (group of actions)
3. The switch statement is called a multiple-selection structure.
It selects among different actions (group of actions)
IF SELECTION STATEMENTS
• Example: Let’s have pseudocode statement
• » If student’s grade is greater than or equal to 60, Print “Passed”

Start
If studentgrade >= 60
Print “Passed”
Stop
IF…ELSE SELECTION STATEMENTS

• The if…else selection structure allows the


programmer to specify that different action is to
be performed when condition is true and when
the condition is false
IF…ELSE SELECTION STATEMENTS
• The if…else selection structure Start
allows the programmer to specify
If studentgrade >= 60
that different action is to be
Print “Passed”
performed when condition is true and
when the condition is false else

• For example: If a student’s grade is Print “Failed”


greater than or equal to 60, print Stop
passed else print failed
NESTED IF…ELSE SELECTION
if (grade >= 70)
• Nested if…else structure Print A
else if (grade >= 60)
test for multiple cases by Print B

placing if…else selection else if (grade >= 50)


Print C
structures inside if…else else if (grade >= 40)
Print D
selection structure else
Print F
SELECTION/DECISION PROCESSING

Yes No
ITERATIVE PROCESSING
● These are created with repetition statements
• – while
• – do…while
• – For
ITERATIVE PROCESSING: While loop
• A WHILE loop is a loop that repeats while some
condition is satisfied.

• •The WHILE loop tests its condition at the


beginning of every loop.

• •If the condition is false from the start, the


sequence of activities contained in the loop
never runs at all.
ITERATIVE PROCESSING: While loop
• Write a program to print “I love computers” five times.

1. Start
2. count = 0
3. While count < 5
Display "I love computers!"
4. Increase count by 1
5. Endwhile
6. Stop
ITERATIVE PROCESSING: WHILE LOOP
● Actions are repeated based on the answer
to a question

No

Yes
ITERATIVE PROCESSING:
The do-While and the do-Until Loops

While Loop
Do-while or Do-until loop
STACKING STRUCTURES
● ALL logic problems can be solved using only
these three structures
● They can be combined in an infinite number
of ways
● Attaching structures end-to-end is called
stacking
stepA
Sequence
do stepA
stepB do stepB
if conditionC is true then
do stepD
No condition Yes
C?
else
Selection do stepE
stepE stepD endif
while conditionF is true
do stepG
endwhile
Yes
conditionF
? stepG
Loop

No
EXERCISES
● Draw a flowchart to read any 10 integers that a user will input. Output
the sum of the even numbers in the list entered.
● Draw a flowchart to calculate the sum and average of n numbers.
● Draw a flowchart that finds and displays the larger of two numbers
provided they differ.
● The voltage (V) between the poles of a conductor is equal to the
product of the current (I) passing through the conductor and the
resistance (R) present on the conductor. It’s demonstrated by the V = I
* R formula. Draw a flowchart to calculate the voltage between the
poles of the conductor by using the formula according to the current
and resistance values the user enters.
!!!STUDENTS TO READ!!!
● Research on the CASE STRUCTURE .
● Use the CASE STRUCTURE to assign grades scored by a class in
Programming based on the following metrics:
SCORE GRADE
0-49 F
50-59 D
60-69 C
70-79 B
80-100 A
NEXT TOPIC
● Modules
END

You might also like