Beruflich Dokumente
Kultur Dokumente
Introduction
Initialization of Variables
FINDING A SOLUTION TO THE PROBLEM
INTRODUCTION
The word variable is derived from the verb ‘to vary’. This
means that the value stored in a particular location can
change from time to time, although the label remains the
same.
Memory locations
Num 1 5
Variables 3
Num 2
25
Num 3
FINDING A SOLUTION TO THE PROBLEM
THE CONCEPT OF VARIABLES
Option 2 Option 1
Get num1, num2, num3 Get num1, num2, num3
Average = (num1 + num2 num3)/3 Sum = num1 + num2 + num3
Print Average Average = sum/3
Stop Print Average
Stop
E.g. Count = 0
Algorithmic structure
Problem:
Write an algorithm that prompts a student to enter
his/her name and age, accepts the name and age and
then display a welcoming message on the screen such
as “hello Michael! You are 16 years old!”
Print
Average
Stop
CONDITIONAL/SELECTION STRUCTURES
Selection (decision)
The IF…THEN selection statement
Syntax:
IF (expression) THEN
{Statement (s)} Execute this statement if logical
expression is TRUE
IF (expression) THEN
{Statements} executed only if condition is TRUE
ELSE
{Statements} executed only if condition is FALSE
ENDIF
e.g. FOR X = 1 to 10 DO
{Statements to be executed}
ENDFOR
REPETITION STRUCTURES
A teacher has realized an error in his marking after having marked all
his students’ scripts. He has therefore decided to credit all students
who got less than 60 with an additional 5 marks. Those who got 60 and
over would be credited with an additional 15 marks. Write an
algorithm to accept the initial marks obtained by the 20 students in the
class. Calculate and print each student’s adjusted mark.
The teacher would like to determine the class average after the marks
are credited. Should the class average exceed 60, “Instructions well
received” should be printed. Otherwise, “Reconsider Teaching
Methods” should be printed.
REPETITION STRUCTURES
INPUT Value
WHILE (expression) Do
{statements} executed if Boolean argument in logical
expression is true
INPUT value to be tested
ENDWHILE
REPETITION STRUCTURES
WHILE Loop
FOR X = 1 to 3 DO
FOR Y = 1 to 3 DO
Product = Y * X
Print Product
ENDFOR
ENDFOR
TRACE TABLES
What’s printed by the following Algorithm?
AMOUNT = 2
G=4
WHILE AMOUNT < 50 Do
G = G*2
AMOUNT = AMOUNT + G
Print AMOUNT, G
ENDWHILE
TRACE TABLES
INPUT A,B,C
A=B+C
B=A–C
C= A+B
IF A > B THEN
C=A–B
ELSE
C=B–A
ENDIF
Print A,B,C
State what is printed by the algorithm above when the following data is input:
(i) 5, 7, 9
(ii) 9, -7, 5
TRACE TABLES
What is an Array?
Initializing Arrays
Traversing Arrays
Manipulating Arrays
TOP-DOWN DESIGN METHODOLOGY
Hierarchy Charts
Steps in Modularization
Pascal in a Nutshell
Summary
PROGRAM EXECUTION ON THE COMPUTER
Types of Errors
Debugging
THANK YOU
For your attention