A shop sells sandwiches and snacks. The owner chooses a 'daily special' sandwich which is displayed on a board outside the shop. Each 'daily special' has two different fillings and is made with one type of bread. The owner wants a program to randomly choose the 'daily special' sandwich. The program designer decides to store the possible sandwich fillings in a 1D array of type string. The array is declared in pseudocode as shown: DECLARE Filling : ARRAY [1:35] OF STRING Each element contains the name of one filling. An example of the first five elements is as follows: | Index | Element value | |-------|-----------------| | 1 | "Cheese" | | 2 | "Onion" | | 3 | "Salmon" | | 4 | "Anchovies" | | 5 | "Peanut Butter" | A second 1D array stores the possible bread used: DECLARE Bread : ARRAY [1:10] OF STRING Each element contains the name of one type of bread. An example of the first three elements is as follows: | Index | Element value | |-------|---------------| | 1 | "White" | | 2 | "Brown" | | 3 | "Pitta" | Both arrays may contain unused elements. The value of these will be an empty string and they may occur anywhere in each array. A procedure Special() will output a message giving the 'daily special' sandwich made from two randomly selected different fillings and one randomly selected bread. Unused array elements must not be used when creating the 'daily special' sandwich. Using the above examples, the output could be: "The daily special is Cheese and Onion on Brown bread."
- (a)Complete the pseudocode for the procedure Special(). Assume that both arrays are global. PROCEDURE Special() ENDPROCEDURE[7]
- (b)The owner decides that some combinations of fillings do not go well together. For example, anchovies and peanut butter. Describe how the design could be changed to prevent certain combinations being selected.[2]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2024). The mark or mark type is shown in brackets.
- [1] PROCEDURE Special()
- [1] DECLARE Index : INTEGER
- [1] DECLARE Filling1, Filling2 : STRING
- [1] REPEAT ... UNTIL Filling[Index] <> ""
- [1] Index ← INT(RAND(35)) + 1
- [1] Filling1 ← Filling[Index]
- [1] REPEAT ... UNTIL Filling[Index] <> "" AND Filling1 <> Filling[Index]
- [1] Index ← INT(RAND(35)) + 1
- [1] Filling2 ← Filling[Index]
- [1] REPEAT ... UNTIL Bread[Index] <> ""
- [1] Index ← INT(RAND(10)) + 1
- [1] OUTPUT "The daily special is ", Filling1, " and ", Filling2, " on ", Bread[Index], " bread."
- [1] ENDPROCEDURE
- [1] For each filling, create a list of acceptable / incompatible fillings/indexes
- [1] When selecting the second filling, (as well as checking for an unused element) check that the filling / index is / is not on the list
- [1] ALTERNATIVE: Create a list of 'good' combinations
- [1] Randomly select from this list
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →