0% found this document useful (0 votes)
2 views

Caie As Computer Science 9608 Practical

Uploaded by

송준혁
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Caie As Computer Science 9608 Practical

Uploaded by

송준혁
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

TABLE OF CONTENTS

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)

2.3 Unicode  A FOR loop is set to stop the sort


 ASCII allows few number of characters; good for English  Setting a variable ‘sorted’ to be ‘true’ at the beginning
 Unicode allows others too: Chinese, Greek, Arabic etc.  Another FOR loop is set up next in order to search
 Different types of Unicode: through the array
o UTF-8: compatible with ASCII, variable-width encoding  An IF is used to see if the first number of the array is
can expand to 16, 24, 32, 40, 42 greater than the second. If true:
o UTF-16: 16-bit, variable-width encoding can expand to o First number stored to variable
32 bits o Second number assigned as first number
o UTF-32: 32 bit, fixed-width encoding, each character o Stored variable assigned to second number
exactly 32 bits o Set ‘sorted’ to ‘false’ causing loop to start again

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”]

2.8 Abstract Data Types (ADT)


An Abstract Data Type (ADT) is a collection of data with
 A FOR loop goes through the array associated operations. There are three types of ADTs:
 It compares item in question to those in list using an IF:  Stack: an ordered collection of items where the addition
o If item matches with another then search is stopped of new items and removal of existing items always takes
o Also the location where it was found is returned place at the same end.
o If not found it exits the FOR loop  Queue: a linear structure which follows the First In First
 Then returns fact that item in question is not in the list Out (FIFO) mechanism. Items are added at one end
(called the rear) and removed from the other end (called
2.7 File Handling the front)
 Files are needed to import contents (from a file) saved in  Linked List: a linear collection of data elements whose
secondary memory into the program, or to save the order is not given by physical placements in memory
output of a program (in a file) into secondary memory, (non-contiguous). Each element points to the next.
so that it is available for future use
Pseudocode: 3 PROGRAMMING
 Opening a file:  Programming is a transferable skill
OPENFILE <filename> FOR READ/WRITE/APPEND  Transferable skill: skills developed in one situation
 Reading a file: which can be transferred to another situation.
READFILE <filename>
 Writing a line of text to the file: 3.1 Variables
WRITEFILE <filename>, <string>  Declaring a variable:
 Closing a file: o Pseudocode: DECLARE <identifier> : <data type>
CLOSEFILE o Python: no need to declare however must write above
 Testing for end of the file: as a comment (#...)
EOF()
 Assigning variables:
Python: <identifier> ← <value> or <expression>
 Opening a file identifier = value or expression or “string”
variable = open(“filename”, “mode”)
Where the mode can be: 3.2 Selections
Mode Description ‘IF’ Structure
Opens file for reading only. Pointer placed IF <condition>
r THEN if expression:
at the beginning of the file. <statement(s)> statement(s)
Opens a file for writing only. Overwrites file ELSE else:
w <statement(s)> statement(s)
if file exists or creates new file if it doesn’t ENDIF
Opens a file for appending. Pointer at end of ‘CASE’ Structure
a if expression:
file if it exists or creates a new file if not CASE OF <identifier>
statement(s)
<value 1>: <statement>
elif expression:
<value 2>: <statement>
statements(s)
 Reading a file: ...
...
OTHERWISE <statement>
o Read all characters ENDCASE
else:
statement(s)
variable.read()
o Read each line and store as list
PAGE 4 OF 7
CIE AS-LEVEL COMPUTER SCIENCE//9608
3.3 Iterations ENDPROCEDURE
 Calling a procedure:
Count-controlled Loop CALL <identifier>() Identifier()
FOR <identifier> ← <val1> TO <val2> STEP <val3>
<statement(s)>
ENDFOR 3.7 Function
for x in range(value1, value2):
statement(s) Function: subroutine that performs a specific task and
Post condition Loop returns a value.
REPEAT Not possible in Python
<statement(s)>
Functions are best used to avoid having repeating blocks
UNTIL <condition> Use WHILE and IF of code in a program, as well as increasing the reusability
Pre-condition Loop of code in a large program.
WHILE <condition>
while expression: FUNCTION <identifier> (<parameter>: <data type>)
<statement(s)>
statement(s) RETURNS <data type>
ENDWHILE
<statement(s)>
ENDFUNCTION
3.4 Built-in Functions def identifier(param):
String/character manipulation: statement(s)
return [expression]
 Uppercase or lowercase all characters
(“string”).upper() (“string”).lower()
 Finding length of a string 4 SOFTWARE DEVELOPMENT
len(“string”)
 Converting: 4.1 Program Development Cycle
String to Integer Integer to String  Analysis: define problem, record program specifications
int(“string”) str(integer)
and recognize inputs, process, output & UI
Random number generator:
 Design: develop logic plan, write algorithm in e.g.
random.randint(a, b)
where a and b defines the range pseudocode or flowchart and test solution
 Coding: translate algorithm into high level language with
3.5 Benefits of Procedures and Functions: comments/remarks and produce user interface with
 Lines of code can be re-used; don’t have to be repeated executable processes
 Can be tested/improved independently of program  Testing: test program using test data, find and correct
 Easy to share procedures/functions with other programs any errors and ensure results are correct
 Create routines that can be called like built-in command  Formalize solution: review program code, revise internal
documentation and create end-user documentation
3.6 Procedure  Maintain program: provide education and support to
Procedure: subroutine that performs a specific task end-user, correct any bugs and modify if user requests
without returning a value There are three different development life cycles:
 Procedure without parameters:  Waterfall model: a classical model, used to create a
PROCEDURE <identifier>
def identifier(): system with a linear approach, from one stage to
<statement(s)>
statement(s)
ENDPROCEDURE another
 When a procedure has a parameter, the function can  Iterative model: a initial representation starts with a
either pass it by either reference or value small subset, which becomes more complex over time
 Pass by value: data copied into procedure so variable until the system is complete
not changed outside procedure  Rapid Application Development (RAD) model: a
PROCEDURE <identifier> (BYVALUE <param>: <datatype>)
<statement(s)> prototyping model, with no (or less) specific planning put
ENDPROCEDURE into it. More emphasis on development and producing a
def identifier(param):
statement(s)
product-prototype.
 Pass by reference: link to variable provided so variable
changed after going through procedure (not in Python)
PROCEDURE <identifier> (BYREF <param>: <datatype>)
<statement(s)>
PAGE 5 OF 7
CIE AS-LEVEL COMPUTER SCIENCE//9608
4.2 Integrated Development Environment
Condition will be checked and
 A software application that allows the creation of a depending on the result,
program e.g. Python different modules will be
 Consists of a source code editor, build automation tools, executed.
a debugger
Coding: Iteration
 Reserved words are used by it as command prompts
 Listed in the end-user documentation of IDE Implies that module is executed
 A series of files consisting of preprogrammed- multiple times
subroutines may also be provided by the IDE
Initial Error Detection:
 The IDE executes the code & initial error detection Example:
carried out by compiler/interpreter doing the following:
o Syntax/Logic Error: before program is run, an error
message warns the user about this
o Runtime Error: run of the program ends in an error
Debugging:
 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 4.4 Types of Errors
program, variable values shown for comparison Syntax errors:
 When source code does not obey rules of the language
4.3 Structure Charts  Compiler generates error messages
 Purpose: used in structured programming to arrange  Examples:
program modules, each module represented by a box o Misspell identifier when calling it
 Tree structure visualizes relationships between modules, o Missing punctuation – colon after if
showing data transfer between modules using arrows. o Incorrectly using a built-in function
 Example of a top-down design where a problem o Argument being made does not match data type
(program) is broken into its components.
Rules: Run-time errors:
Symbol Description  Source code compiles to machine code but fails upon
execution (red underlines show up in Python)
Process
 When the program keeps running and you have to kill it
Represents a programming
module e.g. a calculation manually
Data Couple  Examples:
Data being passed from module o Division by 0
to module that needs to be o Infinite loop – will not produce error message,
processed program will just not stop until forced to
Flag
Check data sent to start or stop Logic errors:
a process. E.g. check if data sent  Program works but gives incorrect output
in the correct format  Examples:
Selection o Out By One – when ‘>’ is used instead of ‘>=’
o Misuse of logic operators
PAGE 6 OF 7
CIE AS-LEVEL COMPUTER SCIENCE//9608
4.5 Corrective Maintenance  This method allows all the code snippets to integrate
 White-Box testing: making sample data and running it with each other, making the program work.
through a trace table
 Trace table: technique used to test algorithms; make Alpha testing:
sure that no logical errors occur e.g.  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
4.6 Adaptive Maintenance the developer.
 Making amendments to:  Basically another term for ‘second round of testing’
o Parameters: due to changes in specification Acceptance testing:
o Logic: to enhance functionality or more faster or both  A test carried out by the intended users of the system:
o Design: to make it more user friendly the people who requested the software.
 The purpose is to check that the software performs
4.7 Testing Strategies exactly as required.
Black box testing:  The acceptance criteria should completely be satisfied
 Use test data for which results already calculated & for the program to be released.
compare result from program with expected results
 Testing only considers input and output and the code is
Key:
viewed as being in a ‘black box’
Pseudocode
White box testing:
Python
 Examine each line of code for correct logic and accuracy.
 May record value of variables after each line of code
 Every possible condition must be tested
Stub testing:
 Stubs are computer programs that act as temporary
replacement for a called module and give the same
output as the actual product or software.
 Important when code is not completed however must
be tested so modules are replaced by stubs
Dry run testing:
 A process where code is manually traced, without any
software used
 The value of a variable is manually followed to check
whether it is used and updated as expected
 Used to identify logic errors, but not execution errors
Walkthrough testing:
 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 code.
Integration testing:
 Taking modules that have been tested on individually
and testing on them combined together

PAGE 7 OF 7

You might also like