Implementation (Algorithms) (SQA National 5 Computing Science): Exam Questions

Exam code: X816 75

16 mins4 questions
1
4 marks

Input validation is required to ensure that a program will only accept the numbers 1 or 5.

Using a design technique of your choice, design an efficient solution to ensure that the program will only accept valid numbers from the user.

2
4 marks

A program is being written that will allow gamers to add money to their account using gift cards.

£25 gift card with a simple line drawing of a wrapped present and a ribbon on a grey background. Card number: 0976 3421 6475 4377.

The program asks the user to enter their username, their five‑character password and the gift card number. The updated balance in the user’s account is then displayed.

Using a programming language of your choice, write the input validation code to confirm that the password entered has five characters.

3
4 marks

A campsite booking system is being developed to calculate the cost of a stay at £35 per night, per person. The cost will be displayed to the user before they confirm the booking. The system will ask users for their name, number of people, arrival date and length of stay.

The number of guests who stayed at the campsite each night in 2023 is stored in the array guests.

Index

0

1

2

.....

364

Value

271

240

153

.....

87

The campsite want to know the total number of guests who stayed at the site in 2023.

Using a programming language of your choice, write the code to calculate this total.

4
4 marks

A window replacement company employs a programmer to write a program that calculates how much it will cost to fit triple glazed windows.

Small windows cost £299.99 and large windows cost £499.99 to replace.

The algorithm to calculate the cost is shown below.

  1. Set totalCost to 0

  2. Ask for number of rooms

  3. Loop through the number of rooms

  4. Ask for the number of small windows

  5. Ask for the number of large windows

  6. Calculate and update totalCost

  7. End loop

  8. Display totalCost

Step 6 in the algorithm calculates and updates the total cost.

Using a programming language of your choice, write the code for step 6.