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

Higher Computing Science 2022 Question 8

15 marks · Software analysis

Describe two processes of this game. Process 1 Process 2 The first level of the game uses words that are three letters long. These words are stored in a text file called threeLetters.txt. Using a design technique of your choice, design a program to read in this file, pick one of the words at random and assign it to a variable called chosenWord. As the game progresses the words get longer and users can get hints from the game. Using a programming language of your choice, write code to: assign the variable hintOne the first letter of the word stored in the chosenWord variable. assign the variable hintTwo a random letter from the word stored in the chosenWord variable. When the user enters a letter they have not already chosen, this is stored in an array called usedLetters. The number of letters stored in the array is increased by one and is stored in a variable called numLetters. For example: Values usedLetters ["D", "Z", "R", "B", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""] numLetters 4 If the user enters a letter already stored in the array usedLetters an error message is displayed. The user is asked to try again until they enter a letter that is not already stored in this array. Using a programming language of your choice, write the code to implement this feature. A game displays a picture and the user is asked to spell the matching word by entering letters. When a correct letter is entered by the user the letter is filled into the correct box(es). The game displays the number of letters that the user has already guessed. The user is able to get a hint. Once the correct letters have been entered a message of congratulations is displayed. SPELL IT Get a hint Enter Letters Guessed 0/26

Marking scheme

• generate hint • store letters guessed • check entered letter is correct • identify/allocate letter to correct box • count number of guesses • decide if whole word is correct • check entered letter against stored letters 1 mark for each bullet Maximum 2 marks Do not award input/output marks. • Open & close file • Read file into data structure • Generate random number • Assign word at position random number to chosenWord variable 1 mark for each bullet Assignment of first character to hintOne. hintOne= left(chosenWord, 1) hintOne= mid(chosenWord, 1, 1) hintOne= chosenWord[0] hintOne= chosenWord[0:1] hintOne= chosenWord[:1] put char 1 of chosenWord into hintOne • use of length function to generate random number for length of chosenWord • assign letter at position identified to hintTwo 1 mark for each bullet randomPos = random(1, len(chosenWord)) hintTwo = mid(chosenWord, randomPos,1) hintTwo=chosenWord[random.randInt( 0,len(chosenWord)-1)] • conditional loop with terminating condition and input within conditional loop • loop to traverse the array • decide if letter is in usedLetters array • display error message if letter in usedLetters • valid letter is added to array • number of letters incremented 1 mark for each bullet Allow loop for length of array of usedLetters/26 iterations or for numLetters. Only award last two marks if placed in section of code when letter is not found. DECLARE found INITIALLY false REPEAT RECEIVE letter FROM KEYBOARD FOR index FROM 0 TO usedLetters-1 DO IF usedLetters[index]=letter THEN SET found TO true SEND ‘Letter already used. Please re-enter’ END IF END FOR UNTIL found=false SET usedLetters[numLetters] TO letter SET numLetters TO numLetters +1

Previous question: Higher Computing Science 2022 Question 7

Next question: Higher Computing Science 2022 Question 9