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

Higher Computing Science 2025 Question 8

17 marks · Data types and structures

Using a programming language of your choice, define a suitable record structure to store a player’s data. Using a programming language of your choice, declare a variable that could be used to store details for 10 000 attempts. Your answer should make use of the record data structure defined in part (i). The game stores the number of times it has been played that day in a variable numPlays. At the end of each day, the game finds the fastest time. Using a programming language of your choice, write the code to find the fastest time. Your answer should use the record data structure and variable declared in part (a). Explain why the variable numPlays is needed instead of traversing the entire array of 10 000. The reaction time of 0.125 is stored as a binary number as: 0.001 Convert the binary number above into floating-point representation. There are 16 bits for the mantissa (including the sign bit) and 8 bits for the exponent. Space for working mantissa exponent sign A player can play the game multiple times each day. Each time that they play, the program allocates them an attemptID using all the characters before the ‘@’ in their e-mail and the value of numPlays. A function that returns the position of any character in a string is used to implement this feature. The code for this function is shown below. … Line 47 FUNCTION findCharIndex(STRING value, STRING character) RETURNS INTEGER Line 48 DECLARE positionChar INITIALLY −1 Line 49 FOR index FROM 0 TO length(value)−1 DO Line 50 IF value[index]= character THEN Line 51 SET positionChar TO index Line 52 END IF Line 53 END FOR Line 54 RETURN positionChar Line 55 END FUNCTION … Line 70 SET position TO <return value of findCharIndex> Line 71 SET attemptID TO <characters before the ‘@’ character concatenated with the value of numPlays> Using a programming language of your choice, write the code for line 70 to assign the location of the ‘@’ character in the email variable to position by calling the function findCharIndex. Using a programming language of your choice, write the code for line 71 to assign all of the characters before the ‘@’ character concatenated with the value of the variable numPlays to attemptID. An online game measures a player’s reaction time to seeing a green dot appear on the screen. Each time someone plays the game their name, e-mail address, attemptID and reaction time to the nearest thousandth of a second is stored. Sample data is shown below. Lucy Scott lscott@hmail.com lscott8 0.215 Deaglán Mag Uidhir deaghlan@nsm.com deaghlan9 0.125 … … … … The game allows a maximum of 10 000 attempts each day. Players can play more than once, and each time their attemptID will be different.

Marking scheme

• record structure with candidate selected name • four fields specified If data types are indicated they must be appropriate. Example answer: RECORD player IS (STRING name, STRING email, STRING attemptID, REAL time) • array of 10 000 elements • use of record structure from (i) Award 1 mark for allPlayers =[player()]*10000 allPlayers =[player]*10000 Example answer: DECLARE allPlayers AS ARRAY OF player INITIALLY[]*10000 • initialise fastest to first time or suitable high value and re- assigning fastest • loop using numPlays • if condition to update fastest • use of array variable from (ii) • use of fields from (ii) Example answer: SET fastest TO allPlayers[0].time FOR i FROM 1 TO numPlays - 1 DO IF allPlayers[i].time < fastest: SET fastest TO allPlayers[i].time END IF END FOR Traversing array elements which will not have been populated/0/NULL. • sign bit: 0 • mantissa: 100 0000 0000 0000 • exponent: 1111 1110 • assigning to position and calling function • correct parameters in correct order position=findCharIndex(email,’@’) Accept position= findCharIndex(arrayname[index].email,’@’) • extracting substring • assignment to attemptID using concatenation with numPlays Candidate may use variable or reference an element of their record

Previous question: Higher Computing Science 2025 Question 7

Next question: Higher Computing Science 2025 Question 9