Caie As Computer Science 9618 Practical Notes and Guide

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

ZNOTES.

ORG

UPDATED TO 2017 SYLLABUS

CAIE AS LEVEL
COMPUTER
SCIENCE (9618)
SUMMARIZED NOTES ON THE SYLLABUS
CAIE AS LEVEL COMPUTER SCIENCE (9618)

Reading a file into a variable: WHILE Loop


Asking for user input: WHILE/REPEAT Loop
1. Algorithm Design & A loop that should execute n times: FOR Loop

Problem-Solving 1.4. Stepwise Refinement


Abstraction: filtering out and concentrating on the Process of developing a modular design by splitting a
relevant information in a problem; allowing a problem into
smaller sub-tasks, which themselves are
programmer to deal with complexity repeatedly split into even
smaller sub-tasks until each is
Decomposition: breaking down problems into sub- just one element of the final
program.
problems in order to understand a process more clearly;
program modules, procedures and functions all help the
programmer to break down large problems 1.5. Program Modules
Algorithm: a solution to a problem expressed as a
sequence of steps This refers to a modular program design
Subroutines: self-contained section of code, performing a
specific task; part of the main program
1.2. Identifier Table Procedures: performs a specific task, no value returned
to part
of code where called
Identifier: name given to a variable in order to call it Functions: performs a specific task, returns a value to
An identifier table depicts information about the variable, part of
code where called
e.g.

1.6. Logic Statements


Operator Meaning
< Less than
<= Less than/equal
Rules for naming identifiers: > Greater than
Must be unique >= Greater/equal
Spaces must not be used == Equal to
Must begin with a letter of the alphabet != Not equal to
Consist only of a mixture of letters and digits and the
underscore character ‘_’
Must not be a ‘reserved’ word – e.g. Print, If, etc. 2. Data Representation
1.3. Basic Program Operations 2.1. Data Types
Assignment: an instruction in a program that places a
Integer:
value into
a specified variable
Sequence: programming statements are executed Positive or negative number; no fractional part
consequently, as
they appear in the program Held in pure binary for processing and storage
Selection: control structure in which there is a test to Some languages differentiate short/long integers (more
decide
if certain instructions are executed bytes used to
store long integers)
IF selection: testing 2 possible outcomes
CASE selection: testing more than 2 outcomes Real:
Repetition/Iteration: control structure in which a group of
statements is executed repeatedly Number that contains a decimal point
FOR loop: unconditional;
executed a set no. of times Referred to as singles and doubles depending upon
WHILE loop: conditional;
executed based on condition number of bytes
used to store
at start of statements
Character:
REPEAT loop: conditional;
executed based on
condition at end of statements A character is any letter, number, punctuation or space
Takes up a single unit of storage (usually a byte).
As for selecting what loop to use, it is best to use FOR loops
when you know the number of iterations required, and a String:
WHILE or REPEAT loop if you do not know the number of
iterations required. Combination of alphanumeric characters enclosed in “ ”
Each character stored in one byte using ASCII code
Iterate over an array: FOR Loop Each character stored in two bytes using Unicode

WWW.ZNOTES.ORG
CAIE AS LEVEL COMPUTER SCIENCE (9618)

Max length of a string limited by available memory.


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

Date:

Dates are stored as a ‘serial’ number


Equates to the number of seconds since January 1st, 1904
(thus they
also contain the time)
Usually take 8 bytes of storage
Displayed as dd/mm/yyyy or mm/dd/yyyy

Array: 2-Dimensional (2D) Array: declared using two indices, can


be
represented as a table
Data structure consisting of a collection of elements
Identified by at least one array index (or key)

File:

Object that stores data, information, settings or


commands
Can be opened, saved, deleted & moved
Transferrable across network connections

2.2. ASCII Code


Uses 1 byte to store a character
7 bits available to store data and 8th bit is a check
digit Pseudocode:
27 = 128, therefore 128 different values 1-D Array: array = []
ASCII values can take many forms: numbers, letters 2-D Array: array = [[], [], [], …]
(capitals and
lower case are separate), punctuation, non- Python:
printing commands (enter,
escape, F1) Declaring an array: names = []
Adding to an array: names.append(‘ZNotes’)
2.3. Unicode Length of array i.e. number of elements: len(names)
Printing an element in a 1D array:
ASCII allows few number of characters; good for English print(names[element position])
Unicode allows others too: Chinese, Greek, Arabic etc. Printing element in a 2D array: print (a[row]
Different types of Unicode: [column])
UTF-8: compatible with ASCII, variable-width encoding Printing row in a 2D array: names[row] = [new
can expand
to 16, 24, 32, 40, 42 row]
UTF-16: 16-bit, variable-width encoding can expand to Printing column: use for loop and keep adding 1 to
32 bits the row and keep column same
UTF-32: 32 bit, fixed-width encoding, each character
exactly 32
bits
2.5. Bubble Sort
2.4. Arrays
1-Dimensianal (1D) Array: declared using a single index,
can be
represented as a list

WWW.ZNOTES.ORG
CAIE AS LEVEL COMPUTER SCIENCE (9618)

Python:

Opening a file: variable = open(“filename”,


“mode”)

Where the mode can be:


Mode Description
Opens file for reading only. Pointer placed at the
r
beginning of the file.
Opens a file for writing only. Overwrites file if file
w
exists or creates new file if it doesn’t
Opens a file for appending. Pointer at end of file
a
if it exists or creates a new file if not

Reading a file:
Read all characters: variable.read()
A FOR loop is set to stop the sort Read each line and store as list:
Setting a variable ‘sorted’ to be ‘true’ at the beginning variable.readlines()
Another FOR loop is set up next in order to search Writing to a file:
through the array Write a fixed a sequence of characters to file:
An IF is used to see if the first number of the array is variable.write(“Text”)
greater
than the second. If true: Write a list of string to file: variable.write(‘
First number stored to variable ‘.join(‘Z’, ‘Notes’))
Second number assigned as first number
Stored variable assigned to second number
Set ‘sorted’ to ‘false’ causing loop to start again Abstract Data Types
The second FOR loop is count based thus will stop after a
specific
number of times (ADT)
Goes through bigger FOR loop ∴ ‘sorted’ remains ‘true’
This exits the loop ∴ ending the program An Abstract Data Type (ADT) is a collection of data with
associated operations. There are three types of ADTs:
2.6. Linear Search Stack: an ordered collection of items where the addition
of new items and removal of existing items always takes
place at the same end.
Queue: a linear structure which follows the First In First
Out (FIFO) mechanism. Items are added at one end
A FOR loop goes through the array (called the rear) and removed from the other end (called
It compares item in question to those in list using an IF: the front)
If item matches with another then search is stopped Linked List: a linear collection of data elements whose
Also the location where it was found is returned order is not given by physical placements in memory
If not found it exits the FOR loop (non-contiguous). Each element points to the next.
Then returns fact that item in question is not in the list

2.7. File Handling


3. Programming
Programming is a transferable skill
Files are needed to import contents (from a file) saved in
Transferable skill: skills developed in one situation which
secondary
memory into the program, or to save the
can
be transferred to another situation.
output of a program (in a
file) into secondary memory, so
that it is available for future use
3.2. Variables
Pseudocode:
Declaring a variable:
Opening a file: OPENFILE <filename> FOR
Pseudocode: ‘’’python DECLARE <identifier> : <data
READ/WRITE/APPEND
type> ‘’’
Reading a file: READFILE <filename> Python: no need to declare however must write above
Writing a line of text to the file: WRITEFILE as a comment
(‘’’python #...‘’’)
<filename>, <string> Assigning variables:
Closing a file: CLOSEFILE
Testing for end of the file: EOF()

WWW.ZNOTES.ORG
CAIE AS LEVEL COMPUTER SCIENCE (9618)

‘’’python <identifier> ← <value>‘’’ or ‘’’python Create routines that can be called like built-in command
<expression>‘’’

‘’’python identifier = value‘’’ or ‘’’python expression‘’’ or 3.7. Procedure


‘’’python
“string”‘’’
Procedure: subroutine that performs a specific task without
returning a value
3.3. Selections
Procedure without parameters:
“IF” Statement
Pseudocode: IF…THEN…ELSE…ENDIF PROCEDURE def
Python: if (expression): (statements) else: <statement(s)>ENDPROCEDURE identifier():statement(s)
(statements)
“CASE” Statement When a procedure has a parameter, the function can
Pseudocode: CASE OF variable: … … … either pass it by either reference or value
OTHERWISE: … ENDCASE Pass by value: data copied into procedure so variable not
Python: if (expression): (statement) elif changed outside procedure
(expression): statement) … else: PROCEDURE <identifier> (BYVALUE <param>:
(statement) <datatype>)
<statement(s)>
3.4. Iterations ENDPROCEDURE
def identifier(param):
Count-controlled Loop statement(s)

FOR <identifier> ← <val1> TO Pass by reference: link to variable provided so variable


<val2> STEP <val3> changed after going through procedure (not in Python)
<statement(s)>
ENDFOR PROCEDURE <identifier> (BYREF <param>:
for x in range(value1, value2): <datatype>)
statement(s) <statement(s)>
ENDPROCEDURE
Post condition Loop
REPEAT Not possible in Python Calling a procedure:
<statement(s)> Use ‘’’python WHILE‘’’ and
UNTIL <condition> ‘’’python IF‘’’ CALL () Identifier()
Pre-condition Loop
WHILE <condition> 3.8. Function
while expression:
<statement(s)>
statement(s)
ENDWHILE Function: subroutine that performs a specific task and
returns a value
3.5. Built-in Functions Functions are best used to avoid having repeating blocks of
code in a program, as well as increasing the reusability of
String/character manipulation: code in a large program.
FUNCTION <identifier> (<parameter>: <data
Uppercase or lowercase all characters: type>) RETURNS <datatype>
(“string”).upper() (“string”).lower() <statement(s)>
Finding length of a string: len(“string”) ENDFUNCTION
Converting: def identifier(param):
String to Integer - int(“string”) statement(s)
Integer to String - str(integer) return expression

Random number generator: random.randint(a, b)


Where a and b defines the range 4. Software Development
3.6. Benefits of Procedures and 4.1. Program Development Cycle
Functions: Analyze problem: define problem, record program
specifications
and recognize inputs, process, output & UI
Lines of code can be re-used; don’t have to be repeated
Design program: develop logic plan, write algorithm in
Can be tested/improved independently of program
e.g.
pseudocode or flowchart and test solution
Easy to share procedures/functions with other programs

WWW.ZNOTES.ORG
CAIE AS LEVEL COMPUTER SCIENCE (9618)

Code program: translate algorithm into high level Example of a top-down design where a problem
language with
comments/remarks and produce user (program) is broken
into its components.
interface with executable
processes
Test and debug program: test program using test data, Rules:
find and
correct any errors and ensure results are correct
Process: Represents a programming module e.g. a
Formalize solution: review program code, revise internal
calculation
documentation and create end-user documentation
Maintain program: provide education and support to
end-user,
correct any bugs and modify if user requests

There are three different development life cycles:

Waterfall model: a classical model, used to create a Data couple: Data being passed from module to module
system with a linear approach, from one stage to another that needs
to be processed
Iterative model: a initial representation starts with a small
subset, which becomes more complex over time until the
system is complete
Flag: Check data sent to start or stop a process. E.g. check
Rapid Application Development (RAD) model: a
prototyping model, with no (or less) specific planning put if
data sent in the correct format
into it. More emphasis on development and producing a
product-prototype.

Selection: Condition will be checked and depending on


4.2. Integrated Development the
result, different modules will be executed
Environment
A software application that allows the creation of a
program e.g.
Python
Consists of a source code editor, build automation tools,
a debugger

Coding:

Reserved words are used by it as command prompts


Listed in the end-user documentation of IDE
A series of files consisting of preprogrammed- Iteration: Implies that module is executed multiple times
subroutines may also
be provided by the IDE

Initial Error Detection:

The IDE executes the code & initial error detection carried
out by
compiler/interpreter doing the following:
Syntax/Logic Error: before program is run, an error
message
warns the user about this
Runtime Error: run of the program ends in an error

Debugging:
Example:
Single stepping: traces through each
line of code and
steps into procedures. Allows you to view the
effect of
each statement on variables
Breakpoints: set within code; program
stops temporarily
to check that it is operating correctly up to that
point
Variable dumps (report window): at
specific parts of
program, variable values shown for comparison

4.3. Structure Charts


Purpose: used in structured programming to arrange
program
modules, each module represented by a box
Tree structure visualizes relationships between modules,
showing
data transfer between modules using arrows.

WWW.ZNOTES.ORG
CAIE AS LEVEL COMPUTER SCIENCE (9618)

Use test data for which results already calculated &


4.4. Types of Errors compare result
from program with expected results
Testing only considers input and output and the code is
Syntax errors:
viewed as
being in a ‘black box’
When source code does not obey rules of the language
White box testing:
Compiler generates error messages
Examples: Examine each line of code for correct logic and accuracy.
Misspell identifier when calling it May record value of variables after each line of code
Missing punctuation – colon after if Every possible condition must be tested
Incorrectly using a built-in function
Argument being made does not match data type Stub testing:

Run-time errors: Stubs are computer programs that act as temporary


replacement for a
called module and give the same
Source code compiles to machine code but fails upon output as the actual product or
software.
execution (red
lines show up in Python) Important when code is not completed however must be
When the program keeps running and you have to kill it tested so
modules are replaced by stubs
manually
Examples: Dry run testing:
Division by 0
Infinite loop – will not produce error message, A process where code is manually traced, without any
program will
just not stop until forced to software used
The value of a variable is manually followed to check
Logic errors: whether it is used and updated as expected
Used to identify logic errors, but not execution errors
Program works but gives incorrect output
Examples: Walkthrough testing:
Out By One – when ‘>’ is used instead of ‘>=’
Misuse of logic operators A test where the code is reviewed carefully by the
developer’s peers, managers, team members, etc.
It is used to gather useful feedback to further develop the
4.5. Corrective Maintenance code.

White-Box testing: making sample data and running it Integration testing:


through a
trace table
Trace table: technique used to test algorithms; make sure Taking modules that have been tested on individually and
that
no logical errors occur e.g. testing on them combined together
This method allows all the code snippets to integrate with
each other, making the program work.

Alpha testing:

This is the testing done on software ‘in-house’, meaning it


is done by the developers
Basically another term for ‘first round of testing’

Beta testing:

This is the testing done on the software by beta users,


who use the program and report any problems back to
the developer.
4.6. Adaptive Maintenance Basically another term for ‘second round of testing’

Making amendments to: Acceptance testing:


Parameters: due to changes in specification
A test carried out by the intended users of the system:
Logic: to enhance functionality or more faster or both
the people who requested the software.
Design: to make it more user friendly
The purpose is to check that the software performs
exactly as required.
4.7. Testing Strategies The acceptance criteria should completely be satisfied for
the program to be released.
Black box testing:

WWW.ZNOTES.ORG
CAIE AS LEVEL
COMPUTER SCIENCE (9618)

Copyright 2021 by ZNotes


These notes have been created by Zubair Junjunia for the 2017 syllabus
This website and its content is copyright of ZNotes Foundation - © ZNotes Foundation 2021. All rights reserved.
The document contains images and excerpts of text from educational resources available on the internet and
printed books. If you are the owner of such media, test or visual, utilized in this document and do not accept its
usage then we urge you to contact us and we would immediately replace said media.
No part of this document may be copied or re-uploaded to another website without the express, written
permission of the copyright owner. Under no conditions may this document be distributed under the name of
false author(s) or sold for financial gain; the document is solely meant for educational purposes and it is to
remain a property available to all at no cost. It is current freely available from the website www.znotes.org
This work is licensed under a Creative Commons Attribution-NonCommerical-ShareAlike 4.0 International
License.

You might also like