Caie As Computer Science 9608 Practical
Caie As Computer Science 9608 Practical
2
CHAPTER 1
Algorithm Design & Problem Solving
3
CHAPTER 2
Data Representation
4
CHAPTER 3
Programming
5
CHAPTER 4
Software Development
CIE AS-LEVEL COMPUTER SCIENCE//9608
1. ALGORITHM DESIGN & PROBLEM-SOLVING As for selecting what loop to use, it is best to use FOR
Abstraction: filtering out and concentrating on the loops when you know the number of iterations
relevant information in a problem; allowing a programmer required, and a WHILE or REPEAT loop if you do not
to deal with complexity know the number of iterations required.
Decomposition: breaking down problems into sub- o Iterate over an array: FOR Loop
problems in order to understand a process more clearly; o Reading a file into a variable: WHILE Loop
program modules, procedures and functions all help the o Asking for user input: WHILE/REPEAT Loop
programmer to break down large problems o A loop that should execute n times: FOR Loop
Algorithm: a solution to a problem expressed as a
1.3 Stepwise Refinement
sequence of steps
Process of developing a modular design by splitting a
1.1 Identifier Table problem into smaller sub-tasks, which themselves are
repeatedly split into even smaller sub-tasks until each is
Identifier: name given to a variable in order to call it
just one element of the final program.
An identifier table depicts information about the
variable, e.g.
1.4 Program Modules
This refers to a modular program design
Subroutines: self-contained section of code, performing
a specific task; part of the main program
Procedures: performs a specific task, no value returned
Rules for naming identifiers: to part of code where called
o Must be unique Functions: performs a specific task, returns a value to
o Spaces must not be used part of code where called
o Must begin with a letter of the alphabet
o Consist only of a mixture of letters and digits and the 1.5 Logic Statements
underscore character ‘_’ Operato Meaning Operator Meaning
o Must not be a ‘reserved’ word – e.g. Print, If, etc. r
< Less than >= Greater/equal
1.2 Basic Program Operations <= Less than/equal == Equal to
Assignment: an instruction in a program that places a > Greater than != Not equal to
value into a specified variable
Sequence: programming statements are executed 2 DATA REPRESENTATION
consequently, as they appear in the program
2.1 Data Types
Selection: control structure in which there is a test to
Integer:
decide if certain instructions are executed
Positive or negative number; no fractional part
o IF selection: testing 2 possible outcomes
Held in pure binary for processing and storage
o CASE selection: testing more than 2 outcomes
Some languages differentiate short/long integers (more
Repetition/Iteration: control structure in which a group
bytes used to store long integers)
of statements is executed repeatedly
Real:
o FOR loop: unconditional; executed a set no. of times
Number that contains a decimal point
o WHILE loop: conditional; executed based on condition
Referred to as singles and doubles depending upon
at start of statements
number of bytes used to store
o REPEAT loop: conditional; executed based on
Character:
condition at end of statements
A character is any letter, number, punctuation or space
Takes up a single unit of storage (usually a byte).
PAGE 2 OF 7
CIE AS-LEVEL COMPUTER SCIENCE//9608
String: 2.4 Arrays
Combination of alphanumeric characters enclosed in “ ” 1-Dimensianal (1D) Array 2-Dimensional (2D) Array
Each character stored in one byte using ASCII code declared using a single declared using two
Each character stored in two bytes using Unicode index, can be represented indices, can be
Max length of a string limited by available memory. as a list represented as a table
Incorrect to store dates or numbers as strings
Phone no. must be stored as string else initial 0 lost
Boolean:
Can store one of only two values; “True” or “False”
Stored in 1 byte: True = 11111111, False = 00000000 Pseudocode:
Date: o 1-D Array: A[1:n]
Dates are stored as a ‘serial’ number o 2-D Array: A[1:m, 1:n]
Equates to the number of seconds since January 1st, Python:
1904 (thus they also contain the time)
o Declaring an array: a = []
Usually take 8 bytes of storage
o Adding to an array: a.append(anything)
Displayed as dd/mm/yyyy or mm/dd/yyyy
o Length of array i.e. number of elements: len(a)
Array:
o Printing an element in a 1D array: print(a[x])
Data structure consisting of a collection of elements
o Printing element in a 2D array:
Identified by at least one array index (or key)
print(a[row][column])
File:
o Printing row in a 2D array: print(a[row])
Object that stores data, information, settings or
o Printing column: use for loop and keep adding 1 to the
commands
row and keep column same
Can be opened, saved, deleted & moved
Transferrable across network connections 2.5 Bubble Sort
2.2 ASCII Code
Uses 1 byte to store a character
7 bits available to store data and 8th bit is a check digit
27 = 128, therefore 128 different values
ASCII values can take many forms: numbers, letters
(capitals and lower case are separate), punctuation, non-
printing commands (enter, escape, F1)
PAGE 3 OF 7
CIE AS-LEVEL COMPUTER SCIENCE//9608
The second FOR loop is count based thus will stop after a variable.readlines()
specific number of times Writing to a file:
o Write a fixed a sequence of characters to file
Goes through bigger FOR loop ∴ ‘sorted’ remains ‘true’
variable.write(“Text”)
This exits the loop ∴ ending the program o Write a list of string to file
2.6 Linear Search variable.write[“line1”, “line2”, “line3”]
PAGE 7 OF 7