Computer Science Theory Paper 2
Computer Science Theory Paper 2
7: Constant:
A named data store that contains the value that does not change
during the execution of a program.
8: Comments:
They are blocks of texts in the pseudocode that are not executed
and used to explain the code.
9: Features of a maintainable program:
Use comments to explain the purpose of each section in the code.
Use meaningful identifiers names to clearly identify the purpose of
variables, constants, arrays, procedures and functions.
Use procedures and functions to avoid repeated code and simplify
logic.
Use indentation and white space to make the program readable.
10: Component parts after decomposition:
Inputs: The data that needs to be entered into the system.
Processes: The tasks that need to be performed using the input
data and any previously stored data.
Outputs: Information that needs to be displayed or printed for the
users.
Storage: Data that needs to be stored in files for use in the future.
11: Top-Down design
The breaking of a computer system into set of sub-systems and
then breaking each sub-system into a set of smaller ones until each
sub-system performs a single action.
Stepwise refinement definition:
It is the process of breaking down into smaller sub-systems.
Module definition:
An individual section of a code that can be used by other programs.
12: Structure Chart // Structure Diagram:
Diagram that shows the design of a computer system in a hierarchal
way, with each level giving a more detailed breakdown of the
system.
It’s purpose is to provide an overview of the system hierarchy and
to provide an overview of how the problem is broken down.
13: Ways to represent an algorithm:
Flowcharts
Pseudocode
Structure Diagrams // Structure Charts
14: Basic concepts to use when developing a program:
Data use – variables, constants and arrays.
Sequence – order of steps in a task
Selection – choosing a path through a program
Iteration – repetition of a sequence of steps in a program
Operator use – arithmetic operations for calculation and logical and
Boolean operators for decisions.
23: CASE..OF..OTHERWISE..ENDCASE:
A conditional structure that allows selection to be made based on
the value of a variable.
It is used to test for a large number of discrete values.
30: Counting:
The process of finding how many items are in a list.
Example: Count <- Count + 1
Arrays
31: Array:
A data structure that holds several elements of the same data type.
Its purpose is to store multiple values under the same identifier
making the code shorter and allows for simpler programming.
Index definition:
It is the position of an element in an array.
Dimension definition:
The number of indexes required to access an element in an array.
32: One-dimensional (1-D) array:
A list / one column of items
… of the same data type
… stored under a single name/identifier
… with a single index to identify each element stored in it.
Purpose of using arrays:
Makes the program easier to design/code/test/understand.
Code will be more compact.
Code will be more organized.
Less likely to make errors.
Declaring a 1D array:
DECLARE Numbers : ARRAY[1:10] OF INTEGER
OR
DECLARE Numbers[1:10] : INTEGER
33: Two-dimensional (2-D) array:
A table-like collection of items
… of the same data type
… has row and columns
… stored under a single name/identifier
… with two indexes to identify each element
Declaring a 2D array:
DECLARE Marks: ARRAY[1:10, 1:3] OF INTEGER
OR
DECLARE Marks[1:10, 1:3] : INTEGER
Linear Search and Bubble Sort
File Handling
36: Purpose of using files:
Data is not lost when the computer is switched off (data is stored
permanently).
Data can be used by more than one program or reused when a
program is run again.
Data can be transported from one computer to another.
37: Subroutine:
Sub-program
Used to perform a frequently used operation within a program
Given a name and can be called when needed
Can be reused by another program
Written in high-level language
Purpose of using subroutines(functions/procedures):
To enable the programmer to write a collection of programming
statements under a single identifier.
To allow procedures to be re-used within the program or in other
programs.
To enable different programmers to work on different procedures in
the same project.
To make programs easier to maintain due to program code being
shorter.
38: Function:
A subroutine that always returns a value.
39: Procedure:
A subroutine that doesn’t always return a value.
40: Function/Procedure definition:
Setting-up the function/procedure
Includes defining the:
Function/Procedure name
Parameter names and data types
In case of a functions, the return data type.
Done only once. (Doesn't need to be redefined every time the
function is used.)
41: Function/Procedure call:
Using/executing the function code with parameters values.
Can be done multiple times.
Difference between function/procedure definition and
function/procedure call:
Defining is done once, calling can be done multiple times.
Defining is setting up the function/procedure and calling is using
the function itself.
Library routines:
ROUND:
Returns a value rounded to a specified number of digits.
The result will either be rounded to the next highest or the next
lowest value…
… depending whether the value of the preceding digit is >=5 or
<5
Example: ROUND(4.56, 1) = 4.6
RANDOM:
Generates (pseudo) random numbers
… within a specified range
Example: RANDOM() * 10
(returns a random number between 0 and 10)
DIV:
Performs an integer division of two numbers…
… with the fractional part discarded
Example: DIV(9,4) = 2
MOD:
Performs an integer division when one number is divided by
another
… and find the remainder
Example: 7 MOD 2 = 1
Databases
46: Database:
A structured collection of related data that allows people to extract
information in a way that meets their needs.
48: Purpose of SQL keywords:
Purpose of SELECT: An SQL command that identifies the fields to be
displayed.
Purpose of FROM: An SQL command that identifies the table to use.
Purpose of WHERE: An SQL command that identifies the search
criteria // An SQL command to include only the records that match
a given condition
Purpose of ORDERBY: An SQL command that sorts the result of the
query by a given column
Purpose of SUM keyword in SQL: An SQL command that returns the
sum of all values in a field
Purpose of COUNT keyword in SQL: An SQL command that counts
the number of records returned by the query.
49: Database terms:
Table: A collection of related records
Example: Table of students
Field: A column that contains one specific piece of information and
has one data type.
Examples: Student name / Student ID / Age / Address
Field Name: Title given to each field
Record: A row within a table that contains data about a single item,
person or event.
Primary Key: A field that contains unique data and can’t have
duplicates.
Example: Student ID field
Testing data
Data is used to check that a computer responds correctly to correct
and incorrect values.
Purpose:
Checks that the program works as expected.
Check for errors.
Check that the program rejects any invalid data that is input.
Check that the program accepts sensible and reasonable data.
Digital Logic