0% found this document useful (0 votes)
2 views5 pages

Revision Note

The document is a cheat sheet for IGCSE algorithms, covering various programming concepts such as variable declaration, data types, control structures (if statements, loops), and array manipulation. It includes examples of basic operations, functions, and procedures, as well as file handling. The content is structured to aid students in understanding and applying algorithmic principles in programming.

Uploaded by

jwj080908wkd
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)
2 views5 pages

Revision Note

The document is a cheat sheet for IGCSE algorithms, covering various programming concepts such as variable declaration, data types, control structures (if statements, loops), and array manipulation. It includes examples of basic operations, functions, and procedures, as well as file handling. The content is structured to aid students in understanding and applying algorithmic principles in programming.

Uploaded by

jwj080908wkd
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

IGCSE Algorithms Cheat Sheet

numStudents =
numStudents + 1

Declaration ELSE
Setting the name and datatype of a variable OUTPUT "Answer not recognised"
END If
Declaring variables
DECLARE counter : INTEGER NEXT X

DECLARE Total To Pay ; REAL Totaling


DECLARE GameOver : BOOLEAN total Merits = 0

Declaring Constants termEND :


FALSE
CONSTANT Hourly Rate < 6 50 . WHILE termEND == FAISE
"

CONSTANT Default Text < "NIA" OUTPUT "is the term over ?

Declaring Arrays/List INPUT choice

DECLARE Students Names : ARRAY (1 : 30] OF STRING If choice == "No"


DECLARE test Grades ARRAY (1 : 3 lis] Of OUTPUT "How do you have?"
CHAR
:
, many merits
2) for 3 grades for 3 Students INPUT merit
Basic Skills totalMerits = total Merits + merits

Assigning values to a variable ELSE If Choice ==


"Yes"
a <100 termEND :
TRUE
b +
19 END If
total (a + b 1 or = END WHiLE
product (a x b
Average
remainders a %b For X= 1 TO 7
using a constant OUTPUT "How much rain today"
CONSTANT required Score >45 INPUT rain Amount

INPUT Score total Rain& total Rain + rain amount

If score ! = required Score NEXT X

OUTPUT "You "Averge


"
can't OUTPUT :
rain per day" + total rain 0.

ELSE OUTPUT "You got Loop


"
it

END If Loop based on user input -


for Loop

checking if numbers are in range INPUTnumloops


Score' 80 For X= 1 to numloops

If score < 50 THEN OUTPUT "Loop" + X

OUTPUT "Fail" NEXT X


EISE If THENV Loop based on user input-while loop
OUTPUT "Pass" INPUT numLoops
EISE If XX 1

OUTPUT"Distinction" WHILE numloops) X =

END IF OUTPUT "Loop" + X


Counting X = X+ 1

numTeachers > O END WHILE

num Students = O For Loop increment


For X = 1 To 10 includes 1 and 10
day =
[ "Mon" "Thes" "Wed" "Thurs"
, , , ,
"Fri"]
OUTPUT "Are you FORX STEP
"
a teacher or student ? = 0TO 4 2

INPUT Choice OUTPUT day(s)


If Choice == "Teacher" NEXT X
numTeachers - numteachers + 1 / this would print mon , wed , fri
ELSE If Choice == "Student"
For loop decrements Insert a value to an array
day = [ "Mon" "Thes" "Wed" "Thurs" "Fri"]
, , , ,
DECLARE animalNames : ARRAY [1 : 30] OF STRING
FOR X =
4 to 0 STEP -1 For X = 0 To 9
OUTPUT day [x] INPUT name

NEXT X animal Names[x] - name

1/ This would print fr Thurs wed Thes Mon NEXT X

Repeat Untill Loop Linear Search


attempts = 0 animals : [ "Pig" "horse" "(at"]
, ,

REPEAT FOR X = 0 TO 2
INPUT Pw INPUT SearchName
attempts = attempts + 1 IfSearch Name == animal Names[(c]
UNTIL Pw "flower" = OUTPUT "Found"
me

Bubble false condition BREAK


sor
nums = [62 , 60 , 44 , 11] END If
FOR X 0 TO
E
= 2 NEXT X

FORY = 0 TO 2 Totalling values in an


array
If nums[Y] > nums [YH] Sales : ['i0" "zo" "3o" "8"]
, , ,

temp = nums[Y) total Sales = 0

nums[Y] = nums [y+) FORX = 0 TO 3

nums [Y +1) = temp totalsules < total Sales + Sales [x)


END If NEXT X

NEXT Y OUTPUT total Sales


NEXT Y 2D arrays
ID Arrays Outputting all contents

Outputting all values in array names : ( "Bill" "Bob" "Sue"]


, ,

names : ("Tom"" Harry" "Suzy" "Minji") , ,


grades = (162 , 60 44] , ,
16 27 22] (1
, ,
. ,
6. 81)
F OR X = 0 To 3 FOR X = 0 TO 2

OUTPUT names (x) OUTPUT "Student : " ,


names [x)

NEXT X FOR Y = 0 TO

Finding highest number OUTPUT grades [X][Y]

numbers = (20 , 50 , 94) NEXT Y

highest+o NEXT X
FOR X = 1 TO 2 Using If statements
If numbers [c) > highest names : ( "Bill" "Bob" "Sue"]
, ,

highest = numbers [x] grades = (162 6044) (6 27 22] (1


, , ,
. ,
6. 81)
END) If FOR X = 0 TO 2

NEXT X OUTPUT "Student : " ,


names [x)

OUTPUT highest FOR Y = 0 TO

Finding lowest number OUTPUT grades [X][Y]

numbers = (20 , 50 , 94) If grades [x][+] < 90


lowes
= 999 OUTPUT "Excellent Grade"
If numbers [x)) lowest EISE IF grades [x][Y] > 70
lowest = numbers [x] OUTPUT "good grade"
END) If ELSE
NEXT X OUTPUT "Bad Grade"
OUTPUT highest NEXT Y
NEXT X
Averaging values in a 2D array Reading from file
names : ( "Bill" "Bob" "Sue"]
, ,
OPEN names . txt FOR READ // opens file
grades = (162 6044) (6 27 22] (1
, , ,
. ,
6. 81) DECLARE line : STRING 11 declares variable
grandTotal :0 WHILE NOT Endoffile DO // Check if at end of file

FOR X = 0 TO 2 READFILE Marks . Ext , line/1 read the next line


total= 0 to the line variable

OUTPUT "Student:" names (x) output line// output the line just read
,

fOR Y = 0 TO 2 END WHILE

&otal =
total + grades [x][y] CLOSEFilE names .
Ext 1/ close the file

grandTotal : grandTotal + grades [x] [y] Writing to file

NEXT Y 1 opens a file in written role

OUTPUT total OPEN marns txt FOR


OUTPUT names() , "Average" total/3 INPUT name

NEXT X INPUT mark

OUTPUT "All Student average :


"
Grand Total/a / is used to save some fin me

Counting values in 21 array recorda name + "Murk" in I

names : ( "Bill" "Bob" "Sue"]


, , WRITEFILE marks .
Ext // close the filter has its

grades = (162 6044) (6 27 22] (1


, , ,
. ,
6. 81) housesou

INPUT Score

Count = 0

FOR X 0 To = 2

FOR Y =
0 To 2

If grades [][y] <: Score

Count = Count + 1

NEXT Y
NEXT X DECLARE Maths :
ARBAY[O : 2] OF INTEGER
OUTPUT "Scores >: " score ,
"is" ,
count [012 ,
0: 2]
Function
FUNCTION add (num1 : INTEGER ,
num2 : INTEGER
RETURNS INTEGER

RETURN num1 + num

ENDFUNCTION

INPUT firstNuM
INPUT secondNUM
OUTPUT "Adding numbers : add /firstNum , Second Num)
"

Procedures
PROCEDURE WelcomeMSG
OUTPUT "Hello"
ENDPROCEDURE

PROCEDURE area Circle (al (radius : INTEGER


*
OUTPUT 3 14
. radius" radius

ENDPROCEDURE

WelcomeMsy()
areaCircle (al (5)
or
-

=
= -

I
1 .
Declaration IF
.
2 Symbel & Variables IF Marks) =
10 THEN
.
3
4 Conditional
.
Lop
Starment
path
( END
-

IF

. Function Case Of
5

.
6 Sprocedure le
of Exce => Variable
17 .
Openfile condition :
Petebration
-

-
OTHERWISE OUTPUT
1 Declaration
.

SE
DECLARE Math INTEGER :

CONSTANT English" TYPE CHECK


DECLARE Marks ARRAYI 0 31 OF INTEGER : : buse MOD/ DIV
DECLARE Mary : ARRAY EO,3 0 : 3) OF INTEGER ,
LENGE
2 Warnings
.
LENGFH) /
MOD(0 1) ,
1 .

Always in
Capital Range
DIVCO 1),
2 . (/ )( = ) (1 /x) = = = >
3 .
All variables must have meanings (X ,
X
.2 2) FUNCTION
.

.
3 Loop 4 PRINT
.
WithHext
,
While FUNCTION Variable Name (Received Variable : TYPE)
CONSTANT Count
= 0 RETURNS TYPE
<The Conditio
-
WHILE Count
mu
to (Operations]
INPUT Marks END When it is Falr RETURN Vi What

Count+ Can+ +1 EIUDFUNCTIO


END WHILE
FOR COUNT LOGG PROCEDURE
INPUT Marks- PROCEDURE Name PROCEDURE Name (Value : Type
include all
NEXT COUNT END PROCEDURE ENCS PROCEDURE
RepeatUntil
REPEAT Bubble Sort +1

Counter - Carter * 2
UNTIL Counter >9
nu
DECLARE Textin : Start
fale condition DECLARE My file :
Strin
END When it is tuve

Myth - "fil Ext" .

CHESIZI] TYPE CPEN MyFil FOR WRITE


INPUT
[Ni(X) - X =
0 WRITETIE, Text
CLOSEFILE (MyFir)
DECLARE
READFILE OPEN FOR OPEN My Fil FOR PLE
OPEN FFFCLOSE) (
Myth Ext EAd Nate TextLin
TExEhe
.

①G OUT Run
OPENFILE CLOr T
CREN My Fil Ter With
INPUT Textin
UR
&

Pro

PROCEDURE Ap)A Integer(


:

END PROCEDURE

FUNCTION Ap)A: Inlyt


RETURNS INTEGER

RETURN
-

DECH

You might also like