Sie sind auf Seite 1von 17

Logic Building and Effective Problem Solving

Objectives
In this session, you will learn to:
Identify repetitive processes
Work with arrays
Manipulate arrays using loops

Ver. 1.0

Slide 1 of 17

Logic Building and Effective Problem Solving


The repeatuntil Loop
repeatuntil loop:
Body executes at least once regardless of the condition
Condition is evaluated after the body is executed once
Syntax:
:
repeat
begin
//Body of the repeat...until loop
end until (condition)
:

The following embedded Word document contains the flowchart to


depict the repeatuntil loop syntax.

Repeat Until

Ver. 1.0

Slide 2 of 17

Logic Building and Effective Problem Solving


The repeatuntil Loop (Contd.)

The following embedded Word document contains the


flowchart to calculate the average score of 30 students.

Average Score
Flowchart

The following embedded Word document contains the


pseudocode segment to calculate the average score of 30
students.
Average Score
Pseudocode

Ver. 1.0

Slide 3 of 17

Logic Building and Effective Problem Solving


Working with Arrays
Array:
Store more than one value at a time
Collection of homogeneous data types
Elements are stored in adjacent memory locations
Elements are accessed using subscript\index
First element has an index 0
Last element has an index one less than the size of the array

Ver. 1.0

Slide 4 of 17

Logic Building and Effective Problem Solving


Declaring an Array
Array:
Should be declared before use
Syntax:
<data_type> <variable_name>[<size>]

Ver. 1.0

Slide 5 of 17

Logic Building and Effective Problem Solving


Declaring an Array (Contd.)
The following pseudocode segment declares a numeric
array of size five:
begin
numeric arr[5]
.....
.....
.....
end

The following figure shows a schematic representation of


the array elements in the memory.

arr[0]

Ver. 1.0

arr[1]

arr[2]

arr[3]

arr[4]

Slide 6 of 17

Logic Building and Effective Problem Solving


Initializing and Assigning Values to an Array
Array initialization:
Process of populating an array with values
Can be done in the following ways:
During declaration
After declaration

Ver. 1.0

During Declaration

After Declaration

begin
numeric arr[5] = {14, 15,
17, 45, 81}
.....
.....
End

begin
numeric arr[5]
display Enter the values for an
array
accept arr[0]
accept arr[1]
accept arr[2]
accept arr[3]
accept arr[4]
end

Slide 7 of 17

Logic Building and Effective Problem Solving


Initializing and Assigning Values to an Array
(Contd.)
Array elements are displayed using the display keyword.
The following pseudocode initializes and displays the array
elements:
begin
numeric arr[5]
arr[0] = 14
arr[1] = 15
arr[2] = 17
arr[3] = 45
arr[4] = 81
display arr[1]
display arr[2]
end

Ver. 1.0

Slide 8 of 17

Logic Building and Effective Problem Solving


Quiz #1

Ver. 1.0

Slide 9 of 17

Logic Building and Effective Problem Solving


Quiz
Which of the following constructs executes until the
condition is false and breaks if the condition becomes true?
1.
2.
3.
4.

for
switchcase
repeatuntil
if

Solution:
repeatuntil
Ver. 1.0

Slide 10 of 17

Logic Building and Effective Problem Solving


Quiz (Contd.)
Which of the following options will you use to initialize an
array with the values entered by the user?
1.
2.
3.
4.

display
begin
end
accept

Solution:
accept
Ver. 1.0

Slide 11 of 17

Logic Building and Effective Problem Solving


Quiz (Contd.)
Which of the following options is used to access a particular
array element?
1. subscript
2. accept
3. size

Solution:
subscript
Ver. 1.0

Slide 12 of 17

Logic Building and Effective Problem Solving


Manipulating Arrays Using Loops

Let us see how to


manipulate arrays using
loops.

Ver. 1.0

Slide 13 of 17

Logic Building and Effective Problem Solving


Manipulating Arrays Using Loops (Contd.)
The following embedded Word document shows the
pseudocode to accept and display the marks of five
subjects.
Use of array

Ver. 1.0

Slide 14 of 17

Logic Building and Effective Problem Solving


Exercises

Let us practice the


concepts learned by
solving a problem.

Ver. 1.0

Slide 15 of 17

Logic Building and Effective Problem Solving


Problem Statement
Draw a flowchart and write the pseudocode to accept five
numbers and display the total number of odd and even
numbers.
(Allocated time to solve the problem is 40 minutes.)

Use LBEPS Session8 Simulation1

Ver. 1.0

Slide 16 of 17

Logic Building and Effective Problem Solving


Summary
In this session, you learned that:
In a repeatuntil loop, the body of the loop is executed at
least once, regardless of the condition.
An array is a collection of elements of a single data type stored
in adjacent memory locations.
An array element can be accessed using subscript\index.
Subscript\index specifies the position of an element within the
array.
The first element of an array has an index 0 and the last
element has an index one less than the size of the array.
An array should be declared before use.
An array can be initialized in two ways:
During declaration
After declaration

Ver. 1.0

Slide 17 of 17

Das könnte Ihnen auch gefallen