Programming and Software Development: Computer Science 9618 (Cambridge International AS & A Level)
Syllabus 11.1, 11.2, 11.3, 12.1, 12.2, 12.3 · Strand 7 Programming and Software Engineering
- Questions
- 10
- Total marks
- 48
- Tier mix
- 10 Core
0 of 10 questions completed
Syllabus coverage
- 11.1 1 question completed
- 11.2 2 questions completed
- 11.3 2 questions completed
- 12.1 2 questions completed
- 12.2 1 question completed
- 12.3 5 questions completed
Writing a working program and building it responsibly are two connected skills, and this topic (syllabus ref 11.1–11.3, 12.1–12.3) covers both. At the statement level, pseudocode declares constants and variables, evaluates expressions, and branches with IF/ELSE or CASE, and repeats with a count-controlled, pre-condition or post-condition loop, each loop shape suits a different kind of “how many times” question. Procedures and functions package reusable logic behind a defined interface, taking parameters by value or by reference, with a function additionally returning a value for use in an expression.
Zooming out, a development life cycle (waterfall, iterative, rapid application development) structures the whole build, and a structure chart or state-transition diagram documents the design before coding starts. Once code exists, testing is not optional: syntax, logic and run-time errors each need a different fix, and a test plan should choose normal, abnormal and extreme/boundary data deliberately, using methods from a simple dry run up to alpha and beta testing.
The exam-style problems below are original, each with a complete worked solution.
Question 1
A program validates a student's percentage exam score before storing it. The score must be entered as a whole number in the range 0 to 100 inclusive; any other value must be rejected by the validation check, and the user asked to re-enter it.
Which one of the following is an example of erroneous (abnormal) test data for this validation check?
Question 2
A programmer writes this line of pseudocode, intending to declare an integer variable to store a customer's account number, but the colon before the data type has accidentally been left out.
DECLARE AccountNumber INTEGER
When this program is translated, before it is even run, what type of error will this line cause?
Question 3
A programmer writes this procedure, intending it to swap the values held in two variables in the main program.
PROCEDURE Swap(BYVAL A : INTEGER, BYVAL B : INTEGER)
DECLARE Temp : INTEGER
Temp ← A
A ← B
B ← Temp
OUTPUT "Inside Swap: A = ", A, " B = ", B
ENDPROCEDURE
// Main program
DECLARE X : INTEGER
DECLARE Y : INTEGER
X ← 5
Y ← 9
CALL Swap(X, Y)
OUTPUT "After call: X = ", X, " Y = ", Y
(a) Copy and complete a trace table showing the value of A, B and Temp after each of the
three assignment statements inside Swap, and state the values output by the OUTPUT statement
inside Swap. [3]
(b) State the values output by the final line, OUTPUT "After call: X = ", X, " Y = ", Y, and
explain, in terms of how a BYVAL parameter works, why these values are not the swapped values
seen inside Swap. [2]
(c) State the one change needed to the header line of Swap so that calling CALL Swap(X, Y)
actually swaps the values stored in X and Y in the main program, and explain why this change
achieves a real swap. [2]
Question 4
A self-service checkout scans the items a customer buys, one at a time. The price of each item is entered as a REAL number, and the customer finishes scanning by entering 0 instead of a price. The pseudocode below reads in each price, adds it to a running total, and counts how many items were scanned, ignoring the terminating value 0 itself.
DECLARE Price : REAL
DECLARE Total : REAL
DECLARE ItemCount : INTEGER
Total ← 0
ItemCount ← 0
REPEAT
INPUT Price
IF Price > 0
THEN
Total ← Total + Price
ItemCount ← ItemCount + 1
ENDIF
UNTIL Price = 0
OUTPUT "Number of items: ", ItemCount
OUTPUT "Total cost: ", Total
(a) The pseudocode above uses a REPEAT ... UNTIL loop rather than a WHILE ... DO loop. State
whether REPEAT ... UNTIL is a pre-condition or a post-condition loop, referring to when its
condition is tested, and explain why this makes it a sensible choice for reading in the first
price scanned by a customer who always scans at least one item. [2]
(b) A customer scans three items, entering the prices 12.50, 8.00 and 5.50 in that order, then
finishes scanning by entering 0. Trace the execution of the REPEAT ... UNTIL loop for this
customer by copying and completing a trace table showing, for each pass through the loop, the
value read into Price, whether the condition Price > 0 is true, the resulting values of
Total and ItemCount, and whether the condition Price = 0 is true. State the two values
output once the loop has finished. [4]
(c) Rewrite the loop above as an equivalent WHILE ... DO ... ENDWHILE loop that produces exactly
the same output for the same four values entered, and explain why the IF Price > 0 check used
inside the REPEAT ... UNTIL loop is no longer needed once the loop is rewritten using WHILE.
[2]
Question 5
A software house is building a system for a small boutique hotel to track the status of each of its rooms.
(a) The hotel manager is unsure exactly which room-status features will be useful in day-to-day practice, and wants to try out an early working version of the system and give feedback before more features are added. State which development life cycle model, waterfall or iterative development, is more appropriate for building this system, and give one reason for your choice. [2]
(b) The design team represents each room's status using a state-transition table, with states Vacant, Reserved, Occupied and NeedsCleaning. Part of the table is shown below, with three Next state entries left blank.
| Current state | Event | Next state |
|---|---|---|
| Vacant | Room reserved by a guest for a future date | Reserved |
| Reserved | Guest checks in | Occupied |
| Reserved | Guest cancels the reservation | Vacant |
| Occupied | Guest checks out | ..... |
| NeedsCleaning | Housekeeping finishes cleaning the room | ..... |
| Vacant | Guest checks in directly with no prior reservation | ..... |
Copy and complete the table by stating the correct Next state for each of the three blank rows. [3]
(c) Two testers are testing a function IsLateCheckOut(ExpectedTime, ActualTime), which should
return TRUE if ActualTime is later than ExpectedTime.
- Tester 1 reads only the specification for
IsLateCheckOut, then designs test times and checks that the TRUE/FALSE result returned matches what the specification says it should be, without ever looking at the function's own code. - Tester 2 reads the source code of
IsLateCheckOut, then designs test times so that every branch of code inside the function is executed at least once during testing.
State which tester is using black-box testing and which is using white-box testing, and state one difference between black-box and white-box testing that this scenario illustrates. [2]
Question 6
A program is intended to read in a list of numbers entered by the user, one at a time, adding
each number to a running Total and counting how many numbers have been entered in Count,
until the user enters -1 to stop. Once this loop finishes, the pseudocode below calculates and
outputs the average of the numbers entered.
DECLARE Total : INTEGER
DECLARE Count : INTEGER
DECLARE Average : REAL
Total ← 0
Count ← 0
// ... a loop here reads numbers from the user, adding each one to Total and
// adding 1 to Count, until the user enters -1 to stop ...
Average ← Total / Count
OUTPUT Average
This pseudocode translates successfully, and the program runs correctly for a user who enters
several numbers before -1. However, if a user enters -1 immediately, without entering any
numbers first, the program crashes when it reaches the line Average ← Total / Count.
Which one of the following best describes the type of error that occurs in this situation, and when it is detected?
Question 7
A gym records how many times each of 5 members visited during the last month, storing these
counts in the array Visits. The pseudocode below classifies each member using their number of
visits, and counts how many members qualify as "Regular" (9 or more visits in the month).
DECLARE Visits : ARRAY[1:5] OF INTEGER
DECLARE i : INTEGER
DECLARE Category : STRING
DECLARE RegularCount : INTEGER
Visits[1] ← 0
Visits[2] ← 5
Visits[3] ← 12
Visits[4] ← 8
Visits[5] ← 20
RegularCount ← 0
FOR i ← 1 TO 5
IF Visits[i] = 0
THEN
Category ← "Inactive"
ELSE
IF Visits[i] >= 9
THEN
Category ← "Regular"
RegularCount ← RegularCount + 1
ELSE
Category ← "Occasional"
ENDIF
ENDIF
OUTPUT Visits[i], " : ", Category
NEXT i
OUTPUT "Regular members: ", RegularCount
(a) Copy and complete a trace table showing, for each of the 5 passes through the FOR loop,
the value of i, the value of Visits[i], the Category assigned on that pass, and the value
of RegularCount after that pass. [4]
(b) State the value output by the final line, OUTPUT "Regular members: ", RegularCount. [1]
(c) State why a FOR ... NEXT loop (a count-controlled loop) is a sensible choice for this
task, referring to the length of the Visits array. [1]
(d) The gym wants to adapt this code to work for a list of members whose length is not known in
advance, and could be different each month. State whether a FOR ... NEXT loop is still the
most suitable choice for stepping through this new list, name a more suitable loop construct if
not, and give one reason for your choice. [2]
Question 8
A mail-order company calculates the postage cost for a parcel using its weight in grams. The
FUNCTION below returns the correct postage cost, and the main program then adds together the
postage for two separate parcels.
FUNCTION CalculatePostage(WeightGrams : INTEGER) RETURNS REAL
DECLARE Cost : REAL
IF WeightGrams <= 100
THEN
Cost ← 1.50
ELSE
IF WeightGrams <= 500
THEN
Cost ← 2.75
ELSE
Cost ← 4.20
ENDIF
ENDIF
RETURN Cost
ENDFUNCTION
// Main program
DECLARE TotalCost : REAL
TotalCost ← CalculatePostage(80) + CalculatePostage(650)
OUTPUT "Total postage: ", TotalCost
(a) State the value returned by the call CalculatePostage(80), and identify which branch of
the nested IF statement inside CalculatePostage produces this value. [2]
(b) State the value returned by the call CalculatePostage(650), and identify which branch of
the nested IF statement inside CalculatePostage produces this value. [2]
(c) State the value of TotalCost output by the final line of the main program, showing your
working. [2]
(d) Explain why CalculatePostage must be written as a FUNCTION rather than as a
PROCEDURE for the line TotalCost ← CalculatePostage(80) + CalculatePostage(650) to work
correctly. [1]
Question 9
A website requires users to create a new password between 8 and 20 characters long, inclusive. During validation, any password whose length is outside this range must be rejected, and the user asked to try again; any password whose length is within this range must be accepted.
(a) State one item of boundary (extreme) test data for the lower edge of the accepted length range, and one item of boundary (extreme) test data for the upper edge. For each, state whether the validation check should accept or reject it. [2]
(b) State one item of normal test data for the password length, and one item of erroneous (abnormal) test data for the password length, each different from your answers to part (a). For each, state whether the validation check should accept or reject it, and briefly explain why. [3]
(c) Explain why testing this validation check using only normal test data would not be sufficient to show that it works correctly. [2]
Question 10
A software company needs to build a simple internal booking tool very quickly. The developers make heavy use of prototyping tools to automatically generate much of the user interface, and work in short, fixed time periods (timeboxes), accepting less thorough documentation and a lower degree of code optimisation in exchange for a fast delivery time.
Which development life cycle model does this scenario best describe?