Learn Extracted exam questions A-Level Computer Science 9618 Computer Science November 2024 Question paper 22
9618 Computer Science November 2024 Question paper 22
Source PDF on the left, extracted YAML on the right. Compare numbering, marks, options and text.
A program has been developed and released for general use. After a few months of use an error is detected where under certain circumstances it outputs an unexpected value.
The error in the program needs to be corrected.
Identify the stage of the program development life cycle that this correction is made in.
The program contains a function \texttt{Lookup()}. After investigation, it is found that this is the function that sometimes returns an incorrect value.
An Integrated Development Environment (IDE) is used to help locate the error.
The IDE features of watch window, single stepping and breakpoint will be used.
Explain these features including the order that they will be used in to locate the error in \texttt{Lookup()}.
To solve the error a programmer decides to create a new module.
The design of the new module has been completed and the module is being coded.
Identify \textbf{two} features of an IDE that will help during the coding of this new module.
- \hrulefill
- \hrulefill
The new module referred to in part (c) introduces \textbf{three} new variables.
Complete the following table by giving the appropriate data type for each.
\begin{tabular}{|l|l|l|} \hline \textbf{Variable name} & \textbf{Used to store} & \textbf{Data type} \ \hline \texttt{Name} & A customer name. & \hrulefill \ \hline \texttt{Index} & An array index. & \hrulefill \ \hline \texttt{Result} & The result of the division of any two non-zero numbers. & \hrulefill \ \hline \end{tabular}
A program is being developed to process bank card information.
When a card number is displayed, all the characters \textbf{except} the last four are replaced with the asterisk character '*'.
Card numbers are stored as strings. The strings are between 10 and 20 characters in length.
The function \texttt{Conceal()} will take a string representing a card number and return a modified string.
Example strings:
\begin{tabular}{|l|l|} \hline \textbf{Original string} & \textbf{Modified string} \ \hline \texttt{"1234567890"} & \texttt{"******7890"} \ \hline \texttt{"1234567897652"} & \texttt{"*********7652"} \ \hline \texttt{"1234567890123456"} & \texttt{"************3456"} \ \hline \end{tabular}
The function \texttt{Conceal()} will:
\begin{itemize} \item take a numeric string as a parameter representing the card number \item return a string in which the asterisk character replaces all except the last four characters of the card number parameter. \end{itemize}
Write pseudocode for the function \texttt{Conceal()}.
The requirements have been changed. \texttt{Conceal()} will now be written as a procedure which will process 100 card numbers each time it is called.
The card numbers will be stored in a 2D array \texttt{CardNumber}. The original string will be stored in column one and the modified string in column two.
Write pseudocode to declare the array.
The new procedure \texttt{Conceal()} will write the modified string to the corresponding element in column two.
The array \texttt{CardNumber} is passed as a parameter to the new procedure \texttt{Conceal()}.
Identify how this parameter should be specified in the new procedure header.
A program uses a stack to hold up to 60 numeric values. The stack is implemented using two integer variables and a 1D array.
The array is declared in pseudocode as shown:
\begin{alltt} DECLARE ThisStack : ARRAY[1:60] OF REAL \end{alltt}
The stack operates as follows:
\begin{itemize} \item Global variable \texttt{SP} acts as a stack pointer that points to the next available stack location. The value of \texttt{SP} represents an array index. \item Global variable \texttt{OnStack} represents the number of values currently on the stack. \item The stack grows upwards from array element index 1. \end{itemize}
Give the initial values that should be assigned to the two variables.
SP \hrulefill OnStack \hrulefill
Explain why it is not necessary to initialise the array elements before the stack is used.
A function to add a value to \texttt{ThisStack} is expressed in pseudocode as shown. The function will return a value to indicate whether the operation was successful or not.
Complete the pseudocode by filling in the gaps.
\begin{alltt} FUNCTION Push(ThisValue : REAL) RETURNS BOOLEAN
DECLARE ReturnValue : BOOLEAN
IF ................................................ THEN
RETURN ................................................ // stack is already full
ENDIF
................................................ <- ThisValue
SP <- ................................................
OnStack <- OnStack + 1
RETURN TRUE
ENDFUNCTION \end{alltt}
A global integer variable \texttt{Tick} is always incremented every millisecond (1000 times per second) regardless of the other programs running.
The value of \texttt{Tick} can be read by any program but the value should not be changed.
Assume that the value of \texttt{Tick} does not overflow.
As an example, the following pseudocode algorithm would output "Goodbye" 40 seconds after outputting "Hello".
\begin{alltt} DECLARE Start : INTEGER
OUTPUT "Hello" Start <- Tick
REPEAT //do nothing UNTIL Tick = Start + 40000
OUTPUT "Goodbye" \end{alltt}
A program is needed to help a user to time an event such as boiling an egg.
The time taken for the event is known as the elapsed time.
The program contains a procedure \texttt{Timer()} which will:
\begin{itemize} \item take two integer values representing an elapsed time in minutes and seconds \item use the value of variable \texttt{Tick} to calculate the elapsed time \item output a warning message 30 seconds before the elapsed time is up \item output a final message when the total time has elapsed. \end{itemize}
For example, to set an alarm for 5 minutes and 45 seconds the program makes the following call:
\begin{alltt} CALL Timer(5, 45) \end{alltt}
When 5 minutes and 15 seconds have elapsed, the program will output:
"30 seconds to go"
When 5 minutes and 45 seconds have elapsed, the program will output:
"The time is up!"
A program contains a global 1D array \texttt{Data} with 100 elements of type \texttt{INTEGER}.
The program contains a function \texttt{Process()} expressed in pseudocode as follows:
\begin{alltt} FUNCTION Process(Number : INTEGER, Label : STRING) RETURNS STRING DECLARE Index, Count : INTEGER DECLARE ReturnValue : STRING
Count <- INT(100 / Number)
Index <- Data[Number]
CASE OF (Index MOD 2)
0 : ReturnValue <- TO_UPPER(RIGHT(Label, Count))
1 : ReturnValue <- "*****"
ENDCASE
RETURN ReturnValue
ENDFUNCTION \end{alltt}
Run-time errors can be generated in different ways. For example, a run-time error will be generated if a function is called with invalid parameters.
The pseudocode contains three statements that could generate a run-time error.
Write the three statements \textbf{and} explain how each could generate a run-time error.
Statement 1 \hrulefill
Explanation \hrulefill
Statement 2 \hrulefill
Explanation \hrulefill
Statement 3 \hrulefill
Explanation \hrulefill
One type of run-time error can cause a program to stop responding ('freezing').
Identify a particular type of programming construct that can generate this type of error \textbf{and} explain why it occurs.
Construct \hrulefill
Explanation \hrulefill
The function \texttt{Process()} contains a selection construct using a \texttt{CASE} structure.
Write pseudocode using a single selection construct with the same functionality \textbf{without} using a \texttt{CASE} structure.
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 follows:
\begin{alltt} DECLARE Filling : ARRAY [1:35] OF STRING \end{alltt}
Each element contains the name of one filling.
An example of the first five elements is as follows:
\begin{tabular}{|c|l|} \hline \textbf{Index} & \textbf{Element value} \ \hline 1 & "Cheese" \ \hline 2 & "Onion" \ \hline 3 & "Salmon" \ \hline 4 & "Anchovies" \ \hline 5 & "Peanut Butter" \ \hline \end{tabular}
\vfill
A second 1D array stores the possible bread used:
\begin{alltt} DECLARE Bread : ARRAY [1:10] OF STRING \end{alltt}
Each element contains the name of one type of bread.
An example of the first three elements is as follows:
\begin{tabular}{|c|l|} \hline \textbf{Index} & \textbf{Element value} \ \hline 1 & "White" \ \hline 2 & "Brown" \ \hline 3 & "Pitta" \ \hline \end{tabular}
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 \texttt{Special()} will output a message giving the 'daily special' sandwich made from \textbf{two} randomly selected different fillings and \textbf{one} randomly selected bread.
Unused array elements must \textbf{not} be used when creating the 'daily special' sandwich.
Using the above examples, the output could be:
\texttt{"The daily special is Cheese and Onion on Brown bread."}
Complete the pseudocode for the procedure \texttt{Special()}.
Assume that both arrays are global.
\begin{alltt} PROCEDURE Special() \end{alltt}
\begin{alltt} ENDPROCEDURE \end{alltt}
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.
A coffee shop runs a computerised loyalty card system.
Customers are issued with a loyalty card with their name together with a unique customer ID.
Loyalty points are added to their card each time they spend money at the shop.
The following information is stored for each customer: ID, name, home address, email address, mobile phone number, date of birth, number of points, date of last visit and amount of money spent at last visit.
A new module will generate a personalised email message to each loyalty card customer who has not visited the coffee shop in the last three months. The message will include a unique voucher code which can be used to authorise a discount if the customer goes to the shop within the next two weeks.
Identify \textbf{three} items of customer information that will be used by the new module \textbf{and} justify your choices.
Item 1 \hrulefill Justification \hrulefill
Item 2 \hrulefill Justification \hrulefill
Item 3 \hrulefill Justification \hrulefill
Identify the computational thinking skill that you needed to use to answer part (a).
It is decided to adopt a formal program development life cycle model for the development of the new module.
The analysis of the new module is complete and the project moves on to the design stage. During this stage all the necessary algorithms and module designs will be defined.
State \textbf{three other} items that will be defined for the new module during the design stage.
- \hrulefill
- \hrulefill
- \hrulefill
Part of the coffee shop program contains three program modules as follows:
\begin{itemize} \item Module \texttt{Init()} has no parameters and returns a Boolean. \item Module \texttt{Reset()} takes a string as a parameter and returns an Integer. \item Module \texttt{Check()} repeatedly calls \texttt{Init()} followed by \texttt{Reset()}. \end{itemize}
Draw a structure chart to represent the relationship between the \textbf{three} modules, including all parameters and return values.
A program is being developed to implement a game for up to six players.
During the game, each player assembles a team of characters. At the start of the game there are 45 characters available.
Each character has four attributes, as follows:
\begin{tabular}{|l|l|l|} \hline \textbf{Attribute} & \textbf{Examples} & \textbf{Comment} \ \hline Player & 0, 1, 3 & The player the character is assigned to. \ \hline Role & Builder, Teacher, Doctor & The job that the character will perform in the game. \ \hline Name & Bill, Lee, Farah, Mo & The name of the character. Several characters may perform the same role, but they will each have a unique name. \ \hline Level & 14, 23, 76 & The skill level of the character. An integer in the range 0 to 100 inclusive. \ \hline \end{tabular}
The programmer has defined a record type to define each character.
The record type definition is shown in pseudocode as follows:
\begin{alltt} TYPE CharacterType DECLARE Player : INTEGER DECLARE Role : STRING DECLARE Name : STRING DECLARE Level : INTEGER ENDTYPE \end{alltt}
The \texttt{Player} field indicates the player to which the character is assigned (1 to 6). The field value is 0 if the character is \textbf{not} assigned to any player.
The programmer has defined a global array to store the character data as follows:
\begin{alltt} DECLARE Character : ARRAY[1:45] OF CharacterType \end{alltt}
At the start of the game all record fields are initialised, and all \texttt{Player} field values are set to 0
The programmer has defined a program module as follows:
\begin{tabular}{|l|l|} \hline \textbf{Module} & \textbf{Description} \ \hline Assign() & \begin{tabular}[c]{@{}l@{}}• called with two parameters:\ \quad (\circ) an integer representing a player\ \quad (\circ) a string representing a character role\ • search the \texttt{Character} array for an unassigned character with the\ \quad required role\ • If found, assign the character to the given player and output a confirmation\ \quad message, for example:\ \quad \texttt{"Bill the Builder has been assigned to player 3"}\ • If no unassigned character with the required role is found, output a suitable\ \quad message.\end{tabular} \ \hline \end{tabular}
Write pseudocode for module \texttt{Assign()}.
A new module will store the contents of the \texttt{Character} array in a text file.
The module is defined as follows:
\begin{tabular}{|l|l|} \hline \textbf{Module} & \textbf{Description} \ \hline \texttt{Save()} & $\bullet$ form a string from each record with fields separated by the character '^{}' \ & $\bullet$ write each string to a separate line of the new file named \texttt{SaveFile.txt} \ \hline \end{tabular}
Complete the pseudocode for module \texttt{Save()}.
\begin{alltt} PROCEDURE Save()
ENDPROCEDURE \end{alltt}
The program is changed and the record type definition is modified as follows:
\begin{alltt} TYPE CharacterType DECLARE Player : INTEGER DECLARE Role : STRING DECLARE Name : STRING DECLARE Level : INTEGER DECLARE Status : BOOLEAN ENDTYPE \end{alltt}
Describe how the additional Boolean field may be stored with the rest of the fields on one line of a text file.
The save operation is to be extended so that multiple files may be saved as the game progresses. This will allow the user to restore the game from any saved position. The filename must reflect the sequence in which the files are saved.
Describe a method that would allow multiple files to be saved \textbf{and} give an example of \textbf{two} consecutive filenames.
Method \hrulefill
Example \hrulefill