Revision - Paper2
Revision - Paper2
Revision - Paper2
1 Understand the program development life cycle, limited to: analysis, design,
coding and testing
Definition - When a person, or organisation, creates a new computer program they will use a
structured, organised plan of how to create the program. This is called the program
development life cycle.
Stages -
– analysis:
• abstraction, decomposition of the problem, identification of the problem and
requirements
• the first stage of the program development life cycle that involves investigating the
problem.
• Abstraction
• simplifying the problem
• removing unnecessary details from the problem // selecting elements required
• filtering out irrelevant characteristics from those elements
• Decomposition - taking a system and splitting it into smaller sub-systems, which can
in turn be split into smaller sub-systems.
– design:
• decomposition, structure diagrams, flowcharts, pseudocode
• the second stage of the program development life cycle, which involves
decomposition of the problem and algorithms created ready for implementation.
– coding:
• writing program code and iterative testing
• the writing of a program using one or more programming languages.
– testing:
• testing program code with the use of test data
• the writing of a program using one or more programming languages.
– totalling
– counting
– finding maximum, minimum and average values
5 (a) Understand the need for validation checks to be made on input data and
the different types of validation check
• To test if the data entered is possible / reasonable / sensible.
• A range check tests that data entered fits within specified values.
• Example – range check , length check, type check, presence check, format check,
check digit
(b) Understand the need for verification checks to be made on input data and the
different types of verification check
• To test if the data input is the same as the data that was intended to be input.
• A double entry check expects each item of data to be entered twice and compares both
entries to check they are the same.
• Example - visual check, double entry check
6 Suggest and apply suitable test data
• Limited to:
– normal
– abnormal
– extreme
– boundary
• Extreme data is the largest/smallest acceptable value
• Boundary data is the largest/smallest acceptable value and the corresponding
smallest/largest rejected value
Que - A programmer has written an algorithm to check that prices are less than $10.00
These values are used as test data: 10.00 9.99 ten
State why each value was chosen as test data.[3]
• 10.00 boundary / abnormal data // the price should be rejected // value is out of range
• 9.99 boundary / extreme / normal data // the price should be accepted // value is
within normal range
• ten abnormal data // input should be rejected // value is wrong type
8 Identify errors in given algorithms and suggest ways of correcting these errors
Que - An algorithm has been written in pseudocode to input some numbers. It only outputs
any numbers that are greater than or equal to 100. The number 999 is not output and stops the
algorithm. [4]
Identify the four errors in the pseudocode and suggest corrections.
• Numbers should be Number
• IF Number > 100 should be IF Number >= 100
• INPUT Number is missing from inside the loop, insert INPUT Number after the
ENDIF statement.
• The final OUTPUT Number is not needed, remove it.
Que - Write a pseudocode statement to change the corrected algorithm to output all numbers
between 100 and 200 inclusive. You do not need to rewrite the whole algorithm. [2]
Ans - The test should be IF Number >= 100 AND Number <= 200
---------------------------------------------------------------------------------------------------------
8 Programming
8.1 Programming concepts
1 Declare and use variables and constants
DECLARE Counter : INTEGER
DECLARE TotalToPay : REAL
DECLARE GameOver : BOOLEAN
CONSTANT HourlyRate ← 6.50
CONSTANT DefaultText ← "N/A"
Variables and constants should be used when creating and running a program
Variables and constants should have meaningful identifiers so that
programmers/future programmers are able to understand their purpose
They are both used for data storage
Constants store values that never change during the execution of a program e.g.
CONSTANT Pi 3.142
Variables contain values that have been calculated within the program / can change
during the execution of the program e.g. Count Count + 1
Literals
Literals of the above data types are written as follows:
• Integer written as normal in the denary system, e.g. 5, –3
• Real always written with at least one digit on either side of the decimal point, zeros being
added if necessary, e.g. 4.7, 0.3, –4.0, 0.0
• Char a single character delimited by single quotes, e.g. ꞌxꞌ, ꞌcꞌ, ꞌ@ꞌ
• String delimited by double quotes. A string may contain no characters (i.e. the empty
string), e.g. "This is a string", ""
• Boolean TRUE, FALSE
Identifiers
Identifiers (the names given to variables, constants, procedures and functions) are in mixed
case using Pascal case, e.g. FirstName. They can only contain letters (A–Z, a–z) and digits
(0–9). They must start with a capital letter and not a digit. Accented letters and other
characters, including the underscore, should not be used.
As in programming, it is good practice to use identifier names that describe the variable,
procedure or function to which they refer. Single letters may be used where these are
conventional (such as i and j when dealing with array indices, or X and Y when dealing with
coordinates) as these are made clear by the convention.
Keywords should never be used as identifier names.
Identifiers should be considered case insensitive, for example, Countdown and CountDown
should not be used as separate variables.
Que - Four pseudocode descriptions and five pseudocode statements are shown.
Draw a line to link each pseudocode description to the most appropriate pseudocode
statement. Some pseudocode statements will not be used. [4]
Que - Using a single loop, write an algorithm in pseudocode to output 50 names that have
been stored in the array, Name[] [3]
Count ← 0
WHILE Count < 50 DO
OUTPUT Name[Count]
Count ← Count + 1
ENDWHILE
(b) Define and use procedures and functions, with or without parameters
• Procedures and functions may have up to two parameters
Que - Tick (√) one box to show the named section of a program that performs a specific task.
Ans - B
Que - Describe what happens when a function is called during the execution of a program.
A call statement is used in order to make use of a function // the function is called
using its identifier
Parameters are / may be passed (from the main program) to the function (to be used
within the function)
The function performs its task and returns a value / values to the main program
Que - A function is declared using pseudocode.
FUNCTION ConvertToCm(Inches: REAL) RETURNS REAL
RETURN Inches * 2.4
ENDFUNCTION
Tick (√) one box which accurately describes the use of the variable Inches
Ans – C
ROUND(X,Y)
Returns the value of the X rounded to Y places of decimal places.
X should be of data type real, Y should be data type integer.
To return a value rounded to a specified number of digits / decimal places
The result will either be rounded to the next highest or the next lowest value
… depending on whether the value of the preceding digit is >=5 or <5
Example - ROUND(4.56, 1) returns 4.6
DIV(X,Y)
Returns the quotient of X divided by Y with the fractional part discarded.
To perform integer division. Meaning only the whole number part of the answer is
retained
Examples - DIV(10, 3) returns 3
MOD(X,Y)
Returns the remainder of X divided by Y. The identifiers are of data type integer.
This is a library routine returns the remainder of a division
To perform (integer) division when one number is divided by another and find the
remainder
Examples – MOD(10, 3) returns 1
8.2 Arrays
How to initialise and populate the array Days[] at the start of the program?
Days[1] "Sunday"
Days[2] "Monday"
Days[3] "Tuesday"
Days[4] "Wednesday"
Days[5] "Thursday"
Days[6] "Friday"
Days[7] "Saturday"
OR
Days [“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”]
3 Write values into and read values from an array using iteration
• Including the use of variables as indexes in arrays
• The first index can be zero or one
• Including nested iteration
It is good practice to explicitly open a file, stating the mode of operation, before reading from
or writing to it.
OPENFILE <File identifier> FOR <File mode>
The file identifier will be the name of the file with data type string. The following file
modes are used:
• READ for data to be read from the file
• WRITE for data to be written to the file. A new file will be created and any
existing data in the file will be lost.
A file should be opened in only one mode at a time.
Data is read from the file (after the file has been opened in READ mode) using the
READFILE command.
READFILE <File Identifier>, <Variable>
When the command is executed, the data item is read and assigned to the variable.
Data is written into the file after the file has been opened using the WRITEFILE command.
WRITEFILE <File identifier>, <Variable>
When the command is executed, the data is written into the file.
Files should be closed when they are no longer needed using the CLOSEFILE command.
CLOSEFILE <File identifier>
Example – file handling operations
This example uses the operations together, to copy a line of text from FileA.txt to FileB.txt
DECLARE LineOfText : STRING
OPENFILE FileA.txt FOR READ
OPENFILE FileB.txt FOR WRITE
READFILE FileA.txt, LineOfText
WRITEFILE FileB.txt, LineOfText
CLOSEFILE FileA.txt
CLOSEFILE FileB.txt