ExamBank Scot · N5 Computing Science question bank · All N5 Computing Science questions

N5 Computing Science 2021 Question 12

12 marks · Fixed and conditional loops

State the type of loop required when implementing this design. State the standard algorithm used in this design. Several different programming constructs will be required when the program code is written. Complete the table below to show this. Example from design Matching construct Set totalPassengers to 0.00 Conditional statement Arithmetic operation The total number of passengers is set to 0.00 in the design. State a more appropriate data type to store the total number of passengers. Give a reason for your answer. Data type Reason The program is edited to calculate the total value of the passengers’ tickets. The price of a ticket is different for each deck. Deck 1 Deck 2 Saturday’s ticket numbers 1 to 50 51 to 100 Sunday’s ticket numbers 101 to 150 151 to 200 Ticket price £5 £10 The edited code is shown below. … Line 5 RECEIVE lower FROM KEYBOARD Line 6 RECEIVE upper FROM KEYBOARD … Line 14 IF ticketNumber < lower OR ticketNumber > upper THEN Line 15 SEND "Ticket Refused" TO DISPLAY Line 16 ELSE Line 17 SET numberOfPassengers TO numberOfPassengers + 1 Line 18 IF ticketNumber <= (lower + 49) THEN Line 19 SET totalValue TO totalValue + 5 Line 20 END IF Line 21 IF ticketNumber >= (lower + 50) THEN Line 22 SET totalValue TO totalValue + 10 Line 23 END IF Line 24 END IF … Using a programming language of your choice, re‑write lines 18 to 23 in a more efficient way. Tickets include a bit‑mapped graphic. Saturday Ticket Upper Deck Seat Number: 60 Saturday Ticket Lower Deck Seat Number: 37 Describe how a bit‑mapped graphic is represented in a computer system’s memory. A company runs a sightseeing trip around Iron Craig Island each Saturday and Sunday. Their boat can hold 100 passengers. Every weekend the available tickets are numbered as follows. Saturday’s ticket numbers 1 to 100 Sunday’s ticket numbers 101 to 200 A program is being developed to • allow the company to check the validity of each passenger’s ticket as they board the boat • calculate and display the total number of the passengers on each trip. The program design is shown below. PROGRAM daily ticket analyser repeat until display get ticket no more total number range passengers of passengers 0.00 get get lower get upper ticketNumber ticket ticket from number number passenger is ticketNumber within range for today? yes no add 1 to number display of passengers “Ticket Refused” set number of passengers to

Marking scheme

Conditional Running total (within loop) One mark each for • assignment • is ticketNumber within range for today? • add one to number of passengers Example from design Matching construct Set totalPassengers to 0.00 assignment is ticketNumber within range for today? Conditional statement add one to number of passengers Arithmetic operation One mark each for • Data type - Integer • Reason – passenger/people are whole numbers One mark each for • a suitable condition for one ticket • use of ‘else’ for other type of ticket • calculate Running Total Sample answer: IF ticketNumber <= (lower + 49) THEN SET totalValue TO totalValue + 5 ELSE SET totalValue TO totalValue + 10 END IF One mark each for • (grid of) pixels • each pixel (colour) stored as a binary value

Previous question: N5 Computing Science 2021 Question 11

Next question: N5 Computing Science 2021 Question 13