ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
11 marks · Design notations and data flow
Complete the table below to show the missing data flow in steps 2 and 3. Step IN/OUT Data Flow 1 IN OUT password 2 IN OUT randPos1, randPos2, randPos3 3 IN OUT valid By considering the data flow in part (a), explain why it would be appropriate to make use of a function rather than a procedure for step 3. Explain why the programmer refers to the data flow in the top‑level design when implementing the code for the program. The code for step 2 is shown below. … Line 45 PROCEDURE getLetters (STRING word, INTEGER first, INTEGER second, INTEGER third) Line 46 DECLARE wordLength AS INTEGER INITIALLY length(word) Line 47 SET first TO <random number from 1 to wordLength> Line 48 SET second TO <random number from 1 to wordLength> Line 49 SET third TO <random number from 1 to wordLength> Line 50 END PROCEDURE … Line 60 getLetters(password,randPos1,randPos2,randPos3) … Formal and actual parameters are used in the code above. Identify one formal parameter and its associated actual parameter. Formal parameter Actual parameter State the scope of the variable wordLength. During testing it was found that users were asked for duplicate letters, for example asking for letters 1, 1 and 7 of their password. Describe how the procedure could be altered to ensure three different letters are requested from the user. Explain why the use of procedures improves the efficiency of code. An app uses three selected letters from a user’s password to help identify a user when logging in. An example is shown below. The top‑level design for this part of the program is shown below. 1. Ask user for username and find password 2. Generate three random positions within length of password 3. Ask user for letters at generated random positions and check for a match
STEP 2 IN: password STEP 3 IN: randPos1, randPos2, randPos3 1 mark for each step Returns a value The data flow informs parameter passing. The mark is for identifying the relationship to parameter passing. Candidates that use actual or formal incorrectly here should not be penalised as part (d) assesses the use of formal and actual parameters. • correct identification of any formal parameter • corresponding actual parameter 1 mark for each bullet Formal Actual word password first ranPos1 second ranPos2 third ranPos3 Local / only in the getLetters sub- program Award mark if candidate references appropriate line numbers. • use of conditional loop • use of comparison to number(s) already generated 1 mark for each bullet Candidates may choose to exemplify through the use of design or code, for example. Do SET second TO <random number…> Loop until second<>first Do Set third TO <random number…> Loop until third<>second AND third<>first • allows fewer lines of code/removes repetition (1) by calling same procedure more than once (with different actual parameters) (1) • local variables can use less memory (1) as they only allocated memory during the running of the procedure / memory space is freed at the end of the procedure (1) 1 mark for reason which relates to procedures. 1 mark for justification. Do not penalise candidates that refer to functions.