KEMBAR78
Pseudocode - IGCSE OL Notes | PDF | Data Type | Boolean Data Type
0% found this document useful (0 votes)
123 views40 pages

Pseudocode - IGCSE OL Notes

The document outlines the Program Development Life Cycle, detailing the stages from problem analysis to maintenance. It covers key concepts such as abstraction, decomposition, pseudocode, data types, and control structures including loops and conditions. Additionally, it provides examples of programming tasks and the use of arrays for data management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views40 pages

Pseudocode - IGCSE OL Notes

The document outlines the Program Development Life Cycle, detailing the stages from problem analysis to maintenance. It covers key concepts such as abstraction, decomposition, pseudocode, data types, and control structures including loops and conditions. Additionally, it provides examples of programming tasks and the use of arrays for data management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

IGCSE | OL

0478 | 2210 Program Development Life cycle

Problem Program

ñ 3 4
Problem → Analysis → Design → Coding → Testing

5
Maintainence

Program

I Analysis

- Abstraction: The act of removing


unnecessary details
- to focus on important
elements.
- Decomposition: Breaking down a
problem into smaller , clear and
manageable sub-parts.

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
- Requirements Document: A document
which has all the requirements with
a brief description of each.

Smart Watch Problem

Health weather Time Play Store


at
Temp Humi­ Game WhatsApp
Heart dity Date
Rate Time
Oxygen
level

≥ Design

- Structure Chart
- Flow Chart
- Pseudocode → Not a programming -
language

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
Pseudocode: Informal way of writing down
a program.

Topics to be covered in pseudocode:

1 Declaration & Initialization


2 Input & Output ✓
3 Operators
4. Conditions
- IF ELSE -CASE END CASE ✓
≤ Loops
- FOR Loop -WHILE Loop
- REPEAT UNTIL Loop
6. Arrays
- ID Array - 2D Array
≥ Sub-routines
- Procedures - Functions
& String Manipulation
9 Linear Search & Bubble Sort
11 File Handling-

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
730 - 830 pm PST
Monday
Tuesday
Wed P2
Thursday

Topicals Read & write P1 & P2

April : Mocks

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
Pseudocode: Not a programming language

Informal way of writing down a program.

Data Types:
: Integer: 2 , 5,-43, 58, 167895
? Real: 2.5,-3. 7, 58.3
3 Char: ①7 ' i'@" '$' '2'
(q

4. String: pakistan 123@" "A2"


3 Boolean: TRUE , FALSE

Character can be any letter, digit, special


characters and space.

REAL → 2.0
2 integer
'2' ← char (I cannot perform arithematic
operation on it)

"I-iii. 'Joining""Jugini""} string

space character ↳ Length = 19.

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
Variable → it can vary -
Constant → it stays same

Variable:
1 whose value is input by the user
2 whose value is calculated in the program.

marks percent

You have to
initialize it.
"in??!?!code,
of
we use assigning a starting
value to the variable
assignment e.g percent ← 0
operator

U' sum = 0 X sum c- O

"Sameer" O is assigned to
sum
string.

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
① Write a program that takes input two
integers and outputs their sum.
Display relevant messages as well.
name of variables data type
DECLARE numl, num2, sum: INTEGER flow
sum < 0
(c output
OUTPUT Enter
. first number❤ message
INPUT numl 1
OUTPUT" Enter second number" input first no.

INPUT numZ 2
3 I output
sum numl + num2 message
OUTPUT "Sum is " , sum
input second no.

variable sum is calculated


Sum is 3 output message
for sum

variables:
make sure that you - numl
have meaningful names - num2
for variables. - sum

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
2 Write a program that takes input
the name and age of a user. If a
user's age is above 18, he/she will be
allowed to get the driving liscence
otherwise he/she will be rejected.

STRING name
INTEGER age

DECLARE name : STRING output


message
DECLARE age: INTEGER

input name
OUTPUT" Enter your name " ↓
output
INPUT name message
OUTPUT" Enter your age "
INPUT age input age ✓

if age 7 18
IF age > 18
accepted for
TEN OUTPUT "Accepted"
liscence
ELSE OUTPUT "Rejected"
else rejected.
ENDIF

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
3 Write a program that takes input the
name and computer science mid year
marks of a student. The program calculates
the percentage of the student and outputs
a grade according to the following
criteria.
If percentage is greater than or equal to
50, student gets A grade-• else student
gets U grade.
Total marks are 120.
↗ String.
name
DELLARE name: STRING marks → Int
DECLARE marks: INTEGER percent
DECLARE percent: REAL ↳ Real
percent 0.0
OUTPUT "Apka naam Kiya hai?"
INPUT name

OUTPUT "Apne number btao?"


INPUT marks

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
percent ← Marks/120 * 100

IF percent > = 50
THEN OUTPUT "Wah beta A Leliya"
: ELSE OUTPUT "Nikal Yahan se U"
END IF

Multiple IF conditions.

1 Write a program that takes input name.


and marks of a student. The program
calculates the percentage and outputs the
grade using the following criteria.

percent > = 90 and < = 100 ✗ A'

= 80 and < 90 ✗ A

> = 70 and < 80 ✗ B

70 U else
Total marks = 120.

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
DECLARE name : STRING
DECLARE marks : INTEGER
DECLARE percent: REAL
percent ← 0.0

OUTPUT" What is your name? "


INPUT name
OUTPUT" What are your marks?"
INPUT marks
percent ← marks/120 * 100
!

I= percent > = 90 AND percent < = 100


THEN OUTPUT "Your grade is A *"
ELSE IF percent 7=80 AND percents 90
THEN OUTPUT "Your grade is B"
ELSE IF percent 1=70 AND percent < 80
THEN OUTPUT "Your grade is C"
ELSE OUTPUT "Your grade is U"
END IF
END IF
END IF

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
Now lets do it with an easy way.
CASE END CASE statement.
!
percent ← marks/ 120 * 100

CASE OF percent
> = 90 AND 4=100 : OUTPUT "Grade is A "
7=80 AND C 40 : OUTPUT" Grade is A"
> = 70 AND 480 : OUTPUT "Grade is B"
OTHERWISE OUTPUT" Grade is 0"
END CASE

Data Types
Declaration / Initialization
Input / Output
If else condition

Case end case conditions.

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
Loops / Repetitions ← when we want our
program to run more
than once.

1 Count- Controlled Loop/ FOR Loop


- used when you know the number of
times program should run.

Eg Write a program that outputs


statement 5 times.

DECLARE count : INTEGER


FOR count 1 TO 5
OUTPUT "Kon Talha?" ✓
NEXT count

Kon Talha?
Kan Talha?
Kan Talha?
Kan Talha?
Kon Talha?

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
e.g write a program that takes
input the marks of 10 students
and outputs their sum and
average.

DECLARE marks. sum, count: INTEGER marks


DECLARE avg: REAL sum
sum 0 avg
avg ← 0.0

FOR count ← 1 TO 10
-
OUTPUT "Enter your marks:"
INPUT marks
sum ← sum + marks
NEXT count
avg ← sum 110
OUTPUT sum
OUTPUT avg

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
e.g Write a program that takes input
10 integers and output how
many numbers are greater than
20.

DECLARE num, count, counter: INTEGER


counter ← 0

FOR count ← 1 TO 10
OUTPUT "Number enter Karo"
INPUT num
IF num > 20
THEN counter ← counter + 1
END IF
NEXT count

OUTPUT counter

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
2- Pre-condition Loop / While Loop

↳ not equals to

Write a program that takes input


integers until -1 is entered.

DECLARE num: INTEGER


2

OUTPUT "Number enter Karo" 3


INPUT Him 4
1
WHILE num <)-1
7
OUTPUT "Number enter Karo" 1
INPUT num 6
END WHILE 2

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
3 Post - condition Loop /Repeat Until Loop.

Write a program that takes input


integers until -1 is entered.

DECLARE 'Mum : INTEGER

PEPEAT
OUTPUT " Apna number btao?"
INPUT num
UNTIL num = -1

Write a program that is used to


validate the input of a user. User is
supposed to enter numbers in range 10
to 50 inclusive. If a user enters a
number out of range, he should re-enter

the correct number again.

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
DECLARE num : INTEGER

OUTPUT "Enter your number:" 6-0


INPUT num
60 739
WII LE num < 10 OR num > 50
OUTPUT " Invalid number Please re-enter:"
NPUT num
END WHILE

DECLARE num : INTEGER 6-0

REPEAT 10 -50
OUTPUT " Enter number"
INPUT him
UNTIL num > = 10 AND num (= 50

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
Write a program that takes input
30 integers and outputs their sum,
average, minimum and maximum.

DECLARE Num, sum, min, Max, count: INTEGER


DECLARE Eg: REAL
sum ← 0
avg ← 0.0
min ← 10000800 00
max ← 0

FOR count ← 1 TO 50

OUTPUT " Apna number btao?"


INPUT num 10
sum a sum + num
IF num max
THEN Max ← num
ENDIF

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
IF Mum < min
THEN min ← num
END IF

NEXT count

avg ← sum 150

OUTPUT sum, avg, min, max

OUTPUT "Apka sum hai ? ", sum

Apka sun hai 40

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
1 Write a program that takes input
500 integers. The program should
allow only numbers in range of
10 and 90 inclusive. The program
also counts the numbers entered
which are divisible by 3 and
display their count.

it tells → MOD
about the remainder
when 27 is e.g 27 MOD 3
divided by 3. = 0

IF num MOD 3=0


counter ← counter + 1
END IF

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
DECLARE num, count, counter : INTEGER
counter ← 0

FOR count ← 1 TO 500

OUTPUT "Apna number btao?"


INPUT Num

WHILE num < 10 OR num 790


OUTPUT "Out of range! Re input"
INPUT num
ENDWHILE

IF num MOD 3 = 0
1 FN counter ← counter + 1
END IF
NEXT court

OUTPUT counter

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
You are developing a program for the
famous fast food chain - Johnny Jugnu.
The program displays their menu first:

" !Wehshi Burger ≤ Tortilla Wrap ≥ Gochu Wings"


Ask the user to choose an option from
1,2. 3. Update the total bill accordingly
such that we hsi burger is of 950,
tortilla wrap is of 1000 & gochu wings
is of 650.
Display the total bill at the end.

DECLARE option, bill : INTEGER


bill ← 0
. OUTPUT "⟂ Wenshi Burger? Tortilla Wrap 3 hochu Wings"
• OUTPUT "Choose an option from above.!'
INPUT option
CASE OF Option

1 : bill ← 950
2: bill ← 1000
3: bill ← 650
OTHERWISE OUTPUT" Invalid option"

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
END CASE
OUTPUT" Apka bill hai .", bill

Arrays ID & 2D

Store the marks of 50 students of a


class


DECLARE marks : INTEGER
FOR count ← 1 TO 50 marks
INPUT marks - 78
NEXT count
marks

62
1
DECLARE marks: ARRAY (1: 8) OF INTEGER
.
2
78
.
FOR count ← 1 To 8 3 50
y
INPUT marks (count
5
NEXT count index
'6

7
INPUT marks [6]
• 8
location
CS with SR CS with Sameer Raza
cswithsr +92 321 1688024
Storing the marks of e.a 10 students of
a class can be done 0 through 111 Array.

But what about if there are 5 classes


and 10 students in each class.
You can use a 2D array.
student
pass
1 2 3 4 5 6 7 8 9 10

I m M Mm m m q q

5
C

rows col

DECLARE marks: ARRAY [1:5, 1:10] OF INTEGER


DECLARE class , student : INTEGER
FOR class ← 1 TO 5
FOR student ← 1 To 10

INPUT marks (class, student]


NEXT student
NEXT class

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
File Handling:

- Data can be stored in Arrays but not permanen­


tly.

- File Handling is a much better option when it


comes to storing data permanently.

- READ: reading data from the file


- WRITE : create a blank new file and store
data in it.
- APPEND: store data in an already existing
file

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
A company wants you to read the data of
7)
employees from a file called"emp.txt •

The data in the file is e.g STRING

1 Musa Khan
= Manager linel Musa Khan
3 80000 line → Manager
lines → 80000

DECLARE linel, lin.e 2, line}: STRING Ali Imran


OPENFILE "emp.txt" FOR READ Senior Developer
WHILE NOT EOF ( "emp.txt") 100000.

READFILE "emptxt", line/ Fatima Adnan


READFILE "emp-txt", line 2 HR Head
READFILE "emp-txt", line} 125000
I
ENDWHILE
CLOSEFILE "emp.txt"
EOF
Read
end of file
1 Open
2 read
≥ close

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
A program that takes input the name and
status of an employee and stores it in two
lines in a file called"emp. txt".
emp.txt
DECLARE name, status: STRING Fayaz
OPENFILE "emptxt" FOR WRITE CEO

OUTPUT "What is your name?"


INPUT name
OUTPUT "What is your status?"
INPUT status

WRITE FILE "emp.txt" , name


WRITEFILE "erp.txt", status

CLOSEFILE "emp.txt"

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
Scenario Based Pseudocode Question:

A school is conducting a coding competition


where students from different grades participate.
Each grade has multiple students and their
scores are stored in an array. The school wants
to analyze the results to find:

- . 5- grades
Write pseudocode to 10 students
- take input the score of each student
of each grade in the 2D Array.
2 the highest score in each grade
3 the overall highest score across all grades,

≤ display the above data.

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
DECLARE score: ARRAY [1:3, 1:10] OF INTEGER
DECLARE highest, all Highest : INTEGER
highest ← 0
all Highest ← 0
2
FOR class ← 1 TO 5
↳ For students ← 1 TO 10

INPUT score/class, student]


30 10
TF
- score (class, student) > highest
THEN highest- score (class, student)
ENDIF 310
N EXT students

OUTPUT "Highest is ", highest 30

-
IF hig h est > overall Highest
THEN overall Highest ← highest
ENDIF
NEXT class

OUTPUT "Overall Highest is", overall Highest_


.

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
Sub-routine: Reusable piece of code
Procedures
Functions

Procedure:

Write a program that takes input the


marks of three subjects of a user. The
program outputs the grade of each subject
based on the percentage such that:
> = 90 & < = 100 A*
> = 80 2 <= 09 B
> = 70 2 2=79 C
470 F

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
DECLARE phy, comp, math : INTEGER
DECLARE percent : REAL
OUTPUT "Enter your Physics marks:"
INPUT phy
percent ← phy/120 * 100

CASE OF percent
> = 90 AND 2=1:O: OUTPUT "A' hai"
> = 80 AND 2=89: OUTPUT "B hai"
7=70 AND 4=79 : OUTPUT "Chai"
270 : OUTPUT "F hai"
ENDCASE

instead of repeating
the piece of code!
each subject, how about
we use sub-routines?

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
When we use sub routines, we follow
a specific order of things:

1 DECLARATIONS / INITIALISATION
2 SUBROUTINE
3 MAIN PROGRAM.

DECLARE phy, comp, Math: INTEGER


name of procedure 276 Parameter
◦ROCEDURE -find Grade ( marks : INTEGER
DECLARE percent: REAL
✓percent ← marks /120 * 100
CASE OF percent
> = 90 AND 2=100 : OUTPUT "A" hai"
> = 80 AND 2=89: OUTPUT "A hai"
> = 70 AND 4=79: OUTPUT "B hai"
470 : OUTPUT "F hai"
ENDCASE

END PROCEDURE

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
OUTPUT "Physics ke marks btao?"
INPUT Phy
CALL find Grade (phy )
OUTPUT" Computer mein kiya halaat hain?"
INPUT comp
CALL find Grade (comp) .
OUTPUT "Maths ki. smao"
INPUT math
CALL find Crade (math) .

Functions:
unlike procedures, functions return data.

e.g write a function that takes two


numbers as parameter and returns
the largest one.

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
DECLARE large, numl,num2: INTEGER

7 5 7
FUNCTION find Large (n1 , n2 : INTEGER) RETURNS INTEGER
5 7
IF nl > n2
THEN RETURN NI
ELSE RETURN NZ 7
END IF
ENDFUNCTION

11 Main Program

OUTPUT " Pehla number btao?"


INPUT numl 5
OUTPUT " Dusra number btao?"
INPUT num2 7
large ← find Large (nu5ml, nimz)
OUTPUT large 7

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
Linear Search:
* User wants to search a value in an
array.
* Linear search is a method to perf m
the searching

DECLARE arr : ARRAY [1:10] OF INTEGERS


DECLARE key , count: INTEGER
DECLARE found: BOOLEAN TRUE /FALSE
found ← FALSE
count ←
OUTPUT "Enter the number you want to search:"
INPUT key key = 7
arr

I
REPEAT
O

IF key = arr (count] 3


y
THEN found ← TRUE 7

5 8
ENDIF
6 15

count-count + I 7 6

UNTIL found ← TRUE OR count > = Size

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
IF found = TRUE
THEN OUTPUT "Number found at", count-1
ELSE OUTPUT "Number not found"
ENDIF

Bubble Sort: arrange elements of array in


ascending or descending order.

Lets consider an array of integer:

12, 45, 23, 51,19, 8

I Compare jth and (j+1)" element.


2 If jth > (j+1)" element, then swap.
3- repeat till last unsorted element of array.
I repeat step 1 -3. (size-1) times

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
FOR I 1 To size-1
FOR j ← 1 To size-i
IF arr (j] > arr [5+1] THEN
temp ← arr (j)
arr (j) ← arr (jtl] Swap code
arrlj.tl) ← temp

ENDIF

NEXT;
VEXTI

Built in Functions:

- STRING Functions:

Lets consider a string named order

order < "I love Johnny Jight,"


1 2 3456 7 89 10 14 15 '8

LENGTH (order)
returns the total number of characters in
the string. e.g 20

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
UCASE (order)
returns the string in upper case characters.
e.g "I LOVE JOHNNY JUANU."

LCASE (order)
returns the string in lower case characters.
e.g "i love johnny jugnu."

SUBSTRING (order, 3,4) returns "love"


,

steps to count
starting
including starting
position of (
position.
substring

→ ARITHEMATIC Functions:

MOD (5, 2) returns 1

dividend divisor remainder

DIV (5, 2) returns 2



Quotient

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024
ROUND (4.62, 1) returns 4.6

number number of
to be rounded decimal places
e.g
ROUND (4.62, 0) returns 5

RANDOM () returns a random real number


between 0 and 1 inclusive.

CS with SR CS with Sameer Raza


cswithsr +92 321 1688024

You might also like