Arithmetic Operators (additional to Chapter 7)
DIV (Gives the whole number after the first number is divided by the second, i.e. it ignores the fractional part)
E.g. DIV (10,2) gives 5 and DIV(11,9) gives 1
MOD(Gives the remainder after the first number is divided by the second, i.e. it ignores the fractional part)
E.g. DIV (10,2) gives 0 and DIV(11,9) gives 2
String Manipulation
LENGTH(string)
LENGTH(“hi”) would return 2
LENGTH(0123) would return 4
SUBSTRING (String, start character, number of characters)
SUBSTRING (“HELLO”, 0, 1) will return “H”.
SUBSTRING (“GOODBYE”,4,3) will return “BYE”.
UPPER(string) and LOWER(string)
UPPER (“hello”) will return “HELLO”.
LOWER (“HELLO”) will return “hello”.
Library Routines
ROUND (It takes a real value and limits how many numbers there are after the decimal point)
E.g. ROUND(10.123,1) gives 10.1 and ROUND(4.8293,2) gives 4.82
RANDOM (This generates a random number between two values that it takes as parameter)
E.g. RANDOM(10,20) will return any number between 10 and 20
File Handling
Reading from a file (Stages)
Open the file using its filename (filename is a string value)
Read the data value and do something with it (output/store)
Close the file
Syntax
OPEN filename
Variable identifier = READ (filename)
CLOSE filename
Example
OPEN “data.txt”
OUTPUT (READ(“data.txt”))
CLOSE “data.txt”
Writing to a file (Stages)
Open the file using its filename (filename is a string value)
Write the data to the file
Close the file
Syntax
OPEN filename
WRITE data
CLOSE filename
Example
OPEN “colour.txt”
WRITE “red”
CLOSE “colour.txt”
One mark per mark point, max two
a list / one column of items
... of the same data type
... stored under a single identifier
... with a single index to identify each element
One mark for an example of a declaration
example e.g. DECLARE MyArray[1:10] OF INTEGER
One mark per mark point, max two
using a counter to index the array
so that the same code can be repeatedly used to check every element // every element can be checked in a loop
(a) One mark for:
Use of FOR loop
Working loop with the correct number of Iterations
Correct assignment
FOR Count ← 1 TO 20
dataArray[Count] ← 0
NEXT (Count)
(b) (A FOR loop has) a fixed number of repetitions // No need to manage the loop counter // no need to use another variable for the array index
X = "Programming is fun"
Length(X) will return 18
Y= 16
Z= 3
SubString(X,Y,Z) will return "fun"
SubString(X,16,3)