GCSE Computer Science Programming test

<< Previous: Robust programming Programming home GCSE home Next: Units of measurement >>

Exam style questions

Download a pdf version of the test

Use the space below each question or a pen and paper to write your answer. When complete click the button for the answer and mark scheme.

NOTE: Answers typed into the browser will not be retained if you leave the page or refresh

Questions

Complete the missing parts of the table below (5 marks)

Data type Description Example
A number with no decimal part 42
Real 3.14
For variables that store either true or false False
Character 'F'
String A group of characters

Data type Description Example
Integer A number with no decimal part 42
Real A number with a decimal part 3.14
Boolean For variables that store either true or false False
Character A single letter number or symbol 'F'
String A group of characters 'Bob'

1 mark per correct answer



Pseudocode example 1

On what line does assignment first occur? (1 mark)

On what line does selection first occur? (1 mark)

On what line does iteration first occur? (1 mark)

On what line does assignment first occur? Line 1. Assignment is giving a variable a new value as shown by a left facing arrow in pseudocode.
On what line does selection first occur? Line 5. Selection is completed by an IF statement or CASE SELECT statement.
On what line does iteration first occur? Line 3. Iteration is looping and this algorithm has a for loop.

Complete the trace table below if the user enters "oxen" as the word in pseudocode example 1.

word newWord i ascii OUTPUT

The exam board is not particular about which row changes appear on as long as the values in each column are in order. 1 mark each correct column.

word newWord i ascii OUTPUT
'oxen' '' 1 114
'r' 2 123
'ra' 97
'rah' 3 104
'rahq' 4 113 'rahq'



What is the purpose of the pseudocode example 1 algorithm above? (3 marks)


It converts each letter in a word(1) to the letter 3 further on in the alphabet(1) and if it goes past Z loops back to A.(1)

Leyla is a photographer who shoots weddings. She charges £125 per hour for her services plus a travel fee of £10 for every 25 miles or part thereof she has to travel. That means for a booking 55 miles away it would be £30 as it is more than 2 full lots of 25 miles. Write an algorithm that will allow Leyla to enter the number of hours of a booking and the distance to the booking and have it calculate a total price. (5 marks)

NOTE: Use either two or four spaces to show indentation. If you want to draw a left facing arrow hold down the Alt key while you press 27 on the number pad.


hours ← USER INPUT
miles ← USER INPUT
cost ← hours * 125 + ((miles//25)+1) * 10
OUTPUT 'Total cost: ' + cost
If not fully correct individual marks for getting and storing two inputs, muliplying hours by 125, calculating the number of lots of mileage to charge, multiplying that number by 10, calculating and outputting the total amount

Explain what boundary testing is and give an example of a boundary test that would be needed for the photographers cost algorithm in the previous question. (2 marks)


Boundary testing is where we check that either side of a boundary code works as expected.(1)
An example of a boundary test from above would be to ensure that 50 miles evaluated to a distance charge of £20 but 51 miles would mean a charge of £30.(1)


Write an algorithm that will keep asking the user to answer the question 'What is the capital of England?' until they answer 'London'. When they do it should output how many attempts it took to get it right. (6 marks)



OUTPUT 'What is the capital of London?
guess ← USER INPUT
guesses ← 1
WHILE guess != 'London'
    OUTPUT 'What is the capital of London?
    guess ← USER INPUT
    guesses ← guesses + 1
END WHILE
OUTPUT 'Attempts:' + guesses

Individual marks for getting user input and storing it; initiating a variable to track attempts; using a while loop; reasking the question in the while loop and getting new input; incrementing attempts variable in the loop; outputting the number of attempts at the end.


Pseudocode example 2

Which of the basic programming constructs can be seen in the algorithm above? (1 mark)

How many subroutines are called in the algorithm? (1 mark)

Explain how you can tell which subroutines are procedures and which are functions in this algorithm? (3 marks)


This subroutine has sequence and iteration.(1) Although there is a comparison it is part of the loop condition not selection.
There are 3.(1) Random_int, Convert_to_letter and displayResult
A function returns a value but a procedure does not(1) so the result of a function must be stored in a variable but a procedure will be called on their own separate line.(1) Convert_to_letter is a function and displayResult is a procedure.(1)



Explain, using examples from pseudocode example 2 above, what a parameter is. (3 marks)


A parameter is a value passed to a subroutine from the main program(1) that can be used within the running of the subroutine.(1) Any suitable example e.g. randNum, userChoice, compChoice(1)

Write an algorithm for a subroutine to get a username from a user and check its length is between 3 and 12 characters. If it is not then the algorithm should give a message saying so and make the user keep re-enter until they enter a username of a valid length. That should then be returned by the subroutine. (7 marks)


SUBROUTINE getUsername()
    OUTPUT 'Enter a username: '
    username ← USER INPUT
    WHILE LEN(username) < 3 OR LEN(username) > 12
        OUTPUT 'Must be between 3 and 12 characters!'
        username ← USER INPUT
    END WHILE
    RETURN username

If not completely correct individual marks for: declaring a subroutine; Getting user input; Using a while loop; Correct condition; Message to explain what went wrong to user; new input obtained in the loop; username returned

Explain the difference between local and global variables (3 marks)


Global variables are declared in the main program and local variables are declared inside a subroutine.(1)
Global variables are available throughout the program but local variables are only available in the subroutine where they were declared.(1)
Local variables cease to exist when the subroutine they were part of ends.(1)

Explain what structured programming refers too and what its advantages are for programming. (5 marks)


What is structured programming: modularised programming/use of subroutines(1) with well documented interfaces(1) using only local variables.(1)
Advantages of structured programming: different people can write different subroutines(1) and can call other subroutines without knowing how they work as long as they know what to pass them and what they return.(1)



<< Previous: Robust programming Data representation home GCSE home Next: Units of measurement >>

© All materials created by and copyright S.Goff