Paper 2 Theory Questions and Answers
Paper 2 Theory Questions and Answers
4- Describe giving a different example for each, the purpose of these validation checks used
in programming.
Range check: to check the value input falls between a given a given upper bound and a
given lower bound. Eg: if month has to be input using an integer, it must be between 1
and 12 inclusive.
Length check: to check if the data input is over/under a certain number of characters
Eg: an international telephone number can be no longer than 15 digits.
pg. 1
GN.Atoll.Education Center computer science
Character check: checks that when a string of characters is entered it does not contain
any invalid characters or symbols. Eg : name would not contain characters such as %.
Format check: check that data entered confirm to a pre-defined pattern. Eg: CUB
number must be in the form of CUB999
Presence check: checks to ensure that some data has been entered and the value has not
left blank Eg: an email address must be given for an online transaction.
Check digit : final digit included in a code it is calculated from all the other digits in the
code. Eg: International standard book number
pg. 2
GN.Atoll.Education Center computer science
9- Describe and give example for each of the following test data
Normal data: a set of data that are accepted.
Erroneous data: the data that will be rejected as the values are not suitable.
Extreme data: extreme data are the largest and smallest values that normal data can take.
Boundary data: used to establish where the largest and smallest value occur. At each
boundary two values are required; one value is accepted and the other value is rejected.
pg. 3
GN.Atoll.Education Center computer science
14- Write down the difference between library- routine and sub- routine
Library routine: is a set of programming instructions for a given task that is already
available for use. And it is pre-tested and usually performs a task that is frequently
required.
Sub-routine: set of programming instructions for a given task that forms a sub-system
not the whole system. E.g. procedures and functions.
pg. 4
GN.Atoll.Education Center computer science
pg. 5
GN.Atoll.Education Center computer science
known and the actions arc only repeated WHILE a given condition is true. If the WHILE
condition is untrue when the loop is first entered then the actions in the loop arc never
performed.
An array is a data structure containing several elements of the same data type
These elements can be accessed using the same identifier name, the position of the elements is
identified using the index.
1D array : is referred as a list of multiple data items of the same data type
2D array : A two-dimensional array can be referred to as a table, with rows and columns.
pg. 6
GN.Atoll.Education Center computer science
BASIS FOR
LOCAL VARIABLE GLOBAL VARIABLE
COMPARISON
Variables are declared inside a Variables are declared outside any
Declaration
function. function.
Within a function, inside which they
Scope Throughout the program.
are declared.
Uninitialized local variable result in Uninitialized global variable stores
Value
storage of the garbage value. zero by default.
Accessed only by the statements,
Accessed by any statement in the
Access inside a function in which they are
entire program.
declared.
Data sharing Not provided Facilitated
Created when the function block is Remain in existence for the entire
Life
entered and destroyed upon exit. time your program is executing.
Local variables are stored on the Stored on a fixed location decided by
Storage
stack unless specified. a compiler.
Parameter passing Necessarily required Not required for global variables.
Any modification implied in a local The changes applied in the global
Changes in a variable
variable does not affect the other variable of a function reflect the
value
functions of the program. changes in the whole program.
pg. 7
GN.Atoll.Education Center computer science
pg. 8
GN.Atoll.Education Center computer science
34- What are the things to consider when creating maintainable programs arguments
» Always use meaningful identifier names for:
– variables
– constants
– arrays
– procedures
–functions
» be divided into modules for each task using:
– procedures
– functions
» be fully commented using your programming language’s commenting feature.
35- What is the main purpose of storing data in files
Computer programs store data that will be required again in a file. While any
data stored in RAM will be lost when the computer is switched off, when data is
pg. 9
GN.Atoll.Education Center computer science
saved to a file it is stored permanently. Data stored in a file can thus be accessed
by the same program at a later date or accessed by another program. Data stored
in a file can also be sent to be used on other computer(s).
36- What are text files
A text file is often used to store program source code, configuration data, and
other types of textual information.
You can create a text file using any text editor or word processor. Simply
open a new file and start typing your text. When you are done, save the file
with a .txt extension.
37- What are the uses/ advantages of using text files
One of the main advantages of using text files is that they are simple and
easy to read and edit. They can be opened and edited using a simple text
editor, such as notepad, and they can be easily transferred between different
computer systems.
pg. 10
GN.Atoll.Education Center computer science
pg. 11