The program development life cycle (5 stages)
Analysis (Requirement specifications //Abstraction and decomposition of a complex problem into smaller parts
Design (how the program should be developed // completion of tasks using structure diagrams/charts, flowcharts, and pseudocodes
Coding and iterative testing (The program or set of programs are developed using a suitable programming language// Iterative testing- modular tests and amending codes)
Testing (Ensuring the program runs with different data sets)
Maintenance
Top-down design (stepwise refinement)
The breaking down of a computer system into a set of sub-systems, then breaking each sub-system down into a set of smaller sub-systems, until each sub-system just performs a single action.
Decomposing a problem
Input
Processes
Outputs
Storage
Methods used to design and construct a solution to a problem
Structure diagram / chart
flowchart
pseudocode
Structure diagrams
In order to show top-down design in a diagrammatic form, structure diagrams can be used. The STRUCTURE DIAGRAM shows the design of a computer system in a hierarchical way, with each level giving a more detailed breakdown of the system into sub-systems. An example of Alarm App in a phone is given below:
Flowcharts
A FLOWCHART shows diagrammatically the steps required for a task (sub-system) and the order that they are to be performed. These steps together with the order are called an ALGORITHM.
Other Key definitions:
Library routines
A LIBRARY ROUTINE is a set of programming instructions for a given task that is already available for use. It is pre-tested and usually performs a task that is frequently required. For example, the task ‘get time’
Sub-routines
A SUB-ROUTINE is a set of programming instructions for a given task that forms a sub- system, not the whole system. Sub-routines written in high-level programming languages are called ‘procedures’ or ‘functions’ depending on how they are used.
Function [2021]
A subroutine that always returns a value
Procedure [2021]
A subroutine that does not have to return a value
Algorithms
An ALGORITHM sets out the steps to complete a given task. This is usually shown as a flowchart or pseudocode.
Pseudocode
PSEUDOCODE is a simple method of showing an algorithm, using English-like words and mathematical operators that are set out to look like a program.
Identifiers
The names given to variables, constants, procedures, and functions
They can only contain letters (A–Z, a–z) and digits (0–9). They must start with a letter and not a digit.
As in programming, it is good practice to use identifier names that describe the variable, procedure or function they refer to. 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 identified should never be used as variables.
Identifiers should be considered case insensitive, for example, Marks and marks should not be used as separate variables.
Assignment statement
The assignment operator is ←.
Assignments should be made in the following format:
<identifier> ← <value>
Examples
TotalCount ← 0
PositiveCount ← PositiveCount + 1
TotalToPay ← NumberOfHours * HourlyRate
Input and output
Values are input using the INPUT command as follows:
INPUT <identifier>
Ex. INPUT Marks
The identifier should be a variable (that may be an individual element of a data structure such as an array, or a custom data type).
Values are output using the OUTPUT/PRINT command as follows:
OUTPUT <value(s)> // PRINT <value(s)>
Several values, separated by commas, can be output using the same command. Ex. OUTPUT/PRINT TotalMarks, Percentage, Grade
Data Types
The following keywords are used to designate atomic data types:
INTEGER : A whole positive/negative number (Written as normal in the denary system, e.g. 5, -3)
REAL : A number capable of containing a fractional part (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 (A single character delimited by single quotes, e.g. ꞌxꞌ, ꞌCꞌ, ꞌ@ꞌ)
STRING : A sequence of zero or more characters (Delimited by double quotes. A string may contain no characters (i.e. the empty string) e.g. "This is a string", "IGCSE computer science")
BOOLEAN: The logical values TRUE and FALSE
Arithmetic operations
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
^ Raise to the power
( ) Group
Comparison Operators
= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal
AND Both
OR Either
NOT not
Selection// Conditional Statements
IF statements
IF <condition>
THEN
<statements>
ELSE
<statements>
ENDIF
CASE statements
CASE OF <identifier>
<value 1> : <statement>
<value 2> : <statement>
...
OTHERWISE <statement>
ENDCASE
Note that the THEN and ELSE clauses are only indented by two spaces. (They are, in a sense, a continuation of the IF statement rather than separate statements).
When IF statements are nested, the nesting should continue the indentation of two spaces. In particular, run-on THEN IF and ELSE IF lines should be avoided.
Loop structures//Iterations//Repititions
A set number of iterations (FOR…TO…NEXT)
A repetition, where the number of repeats is not known, that is completed at least once (REPEAT … UNTIL)
A repetition, where the number of repeats is not known, that may never be completed (WHILE … DO… ENDWHILE)
Count-controlled (FOR) loops
Count-controlled loops are written as follows:
FOR <identifier> ← <value1> TO <value2>
<statements>
NEXT
The identifier must be a variable of data type INTEGER, and the values should be expressions that evaluate to integers.
It is good practice to repeat the identifier after NEXT, particularly with nested FOR loops.
Post-condition (REPEAT UNTIL) loops
Post-condition loops are written as follows:
REPEAT
<Statements>
UNTIL <condition>
The condition must be an expression that evaluates to a Boolean.
The statements in the loop will be executed at least once. The condition is tested after the statements are executed and if it evaluates to TRUE the loop terminates, otherwise the statements are executed again.
Pre-condition (WHILE) loops
Pre-condition loops are written as follows:
WHILE <condition> DO
<statements>
ENDWHILE
The condition must be an expression that evaluates to a Boolean.
The condition is tested before the statements, and the statements will only be executed if the condition evaluates to TRUE. After the statements have been executed the condition is tested again. The loop terminates when the condition evaluates to FALSE.
The statements will not be executed if, on the first test, the condition evaluates to FALSE.
Standard methods of solution
Totalling
Counting
Finding Maximum, Minimum, and Average (mean) values
Searching using Linear search
Sorting using a Bubble Sort
Totalling
Totalling means keeping a total that values are added to. For example, keeping a running total of the marks awarded to each student in a class.
Counting
Keeping a count of the number of times an action is performed is another standard method.
To do this you need to:
Initialize a variable to start the count
Add 1 to the count variable each time
For example, counting the number of students that were awarded a pass mark:
Maximum, Minimum, and Average
Finding the largest and smallest values in a list are two standard methods that are frequently found in algorithms.
The minimum is the smallest value within the set. To do this you need to:
Initialize a minimum variable to be a large value beyond those that will be entered. E.g. Minimum← 99999
Compare each value to the minimum variable. E.g. IF Number < Minimum
If it is, it replaces the minimum value. E.g. Minimum ← Number
The maximum is the largest value within the set. To do this you need to:
Initialize a maximum variable to be a small value beyond those that will be entered. E.g. Maximum← -99999
Compare each value to the maximum variable. E.g. IF Number > Maximum
If it is, it replaces the maximum value. E.g. Maximum ← Number
The average is referring to the mean. This is all the values added together, then divided by how many numbers are there. To do this, we need to use the Count and Total and then do Total/Count
For example, finding the highest and lowest mark awarded to a class of students.
Linear Search
A linear search is the simplest method of searching a data set. It is also called Sequential Search.
A search is used to check if a value is stored in a list, performed by systematically working through the items in the list.
A linear search will check each item one at a time starting with the first item and continuing it either finds the item or checks the last value
Algorithm:
FOR ArrayIndex← 0 TO LENGTH(Array)-1 //loop through each element
IF DataArray[ArrayIndex] = SearchValue THEN
OUTPUT "Found at ", ArrayIndex //if it is found, the index where it is found
ELSE
ArrayIndex← ArrayIndex+1 //if it is not found, increment array index to check the next value
ENDIF
NEXT ArrayIndex
A written description algorithm for a linear search might be:
Find out the length of the data set.
Set counter to 0.
Examine value held in the list at the counter position.
Check to see if the value at that position matches the value searched for.
If it matches, the value is found. Send a message and end the search.
If not, increment the counter by 1 and go back to step 3 until there are no more items to search.
If all the items have been checked and no match is found, send a message.
In the example below, the search checks how many people chose ice cream as their favourite dessert, where several values in the list can be the same.
ChoiceCount ← 0
FOR Counter ← 1 TO Length
IF "ice cream" = Dessert[Counter] //Checking ice cream has been chosen
THEN
ChoiceCount ← ChoiceCount + 1
ENDIF
NEXT Counter //Checking every item in the list
OUTPUT ChoiceCount, " chose ice cream as their favourite dessert."
Bubble Sort
Items are sorted in a meaningful order.
In bubble sort each element is compared with the next element and swapped if the elements are in the wrong order, starting from the first element
Bubble sorts work as follows:
Start at the beginning of the list.
Compare the first value in the list with the next one up. If the first value is bigger, swap the positions of the two values.
Move to the second value in the list. Again, compare this value with the next and swap if the value is bigger.
Keep going until the there are no more items to compare.
Go back to the start of the list.
Format
Begin BubbleSort(list)
FOR all elements of list
IF list[i] > list[i+1]
SWAP(list[i], list[i+1])
ENDIF
NEXT
RETURN list
End BubbleSort
Sample program
counter = 0
swapped = True
swaps = 0
length = list.length
while swapped == True
while counter < length-1
if list[counter] > list[counter+1] then
temp = list[counter]
list[counter] = list[counter+1]
list[counter+1] = temp
swaps = swaps + 1
endif
counter = counter + 1
endwhile
if swaps == 0 then
swapped = False
else:
swaps = 0
counter = 0
endif
endwhile
For more click here
Example
Validation and Verification [2022, 2021, 2020, 2019....]
Validation
Validation is an automatic check to ensure that the data entered is sensible and feasible.
Validation cannot ensure data is accurate.
When programming, it is important that you include validation for data inputs. This stops unexpected or abnormal data from crashing your program and prevents you from receiving impossible garbage outputs.
Validation methods
Range check: Checks the data falls between an acceptable upper and lower value, within a set range. For example, checking that percentage marks are between 0 and 100 inclusive:
Length check: Checks the number of characters meets expectations, e.g. an 8 character password. for example that a password must be exactly eight characters in length so that passwords with seven or fewer characters or nine or more characters would be rejected, for instance:
Type check: Checks that the data entered is of an expected type, e.g. text or a number. for example, that the number of brothers or sisters would be an integer (whole number).
Presence check: Checks that the user has at least inputted something, stopping them from accidentally entering nothing. for example, an email address for an online transaction must be completed.
Check digit: An extra digit added to a number which is calculated from the other digits, this ensures the rest of the number has been entered properly. A check digit is the final digit included in a code; it is calculated from all the other digits in the code. Check digits are used for barcodes, product codes, International Standard Book Numbers (ISBN), and Vehicle Identification Numbers (VIN).
Verification
Verification is a way of preventing errors when data is copied from one medium to another.
Verification does not check if data makes sense or is within acceptable boundaries, it only checks that the data entered is identical to the original source.
Verification methods:
Double entry Data is entered twice and the computer checks that they match up
Visual check The user manually reads and compares the newly inputted data against the original source to ensure they match
Test data [2022, 2021, 2020, 2019.......2023]
check that the program works as expected
check for logic/runtime errors
check that the program rejects any invalid data that is input
check that the program only accepts reasonable data
All the items of data are required to work through a solution. It is inputted into the program and compared with the expected results.
Normal: Data that a program should accept
Abnormal: Data that a program should not accept
Extreme: Data that is at the edge of what is allowed
Boundary: Data that is on the edge of being accepted or rejected.
Examples are for a school grade (out of 100)
Normal – 28; 64; 98 - Accepted
Erroneous/Abnormal – eleven; -12; 158 - Rejected
Extreme – 0; 100 – Accepted
Boundary – 0; -1 – Accepted; Rejected or 100; 101 – Accepted; Rejected
One mark per mark point, max four
Normal test data
computerscience@cambridge.org.uk
Reason
this is a valid email address (containing the @ symbol) and should be accepted
Erroneous test data
computerscienceisgreat
Reason
this is just a string, and should be rejected (as an email address needs a single ’@’)
One mark for each point max three.
• variables / constants are used to store items of data
• the data stored in variables / constants are accessed by an identifier // named data stores
• the value of a variable may change during the execution of a program
• the value of a constant will remain the same during the execution of a program
One mark per mark point, max four
variables are used to represent values that can change during the execution of a program // variables can be used to store the results of calculations / counting / totalling // can store values entered by the user
variable example – any data that is input into a program such as a date
constants represent values that must stay the same throughout the execution of a program
constant example– any value that does not change, such as Pi in mathematical formulae
One mark per mark point for each piece of test data (3× two marks)
Correct validation check name
Correct use identified
Example answers
Id27@cambridgeuniversity.com
• Validation check name: Length (check)
• Use Counts of the number of characters in the data to make sure it isn’t too long (max length 320 characters).
2021
• Validation check name: Range (check)
• Use Checks that the number entered fits within the given parameters
Ericson-Bower
• Validation check name: Type (check)
• Use Checks the type of data entered (in this case) to make sure no numbers are present
One mark for explaining why a validation check is needed when data is input
To check that data is sensible / reasonable / meets required criteria
One mark for explaining why a verification check is needed when data is input
To check that data is not changed on entry
One mark for an example of a validation check
Range check // Length check // Type check
One mark for an example of a verification check
Double entry // Visual check
Two from
Sub-program / system not the whole program / system
To perform a frequently used operation within a program
That can be called when needed
That can be reused by another program
2 marks for identification, 1 mark for description, 1 mark for reason.
Identification:
CASE ...
... OF ... OTHERWISE ... (ENDCASE)or
... OF ... (OTHERWISE) ... ENDCASE
Description:
– a statement that allows for multiple selections // not any of the above
Reason:
– to simplify pseudocode/ make pseudocode more understandable etc.
RANGE CHECK
OUTPUT "ENTER A NUMBER BETWEEN 1 TO 10"
INPUT Number
IF Number<1 OR Number>10 THEN
OUTPUT "Invalid"
ELSE
OUTPUT "Valid"
ENDIF
LENGTH CHECK (Use function LENGTH)
INPUT NewPassword
IF LENGTH (NewPassword)<8 THEN
OUTPUT "Invalid"
ELSE
OUTPUT "Valid"
ENDIF
TYPE CHECK (Use functions .GetDataType() or .IsInteger() or .IsString, etc. )
INPUT PhoneNumber
IF PhoneNumber.GetDataType()<> Integer THEN
OUTPUT "Invalid"
ELSE
OUTPUT "Valid"
ENDIF
PRESENCE CHECK (Use of value NULL)
INPUT PhoneNumber
IF PhoneNumber = NULL THEN
OUTPUT "Invalid"
ELSE
OUTPUT "Valid"
ENDIF
FORMAT CHECK
OUTPUT "Enter your school No. in the format 444-H where first three digits are your school number followed by the boarding house you are in"
INPUT SchoolNumber
IF SUBSTRING (SchoolNumber, 1,3).IsInteger = TRUE AND SUBSTRING (SchoolNumber, 4,2).IsString=TRUE THEN
OUTPUT "Valid"
ELSE
OUTPUT "Invalid"
ENDIF
2 marks for appropriate explanation, 1 mark example programming statements showing sequence, 1 mark example
programming statement(s) showing selection e.g.
Sequence is the concept of one statement being executed after another(1) whereas selection decides which statement(s) are to be executed depending upon the result of a question (1)
sequence example (1)
PRINT X
PRINT Y
Selection example (1)
IF X > Y THEN PRINT X ELSE PRINT Y
One mark for each point max two.
• check that the program works as expected
• check for logic/runtime errors
• check that the program rejects any invalid data that is input
• check that the program only accepts reasonable data
One mark for example
Normal // erroneous // abnormal // extreme // boundary